/*
 *@description：所有订单
 *@author: hudw
 *@date: 2022-06-16 11:35:37
*/
<template>
  <div class="pages">

    <orderView
      :goodsTableColumn="v_goodsTableColumn"
      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"
        :exportUrls="exportUrls"
        :options="options"
        :activeID="mainId"
        :tableColumnsList="[null,ColumnsList]"
        :tableExtendedField="tableExtendedField"
        @clickRow="handleRowClick"
        @selectChange="selectChange"
        :operation="false"
        @view="handleView"
        @print="handPrint"
      >

      </mainTable>
      <a-row :gutter="10">
        <a-col :span="12">
          <p-card :bordered="false" title="商品信息" style="min-height: 300px">
            <goodsTable ref="goodsTable" :tableColumnsList="m_tableColumnsList" :url="goodsTableUrl" :options="options" :activeID="mainId" :tableExtendedField="tableExtendedField" />
          </p-card>
        </a-col>
        <a-col :span="12">
          <p-card :bordered="false" title="包裹信息" style="min-height: 300px">
            <parcelTable ref="parcelTable" :url="packageTableUrl" :options="options" :activeID="mainId" :tableExtendedField="tableExtendedField"/>
          </p-card>
        </a-col>
      </a-row>
    </div>
  </div>
</template>
<script>
import useMixin from '../$common/mixins/useMixin.js'
import dictionary from '../$common/mixins/dictionary.js'
import { mainTableInfoUrl, goodsTableUrl, packageTableUrl, printUrl, exportUrls } from './api.js'
import { setViewGoodsColumns,setGoodsColumns } from './goodsTableConfig.js'
import { setMainColumns } from './tableConfig'//运单模式

export default {
  mixins: [useMixin, dictionary],
  data() {
    const goods = {
      url: goodsTableUrl,
    }
    const parcel = {
      url: packageTableUrl,
    }
    this.$watch('goodsExtendedField', (value) => {
      if (value.length > 0) {
        this.m_tableColumnsList = setGoodsColumns(this, value)
      }
    });
    this.$watch('formExtendedField.formTable', (value) => {
      //运单详情商品扩展字段
      if (value.length > 0) {
        this.v_goodsTableColumn = setViewGoodsColumns(this, value)
      }
    });
    return {
      ColumnsList:setMainColumns,
      m_tableColumnsList:setGoodsColumns(this),//明细表商品配置
      v_goodsTableColumn:setViewGoodsColumns(this),
      goods,
      exportUrls,
      parcel,
      printUrl,
      goodsTableUrl,
      packageTableUrl,
      card_title: '',
      mainTableInfoUrl,
      visible: false,
      updateFormItems: null,
      detailsState: 0 /**0=不显示, 1=新建，2=修改 ，3=查看 ，4=复制  */,
    }
  },
  mounted() {},
  methods: {

    selectChange(selectKey, selectData) {
      this.mainsSelectedRowKeys=selectKey
      this.exportUrls.ids=[]
      this.mainsSelectedRowKeys = selectData.map((item) => {
        this.exportUrls.ids.push(item.shipbillId)
        return item.shipbillId
      },this)
    },

    handleRowClick(event, key, data) {
      event.stopPropagation()
      this.mainCurrent = null
      this.mainId = ''
      this.clearChildrenTableAll()
      if (data) {
        this.mainCurrent = data
        this.mainId = key
        const { goodsTable, parcelTable } = this.$refs
        goodsTable.reload({ data: { shipbillId: data.shipbillId } })
        parcelTable.reload({ data: { shipbillId: data.shipbillId } })
      }
    },
  },
}
</script>

