<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
<!--      <el-input v-model="query.itemCode" clearable placeholder="物料代码" style="width: 140px;" class="filter-item"-->
<!--                @keyup.enter.native="crud.toQuery"/>-->
      <el-select v-model="query.itemCode" placeholder="物料代码" style="width: 140px;" class="filter-item">
        <el-option
          @keyup.enter.native="crud.toQuery"
          v-for="item in this.itemListData"
          :key="item.code"
          :label="item.code"
          :value="item.code">
          <span style="float: left">{{ item.code }}</span>
          <span style="float: right; color: #8492a6; font-size: 13px">{{ item.name }}</span>
        </el-option>
      </el-select>
      <el-input v-model="query.itemName" clearable placeholder="物料名称" style="width: 140px;" class="filter-item"
                @keyup.enter.native="crud.toQuery"/>
      <el-select v-model="query.logType" clearable placeholder="操作类型" class="filter-item"
                 @keyup.enter.native="crud.toQuery">
        <el-option
          v-for="logtype in dict.inv_log_type"
          :key="logtype.id"
          :label="logtype.label"
          :value="logtype.value"
          @change="crud.toQuery"
        />
      </el-select>
      <el-select v-model="query.incDec" clearable placeholder="增加/减少" class="filter-item"
                 @keyup.enter.native="crud.toQuery">
        <el-option
          v-for="incdec in dict.inc_dec"
          :key="incdec.id"
          :label="incdec.label"
          :value="incdec.value"
          @change="crud.toQuery"
        />
      </el-select>
      <el-input v-model="query.propC1" clearable placeholder="请输入批次号" style="width: 140px;" class="filter-item"
                @keyup.enter.native="crud.toQuery"/>
      <date-range-picker v-model="query.createTime" class="date-item" style="width: 100px"/>
      <rrOperation :crud="crud"/>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" :tableKey="this.$options.name"/>
      <!--表单组件-->
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
        height="70vh"
      >
        <el-table-column type="selection" width="55"/>
        <el-table-column prop="logType" label="操作类型">
          <template slot-scope="scope">
            {{ dict.label.inv_log_type[scope.row.logType] }}
          </template>
        </el-table-column>
        <el-table-column prop="incDec" label="增加/减少">
          <template slot-scope="scope">
            {{ dict.label.inc_dec[scope.row.incDec] }}
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="itemCode" label="物料编码">
          <template slot-scope="scope">
            <div>{{ scope.row.itemKey.item.code }}</div>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="itemName" label="物料名称">
          <template slot-scope="scope">
            <div>{{ scope.row.itemKey.item.name }}</div>
          </template>
        </el-table-column>
        <el-table-column :show-overflow-tooltip="true" prop="propC1" label="批次号">
          <template slot-scope="scope">
            <div>{{ scope.row.itemKey.propC1 }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="srcPointCode" label="原点位号" width="150"/>
        <el-table-column prop="dstPointCode" label="目标点位号" width="150"/>
        <el-table-column prop="srcStockCode" label="原容器号"/>
        <el-table-column prop="dstStockCode" label="目标容器号"/>
        <el-table-column prop="occurQuantity" label="发生数量"/>
        <el-table-column prop="occurTime" label="发生时间" width="150"/>
        <el-table-column prop="description" label="描述"/>
      </el-table>
      <!--分页组件-->
      <div style="float: right;">
        <pagination/>
      </div>
    </div>
  </div>
</template>

<script>
import crudInventoryLog from '@/api/inventoryLog'
import crudItem from "@/api/item";
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 crudTask from "@/api/task";
import DateRangePicker from "@/components/DateRangePicker/index.vue";


const defaultForm = {
  id: null,
  logType: null,
  incDec: null,
  relatedBill: null,
  itemKeyId: null,
  soi: null,
  occurQuantity: null,
  occurTime: null,
  status: null,
  refObj: null,
  refObjId: null,
  description: null,
  deptId: null,
  createBy: null,
  updateBy: null,
  createTime: null,
  updateTime: null,
  srcPointId: null,
  srcPointCode: null,
  srcStockId: null,
  srcStockCode: null,
  dstPointId: null,
  dstPointCode: null,
  dstStockId: null,
  dstStockCode: null,
  srcQty: null,
  dstQty: null
}
export default {
  name: 'InventoryLog',
  components: {DateRangePicker, pagination, crudOperation, rrOperation, udOperation},
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['inv_log_type', 'inc_dec'],
  cruds() {
    return CRUD({
        title: 'inventoryLog', url: 'api/inventoryLog', idField: 'id', sort: 'id,desc', crudMethod: {...crudInventoryLog},
        optShow: {
          add: false,
          edit: false,
          del: false,
          reset: true,
          download: true
        },
        queryOnPresenterCreated: true,
      }
    )
  },
  data() {
    return {
      permission: {
        add: ['admin', 'inventoryLog:add'],
        edit: ['admin', 'inventoryLog:edit'],
        del: ['admin', 'inventoryLog:del']
      },
      rules: {
        logType: [
          {required: true, message: '操作类型不能为空', trigger: 'blur'}
        ],
        incDec: [
          {required: true, message: '增加/减少不能为空', trigger: 'blur'}
        ]
      },
      itemListData: []
    }
  },
  mounted() {
    //初始化数据
    this.itemDataGet();
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    //物料数据
    itemDataGet() {
      crudItem.queryItemAll({}).then(res => {
        this.itemListData = res;
      }).catch(e => {
        this.crud.notify('物料加载失败！', CRUD.NOTIFICATION_TYPE.ERROR);
      })
    }
  }
}
</script>

<style scoped>

</style>
