<template>
  <div>
    <!-- 立库合拖开票 -->
    <p-card title="立库合拖开票">
      <span slot="extra">
        <p-button type="primary" style="margin-right: 10px" @click="saveStereo">合托</p-button>
      </span>
      <p-grid-form ref="gridform" :span="8" :items="config.items" @submit="hanlderSubmit" />
      <p-table
        ref="table"
        row-key="id"
        bordered
        :autoLoad="false"
        :columns="config.columns"
        :remoteUrl="config.remoteUrl"
        :remoteParams="remoteParams"
        :selectedRowKeys.sync="selectedRowKeys"
        @selectChange="selectChange"
        :rowSelectType="2"
        :data-source="data"
        :scroll="{ x: true }"
      >
        <template slot="operation" slot-scope="text, record">
          <!-- {{ text ? '禁用' : '启用' }} -->
          <a @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="Modeltable"
        row-key="id"
        bordered
        :columns="config.ModelColumns"
        :remoteUrl="remoteUrl"
        :remoteParams="ModelremoteParams"
        :rowSelectType="false"
        :data-source="ModelData"
        :scroll="{ x: true }"
      >
      </p-table>
    </p-modal>
  </div>
</template>

<script>
import { setwarehouse } from "@/views/kzyWMS/SearchModal/mixins_warehouse.js";
import config from "./config.js";
import pick from "lodash.pick";
import { saveStereo } from "./api";
import { diffOption } from "@/views/kzyWMS/utils/index.js";
import { upcloud_base_inventory } from "@/config/serviceSettings";
export default {
  data() {
    return {
      remoteUrl: {
        url: upcloud_base_inventory + "/stock-lot/getDeviceContainerItemStockPage",
        headers: {
          "Content-Type": "application/JSON",
        },
        method: "get",
      },
      config: config(this),
      data: [],
      ModelData: [],
      type: true,
      remoteParams: {},
      ModelremoteParams: {},
      visible: false,
      confirmLoading: false,
      selectedRowKeys: [],
      selectedRows: [],
    };
  },
  mixins: [setwarehouse],
  mounted() {
    // this.getinfo()
  },
  created() {
    diffOption(this.config.columns).then((res) => {
      this.columns = res;
    });
  },
  methods: {
    selectChange(selectedRowKeys, selectedRows) {
      this.selectedRows = selectedRows;
    },
    async saveStereo() {
      if (this.selectedRows.length != 2) {
        // 只能勾选两个托盘
        this.$message.warning("只能勾选两个托盘进行合托!");
        return;
      }

      try {
        let res = await saveStereo(this.selectedRows);
        if (res.success) {
          this.$message.success(res.message);
          this.remoteParams = { ...this.remoteParams };
        } else {
          this.$exception(res);
        }
      } catch (error) {
        this.$exception(error);
      }
    },
    hanlderSubmit(e, form) {
      e.preventDefault();
      form.validateFields((error, values) => {
        if (!error) {
          console.log(error, values, "valuesvaluesvaluesvaluesvalues");
          this.remoteParams = { ...this.remoteParams, ...values };
        }
      });
    },
    handleOk(e) {
      this.visible = false;
      this.confirmLoading = false;
      //
    },
    handleCancel(e) {
      console.log("Clicked cancel button");
      this.visible = false;
    },
    //点击弹出
    showmodel(data) {
      console.log(data);
      this.visible = true;
      this.ModelremoteParams = { ...this.ModelremoteParams, ...data };
    },
  },
};
</script>

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