<template>
  <div>
    <p-card title="供包任务记录">
      <template slot="extra">
        <a-space>
          <!-- <p-button class="btn" type="primary" @click="showmodel">导出</p-button> -->
        </a-space>
      </template>

      <p-grid-form :label-col="{ span: 8 }" :span="8" :items="config.items" @submit="hanlderSubmit" />
      <p-table
        ref="table"
        row-key="id"
        bordered
        :columns="config.columns"
        :remoteUrl="config.remoteUrl"
        :remoteData="remoteData"
        :doneBefore="doneBefore"
        @selectChange="selectChange"
        :rowSelectType="2"
        :data-source="data"
        :scroll="{ x: true }"
      >
        <template slot="operation" slot-scope="text, record">
          <!-- {{ text ? '禁用' : '启用' }} -->
          <a @click="allotmentTaskRecordSaveFun(text)">重新推送</a>
          <a-divider type="vertical" />
          <a v-if="text.code" @click="showmodel(text)">条码集合</a>
        </template>
      </p-table>
    </p-card>

    <p-modal title="供包条码集合" width="90%" :visible="visible" :confirm-loading="confirmLoading" @ok="handleOk" @cancel="handleCancel">
      <p-table ref="table" row-key="id" bordered :columns="config.columns1" :pagination="false" :autoLoad="false" :rowSelectType="false" :data-source.sync="data1" :scroll="{ x: true }"> </p-table>
    </p-modal>
  </div>
</template>

<script>
import config from "./config.js";
import { diffOption } from "@/views/kzyWMS/utils/index.js";
import { allotmentTaskRecordSave, allotmentTaskRecordDetail } from "./api";

export default {
  data() {
    return {
      config: config(this),
      data: [{ id: 1 }],
      data1: [],
      confirmLoading: false,
      type: true,
      remoteData: {},
      detailInfo: {},
      visible: false,

      selectedRows: [],
    };
  },
  mounted() {
    // this.getinfo()
    // id
  },
  created() {
    diffOption(this.config.columns).then((res) => {
      this.config.columns = res;
    });
  },
  methods: {
    async allotmentTaskRecordSaveFun(value) {
      let { id } = value;
      let that = this;
      this.$confirm({
        title: "确定是否要重新推送吗?",
        content: "",
        async onOk() {
          try {
            let res = await allotmentTaskRecordSave({ id });
            if (res.success) {
              that.$message.success(res.message);
              that.remoteData = { ...that.remoteData };
            } else {
              that.$exception(res);
            }
          } catch (error) {
            that.$exception(error);
          }
        },
        onCancel() {},
      });


    },
    selectChange(selectedRowKeys, selectedRows) {
      this.selectedRows = selectedRows;
    },

    //点击弹出
    async showmodel(data) {
      // console.log(data)
      let { id } = data;
      try {
        let res = await allotmentTaskRecordDetail({ id });
        if (res.success) {
          this.visible = true;
          this.data1 = res.data;
        } else {
          this.$exception(res);
        }
      } catch (error) {
        this.$exception(error);
      }
    },

    //取消调度任务

    doneBefore(res) {
      // console.log(res)
      return res;
    },
    hanlderSubmit(e, form) {
      e.preventDefault();
      form.validateFields((error, values) => {
        // console.log(error, values, 'valuesvaluesvaluesvaluesvalues')
        // this.queryName = values.name
        // this.queryType = values.type
        // this.getlistCompanyByAuthId()
        if (!error) {
          this.remoteData = { ...this.remoteData, ...values };
        }
      });
    },
    handleOk(e) {
      this.$refs.model.form.validateFields(async (err, value) => {
        if (!err) {
          this.confirmLoading = true;

          let res = await updateOutboundTaskPriority(value);
          // console.log(res)
          if (res.success) {
            this.visible = false;
            this.remoteData = { ...this.remoteData };
          } else {
            this.$exception(res);
          }

          this.confirmLoading = false;
          //
        }
      });
    },
    handleCancel(e) {
      // console.log('Clicked cancel button')
      this.visible = false;
      this.visibleDetails = false;
      this.visiblepriority = false;
    },
  },
};
</script>

<style lang="less" scoped></style>
