<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--      查询操作-->
      <el-form ref="form" :inline="true" :model="form" label-width="70px">
        <el-select v-model="query.rkAreaCode"  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-form-item label="品番">
          <el-input v-model="query.itemCode" clearable placeholder="请输入部品品番" style="width: 140px;"
                    class="filter-item"
                    @keyup.enter.native="crud.toQuery"/>
        </el-form-item>

        <el-form-item label="品名">
          <el-input v-model="query.itemName" clearable placeholder="请输入部品品名" style="width: 140px;"
                    class="filter-item"
                    @keyup.enter.native="crud.toQuery"/>
        </el-form-item>
        <el-form-item label="纯需求不足数>=" label-width="120px">
          <el-input v-model="query.pureXqBz" clearable placeholder="请输入数值" style="width: 140px;"
                    class="filter-item"
                    @keyup.enter.native="crud.toQuery"/>
        </el-form-item>
        <!--        搜索-->
        <rrOperation :crud="crud"/>
        <!--        重置-->
        <el-button class="filter-item" size="mini" type="warning" icon="el-icon-refresh-left" @click="resetQuery">重置
        </el-button>
      </el-form>
      <!--      业务操作-->
      <crudOperation :permission="permission" :tableKey="this.$options.name">

      </crudOperation>
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small"
                style="width: 100%;"
                height="58vh"
                @selection-change="selectionChangeHandlerTwo" border>
        <el-table-column type="selection" width="50"/>
        <el-table-column prop="id" width="100" label="ID"/>
        <el-table-column width="160px" prop="pickTicket.shArea.name" label="入库库区" align="center">
          <template slot-scope="scope">
            {{ scope.row.pickTicket.shArea.name }}
          </template>
        </el-table-column>
        <el-table-column prop="pickTicket.code" width="120" label="备货单号"/>
        <el-table-column width="160px" prop="pickTicket.area.name" label="出库库区" align="center">
          <template slot-scope="scope">
            {{ scope.row.pickTicket.area.name }}
          </template>
        </el-table-column>
        <el-table-column prop="pick_status#pickTicket.status" label="状态" align="center">
          <template slot-scope="scope">
            {{ dict.label.pick_status[scope.row.pickTicket.status] }}
          </template>
        </el-table-column>
        <el-table-column width="100px" prop="pickTicket.orderDate" label="订单日期" align="center">
          <template slot-scope="scope">
            {{ getFormatDate(scope.row.pickTicket.orderDate) }}
          </template>
        </el-table-column>
        <el-table-column prop="item.code" label="品番" width="100px"/>
        <el-table-column prop="item.name" label="品名" width="120px"/>
        <el-table-column prop="supplier" label="供应商" width="150px"/>
        <el-table-column :show-overflow-tooltip="true" prop="item.unit" label="单位">
          <template slot-scope="scope">
            <div>{{ scope.row.item == null ? '' : scope.row.item.unit }}</div>
          </template>
        </el-table-column>
        <!--需求数量-->
        <el-table-column prop="xqQty" label="需求数" width="60px"/>
        <el-table-column prop="item.extendD3" label="收容数" width="60px" align="center"/>
        <!--纯需求-->
        <el-table-column prop="propC4" label="纯需求数" width="80px"/>
        <!--纯需求-->
        <el-table-column prop="pureXqBz" label="纯需求不足" width="90px"/>
        <!--纯需求数量-->
        <el-table-column prop="orderQty" label="备货需求数" width="90px"/>
        <!--未单数量  未出单=纯需求-出单数-->
        <el-table-column prop="wcdn" label="未单数" width="60px">
          <template slot-scope="scope">
            {{ scope.row.orderQty - scope.row.allocatedQty }}
          </template>
        </el-table-column>
        <!--出单数量 分配 出单数=分配时候写入的数量-->
        <el-table-column prop="allocatedQty" label="出单数" width="60px"/>
        <!--备货数量 拣货-->
        <el-table-column prop="pickedQty" label="备货数" width="60px"/>
        <!--在途数量 发运-->
        <el-table-column prop="shippedQty" label="在途数" width="60px"/>
        <!--线边数量-->
        <el-table-column prop="xbQty" label="线边数" width="60px"/>
        <el-table-column prop="contents" label="加工内容" width="70px"/>
        <el-table-column prop="ac" label="a/c" width="70px"/>
        <!--制造库位 点位-->
        <el-table-column prop="point.code" label="制造库位" width="100px"/>
        <el-table-column :show-overflow-tooltip="true" prop="remark" label="备注">
          <template slot-scope="scope">
            <div>{{ scope.row.remark }}</div>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <div style="float: right;">
        <pagination/>
      </div>
    </div>
  </div>
</template>

<script>
import crudPickDetail from '@/api/pickDetail'
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 {getItems, getItemsList} from "@/api/item"
import PickTask from "@/views/business-pick/pickDetail/pickTicketTask.vue"
import DateRangePicker from "@/components/DateRangePicker/index.vue";
import { formatDate } from '@/utils/commonUtils'
import {getAreas} from "@/api/area";

const defaultForm = {
  id: null,
  pickId: null,
  item: null,
  lineNo: null,
  po: null,
  status: 'OPEN',
  orderQty: 0,
  allocatedQty: 0,
  pickedQty: 0,
  shippedQty: 0,
  weight: 0,
  volume: 0,
  remark: null,
  propC1: null,
  propC2: null,
  propC3: null,
  propC4: null,
  propC5: null,
  propC6: null,
  propD1: null,
  propD2: null,
  deptId: null,
  sourceName: null,
  sourceId: null,
  createBy: null,
  updateBy: null,
  createTime: null,
  updateTime: null
}
export default {
  name: 'ViewPickDetailInfo',
  components: {DateRangePicker, PickTask, pagination, crudOperation, rrOperation, udOperation},
  mixins: [presenter(), header(), form(defaultForm), crud()],
  dicts: ['pick_status'],
  cruds() {
    return CRUD({
      title: '出库明细',
      url: 'api/pickDetail',
      idField: 'id',
      sort: 'id,desc',
      crudMethod: {...crudPickDetail},
      optShow: {
        add: false,
        edit: false,
        del: false,
        reset: false,
        download: true
      },
      queryOnPresenterCreated: true
    })
  },
  data() {
    return {
      items: [],
      permission: {
        add: ['admin', 'pickDetail:add'],
        edit: ['admin', 'pickDetail:edit'],
        del: ['admin', 'pickDetail:del']
      },
      itemListData: [],
      areaOptions: []
    }

  },
  mounted() {
    //初始化数据
    this.getItem();
    this.getAreaOptionsAll();
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    getItem() {
      getItems({}).then(res => {
        this.items = res.content.map(function (obj) {
          if (obj.hasChildren) {
            obj.children = null
          }
          return obj
        })
      })
    },
    //获取库区数据
    getAreaOptionsAll() {
      getAreas().then(res => {
        this.areaOptions = res
      })
    },
    shuaxin() {
      this.crud.toQuery();
    },
    resetQuery() {
      this.radio3 = '全部';
      this.crud.resetQuery()
    },
    //日期格式化
    getFormatDate(data){
      return  formatDate(data);
    },
  }
}
</script>

<style scoped>

</style>
