<template>
  <div>
    <div class="main">
      <div class="maintop">
        <div class="mainbtn">
          <el-button
            v-hasButtons="['DeliveryImmediateAdd']"
            size="small"
            :disabled="multiple"
            class="thebtn2"
            @click="getImmediateData"
          >{{ '立即发货' }}</el-button>
          <el-button
            v-hasButtons="['DeliveryImmediateUpdateCode']"
            size="small"
            :disabled="single"
            class="thebtn2"
            @click="updateCode"
          >{{ '修改单号' }}</el-button>

          <el-button
            v-hasButtons="['DeliveryImmediateExport']"
            size="small"
            class="thebtn1"
            @click="handleExport"
          >
            {{ '导出' }}</el-button>
        </div>
      </div>
      <el-table
        :data="tableData"
        height="540px"
        style="width: 100%"
        :header-cell-style="{ background: '#EEEEEE' }"
        :span-method="objectSpanMethod"
        @selection-change="handleSelectionChange"
      >
        <el-table-column prop="colsele" type="selection" width="55" />
        <el-table-column
          min-width="180px"
          align="center"
          prop="deliverCode"
          :label="'发货单号'"
        />
        <el-table-column
          min-width="180px"
          align="center"
          prop="orderCode"
          :label="'订单编号'"
        />
        <el-table-column
          align="center"
          prop="orderTypeVal"
          :label="'订单类型'"
        />
        <el-table-column
          align="center"
          prop="deliverStatusVal"
          :label="'发货状态'"
        />
        <el-table-column
          min-width="120px"
          align="center"
          prop="memberCode"
          :label="'会员编号'"
        />

        <el-table-column
          min-width="120px"
          align="center"
          prop="memberName"
          :label="'会员姓名'"
        />
        <el-table-column
          min-width="120px"
          align="center"
          prop="phone"
          :label="'联系方式'"
        />

        <el-table-column
          align="center"
          min-width="120px"
          prop="productCode"
          :label="'产品编号'"
        />
        <el-table-column
          min-width="150px"
          align="center"
          prop="productName"
          :label="'产品名称'"
        />

        <el-table-column
          min-width="150px"
          align="center"
          prop="specsName"
          :label="'产品规格'"
        />
        <el-table-column align="center" prop="unitName" :label="'产品单位'" />
        <el-table-column align="center" prop="quantity" :label="'产品数量'" />
        <!-- <el-table-column align="center" prop="isBarCodeVal" label="是否追溯">
        </el-table-column>
        <el-table-column align="center" prop="barCode" :label="'追溯编号'">
        </el-table-column> -->
        <el-table-column align="center" prop="recName" :label="'收货人'" />
        <el-table-column
          min-width="120px"
          align="center"
          prop="recPhone"
          :label="'收货电话'"
        />
        <!-- <el-table-column
          align="center"
          prop="recProvinceVal"
          :label="'省'"
        >
        </el-table-column>
        <el-table-column
          align="center"
          prop="recCityVal"
          :label="'市'"
        >
        </el-table-column>
        <el-table-column
          align="center"
          prop="recCountyVal"
          :label="'区/县'"
        >
        </el-table-column> -->
        <el-table-column
          min-width="180px"
          align="center"
          prop="recAddress"
          :formatter="formatAddress"
          :label="'收货地址'"
        />
        <el-table-column
          align="center"
          prop="logisticsCompany"
          :label="'物流公司'"
        />
        <el-table-column
          align="center"
          min-width="120px"
          prop="logisticsCode"
          :label="'快递单号'"
        />
        <el-table-column
          align="center"
          prop="shippingChannelVal"
          :label="'发货类型'"
        />
        <el-table-column
          min-width="100px"
          align="center"
          prop="storehouseName"
          :label="'发货仓库'"
        />
        <el-table-column
          min-width="180px"
          align="center"
          prop="payTime"
          :label="'支付日期'"
        />
        <el-table-column
          min-width="180px"
          align="center"
          prop="deliverTime"
          :label="'发货日期'"
        />
        <el-table-column
          align="center"
          prop="deliveryWayVal"
          :label="'发货方式'"
        />
        <el-table-column
          align="center"
          prop="operateScopeVal"
          :label="'供应方式'"
        />
        <el-table-column
          align="center"
          prop="tranTypeVal"
          :label="'运输方式'"
        />
        <el-table-column
          align="center"
          prop="vertexName"
          :label="$t('隶属体系')"
        />
        <!-- <el-table-column
          align="center"
          prop="systemType"
          :label="$t('系统类型')"
        >
          <template slot-scope="scope">
            <div
              v-for="item in systemTypes"
              :key="item.value"
              v-if="scope.row.systemType == item.value"
            >
              {{ item.label }}
            </div>
          </template>
        </el-table-column> -->
        <el-table-column
          min-width="180px"
          align="center"
          prop="printTime"
          :label="'打印日期'"
        />
        <el-table-column
          min-width="180px"
          align="center"
          prop="creationTime"
          :label="'创建日期'"
        />
      </el-table>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="params.pageNum"
      :limit.sync="params.pageSize"
      :page-sizes="pageSizes"
      @pagination="getList"
    />
    <!-- 立即发货 -->
    <el-dialog
      :title="'立即发货'"
      :close-on-click-modal="false"
      :visible.sync="ljfhShow"
      width="80%"
      append-to-body
      class="nowFhbox"
    >
      <div class="maintable">
        <div class="btnbox">
          <el-button size="small" class="thebtn1" @click="handleImport">
            {{ '导入' }}</el-button>
        </div>
        <el-table
          :data="fhTable"
          height="400px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :span-method="objectSpanMethod2"
        >
          <el-table-column
            align="center"
            prop="deliverCode"
            :label="'发货单号'"
          />
          <el-table-column
            align="center"
            prop="productName"
            :label="'产品名称'"
          />
          <el-table-column
            align="center"
            prop="specsName"
            :label="'产品规格'"
          /><el-table-column
            align="center"
            prop="quantity"
            :label="'产品数量'"
          />

          <!-- <el-table-column align="center" prop="barCode" :label="'追溯编号'" /> -->
          <el-table-column
            align="center"
            prop="orderCode"
            :label="'订单编号'"
          />
          <el-table-column
            align="center"
            prop="memberCode"
            :label="'会员编号'"
          />

          <el-table-column
            align="center"
            prop="memberName"
            :label="'会员姓名'"
          />
          <el-table-column
            align="center"
            prop="recName"
            :label="'收货人'"
          />
          <el-table-column
            align="center"
            prop="recPhone"
            :label="'收货电话'"
          />
          <!-- <el-table-column
            align="center"
            prop="recProvinceVal"
            :label="'省'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="recCityVal"
            :label="'市'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="recCountyVal"
            :label="'区/县'"
          >
          </el-table-column> -->
          <el-table-column
            align="center"
            prop="recAddress"
            :formatter="formatAddress"
            :label="'详细地址'"
          />

          <el-table-column
            align="center"
            prop="logisticsCompany"
            width="130px"
            :label="'物流公司'"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.logisticsCompany"
                :placeholder="'请输入物流名称'"
              />
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="logisticsCode"
            min-width="150px"
            :label="'物流单号'"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.logisticsCode"
                :placeholder="'请输入物流单号'"
              />
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            align="center"
            prop="thedel"
            :label="'操作'"
          >
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                style="color: #c73030"
                @click="handleDelete(scope.row, scope.$index, fhTable)"
              >
                {{ '删除' }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="footer" style="text-align: center; margin-top: 20px">
          <el-button @click="ljfhShow = false">
            {{ '取消' }}</el-button>
          <el-button type="primary" @click="sureFh">{{
            '确定'
          }}</el-button>
        </div>
      </div>
    </el-dialog>
    <el-dialog
      :title="upload.title"
      :close-on-click-modal="false"
      :visible.sync="upload.open"
      width="600px"
      append-to-body
    >
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :on-exceed="handleExceed"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">
          {{ '将文件拖到此处，或' }}
          <em>{{ '点击上传' }}</em>
        </div>
        <div slot="tip" class="el-upload__tip">
          <el-link type="info" style="font-size: 12px" @click="importTemplate">
            {{ '下载模板' }}</el-link>
        </div>
        <div slot="tip" class="el-upload__tip" style="color: red">
          {{ '提示：仅允许导入“xls”或“xlsx”格式文件！' }}
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">{{
          '确定'
        }}</el-button>
        <el-button @click="upload.open = false">{{
          '取消'
        }}</el-button>
      </div>
    </el-dialog>
    <!-- 修改单号 -->
    <el-dialog
      :title="'修改单号'"
      :close-on-click-modal="false"
      :visible.sync="updateCodeShow"
      width="80%"
      append-to-body
      class="nowFhbox"
    >
      <div class="maintable">
        <el-table
          :data="updateCodeList"
          height="400px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
        >
          <el-table-column
            align="center"
            prop="deliverCode"
            :label="'发货单号'"
          />
          <!-- <el-table-column
            align="center"
            prop="productName"
            :label="'产品名称'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="specsName"
            :label="'产品规格'"
          >
          </el-table-column
          ><el-table-column
            align="center"
            prop="quantity"
            :label="'产品数量'"
          >
          </el-table-column>
          <el-table-column align="center" prop="barCode" :label="'追溯编号'">
          </el-table-column>
          <el-table-column
            align="center"
            prop="orderCode"
            :label="'订单编号'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="memberCode"
            :label="'会员编号'"
          >
          </el-table-column>

          <el-table-column
            align="center"
            prop="memberName"
            :label="'会员姓名'"
          >
          </el-table-column> -->
          <el-table-column
            align="center"
            prop="recName"
            :label="'收货人'"
          />
          <el-table-column
            align="center"
            prop="recPhone"
            :label="'收货电话'"
          />
          <el-table-column
            align="center"
            prop="recProvinceVal"
            :label="'省'"
          />
          <el-table-column
            align="center"
            prop="recCityVal"
            :label="'市'"
          />
          <el-table-column
            align="center"
            prop="recCountyVal"
            :label="'区/县'"
          />
          <el-table-column
            align="center"
            prop="recAddress"
            :label="'详细地址'"
          />
          <el-table-column
            align="center"
            prop="logisticsCompany"
            width="120px"
            :label="'物流公司'"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.logisticsCompany"
                :placeholder="'请输入物流名称'"
              />
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="logisticsCode"
            width="120px"
            :label="'物流单号'"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.logisticsCode"
                :placeholder="'请输入物流单号'"
              />
            </template>
          </el-table-column>
        </el-table>
        <div class="footer" style="text-align: center; margin-top: 20px">
          <el-button @click="updateCodeShow = false">
            {{ '取消' }}</el-button>
          <el-button type="primary" @click="sureUpdateCode">{{
            '确定'
          }}</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import * as del from '@/api/delivery'
import { getToken } from '@/utils/auth'
export default {
  name: 'Nowdelivery',
  props: {
    params: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      tableData: [],
      total: 0,
      idList: [],
      // 非多个禁用
      multiple: true,
      // 非单个禁用
      single: true,
      ljfhShow: false,
      fhTable: [],
      updateCodeShow: false,
      updateCodeList: [],
      pageSizes: [50, 100, 200, 500, 1000, 2000],
      // 需要合并项的列
      needMergeArr: [
        {
          colName: 'colsele',
          mergeCheckNames: ['deliverCode']
        },
        {
          colName: 'deliverCode',
          mergeCheckNames: ['deliverCode']
        },
        {
          colName: 'orderCode',
          mergeCheckNames: ['deliverCode', 'orderCode']
        },
        {
          colName: 'orderTypeval',
          mergeCheckNames: ['deliverCode', 'orderCode', 'orderTypeval']
        },
        {
          colName: 'orderTypeVal',
          mergeCheckNames: ['deliverCode', 'orderCode', 'orderTypeVal']
        },
        {
          colName: 'memberCode',
          mergeCheckNames: ['deliverCode', 'orderCode', 'memberCode']
        },
        {
          colName: 'memberName',
          mergeCheckNames: ['deliverCode', 'orderCode', 'memberName']
        },
        {
          colName: 'phone',
          mergeCheckNames: ['deliverCode', 'orderCode', 'phone']
        },
        {
          colName: 'recName',
          mergeCheckNames: ['deliverCode', 'orderCode', 'recName']
        },
        {
          colName: 'recPhone',
          mergeCheckNames: ['deliverCode', 'orderCode', 'recPhone']
        },
        {
          colName: 'recProvinceVal',
          mergeCheckNames: ['deliverCode', 'orderCode', 'recProvinceVal']
        },
        {
          colName: 'recCityVal',
          mergeCheckNames: ['deliverCode', 'orderCode', 'recCityVal']
        },
        {
          colName: 'recCountyVal',
          mergeCheckNames: ['deliverCode', 'orderCode', 'recCountyVal']
        },
        {
          colName: 'recAddress',
          mergeCheckNames: ['deliverCode', 'orderCode', 'recAddress']
        },
        {
          colName: 'operateScopeVal',
          mergeCheckNames: ['deliverCode']
        },
        {
          colName: 'tranTypeVal',
          mergeCheckNames: ['deliverCode']
        },

        {
          colName: 'remark',
          mergeCheckNames: ['deliverCode', 'orderCode', 'remark']
        },
        {
          colName: 'creationTime',
          mergeCheckNames: ['deliverCode', 'orderCode', 'creationTime']
        },
        {
          colName: 'payTime',
          mergeCheckNames: ['deliverCode', 'orderCode', 'payTime']
        },
        {
          colName: 'deliveryWayVal',
          mergeCheckNames: ['deliverCode']
        },
        {
          colName: 'preSaleStatusVal',
          mergeCheckNames: ['deliverCode']
        },
        {
          colName: 'printStatusVal',
          mergeCheckNames: ['deliverCode', 'orderCode', 'printStatusVal']
        },
        {
          colName: 'deliverStatusVal',
          mergeCheckNames: ['deliverCode']
        },
        {
          colName: 'logisticsCompany',
          mergeCheckNames: ['deliverCode']
        },
        {
          colName: 'shippingChannelVal',
          mergeCheckNames: ['deliverCode']
        },
        {
          colName: 'storehouseName',
          mergeCheckNames: ['deliverCode']
        },

        {
          colName: 'logisticsCode',
          mergeCheckNames: ['deliverCode']
        },
        {
          colName: 'secondDeliverVal',
          mergeCheckNames: ['deliverCode', 'orderCode', 'secondDeliverVal']
        },
        {
          colName: 'printTime',
          mergeCheckNames: ['deliverCode']
        },
        {
          colName: 'deliverTime',
          mergeCheckNames: ['deliverCode']
        },

        {
          colName: 'orderStatusVal',
          mergeCheckNames: ['deliverCode', 'orderCode', 'orderStatusVal']
        }
      ],
      rowMergeArrs: {}, // 包含需要一个或多个合并项信息的对象
      needMergeArr2: [
        {
          colName: 'deliverCode',
          mergeCheckNames: ['deliverCode']
        },
        {
          colName: 'orderCode',
          mergeCheckNames: ['deliverCode', 'orderCode']
        },
        {
          colName: 'memberCode',
          mergeCheckNames: ['deliverCode', 'orderCode', 'memberCode']
        },
        {
          colName: 'memberName',
          mergeCheckNames: ['deliverCode', 'orderCode', 'memberName']
        },
        {
          colName: 'recName',
          mergeCheckNames: ['deliverCode', 'orderCode', 'recName']
        },
        {
          colName: 'recProvinceVal',
          mergeCheckNames: ['deliverCode', 'orderCode', 'recProvinceVal']
        },
        {
          colName: 'recCityVal',
          mergeCheckNames: ['deliverCode', 'orderCode', 'recCityVal']
        },
        {
          colName: 'recCountyVal',
          mergeCheckNames: ['deliverCode', 'orderCode', 'recCountyVal']
        },
        {
          colName: 'recAddress',
          mergeCheckNames: ['deliverCode', 'orderCode', 'recAddress']
        },
        {
          colName: 'orderStatusVal',
          mergeCheckNames: ['deliverCode', 'orderCode', 'orderStatusVal']
        },
        {
          colName: 'logisticsCompany',
          mergeCheckNames: ['deliverCode', 'orderCode', 'logisticsCompany']
        },
        {
          colName: 'logisticsCode',
          mergeCheckNames: ['deliverCode', 'orderCode', 'logisticsCode']
        },
        {
          colName: 'thedel',
          mergeCheckNames: ['deliverCode', 'orderCode', 'thedel']
        }
      ],

      rowMergeArrs2: {}, // 包含需要一个或多个合并项信息的对象
      upload: {
        // 是否显示弹出层（物流导入）
        open: false,
        // 弹出层标题（物流导入）
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的物流数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
        // 上传的地址
        url:
          process.env.VUE_APP_BASE_API +
          '/sale/manage/deliver/immediate-import'
      },
      logisticsTable: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    formatAddress(row) {
      return (
        row.recProvinceVal +
        row.recCityVal +
        (row.recCountyVal || '') +
        row.recAddress
      )
    },
    // 下载模板
    importTemplate() {
      this.download(
        '/sale/manage/deliver/template-export',
        {},
        `${'模板'}${new Date().getTime()}.xlsx`
      )
    },

    /** 导入按钮操作 */
    handleImport() {
      this.upload.url =
        process.env.VUE_APP_BASE_API +
        '/sale/manage/deliver/immediate-import?idList=' +
        this.idList
      this.upload.title = '导入'
      this.upload.open = true
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      var fileName = response.fileName
      if (fileName != undefined && fileName != '') {
      }
      if (response.code == 200) {
        this.logisticsTable = response.data
        if (this.logisticsTable.length > 0) {
          this.fhTable.forEach((ele) => {
            this.logisticsTable.forEach((item) => {
              if (ele.pkId == item.pkId) {
                this.$set(ele, 'logisticsCompany', item.logisticsCompany || '')
                this.$set(ele, 'logisticsCode', item.logisticsCode || '')
              }
            })
          })
        }
      }

      this.upload.open = false
      this.upload.isUploading = false
      this.$refs.upload.clearFiles()
      this.$alert(response.msg, '导入结果', {
        dangerouslyUseHTMLString: true
      })
      // this.getList();
    },
    // 上传文件数量超出后的动作
    handleExceed() {
      this.upload.isUploading = false
      this.msgInfo('仅可上传一个文件哦')
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit()
    },
    // 解决多列行列合并，根据某一列 合并其他列
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      const needMerge = this.needMergeArr.some((item) => {
        return item.colName === column.property
      })
      if (needMerge === true) {
        return this.mergeAction(column.property, rowIndex, column)
      }
    },
    mergeAction(val, rowIndex, colData) {
      const _row = this.rowMergeArrs[val].rowArr[rowIndex]
      const _col = _row > 0 ? 1 : 0
      return [_row, _col]
    },
    rowMergeHandle(arr, data) {
      if (!Array.isArray(arr) && !arr.length) return false
      if (!Array.isArray(data) && !data.length) return false
      const needMerge = {}

      arr.forEach((mergeItem) => {
        // 创建合并管理对象
        needMerge[mergeItem.colName] = {
          rowArr: [],
          rowMergeNum: 0
        }
        const currentMergeItemData = needMerge[mergeItem.colName]

        // 进行合并管理对象数据的遍历整理
        data.forEach((item, index) => {
          if (index === 0) {
            currentMergeItemData.rowArr.push(1)
            currentMergeItemData.rowMergeNum = 0
          } else {
            const currentRowData = data[index]
            const preRowData = data[index - 1]

            if (
              this.colMergeCheck(
                currentRowData,
                preRowData,
                mergeItem.mergeCheckNames
              )
            ) {
              currentMergeItemData.rowArr[
                currentMergeItemData.rowMergeNum
              ] += 1
              currentMergeItemData.rowArr.push(0)
            } else {
              currentMergeItemData.rowArr.push(1)
              currentMergeItemData.rowMergeNum = index
            }
          }
        })
      })
      return needMerge
    },
    colMergeCheck(currentRowData, preRowData, mergeCheckNames) {
      if (!Array.isArray(mergeCheckNames) && !mergeCheckNames.length) { return false }
      let result = true
      for (let index = 0; index < mergeCheckNames.length; index++) {
        const mergeCheckName = mergeCheckNames[index]
        if (currentRowData[mergeCheckName] !== preRowData[mergeCheckName]) {
          result = false
          break
        }
      }
      return result
    },
    getList() {
      this.params.pkIdList = []
      del.getDeliverList(this.params).then((res) => {
        this.tableData = res.rows
        this.total = res.total
        this.rowMergeArrs = this.rowMergeHandle(
          this.needMergeArr,
          this.tableData
        )
      })
    },
    // 立即发货弹框删除
    handleDelete(row, index, tab) {
      this.$confirm(`${'是否删除'}?`).then((_) => {
        const delList = []
        this.fhTable.forEach((ele, eindex) => {
          if (
            row.deliverCode == ele.deliverCode &&
            row.orderCode == ele.orderCode
          ) {
            delList.push(eindex)
          }
        })
        tab.splice(index, delList.length)
        this.rowMergeArrs2 = this.rowMergeHandle2(this.needMergeArr2, tab)
      })
    },
    handleSelectionChange(selection) {
      this.idList = selection.map((item) => item.pkId)
      this.multiple = !selection.length
      this.single = selection.length !== 1
    },
    // 导出
    handleExport() {
      this.params.pkIdList = this.idList
      this.$confirm('是否确认导出所有数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then((_) => {
        this.download(
          '/sale/manage/deliver/export',
          // {pkIdList:this.idList},
          { ...this.params },
          `${'发货清单-立即发货'}${new Date().getTime()}.xlsx`
        )
      })
    },
    getImmediateData() {
      this.ljfhShow = true
      del
        .getImmediateData({ deliverIdList: this.idList.join() })
        .then((res) => {
          this.fhTable = res.data
          this.rowMergeArrs2 = this.rowMergeHandle2(
            this.needMergeArr2,
            this.fhTable
          )
        })
    },
    // 修改单号
    updateCode() {
      this.updateCodeShow = true
      del.getUpdateCodeList({ deliverId: this.idList[0] }).then((res) => {
        this.updateCodeList = [res.data]
      })
    },
    sureUpdateCode() {
      del
        .changeDeliverCode({
          pkId: this.updateCodeList[0].pkId,
          logisticsCode: this.updateCodeList[0].logisticsCode,
          logisticsCompany: this.updateCodeList[0].logisticsCompany
        })
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.updateCodeShow = false
            this.getList()
          }
        })
    },
    sureFh() {
      if (this.fhTable.length > 0) {
        del.deliverConfirm(this.fhTable).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: 'success'
            })
            this.ljfhShow = false
          }
        })
      } else {
        this.$message({
          message: res.msg,
          type: 'warning'
        })
        this.ljfhShow = false
      }
    },
    // 解决多列行列合并，根据某一列 合并其他列
    objectSpanMethod2({ row, column, rowIndex, columnIndex }) {
      const needMerge = this.needMergeArr2.some((item) => {
        return item.colName === column.property
      })
      if (needMerge === true) {
        return this.mergeAction2(column.property, rowIndex, column)
      }
    },
    mergeAction2(val, rowIndex, colData) {
      const _row = this.rowMergeArrs2[val].rowArr[rowIndex]
      const _col = _row > 0 ? 1 : 0
      return [_row, _col]
    },
    rowMergeHandle2(arr, data) {
      if (!Array.isArray(arr) && !arr.length) return false
      if (!Array.isArray(data) && !data.length) return false
      const needMerge = {}

      arr.forEach((mergeItem) => {
        // 创建合并管理对象
        needMerge[mergeItem.colName] = {
          rowArr: [],
          rowMergeNum: 0
        }
        const currentMergeItemData = needMerge[mergeItem.colName]

        // 进行合并管理对象数据的遍历整理
        data.forEach((item, index) => {
          if (index === 0) {
            currentMergeItemData.rowArr.push(1)
            currentMergeItemData.rowMergeNum = 0
          } else {
            const currentRowData = data[index]
            const preRowData = data[index - 1]

            if (
              this.colMergeCheck2(
                currentRowData,
                preRowData,
                mergeItem.mergeCheckNames
              )
            ) {
              currentMergeItemData.rowArr[
                currentMergeItemData.rowMergeNum
              ] += 1
              currentMergeItemData.rowArr.push(0)
            } else {
              currentMergeItemData.rowArr.push(1)
              currentMergeItemData.rowMergeNum = index
            }
          }
        })
      })
      return needMerge
    },
    colMergeCheck2(currentRowData, preRowData, mergeCheckNames) {
      if (!Array.isArray(mergeCheckNames) && !mergeCheckNames.length) { return false }
      let result = true
      for (let index = 0; index < mergeCheckNames.length; index++) {
        const mergeCheckName = mergeCheckNames[index]
        if (currentRowData[mergeCheckName] !== preRowData[mergeCheckName]) {
          result = false
          break
        }
      }
      return result
    }
  }
}
</script>

<style lang="scss" scoped>
.nowFhbox ::v-deep .el-dialog__body {
  padding: 0;
  padding-bottom: 20px;
}
.btnbox {
  padding: 10px;
  .thebtn1 {
    background: rgba(255, 103, 35, 1);
    color: #ffffff;
  }
}

::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
.main {
  // margin-top: 20px;
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);

  .main_content {
    padding: 20px 25px;
  }

  .maintop {
    display: flex;
    // padding: 10px 20px;
    padding-bottom: 10px;
    justify-content: space-between;
    align-items: center;
    .mainbtn {
      .thebtn1 {
        color: #ffffff;
        background: rgba(243, 169, 0, 1);
      }
      .thebtn2 {
        color: #ffffff;
        background: rgba(72, 178, 253, 1);
      }
      .thebtn3 {
        color: #ffffff;
        background: rgba(83, 177, 30, 1);
      }
      .thebtn4 {
        color: #ffffff;
        background: rgba(199, 48, 48, 1);
      }
      .thebtn5 {
        color: #ffffff;
        background: rgba(0, 155, 88, 1);
      }
      .thebtn6 {
        color: #ffffff;
        background: rgba(236, 108, 0, 1);
      }
    }
  }
}
</style>
