<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <el-select v-model="query.areaCode"  value-key="id" filterable placeholder="库区" style="width: 185px;" class="filter-item"  @keyup.enter.native="crud.toQuery" clearable>
        <el-option
          v-for="item in areaOptions"
          :key="item.id"
          :label="item.name"
          :value="item.code"
        />
      </el-select>
      <el-input v-model="query.relatedBill" clearable placeholder="单号" style="width: 120px;" class="filter-item"
                @keyup.enter.native="crud.toQuery"/>
      <el-input v-model="query.itemCode" clearable placeholder="品番" style="width: 120px;" class="filter-item"
                @keyup.enter.native="crud.toQuery"/>
      <el-input v-model="query.itemName" clearable placeholder="品名" style="width: 120px;" class="filter-item"
                @keyup.enter.native="crud.toQuery"/>
      <el-select v-model="query.logType" clearable placeholder="操作类型"  style="width: 120px;" 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="增加/减少" style="width: 100px;" 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: 120px;" 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" border :height="crud.tableHeight">
        <el-table-column type="selection" width="55"/>
        <el-table-column prop="id" label="序号"  align="center"/>
        <el-table-column prop="area.name" label="库区"  width="150px" align="center">
        </el-table-column>
        <el-table-column prop="itemKey.item.code" label="品番" width="100">
        </el-table-column>
        <el-table-column prop="itemKey.item.name" label="品番名称" width="120">
        </el-table-column>
<!--        <el-table-column :show-overflow-tooltip="true" prop="itemName" label="批次号">-->
<!--          <template slot-scope="scope">-->
<!--            <div>{{ scope.row.itemKey.propC1 }}</div>-->
<!--          </template>-->
<!--        </el-table-column>-->
        <el-table-column prop="inv_log_type#logType" label="操作类型">
          <template slot-scope="scope">
            {{ dict.label.inv_log_type[scope.row.logType] }}
          </template>
        </el-table-column>
        <el-table-column prop="inc_dec#incDec" label="增加/减少">
          <template slot-scope="scope">
            {{ dict.label.inc_dec[scope.row.incDec] }}
          </template>
        </el-table-column>
        <el-table-column prop="itemKey.propC1" label="批次号"  width="100"/>
        <el-table-column prop="srcPointCode" label="源库位" width="80px" align="center"/>
<!--        <el-table-column prop="srcStockCode" label="源容器号"/>-->
        <el-table-column prop="dstPointCode" label="目标库位" width="80px" align="center"/>
        <el-table-column prop="zckw.code" label="暂存库位" width="80px" align="center">
        </el-table-column>
        <el-table-column prop="zzkw.code" label="制造库位" width="80px" align="center">
        </el-table-column>
        <el-table-column prop="srcQty" label="源数量"  width="80px"/>
        <el-table-column prop="dstQty" label="目标数量"  width="80px"/>
<!--        发生数量-->
        <el-table-column prop="occurQuantity" label="发生数量"  width="80px"/>
        <el-table-column prop="relatedBill" label="关联单号" width="120px"/>
        <el-table-column prop="srcStockCode" label="条码"/>
<!--        发生日期-->
        <el-table-column prop="occurTime" label="发生日期" width="150px" align="center"/>
        <el-table-column prop="description" label="描述"/>
        <el-table-column prop="createBy" label="创建人"/>
      </el-table>
      <!--分页组件-->
      <div style="float: right;">
        <pagination/>
      </div>
    </div>
  </div>
</template>

<script>
import crudInventoryLog from '@/api/inventoryLog'
import CRUD, {presenter, header, form, crud} from '@crud/crud'
import rrOperation from '@crud/RR.operation.vue'
import crudOperation from '@crud/CRUD.operation.vue'
import udOperation from '@crud/UD.operation.vue'
import pagination from '@crud/Pagination.vue'
import crudTask from "@/api/task";
import DateRangePicker from "@/components/DateRangePicker/index.vue";
import {getItemsList} from "@/api/item";
import { formatDate } from '@/utils/commonUtils'
import {getAreas} from "@/api/area";

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,
  zckw:null,
  zzkw:null,
  area: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: [],
      areaOptions: []
    }
  },
  mounted() {
    //初始化数据
    this.itemDataGet();
    this.getAreaOptionsAll();
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    //物料数据
    itemDataGet() {
      getItemsList().then(res => {
        this.itemListData = res;
      }).catch(e => {
        this.$message({
          showClose: true,
          message: '物料加载失败',
          type: 'error'
        });
      })
    },
    //获取库区数据
    getAreaOptionsAll() {
      getAreas().then(res => {
        this.areaOptions = res
      })
    },
    //日期格式化
    getFormatDate(data){
      return  formatDate(data);
    },
  }
}
</script>

<style scoped>

</style>
