<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-form
          :inline="true"
          size="mini"
          class="demo-form-inline"
          label-position="right"
          label-width="80px"
          label-suffix=":"
        >
          <el-form-item label="物料编码">
            <el-input
              v-model="query.material_code"
              clearable
              size="mini"
              placeholder="请输入物料编码"
              style="width: 210px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="批次">
            <el-input
              v-model="query.pcsn"
              clearable
              size="mini"
              placeholder="请输入批次"
              style="width: 210px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>

          <el-form-item label="日期">
            <date-range-picker v-model="query.createTime" class="date-item" />
          </el-form-item>

          <el-form-item label="品质类型">
            <el-select
              v-model="query.status"
              clearable
              size="mini"
              placeholder="请选择"
              class="filter-item"
              style="width: 210px;"
              @change="hand"
            >
              <el-option
                v-for="item in this.qualitylist"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="是否可用">
            <el-select
              v-model="query.available"
              clearable
              size="mini"
              placeholder="请选择"
              class="filter-item"
              style="width: 210px;"
              @change="hand"
            >
              <el-option
                v-for="item in dict.is_usable"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="站点">
            <el-select
              v-model="form.agvaddr"
              clearable
              size="mini"
              placeholder="请选择"
              class="filter-item"
              style="width: 210px;"
            >
              <el-option
                v-for="item in ponitList"
                :label="item.name"
                :value="item.code"
              />
            </el-select>
          </el-form-item>
          <rrOperation />
        </el-form>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission">
        <el-button
          slot="right"
          class="filter-item"
          type="primary"
          size="mini"
          :disabled="crud.selections.length !== 1"
          @click="outLk"
        >
          立库出库
        </el-button>
      </crudOperation>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="mini" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column show-overflow-tooltip prop="pallet_code" label="托盘" width="120px">
          <template slot-scope="scope">
            <el-link type="warning" @click="queryDtl(scope.row)">{{ scope.row.pallet_code }}</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="material_code" label="物料编码" />
        <el-table-column prop="material_name" label="物料名称" />
        <el-table-column prop="pcsn" label="批号" />
        <el-table-column prop="weight" label="重量" :formatter="crud.formatNum3"/>
        <el-table-column prop="status" label="品质类型" :formatter="formatStatus"/>
        <el-table-column prop="available" label="是否可用" :formatter="formatIsUsable"/>
        <el-table-column prop="inputtime" label="入库时间" />
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
    <QueryDtlDialog :dialog-show.sync="queryDtlShow" :open-param="openParam" />
  </div>
</template>

<script>
import crudLibraryquery from '@/api/wms/lk/libraryquery'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker'
import QueryDtlDialog from '@/views/wms/lk/libraryquery/QueryDtlDialog'

const defaultForm = { agvaddr: null }
export default {
  name: 'Libraryquery',
  dicts: ['is_usable', 'ST_QUALITY_SCODE'],
  components: { QueryDtlDialog, pagination, crudOperation, rrOperation, udOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '立库库存查询',
      url: 'api/libraryquery',
      idField: '',
      sort: 'desc',
      crudMethod: { ...crudLibraryquery },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: false,
        reset: true
      }
    })
  },
  data() {
    return {
      permission: {
      },
      openParam: null,
      queryDtlShow: false,
      ponitList: [],
      qualitylist: [
        { 'label': '合格', 'value': '01' },
        { 'label': '不合格', 'value': '02' }
      ],
      rules: {
      }}
  },
  created() {
    crudLibraryquery.getPoint().then(res => {
      this.ponitList = res
    })
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    hand(value) {
      this.crud.toQuery()
    },
    outLk() {
      if (!this.form.agvaddr) {
        this.crud.notify('站点不能为空', CRUD.NOTIFICATION_TYPE.INFO)
        return false
      }
      const _selectData = this.$refs.table.selection
      crudLibraryquery.outLk({ 'data': _selectData[0], 'agvaddr': this.form.agvaddr }).then(res => {
        this.crud.notify('操作成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
        this.crud.toQuery()
      })
    },
    queryDtl(row) {
      this.openParam = row
      this.queryDtlShow = true
    },
    formatIsUsable(row, column) {
      return this.dict.label.is_usable[row.available]
    },
    formatStatus(row, column) {
      return this.dict.label.ST_QUALITY_SCODE[row.status]
    }
  }
}
</script>

<style scoped>

</style>
