<template>
  <div>
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-form
          :inline="true"
          class="demo-form-inline"
          label-position="right"
          label-width="90px"
          label-suffix=":"
        >
          <el-form-item label="单据编号">
            <el-input
              v-model="query.bill_code"
              clearable
              size="mini"
              style="width: 185px;"
              placeholder="单据编号"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <el-form-item label="单据状态">
            <el-select
              v-model="query.bill_status"
              clearable
              filterable
              size="mini"
              class="filter-item"
              style="width: 185px;"
              @change="crud.toQuery"
            >
              <el-option
                v-for="item in dict.st_bill_status"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="入库时间">
            <el-date-picker
              v-model="query.createTime"
              type="daterange"
              value-format="yyyy-MM-dd HH:mm:ss"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
              @change="crud.toQuery"
            />
          </el-form-item>
          <rrOperation :crud="crud" />
        </el-form>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
          <el-form-item label="单据编号" prop="bill_code">
            <el-input v-model="form.bill_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="出入类型" prop="io_type">
            <el-input v-model="form.io_type" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="批次">
            <el-input v-model="form.pcsn" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="载具编码">
            <el-input v-model="form.vehicle_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="数量">
            <el-input v-model="form.qty" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单据状态" prop="bill_status">
            <el-input v-model="form.bill_status" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="起始点位编码">
            <el-input v-model="form.start_point_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="终点点位编码">
            <el-input v-model="form.end_point_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="起始区域">
            <el-input v-model="form.start_region_id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="终点区域">
            <el-input v-model="form.end_region_id" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <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 prop="bill_code" label="单据编号" min-width="150" />
        <el-table-column prop="io_type" label="出入类型">
          <template slot-scope="scope">
            {{ dict.label.io_type[scope.row.io_type] }}
          </template>
        </el-table-column>
        <el-table-column prop="pcsn" label="批次" />
        <el-table-column prop="vehicle_code" label="载具编码" show-overflow-tooltip />
        <el-table-column prop="qty" label="数量" :formatter="crud.formatNum3" />
        <el-table-column prop="bill_status" label="单据状态">
          <template slot-scope="scope">
            {{ dict.label.st_bill_status[scope.row.bill_status] }}
          </template>
        </el-table-column>
        <el-table-column prop="start_point_code" label="起点" min-width="120" />
        <el-table-column prop="end_point_code" label="终点" min-width="120" />
        <!--        <el-table-column prop="start_region_id" label="起始区域" />-->
        <!--        <el-table-column prop="end_region_id" label="终点区域" />-->
        <el-table-column prop="remark" label="备注" />
        <el-table-column prop="update_optname" label="修改人" min-width="100" />
        <el-table-column prop="update_time" label="修改时间" min-width="140" />
        <el-table-column v-permission="[]" label="操作" width="120px" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudBill from '@/views/wms/st/regionio'
import CRUD, { crud, form, header, presenter } 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'

const defaultForm = { iostorinv_id: null, bill_code: null, io_type: null, material_id: null, pcsn: null, vehicle_code: null, qty: null, qty_unit_id: null, bill_status: null, start_point_code: null, end_point_code: null, start_region_id: null, end_region_id: null, cust_id: null, create_mode: null, task_id: null, remark: null, create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null, confirm_optid: null, confirm_optname: null, confirm_time: null, is_delete: null }
export default {
  name: 'CppInRegion',
  components: { pagination, crudOperation, rrOperation, udOperation },
  dicts: ['io_type', 'st_bill_status'],
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '养生区入库管理',
      url: 'api/regionio',
      idField: 'qty_unit_id',
      sort: 'qty_unit_id,desc',
      query: {
        io_type: '1',
        io_region: "'CPQYA01'"
      },
      crudMethod: { ...crudBill }
    })
  },
  data() {
    return {
      permission: {
      },
      rules: {
        bill_code: [
          { required: true, message: '单据编号不能为空', trigger: 'blur' }
        ],
        io_type: [
          { required: true, message: '出入类型不能为空', trigger: 'blur' }
        ],
        bill_status: [
          { required: true, message: '单据状态不能为空', trigger: 'blur' }
        ]
      }}
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
