<template>
  <div>
    <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
      <el-tab-pane label="退货物品明细" name="退货物品明细">
        <el-form :rules="rules" ref="formRef" :model="form">
          <header-title title="退货物品明细" size="16px"></header-title>
          <ele-pro-table
            ref="table"
            :needPage="false"
            :columns="columns"
            :toolkit="[]"
            :datasource="form.detailList"
            cache-key="customerReturnOrderDialog"
            class="time-form"
          >
            <!-- 表头工具栏 -->
            <!--        <template v-slot:toolbar>-->
            <!--          <el-button-->
            <!--            size="small"-->
            <!--            type="primary"-->
            <!--            icon="el-icon-plus"-->
            <!--            class="ele-btn-icon"-->
            <!--            @click="handleSelectGoods"-->
            <!--            v-if="taskDefinitionKey=='stater'">-->
            <!--            选择退货物品-->
            <!--          </el-button>-->
            <!--        </template>-->
            <template v-slot:action="{ row, $index }">
              <el-popconfirm
                v-if="taskDefinitionKey == 'stater'"
                class="ele-action"
                title="确定要删除吗？"
                @confirm="remove(row, $index)"
              >
                <template v-slot:reference>
                  <el-link
                    type="danger"
                    :underline="false"
                    icon="el-icon-delete"
                  >
                    删除
                  </el-link>
                </template>
              </el-popconfirm>
            </template>
            <template v-slot:packageCount="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.packageCount'"
                :rules="{
                  required: row.outboundType != 2 ? true : false,
                  trigger: 'blur',
                  message: '请输入'
                }"
              >
                <el-input
                  v-if="isTrue && row.outboundType != 2"
                  v-model="row.packageCount"
                ></el-input>
                <div v-else>{{ row.packageCount }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerPackageCount="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <template v-slot:measurementCount="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.measurementCount'"
                :rules="{ required: true, trigger: 'blur', message: '请输入' }"
              >
                <el-input
                  v-if="isTrue"
                  v-model="row.measurementCount"
                ></el-input>
                <div v-else>{{ row.measurementCount }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerMeasurementCount="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <template v-slot:weight="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.weight'"
                :rules="{ required: true, trigger: 'blur', message: '请输入' }"
              >
                <el-input v-if="isTrue" v-model="row.weight"></el-input>
                <div v-else>{{ row.weight }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerWeight="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <template v-slot:carveCode="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.carveCode'"
                :rules="{ required: true, trigger: 'blur', message: '请输入' }"
              >
                <el-input v-if="isTrue" v-model="row.carveCode"></el-input>
                <div v-else>{{ row.carveCode }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerCarveCode="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <!--  ///  发起人展示字段 -->
            <template v-slot:reason="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.reason'"
                :rules="{ required: true, trigger: 'blur', message: '请输入' }"
              >
                <el-input
                  type="textarea"
                  v-if="isTrue"
                  v-model="row.reason"
                ></el-input>
                <div v-else>{{ row.reason }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerReason="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <template v-slot:feedbackDate="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.feedbackDate'"
                :rules="{
                  required: true,
                  trigger: 'change',
                  message: '请选择'
                }"
              >
                <el-date-picker
                  v-if="isTrue"
                  v-model="row.feedbackDate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyy-MM-dd"
                  placeholder="选择日期"
                >
                </el-date-picker>
                <div v-else>{{ row.feedbackDate }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerFeedbackDate="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <template v-slot:sendDate="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.sendDate'"
                :rules="{
                  required: true,
                  trigger: 'change',
                  message: '请选择'
                }"
              >
                <el-date-picker
                  v-if="isTrue"
                  v-model="row.sendDate"
                  style="width: 100%"
                  value-format="yyyy-MM-dd"
                  type="date"
                  placeholder="选择日期"
                >
                </el-date-picker>
                <div v-else>{{ row.sendDate }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerSendDate="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <!--////-->
            <!--  ///  仓管入库展示字段 -->
            <template v-slot:ifPackageOk="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.ifPackageOk'"
                :rules="{
                  required: true,
                  trigger: 'change',
                  message: '请选择'
                }"
              >
                <el-select
                  v-if="isTrue"
                  v-model="row.ifPackageOk"
                  placeholder="请选择"
                  clearable
                  style="width: 100%"
                >
                  <el-option label="是" :value="1" />
                  <el-option label="否" :value="0" />
                </el-select>
                <div v-else>{{ row.ifPackageOk ? '是' : '否' }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerIfPackageOk="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <template v-slot:unpackUserName="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.unpackUserName'"
                :rules="{
                  required: true,
                  trigger: 'change',
                  message: '请选择'
                }"
              >
                <el-input
                  v-if="isTrue"
                  @click.native="handHead(row, $index)"
                  v-model="row.unpackUserName"
                  placeholder="请选择"
                ></el-input>
                <div v-else>{{ row.unpackUserName }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerUnpackUserName="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <!--////-->
            <!--  ///  质检员审核展示字段 -->
            <template v-slot:ifReasonMatch="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.ifReasonMatch'"
                :rules="{
                  required: true,
                  trigger: 'change',
                  message: '请选择'
                }"
              >
                <el-select
                  v-if="isTrue"
                  v-model="row.ifReasonMatch"
                  placeholder="请选择"
                  clearable
                  style="width: 100%"
                >
                  <el-option label="是" :value="1" />
                  <el-option label="否" :value="0" />
                </el-select>
                <div v-else>{{ row.ifReasonMatch ? '是' : '否' }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerIfReasonMatch="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <!--////-->
            <!--  ///  技术员审核展示字段 -->
            <template v-slot:unqualifiedReasonAnalysis="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.unqualifiedReasonAnalysis'"
                :rules="{ required: true, trigger: 'blur', message: '请输入' }"
              >
                <el-input
                  v-if="isTrue"
                  v-model="row.unqualifiedReasonAnalysis"
                ></el-input>
                <div v-else>{{ row.unqualifiedReasonAnalysis }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerUnqualifiedReasonAnalysis="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <template v-slot:unqualifiedType="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.unqualifiedType'"
                :rules="{ required: true, trigger: 'blur', message: '请输入' }"
              >
                <DictSelection
                  dict-name="产品不合格类型"
                  multiple
                  collapse-tags
                  clearable
                  v-if="isTrue"
                  v-model="row.unqualifiedTypeList"
                  @change="
                    (val) =>
                      changeGetValue(
                        val,
                        row,
                        'dictList',
                        'unqualifiedType',
                        'unqualifiedTypeName',
                        $index
                      )
                  "
                >
                </DictSelection>

                <!--                <el-input-->
                <!--                  v-if="isTrue"-->
                <!--                  v-model="row.unqualifiedType"-->
                <!--                ></el-input>-->
                <div v-else>{{ row.unqualifiedTypeName }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerUnqualifiedType="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <template v-slot:handleWay="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.handleWay'"
                :rules="{ required: true, trigger: 'blur', message: '请输入' }"
              >
                <el-input v-if="isTrue" v-model="row.handleWay"></el-input>
                <div v-else>{{ row.handleWay }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerHandleWay="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <template v-slot:handleOpinion="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.handleOpinion'"
                :rules="{ required: true, trigger: 'blur', message: '请输入' }"
              >
                <el-input v-if="isTrue" v-model="row.handleOpinion"></el-input>
                <div v-else>{{ row.handleOpinion }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerHandleOpinion="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <!--////-->
            <!--  ///  生产员审核 -->
            <template v-slot:inOrOut="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.inOrOut'"
                :rules="{
                  required: true,
                  trigger: 'change',
                  message: '请选择'
                }"
              >
                <el-select
                  v-if="isTrue"
                  v-model="row.inOrOut"
                  @change="() => (row.outerInfo = '')"
                >
                  <el-option label="内部" :value="1" />
                  <el-option label="外部" :value="2" />
                </el-select>
                <div v-else>{{
                  row.inOrOut && (row.inOrOut == 1 ? '内部' : '外部')
                }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerInOrOut="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <template v-slot:outerInfo="{ row }">
              <el-form-item prop="outerInfo">
                <el-input
                  v-if="isTrue && row.inOrOut == 2"
                  v-model="row.outerInfo"
                ></el-input>
                <div v-else>{{ row.outerInfo }}</div>
              </el-form-item>
            </template>
            <!--////-->
            <!--  ///  质检员反馈 -->
            <template v-slot:improveCorrect="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.improveCorrect'"
                :rules="{ required: true, trigger: 'blur', message: '请输入' }"
              >
                <el-input v-if="isTrue" v-model="row.improveCorrect"></el-input>
                <div v-else>{{ row.improveCorrect }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerImproveCorrect="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <template v-slot:improveOpinion="{ row, $index }">
              <el-form-item
                :prop="'detailList.' + $index + '.improveOpinion'"
                :rules="{ required: true, trigger: 'blur', message: '请输入' }"
              >
                <el-input v-if="isTrue" v-model="row.improveOpinion"></el-input>
                <div v-else>{{ row.improveOpinion }}</div>
              </el-form-item>
            </template>
            <template v-slot:headerImproveOpinion="{ column }">
              <span class="is-required">{{ column.label }}</span>
            </template>
            <!--////-->
          </ele-pro-table>
        </el-form>
      </el-tab-pane>
      <el-tab-pane v-if="isShowReturnOrder" label="入库明细" name="入库明细">
        <inbound-details
          ref="inboundDetails"
          :returnDetailsForm="form"
        ></inbound-details>
      </el-tab-pane>
    </el-tabs>

    <!--出库详情-->
    <outbound-details-dialog
      v-if="outboundDetailsDialogFlag"
      ref="outboundDetailsDialogRef"
      :outboundDetailsDialogFlag.sync="outboundDetailsDialogFlag"
      @saveDate="saveDate"
    ></outbound-details-dialog>
    <head-list ref="headRef" @changeParent="changeHead"></head-list>
  </div>
</template>

<script>
  import inboundDetails from './inboundDetails.vue';
  import outboundDetailsDialog from './outboundDetailsDialog.vue';
  import headList from '@/components/headList';
  import {
    getOutInByIdAPI,
    saleReturnGetByIdAPI
  } from '@/api/bpm/components/saleManage/saleorder';
  import { deepClone } from '@/utils';
  import { EventBus } from './eventBus.js';
  import { mapActions, mapGetters } from 'vuex';
  import dictEnum from '@/enum/dict';

  export default {
    name: 'customerReturnOrder',
    props: {
      taskDefinitionKey: {
        type: String,
        default: 'stater'
      },
      activeComp: {
        type: String,
        default: 'stater'
      },
      permissionType: {
        type: String,
        default: 'view'
      },
      businessId: {
        type: String,
        default: ''
      },
      isShowReturnOrder: {
        type: Boolean,
        default: false
      }
    },
    components: { outboundDetailsDialog, headList, inboundDetails },
    data() {
      return {
        activeName: '退货物品明细',
        title: '客户退货处理单',
        outboundDetailsDialogFlag: false,
        isTrue: false,
        warehousingMaterialList: [],
        materialCodeReqList: [],
        metaList: [],
        form: {
          detailList: []
        },
        rules: {}
      };
    },
    computed: {
      columns() {
        let basicFields = [
          {
            columnKey: 'action',
            label: '操作',
            width: 120,
            align: 'center',
            resizable: false,
            slot: 'action',
            fixed: 'right',
            showOverflowTooltip: true
          },
          {
            width: 45,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            fixed: 'left'
          },
          {
            minWidth: 120,
            prop: 'name',
            label: '名称',
            align: 'center',
            slot: 'name'
          },
          {
            minWidth: 120,
            prop: 'categoryCode',
            label: '编码',
            align: 'center',
            slot: 'categoryCode'
          },
          // {
          //   minWidth: 120,
          //   prop: 'modelType',
          //   label: '型号',
          //   align: 'center',
          //   slot: 'modelType'
          // },
          {
            minWidth: 120,
            prop: 'specification',
            label: '规格',
            align: 'center',
            slot: 'specification'
          },
          {
            minWidth: 120,
            prop: 'packageCount',
            label: '包装数量',
            align: 'center',
            slot: 'packageCount',
            headerSlot: 'headerPackageCount'
          },
          {
            minWidth: 80,
            prop: 'packingUnit',
            label: '包装单位',
            align: 'center',
            slot: 'packingUnit'
          },
          {
            minWidth: 80,
            prop: 'measurementCount',
            label: '计量数量',
            align: 'center',
            slot: 'measurementCount',
            headerSlot: 'headerCount'
          },
          {
            minWidth: 80,
            prop: 'measuringUnit',
            label: '计量单位',
            align: 'center'
          },
          {
            minWidth: 80,
            prop: 'weight',
            label: '重量',
            align: 'center',
            slot: 'weight',
            headerSlot: 'headerWeight'
          },
          {
            minWidth: 80,
            prop: 'weightUtil',
            label: '重量单位',
            align: 'center',
            slot: 'weightUtil'
          },
          {
            minWidth: 120,
            prop: 'carveCode',
            label: '刻码',
            slot: 'carveCode',
            align: 'center',
            headerSlot: 'headerCarveCode'
          }
        ];
        let processNodes = {
          //发起人
          stater: [
            {
              minWidth: 140,
              prop: 'reason',
              label: '客户退货理由',
              align: 'center',
              slot: 'reason',
              headerSlot: 'headerReason'
            },
            {
              minWidth: 180,
              prop: 'feedbackDate',
              label: '客户反馈日期',
              align: 'center',
              slot: 'feedbackDate',
              headerSlot: 'headerFeedbackDate'
            },
            {
              minWidth: 180,
              prop: 'sendDate',
              label: '客户发出日期',
              slot: 'sendDate',
              align: 'center',
              headerSlot: 'headerSendDate'
            }
          ],
          //销售主管审批
          deptLeader: [
            {
              minWidth: 140,
              prop: 'reason',
              label: '客户退货理由',
              align: 'center',
              slot: 'reason',
              headerSlot: 'headerReason'
            },
            {
              minWidth: 140,
              prop: 'feedbackDate',
              label: '客户反馈日期',
              align: 'center',
              slot: 'feedbackDate',
              headerSlot: 'headerFeedbackDate'
            },
            {
              minWidth: 140,
              prop: 'sendDate',
              label: '客户发出日期',
              slot: 'sendDate',
              align: 'center',
              headerSlot: 'headerSendDate'
            }
          ],
          //仓管入库
          storeman: [
            {
              minWidth: 140,
              prop: 'ifPackageOk',
              label: '包装完好与否',
              align: 'center',
              slot: 'ifPackageOk',
              headerSlot: 'headerIfPackageOk'
            },
            {
              minWidth: 140,
              prop: 'unpackUserName',
              label: '拆包装责任人',
              align: 'center',
              slot: 'unpackUserName',
              headerSlot: 'headerUnpackUserName'
            }
          ],
          //质量部主管指派
          QCLeader: [
            {
              minWidth: 140,
              prop: 'ifPackageOk',
              label: '包装完好与否',
              align: 'center',
              slot: 'ifPackageOk',
              headerSlot: 'headerIfPackageOk'
            },
            {
              minWidth: 140,
              prop: 'unpackUserName',
              label: '拆包装责任人',
              align: 'center',
              slot: 'unpackUserName',
              headerSlot: 'headerUnpackUserName'
            }
          ],
          //质检员审核
          QCApprove: [
            {
              minWidth: 250,
              prop: 'ifReasonMatch',
              label: '退货原因是否与退货信息一致',
              align: 'center',
              slot: 'ifReasonMatch',
              headerSlot: 'headerIfReasonMatch'
            },
            {
              minWidth: 140,
              prop: 'reason',
              label: '客户退货理由',
              align: 'center',
              slot: 'reason',
              headerSlot: 'headerReason'
            }
          ],
          //技术部主管指派
          techLeader: [
            {
              minWidth: 250,
              prop: 'ifReasonMatch',
              label: '退货原因是否与退货信息一致',
              align: 'center',
              slot: 'ifReasonMatch',
              headerSlot: 'headerIfReasonMatch'
            },
            {
              minWidth: 140,
              prop: 'reason',
              label: '客户退货理由',
              align: 'center',
              slot: 'reason',
              headerSlot: 'headerReason'
            }
          ],
          //技术员审核
          techApprove: [
            {
              minWidth: 250,
              prop: 'unqualifiedReasonAnalysis',
              label: '不合格原因分析',
              align: 'center',
              slot: 'unqualifiedReasonAnalysis',
              headerSlot: 'headerUnqualifiedReasonAnalysis'
            },
            {
              minWidth: 200,
              prop: 'unqualifiedType',
              label: '不合格类型',
              align: 'center',
              slot: 'unqualifiedType',
              headerSlot: 'headerUnqualifiedType'
            },
            // {
            //   minWidth: 250,
            //   prop: 'handleWay',
            //   label: '不合格品处理方式',
            //   align: 'center',
            //   slot: 'handleWay',
            //   headerSlot: 'headerHandleWay'
            // },
            {
              minWidth: 250,
              prop: 'handleOpinion',
              label: '对不合格品的处理意见',
              align: 'center',
              slot: 'handleOpinion',
              headerSlot: 'headerHandleOpinion'
            }
          ],
          //生产部主管指派
          produceLeader: [
            {
              minWidth: 250,
              prop: 'unqualifiedReasonAnalysis',
              label: '不合格原因分析',
              align: 'center',
              slot: 'unqualifiedReasonAnalysis',
              headerSlot: 'headerUnqualifiedReasonAnalysis'
            },
            {
              minWidth: 250,
              prop: 'unqualifiedType',
              label: '不合格类型',
              align: 'center',
              slot: 'unqualifiedType',
              headerSlot: 'headerUnqualifiedType'
            },
            {
              minWidth: 250,
              prop: 'handleOpinion',
              label: '对不合格品的处理意见',
              align: 'center',
              slot: 'handleOpinion',
              headerSlot: 'headerHandleOpinion'
            }
          ],
          //生产员审核
          produceApprove: [
            {
              minWidth: 130,
              prop: 'inOrOut',
              label: '内部或外部',
              align: 'center',
              slot: 'inOrOut',
              headerSlot: 'headerInOrOut'
            },
            {
              minWidth: 120,
              prop: 'outerInfo',
              label: '外协单位',
              align: 'center',
              slot: 'outerInfo'
            }
          ],
          //质检员反馈
          QCApprove2: [
            {
              minWidth: 250,
              prop: 'improveCorrect',
              label: '不合格原因是否改善到位',
              align: 'center',
              slot: 'improveCorrect',
              headerSlot: 'headerImproveCorrect'
            },
            {
              minWidth: 250,
              prop: 'improveOpinion',
              label: '对改善后产品处理意见',
              align: 'center',
              slot: 'improveOpinion',
              headerSlot: 'headerImproveOpinion'
            }
          ]
        };
        processNodes[this.activeComp] &&
          basicFields.push(...processNodes[this.activeComp]);
        //
        this.isTrue =
          this.activeComp == this.taskDefinitionKey &&
          this.permissionType !== 'view';
        return basicFields;
      },
      ...mapGetters(['dict', 'getDict']),
      dictList() {
        return this.dict[dictEnum['产品不合格类型']] || [];
      }
    },
    created() {
      console.log(this.isShowReturnOrder, '====');
    },
    mounted() {
      this.getReturnInfo(this.businessId);
    },
    methods: {
      handleClick(val) {
        this.activeName = val.name;
        if (val.name === '入库明细') {
          this.$refs.inboundDetails.initialize();
        }
      },
      async getReturnInfo(businessId) {
        this.form = await saleReturnGetByIdAPI(businessId);

        let outInIds = [
          ...new Set(this.form?.detailList?.map((item) => item.outInId))
        ];
        for (const outInId of outInIds) {
          //拼接信息
          const data = await getOutInByIdAPI(outInId);
          this.infoData = deepClone(data);
          //出库物料明细
          this.warehousingMaterialList = this.infoData?.outInDetailVOList || [];
          //出库包装明细
          if (this.warehousingMaterialList.length) {
            this.materialCodeReqList = [];
            this.warehousingMaterialList.forEach((item) => {
              if (item.outInDetailRecordVOList?.length) {
                item.outInDetailRecordVOList = item.outInDetailRecordVOList.map(
                  (i) => {
                    return {
                      ...i,
                      outInCode: this.infoData.bizNo,
                      outInId: item.outInId,
                      measurementCount: i.totalCount,
                      outboundDetailId: i.id,
                      outboundType: 1,
                      packageCount: i.packingCount,
                      packingUnit: i.packingUnit,
                      weight: i.weight,
                      specification: item.specification,
                      name: i.name,
                      categoryCode: i.categoryCode,
                      id: ''
                    };
                  }
                );
                this.materialCodeReqList.push(...item.outInDetailRecordVOList);
              }
            });
            //出库物料明细
            if (this.materialCodeReqList.length) {
              this.metaList = [];
              this.materialCodeReqList.forEach((item) => {
                if (item.outInDetailRecordMaterialDetailVOList?.length) {
                  item.outInDetailRecordMaterialDetailVOList =
                    item.outInDetailRecordMaterialDetailVOList.map((i) => {
                      return {
                        ...i,
                        outInId: item.outInId,
                        outInCode: item.outInCode,
                        measurementCount: 1,
                        outboundDetailId: i.id,
                        outboundType: 2,
                        packageCount: i.packingCount,
                        packingUnit: i.packingUnit,
                        weight: i.weight,
                        weightUtil: i.weightUnit,
                        specification: item.specification,
                        categoryCode: i.assetCode,
                        name: i.assetName,
                        id: ''
                      };
                    });
                  this.metaList.push(
                    ...item.outInDetailRecordMaterialDetailVOList
                  );
                }
              });
            }
          }
          this.form.detailList.forEach((item) => {
            if (item.outboundType == 1) {
              let find =
                this.materialCodeReqList.find(
                  (i) => i.outboundDetailId == item.outboundDetailId
                ) || {};
              item.name = find.name;
              item.categoryCode = find.categoryCode;
              item.specification = find.specification;
              item.weightUtil = find.weightUtil;
              item.packingUnit = find.packingUnit;
              item.measuringUnit = find.measuringUnit;
            } else {
              let find =
                this.metaList.find(
                  (i) => i.outboundDetailId == item.outboundDetailId
                ) || {};
              item.name = find.name;
              item.categoryCode = find.categoryCode;
              item.specification = find.specification;
              item.weightUtil = find.weightUtil;
              item.packingUnit = find.packingUnit;
              item.measuringUnit = find.measuringUnit;
            }
            item.unqualifiedTypeList = item.unqualifiedType
              ? item.unqualifiedType?.split(',')
              : [];
          });
        }

        this.$nextTick(() => {
          this.$refs.table.reRenderTable();
        });
      },
      changeGetValue(val, row, list, key, value, index) {
        if (!val.length) {
          row[value] = '';
          row[key] = '';
        }
        let findList =
          this[list].filter((item) => val.includes(item.dictCode)) || [];
        row[value] = findList.map((item) => item.dictValue).join(',');
        row[key] = val.join(',');
        this.$set(this.form.detailList, index, row);
      },
      handleSelectGoods() {
        this.outboundDetailsDialogFlag = true;
        this.$nextTick(() => {
          this.$refs.outboundDetailsDialogRef.init();
        });
      },
      //删除
      remove(row, index) {
        this.form.detailList.splice(index, 1);
      },
      //选择退货信息回调
      saveDate(data) {
        this.form.detailList.push(...data);
      },
      //选择负责人
      handHead(row, index) {
        let item = {
          id: row.unpackUserId
        };
        this.$refs.headRef.open(item, index);
      },
      //选择负责人回调
      changeHead(obj, index) {
        this.$set(this.form.detailList[index], 'unpackUserId', obj.id);
        this.$set(this.form.detailList[index], 'unpackUserName', obj.name);
      },
      getTableValue() {
        return new Promise((resolve) => {
          this.$refs.formRef.validate(async (validate) => {
            if (!validate) {
              resolve(false);
            } else {
              let params = {
                detailList: this.form.detailList.map((i) => {
                  return {
                    outInId: i.outInId,
                    outInCode: i.outInCode,
                    measurementCount: i.measurementCount,
                    outboundDetailId: i.outboundDetailId,
                    outboundType: i.outboundType,
                    productName: i.name,
                    productCode: i.categoryCode,
                    packageCount: i.packageCount,
                    packingUnit: i.packingUnit,
                    weight: i.weight,
                    weightUtil: i.weightUtil,
                    specification: i.specification,
                    modelType: i.modelType,
                    carveCode: i.carveCode,
                    reason: i.reason,
                    sendDate: i.sendDate,
                    feedbackDate: i.feedbackDate,
                    id: i.id,
                    handleOpinion: i.handleOpinion,
                    handleWay: i.handleWay,
                    ifPackageOk: i.ifPackageOk,
                    ifReasonMatch: i.ifReasonMatch,
                    improveCorrect: i.improveCorrect,
                    improveOpinion: i.improveOpinion,
                    outerInfo: i.outerInfo,
                    inOrOut: i.inOrOut,
                    remark: i.remark,
                    unpackUserId: i.unpackUserId,
                    unpackUserName: i.unpackUserName,
                    unqualifiedReasonAnalysis: i.unqualifiedReasonAnalysis,
                    unqualifiedType: i.unqualifiedType,
                    unqualifiedTypeName: i.unqualifiedTypeName
                  };
                }),
                returnRecordId: this.form.returnRecordId,
                id: this.form.id,
                returnStorageData:
                  await this.$refs.inboundDetails?.getReturnStorage()
              };
              resolve(params);
            }
          });
        });
      }
    }
  };
</script>
<style scoped lang="scss"></style>
