<template>
  <ele-modal
    custom-class="ele-dialog-form long-dialog-form"
    :centered="true"
    v-if="visible"
    :visible.sync="visible"
    :title="title"
    :append-to-body="true"
    :maxable="true"
    :resizable="true"
    :close-on-click-modal="false"
    width="70%"
    @close="cancel"
  >
    <div class="switch">
      <div class="switch_left">
        <ul>
          <li
            v-for="item in tabOptions"
            :key="item.key"
            :class="{ active: activeComp == item.key }"
            @click="handleTag(item.key)"
          >
            {{ item.name }}
          </li>
        </ul>
      </div>
    </div>
    <div v-show="activeComp === 'main'">
      <el-form ref="form" :model="form" :rules="rules" label-width="140px">
        <headerTitle title="发货信息"></headerTitle>
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户名称：" prop="contactName">
              <el-input v-model="form.contactName" disabled></el-input>
            </el-form-item>
            <el-form-item label="客户联系人：" prop="linkName">
              <el-input v-model="form.linkName" disabled></el-input>
            </el-form-item>
            <el-form-item label="客户电话：" prop="linkPhone">
              <el-input v-model="form.linkPhone" disabled></el-input>
            </el-form-item>

            <el-form-item label="客户地址：" prop="receiveAddress">
              <el-input v-model="form.receiveAddress" disabled></el-input>
            </el-form-item>

            <el-form-item label="车牌号：" prop="carNo">
              <el-input v-model="form.carNo" disabled></el-input>
            </el-form-item>
            <el-form-item label="托盘数：">
              <el-input v-model="form.trayNum" disabled></el-input>
            </el-form-item>
            <el-form-item label="送货方式：">
              <el-input v-model="form.deliveryTypeName" disabled></el-input>
            </el-form-item>
            <el-form-item label="回执要求：">
              <el-input v-model="form.receiptRequirementTypeName" disabled></el-input>
            </el-form-item>
            <el-form-item label="发货附件：" prop="sendFiles">
              <fileMain v-model="form.sendFiles" type="view"></fileMain>
            </el-form-item>
            <el-form-item label="回执附件：" prop="sendFiles">
              <fileMain v-model="form.repliedFiles" type="view"></fileMain>
            </el-form-item>
          </el-col>

          <el-col :span="12">
   
            <el-form-item label="受托收货单编码：" prop="entrustedCode">
              <el-input v-model="form.entrustedCode" disabled></el-input>
            </el-form-item>
            <el-form-item label="发货单编码：" prop="docNo">
              <el-input v-model="form.docNo" disabled></el-input>
            </el-form-item>
            <el-form-item prop="orderNo" label="订单编码：">
              <el-input v-model="form.orderNo" disabled></el-input>
            </el-form-item>
            <el-form-item prop="replied" label="是否回执：">
              <el-select v-model="form.replied" disabled style="width: 100%">
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="审核状态：" prop="reviewStatus">
              <el-select
                v-model="form.reviewStatus"
                disabled
                style="width: 100%"
              >
                <el-option
                  v-for="item in reviewStatusEnum"
                  :value="item.value"
                  :label="item.label"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="打印编码：" prop="printNo">
              <el-input v-model="form.printNo" disabled></el-input>
            </el-form-item>
            <el-form-item label="制单人：" prop="makerName">
              <el-input v-model="form.makerName" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-tabs type="border-card">
        <el-tab-pane label="物品清单">
          <inventoryTableDetails
            ref="inventoryTableDetailsRef"
          ></inventoryTableDetails>
        </el-tab-pane>
        <el-tab-pane label="托盘清单">
          <palletTable ref="palletTableRef" type="view"></palletTable>
        </el-tab-pane>
        <el-tab-pane label="装载叉车信息">
          <stowageTable ref="stowageTableRef" dialog-type="view"></stowageTable>
        </el-tab-pane>
        <el-tab-pane label="运输清单">
          <taskInfoTable
            ref="taskInfoTableRef"
            dialog-type="view"
          ></taskInfoTable>
        </el-tab-pane>
        <el-tab-pane label="替代料" name="5">
          <replaceTable
            :pricingWay="form.pricingWay"
            :disabled="true"
            ref="replaceRef"
          ></replaceTable>
        </el-tab-pane>
      </el-tabs>
    </div>

    <bpmDetail
      v-if="activeComp === 'bpm' && form.processInstanceId"
      :id="form.processInstanceId"
    ></bpmDetail>

    <out-bound-details
      v-if="activeComp === 'store'&& form.reviewStatus==2"
      ref="innerBoundDetailsRef"
    ></out-bound-details>

    <div slot="footer" class="footer">
      <el-button @click="cancel">返回</el-button>
    </div>
  </ele-modal>
</template>

<script>
  import { getFile } from '@/api/system/file';
  import dictMixins from '@/mixins/dictMixins';
  import { reviewStatusEnum, lbjtList } from '@/enum/dict';
  import { copyObj } from '@/utils/util';
  import { getSendSaleOrderrecordDetailSplit } from '@/api/saleManage/saleordersendrecord';
  import bpmDetail from '@/views/bpm/processInstance/detail.vue';
  import outBoundDetails from '@/BIZComponents/outdetails.vue';
  import taskInfoTable from '@/views/saleManage/saleOrder/invoice/components/taskInfoTable.vue';
  import stowageTable from '@/views/saleManage/saleOrder/invoice/components/stowageTable.vue';
  import getDynamicsColumns from '@/mixins/getDynamicsColumns';
  // import fileMain from '@/components/addDoc/index.vue';
  import PalletTable from '@/views/saleManage/saleOrder/invoice/components/palletTable.vue';
  import replaceTable from './replaceTable.vue';
  import inventoryTableDetails from './inventoryTableDetails.vue';
  import tabMixins from '@/mixins/tableColumnsMixin';

  export default {
    mixins: [dictMixins, getDynamicsColumns, tabMixins],
    components: {
      PalletTable,
      // fileMain,
      taskInfoTable,
      outBoundDetails,
      bpmDetail,
      stowageTable,
      replaceTable,
      inventoryTableDetails
    },
    data() {
      return {
        activeComp: 'main',
        tabOptions: [
          { key: 'main', name: '发货单详情' },
          { key: 'bpm', name: '流程详情' },
          { key: 'store', name: '出库单详情' }
        ],
        fullscreen: false,
        reviewStatusEnum,
        visible: false,
        outboundDetailsDialogFlag: false,
        title: '详情',
        form: {
          orderFiles: []
        },
        rules: {},
        detailData: {},
        childrenColumns: [
          {
            width: 45,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            fixed: 'left'
          },
          {
            minWidth: 100,
            prop: 'code',
            label: '编码',
            align: 'center'
          },
          {
            minWidth: 140,
            prop: 'barcodes',
            label: '发货条码',
            align: 'center'
          },
          {
            minWidth: 100,
            prop: 'engrave',
            label: '刻码',
            align: 'center'
          }
        ],
        receiptRequirementTypeOption: [{
          label: '签回单',
          value: 1
        }, {
          label: '不签回单',
          value: 2
        }],
      };
    },
    created() {
      this.requestDict('产地');
      this.requestDict('生产类型');
      this.requestDict('送货方式');
    },
    computed: {
      clientEnvironmentId() {
        return this.$store.state.user.info.clientEnvironmentId;
      }
    },
    methods: {
      async open(row) {
        this.activeComp = 'main';
        this.visible = true;
        await this.getDetailData(row.id);
      },
      handleTag(val) {
        this.activeComp = val;
        if (val == 'store') {
          this.$nextTick(() => {
            this.$refs.innerBoundDetailsRef._getInfo(this.form.docNo);
          });
        }
      },
      cancel() {
        this.$nextTick(() => {
          // 关闭后，销毁所有的表单数据
          (this.form = copyObj(this.formDef)),
            (this.otherForm = copyObj(this.otherFormDef)),
            (this.tableBankData = []);
          this.tableLinkData = [];
          this.visible = false;
        });
      },
      downloadFile(file) {
        getFile({ objectName: file.storePath }, file.name);
      },
      async getDetailData(id) {
        this.loading = true;
        const data = await getSendSaleOrderrecordDetailSplit(id);
        this.loading = false;
        if (data) {
          data.productList.forEach((item) => {
            item.pricingWay = item.pricingWay || data.pricingWay;
          });
          this.form = data;
          console.log(this.form, 'this.form.receiptRequirementTypeName~~~');  
          this.form.deliveryTypeName = this.getDictValue(
            '送货方式',
            this.form.deliveryTypeId
          );
          this.form.receiptRequirementTypeName = this.receiptRequirementTypeOption.find(item => item.value == this.form.receiptRequirementTypeId)?.label;
          
          this.detailData = data;
          console.log(data.productList, 'data.productList');
          this.$nextTick(() => {
            this.$refs.inventoryTableDetailsRef &&
              this.$refs.inventoryTableDetailsRef.putTableValue(
                data.productList
              );
            this.$refs.taskInfoTableRef &&
              this.$refs.taskInfoTableRef.putTableValue(
                data.logisticTrakListNoteVOList
              );
            this.$refs.stowageTableRef &&
              this.$refs.stowageTableRef.putTableValue(data.carList);
            this.$refs.palletTableRef &&
              this.$refs.palletTableRef.putTableValue(data.trayList);
            this.form.pricingWay = data?.saleOrder?.pricingWay;
            this.$refs.replaceRef &&
              this.$refs.replaceRef.putTableValue(data.replaceList);
          });
        }
      }
    }
  };
</script>

<style scoped lang="scss">
  .ele-dialog-form {
    .el-form-item {
      margin-bottom: 10px;
    }
  }

  .headbox {
    display: flex;
    justify-content: flex-start;
    align-items: center;

    .amount {
      font-size: 14px;
      font-weight: bold;
      margin-right: 20px;
    }
  }
</style>
