<template>
  <div class="page-box" v-loading="Loading.appMainLoading">
    <tablePagination
      :currenButtonData="currenButtonData"
      :tableData="tableData"
      :tableLoading="Loading.tableLoading"
      :tableColumns="tableColumns"
      @rowDrop="rowDrop"
      :totalCount="totalCount"
      :multipleSelection="multipleSelection"
      :MaxResultCount="PageListParams.MaxResultCount"
      @topbutton="topbutton"
      @inlineDialog="inlineDialog"
      @sortChange="sortChange"
      @alertoldSkipCount="alertoldSkipCount"
      @alterResultCount="alterResultCount"
      @handleSelectionChange="handleSelectionChange"
      :currentPageProps="oldSkipCount"
      :quicklySearchOption="quicklySearchOption"
      @quicklySearchClick="quicklySearchClick"
      @quicklySearchClear="quicklySearchClear"
      :primarySearchOption="primarySearchOption"
      @overallSearchFormClick="overallSearchFormClick"
      :httpOverallSearchData="httpOverallSearchData"
    >
    </tablePagination>
    <!-- 执行 -->
    <handelFrom
      :formTitle="formTitle"
      :displayDialog.sync="displayDialog.handleFromDialog"
      :CreateFormData="handleFormData"
      :CreateForm="handleForm"
      :Rules="editRules.handleRule"
      :Options="editOptions"
      :detailsTableColumns="handleDetailsTableColumns"
      @FormSubmit="handleFormSubmit"
    ></handelFrom>
    <!-- 新导入 disabledMethod 导入方式禁用 disabledIsAllowPartImport 是否局部导入禁用-->
    <!-- methodValue 导入方式默认选项  是否局部导入 默认选项  -->
    <importFile
      :loading="Loading.importLoading"
      :show="displayDialog.importDialog"
      :URL="URL"
      :disabledMethod = {method1:false,method2:false,method3:false}
      :disabledIsAllowPartImport = {isAllowPartImport1:false,isAllowPartImport2:false}
      methodValue="0"
      isAllowPartImportValue="1"
      @importClick="postImportMergeClick(arguments)"
      @postImportDown="importDown"
    ></importFile>
    <curren-Drawer
      :title="tableColumns"
      :DrawerLoading="Loading.DrawerLoading"
      :drawer="displayDialog.detailsDialog"
      :propsData="propsData"
      :tabsDesTions="tabsDesTions"
      :Butttondata="[]"
      @drawerShut="(val) => (displayDialog.detailsDialog = val)"
      @drawerbutton="drawerbutton"
      @close-value="closeValue"
      :currenButtonData="currenButtonData"
      :tableColumns="detailsTableColumns"
      :totalCount="totalCountDetails"
      :MaxResultCount="MaxResultCountDetails"
      @alterResultCountDetails="alterResultCountDetails"
      @alertoldSkipCountDetails="alertoldSkipCountDetails"
    ></curren-Drawer>
  </div>
</template>
<script>
import { getDetailed, handle, accept, Invalid  } from "@/api/wms-job"
import { tableMixins } from "@/mixins/TableMixins"
import { LoadingMixins } from "@/mixins/LoadingMixins"
import { drawerMixins } from "@/mixins/drawerMixins"
import { TableHeaderMixins } from "@/mixins/TableHeaderMixins"
import { mixins } from "@/mixins/mixins"
import detailsRules from '@/utils/rules';

export default {
  name: "DeliverJob",
  mixins: [
    tableMixins,
    LoadingMixins,
    drawerMixins,
    TableHeaderMixins,
    mixins,
  ],
  computed: {
    editDialog: {
      get: function () {
        return this.displayDialog.newDialog || this.displayDialog.editDialog;
      },
    },
    hideButton: function () {
      return function (val) {
        let data = true
        val.forEach(key => {
          if (this.propsData.jobStatus == key) {
            data = false
          }
        })
        return data
      }
    },
  },
  data () {
    return {
      URL: 'wms/job/deliver-job',
      //常用按钮数据
      currenButtonData: [
        this.defaultFieldSettingBtn(),//字段设置
        this.defaultFreshBtn(),//刷新
        this.defaultFilterBtn(),//筛选
      ],
      DrawerButtonData: [
        {
          type: 'primary',
          icon: 'el-icon-circle-check',
          label: '承接',
          name: "accept",
          hide: () => { return this.hideButton([1]) },
          size: 'mini'
        },
        {
          type: 'warning',
          icon: 'el-icon-circle-check',
          label: '执行',
          name: "handle",
          hide: () => { return this.hideButton([2]) },
          size: 'mini'
        },
         {
          type: 'danger',
          icon: 'el-icon-delete-solid',
          label: '作废',
          name: "invalid",
          hide: () => { return this.hideButton([1,2]) },
          size: 'mini'
        }
      ],
      handleDetailsTableColumns: [
        {
          label: "实际箱标签",
          prop: "handledPackingCode",
        },
        { label: "物品代码", prop: "itemCode", },
        { type: "objectInput", valueType: Number, label: "实际数量", rules: detailsRules.numberInput, prop: "handledQty", showProp: "qty", },
        { type: "objectInput", label: "实际单位", prop: "handledQty", showProp: "uom", },
        { type: "object", label: "推荐数量", prop: "recomendQty", showProp: "qty", },
        { type: "object", label: "推荐单位", prop: "recomendQty", showProp: "uom", },
        { type: "input", rules: detailsRules.detailsRules, label: "实际库位", prop: "handledLocationCode", },
        { label: "推荐库位", prop: "recommendLocationCode", },
        { type: "objectInput", label: "实际批次", rules: detailsRules.detailsRules, prop: "handledBatch", showProp: "supplierBatch", },
        { type: "objectDateTimeInput", label: "实际日期", prop: "handledBatch", showProp: "produceDate", },
        { type: "object", label: "推荐批次", prop: "recommendBatch", showProp: "supplierBatch", },
        { type: "object", label: "推荐日期", prop: "recommendBatch", showProp: "produceDate", },
        { label: "物品名称",  prop: "itemName" },
        { label: "包装数量", prop: "stdPackQty", },
        { label: "包装单位", prop: "stdPackUom", },
        { label: "备注", prop: 'remark', },
      ],
      editOptions: {},
      handleFormData: {
        "id": "",
        "creationTime": "",
        "lastModificationTime": "",
        "remark": "",
        "concurrencyStamp": "",
        "company": "",
        "number": "",
        "upStreamJobNumber": "",
        "deliverRequestNumber": "",
        "jobType": 1,
        "jobStatus": 1,
        "priority": 0,
        "priorityIncrement": 0,
        "wlgCode": "123",
        "isAutoComplete": true,
        "details": [],
        "acceptTime": "",
        "completeTime": "",
        "customer": ""
      },
      childTableData: [
        {
          "lastModificationTime": "",
          "masterID": "",
          "packingCode": "",
          "containerCode": "",
          "item": {
            "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
            "name": "",
            "desc1": "",
            "desc2": ""
          },
          "itemCode": "",
          "stdPack": {
            "packUom": "string",
            "packQty": 0
          },
          "recommendBatch": {
            "supplierBatch": "",
            "produceDate": ""
          },
          "recommendLot": "",
          "recommendLocationCode": "",
          "recomendQty": {
            "uom": "string",
            "qty": 0
          },
          "handledBatch": {
            "supplierBatch": "",
            "produceDate": ""
          },
          "handledLot": "",
          "handledLocationCode": "",
          "handledQty": {
            "uom": "string",
            "qty": 0
          },
          "fromLocation": "",
          "expiredTime": ""
        }
      ],
      handleForm: [
        { type: "input", label: "任务编号", prop: "number", colSpan: 12, disabled: "true" },
        { type: "select", label: "任务类型", prop: "jobType", options: "taskType", colSpan: 12, disabled: "true" },
        { type: "select", label: "任务状态", prop: "jobStatus", options: "jobStatus", colSpan: 12, disabled: "true" },
        { type: "input", label: "优先级", prop: "priority", colSpan: 12, disabled: "true" },
        { type: "input", label: "工作组", prop: "wlgCode", colSpan: 12, disabled: "true" },
        { type: "dateTime", label: "接收时间", prop: "acceptTime", colSpan: 12, },
        { type: "input", label: "备注", prop: "remark", colSpan: 12, },
      ],
      editRules: {
        handleRule: {
          number: [
            { required: true, trigger: "blur", message: "不可为空" },
          ],
          jobType: [{ required: true, trigger: "blur", message: "不可为空" }],
          jobStatus: [{ required: true, trigger: "blur", message: "不可为空" }],
          priority: [{ required: true, trigger: "blur", message: "不可为空" }],
          wlgCode: [{ required: true, trigger: "blur", message: "不可为空" }],
        }
      },
    };
  },
  mounted () {
    this.paging();
  },
  methods: {
    //抽屉常用按钮
    drawerbutton (val) {
      if (val == 'accept') {
        let data = {
          id: this.propsData.id
        }
        this.Loading.appMainLoading = true
        accept(this.URL, data).then(res => {
          this.$successMsg('已承接任务！')
          this.Loading.appMainLoading = false
          getDetailed(this.propsData.id, this.URL).then(res => {
            this.propsData = res
            // this.displayDialog.detailsDialog = true;
          })
          this.paging();
        }).catch(err => {
          this.Loading.appMainLoading = false
        })
      } else if (val == 'handle') {
        this.Loading.appMainLoading = true
        let propsData = JSON.parse(JSON.stringify(this.propsData));
        this.$listAssign(this.handleFormData, propsData)
        this.handleFormData.details = []
        propsData.details.forEach(item => {
          let data = JSON.parse(JSON.stringify(...this.childTableData))
          this.$listAssign(data, item)
          this.handleFormData.details.push(data)
        })
        this.Loading.appMainLoading = false
        this.formTitle = "执行" + this.$route.meta.title;
        this.displayDialog.handleFromDialog = true
      }else if(val == 'invalid'){
        let data = {
          id: this.propsData.id
        }
        this.Loading.appMainLoading = true
        Invalid(this.URL, data).then(res=>{
           this.displayDialog.detailsDialog = false
           this.$successMsg('已作废任务！')
           this.paging()
           this.Loading.appMainLoading = false
        }).catch(err=>{
           this.Loading.appMainLoading = false
        })
      }
    },
    handleFormSubmit (val) {
      return new Promise((resolve, reject) => {
        let data = {
          id: this.propsData.id
        }
        handle(this.handleFormData, data, this.URL).then(res => {
          this.displayDialog.handleFromDialog = false;
          this.$successMsg('已生成上架记录！')
          getDetailed(this.propsData.id, this.URL).then(res => {
            this.propsData = res
            // this.displayDialog.detailsDialog = true;
          })
          this.paging()
          this.FormRemove(val)
          resolve()
        }).catch(err => {
          reject();
        })
      })
    },
  }
};
</script>
<style lang="scss" scoped>
@import "../../../styles/mainbasicData.scss";
</style>