/*
 *@description：异常订单
 *@author: hudw
 *@date: 2022-06-16 11:35:37
*/

<template>
  <div class="pages">
    <updateFormModal ref="updateFormModal" />

    <orderView
      :formExtendedField="formExtendedField"
      v-show="detailsState === 1"
      :parcelTable="true"
      :st="1"
      :exportUrls="exportUrls"
      :goods="goods"
      :parcel="parcel"
      :record="mainCurrent"
      :mainId="mainId"
      :options="options"
      :formName="'main'"
      @back="onBack"
    />

    <div class="pages" v-show="detailsState === 0">
      <searchBar ref="searchBar" :options="options" @submit="searchSubmit" />
      <mainTable
        ref="mainTable"
        title="运单信息"
        rowKey="_row_count"
        :url="mainTableInfoUrl"
        :options="options"
        :activeID="mainId"
        :rowSelectType="false"
        :tableExtendedField="tableExtendedField"
        @clickRow="handleRowClick"
        :operation="false"
        @view="handleView"
        @print="handPrint"
      >
        <!-- <template #extra>
          <p-button type="primary" :disabled="mainsSelectedRowKeys.length === 0" @click.stop="handelFeedback(mainsSelectedRowKeys)">异常关闭</p-button>
        </template> -->

        <!-- <template slot="operation" slot-scope="props">
          <a href="javascript:;" @click.stop="handelFeedback([props.record.shipbillId])">异常关闭</a>
        </template> -->
      </mainTable>
      <p-card ref="pad" :tab-list="tabList" :active-tab-key="tabsKey" @tabChange="tabChange" :bordered="false" :bodyStyle="{ minHeight: '300px', maxHeight: '300px', overflowY: 'auto' }">
        <!-- <p-button v-if="tabsKey === '3'" slot="tabBarExtraContent" type="primary" @click.stop="handelFeedback(mainsSelectedRowKeys)">关闭</p-button> -->

        <goodsTable v-show="tabsKey === '1'" ref="goodsTable" :url="goodsTableUrl" :options="options" :activeID="mainId" :tableExtendedField="goodsExtendedField" />
        <parcelTable v-show="tabsKey === '2'" ref="parcelTable" :url="packageTableUrl" :options="options" :activeID="mainId" :tableExtendedField="tableExtendedField" />
        <!-- 异常信息 -->
        <goodsTable v-show="tabsKey === '3'" :rowSelectType="2" :autoColWidth="false" @selectChange="selectChange" :url="advancedQueryUrl" :tableColumnsList="abnormalColList" ref="shipbillTable" :options="options" :activeID="mainId">
          <template slot="operation" slot-scope="props">
            <a href="javascript:;" @click.stop="handelFeedback([props.record.id])">关闭</a>
          </template>
        </goodsTable>
      </p-card>
    </div>
  </div>
</template>
<script>
import useMixin from '../$common/mixins/useMixin.js'
import dictionary from '../$common/mixins/dictionary.js'
import { advancedQueryUrl, mainTableInfoUrl, goodsTableUrl, packageTableUrl, printUrl, exportUrls, closeArrangeGoods } from './api.js'

import { setCol } from './config.js'
import updateFormModal from '@/blocks/components/papersUpdateModal/index.updateFormModal.vue'

export default {
  components: { updateFormModal },

  mixins: [useMixin, dictionary],
  data() {
    const goods = {
      url: goodsTableUrl,
    }
    const parcel = {
      url: packageTableUrl,
    }
    return {
      advancedQueryUrl,
      abnormalColList: setCol(this),
      goods,
      exportUrls,
      parcel,
      printUrl,
      goodsTableUrl,
      packageTableUrl,
      card_title: '',
      mainTableInfoUrl,
      visible: false,
      updateFormItems: null,
      detailsState: 0 /**0=不显示, 1=新建，2=修改 ，3=查看 ，4=复制  */,
      tabsKey: '1',
    }
  },
  watch: {
    tabsKey(value) {
      if (this.mainCurrent) {
        this.handleRowClick(null, this.mainId, this.mainCurrent)
      }
    },
  },
  computed: {
    tabList() {
      let list = [
        {
          key: '1',
          tab: '商品信息',
        },
        {
          key: '2',
          tab: '包裹信息',
        },
        {
          key: '3',
          tab: '异常信息',
        },
      ]

      return list
    },
  },
  mounted() {},
  methods: {
    tabChange(key) {
      this.tabsKey = key
    },
    selectChange(selectKey, selectData) {
      this.mainsSelectedRowKeys = selectData.map((item) => {
        return item.shipbillId
      })
    },

    handelFeedback(ids) {
      return closeArrangeGoods(this, ids)
    },
    handleRowClick(event, key, data) {
      event?.stopPropagation()
      this.mainId = key
      this.clearChildrenTableAll()
      if (data) {
        this.mainCurrent = data
        this.mainId = key
        const { goodsTable, parcelTable, shipbillTable } = this.$refs
        let ref = [null, goodsTable, parcelTable, shipbillTable]
        ref = ref[+this.tabsKey]
        //  const { carrierSplitOrderType, splitOrderType } = data
        let shipbillId = data.shipbillId
        if (data.shipbillIds) {
          shipbillId = data.shipbillIds
        }
        ref && ref.reload({ data: { shipbillId } })
      }
    },
  },
}
</script>

