<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-if="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="partaAddress">
              <el-input v-model="form.partaAddress" 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.docNo" disabled></el-input>
            </el-form-item>

            <el-form-item label="发货单编码：" prop="docNo">
              <el-input v-model="form.sendNo" 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="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="收货物品明细">
          <ele-pro-table
            ref="table"
            :needPage="false"
            :columns="columns"
            :datasource="form.productList"
            row-key="id"
            @columns-change="handleColumnChange"
            :cache-key="cacheKeyUrl"
          >
          </ele-pro-table>
        </el-tab-pane>
        <el-tab-pane label="托盘清单">
          <ele-pro-table
            ref="table"
            :needPage="false"
            :columns="trayListColumns"
            :datasource="trayListData"
            row-key="id"
          >
          </ele-pro-table>
        </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-tabs>
    </div>

    <bpmDetail
      v-if="activeComp === 'bpm' && form.processInstanceId"
      :id="form.processInstanceId"
    ></bpmDetail>
    <!--    <out-bound-details v-if="activeComp==='store'" ref="innerBoundDetailsRef"></out-bound-details>-->
    <div slot="footer" class="footer">
      <el-button @click="cancel">返回</el-button>
    </div>
  </ele-modal>
</template>

<script>
  import dictMixins from '@/mixins/dictMixins';
  import { reviewStatusEnum } from '@/enum/dict';
  import { copyObj } from '@/utils/util';
  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 {
    getSendSaleOrderConfirmDetail,
  } from '@/api/saleManage/invoiceConfirm';
  import tabMixins from '@/mixins/tableColumnsMixin';

  export default {
    mixins: [dictMixins, getDynamicsColumns,tabMixins],
    components: {
      PalletTable,
      fileMain,
      taskInfoTable,
      outBoundDetails,
      bpmDetail,
      stowageTable
    },
    data() {
      return {
        cacheKeyUrl:'eos-saleManage-invoiceConfirm-inventoryTableDetails',
        activeComp: 'main',
        tabOptions: [
          { key: 'main', name: '收货确认单详情' },
          { key: 'bpm', name: '流程详情' }
          // {key: 'store', name: '出库单详情'},
        ],
        trayListColumns: [
          {
            width: 45,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            fixed: 'left'
          },
          {
            minWidth: 160,
            prop: 'productCode',
            label: '编码',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 120,
            prop: 'productName',
            label: '名称',
            showOverflowTooltip: true,
            align: 'center'
          },

          {
            minWidth: 160,
            prop: 'batchNo',
            label: '批次号',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 160,
            prop: 'barcodes',
            label: '发货条码',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 120,
            prop: 'materielDesignation',
            label: '物料代号',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 120,
            prop: 'clientCode',
            label: '客户代号',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 120,
            prop: 'engrave',
            label: '刻码',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 160,
            prop: 'packageNo',
            align: 'center',
            label: '包装编码',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            prop: 'packingQuantity',
            align: 'center',
            label: '包装数量',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'packingUnit',
            align: 'center',
            label: '包装单位',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            prop: 'totalCount',
            label: '计量数量',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 150,
            prop: 'measuringUnit',
            label: '计量单位',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            width: 120,
            slot: 'type',
            prop: 'type',
            label: '回收状态',
            align: 'center',
            formatter: (row, column) => {
              return row.type === 0 ? '未回收' : row.type === 1 ? '已回收' : '';
            },
            fixed: 'right'
          }
        ],
        trayListData: [],

        reviewStatusEnum,
        visible: false,
        outboundDetailsDialogFlag: false,
        detailId: '',
        title: '详情',
        row: {},
        activeName: 'base',
        form: {
          orderFiles: []
        },
        rules: {},
        detailData: {},
        columns: [
          {
            width: 45,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            fixed: 'left'
          },
          {
            minWidth: 160,
            prop: 'productCode',
            label: '编码',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 120,
            prop: 'productName',
            label: '名称',
            showOverflowTooltip: true,
            align: 'center'
          },

          {
            minWidth: 160,
            prop: 'batchNo',
            label: '批次号',
            showOverflowTooltip: true,
            slot: 'batchNo',
            align: 'center'
          },
          {
            minWidth: 160,
            prop: 'barcodes',
            label: '发货条码',
            showOverflowTooltip: true,
            slot: 'barcodes',
            align: 'center'
          },
          {
            minWidth: 120,
            prop: 'materielDesignation',
            label: '物料代号',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 120,
            prop: 'clientCode',
            label: '客户代号',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 120,
            prop: 'engrave',
            label: '刻码',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 160,
            prop: 'packageNo',
            align: 'center',
            label: '包装编码',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            prop: 'packingQuantity',
            align: 'center',
            label: '包装数量',
            showOverflowTooltip: true
          },
          {
            minWidth: 120,
            prop: 'packingUnit',
            align: 'center',
            label: '包装单位',
            showOverflowTooltip: true
          },
          {
            minWidth: 100,
            prop: 'totalCount',
            label: '计量数量',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 150,
            prop: 'measuringUnit',
            label: '计量单位',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            width: 160,
            prop: 'pricingWay',
            label: '计价方式',
            slot: 'pricingWay',
            align: 'center',
            formatter: (row, column) => {
              return row.pricingWay == 1
                ? '按数量计费'
                : row.pricingWay == 2
                ? '按重量计费'
                : '';
            }
          },
          {
            width: 100,
            prop: 'singlePrice',
            label: '单价',
            slot: 'singlePrice',
            align: 'center'
          },
          {
            width: 150,
            prop: 'notaxSinglePrice',
            label: '不含税单价',
            slot: 'notaxSinglePrice',
            align: 'center'
          },
          {
            width: 100,
            prop: 'totalPrice',
            label: '合计',
            align: 'center'
          },

          {
            minWidth: 80,
            prop: 'receiveTotalWeight',
            label: '重量',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            minWidth: 100,
            prop: 'weightUnit',
            label: '重量单位',
            showOverflowTooltip: true,
            align: 'center'
          },
          {
            prop: 'provenance',
            label: '产地',
            slot: 'provenance',
            align: 'center',
            // show:this.contractBookType==2,
            minWidth: 200,
            showOverflowTooltip: true,
            formatter: (row, column) => {
              return row.provenance && row.provenance.length
                ? row.provenance
                    .map((item) => this.getDictValue('产地', item))
                    .join(',')
                : '';
            }
          },
          {
            width: 220,
            prop: 'remark',
            label: '备注',
            slot: 'remark',
            align: 'center'
          },

          {
            width: 150,
            prop: 'isException',
            label: '收货状态',
            slot: 'isException',
            formatter: (row, column) => {
              return row.isException == 1 ? '未收货' : '已收货';
            },
            fixed: 'right',
            align: 'center'
          }
        ]
      };
    },

    created() {
      this.requestDict('产地');
    },
    methods: {
      async open(row) {
        this.form = row;
        this.visible = true;
        await this.getDetailData(row.id);
        this.detailId = 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;
        });
      },
      async getDetailData(id) {
        this.loading = true;
        const data = await getSendSaleOrderConfirmDetail(id);
        this.loading = false;
        this.form = data;
        this.detailData = data;
        this.trayListData = data.trayList;
        if (data) {
          this.$refs.taskInfoTableRef &&
            this.$refs.taskInfoTableRef.putTableValue(
              data.logisticTrakListNoteVOList
            );
          this.$refs.stowageTableRef &&
            this.$refs.stowageTableRef.putTableValue(data.carList);

          this.form.pricingWay = data?.saleOrder?.pricingWay;
        }
      }
    }
  };
</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>
