<template>
  <div class="mod-config">
    <el-form :inline="true" label-position="top" :model="searchData">
      <el-form-item :label="'BU'">
        <el-select v-model="searchData.buNo" placeholder="请选择" clearable style="width: 130px">
          <el-option
            v-for = "i in buList"
            :key = "i.buNo"
            :label = "i.buDesc"
            :value = "i.buNo">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'ERP物料编码'">
        <el-input v-model="searchData.partNo" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'SKU'">
        <el-input v-model="searchData.sku" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'物料描述'">
        <el-input v-model="searchData.partDesc" clearable style="width: 210px"></el-input>
      </el-form-item>
      <el-form-item :label="'录入时间'">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item style="margin-top: 23px;">
        <label style="margin-left: 0px;font-size: 19px">&#10142</label>
      </el-form-item>
      <el-form-item :label="'To '">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item :label="' '">
        <el-button @click="searchTable">查询</el-button>
        <!--        <el-button type="primary" @click="delModal()">删除</el-button>-->
        <el-button type="primary" @click="openImportDialog">导入</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ "导出" }}
        </download-excel>
      </el-form-item>
    </el-form>

    <el-table
      @row-click="changeData"
      highlight-current-row
      :height="height"
      :data="dataList"
      ref="mainTable"
      border
      v-loading="dataListLoading"
      style="width: 100%;">
      <el-table-column
        header-align="center"
        align="center"
        width="80"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" @click="hsCodeModel(scope.row)">维护</a>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]"
                                             style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 1000]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <el-tabs style="font-size: 12px;min-height: 200px" class="customer-tab" v-model="activeName"   type="border-card" @tab-click="tabClick" >
      <el-tab-pane label="基本信息" name="attribute">
        <order-attribute ref="dialogAttribute" :site="currentRow.site" :buNo="currentRow.buNo" :order-no="currentRow.partNo" :code-no="'BG001'" :brand="currentRow.brand" :function-type="'ECSSPART'"></order-attribute>
      </el-tab-pane>
    </el-tabs>

    <el-dialog title="维护HS Code" :close-on-click-modal="false" v-drag :visible.sync="hsCodeModelFlag" width="500px">
      <el-form  label-position="top"  style="margin-left: 7px;margin-top: -5px;">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item :label="'物料编码:'">
              <el-input v-model="hsCodeModelData.partNo" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'物料名称'" >
              <el-input v-model="hsCodeModelData.partDesc" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item >
              <template #label>
                <span slot="label" style="" class="big-label">
                  <a href="#" @click="hsCodeFlag=true">品名</a>
                </span>
              </template>
              <el-input v-model="hsCodeModelData.hsCodeDesc" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="'HS Code'" >
              <el-input v-model="hsCodeModelData.hsCode" disabled ></el-input>
            </el-form-item>
          </el-col>
<!--          <el-col :span="12">
            <el-form-item >
              <template #label>
                <span slot="label" style="" class="big-label">
                  <a href="#" @click="palletFlag=true">栈板</a>
                </span>
              </template>
              <el-input v-model="hsCodeModelData.palletType" disabled ></el-input>
            </el-form-item>
          </el-col>-->
          <el-col :span="12">
            <el-form-item>
              <template #label>
                <span slot="label" style="" class="big-label">
                  <a href="#" @click="packageFlag=true">包装箱</a>
                </span>
              </template>
              <el-input v-model="hsCodeModelData.packageNo" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'长(M)'">
              <el-input v-model="hsCodeModelData.length" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'宽(M)'">
              <el-input v-model="hsCodeModelData.width" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'高(M)'">
              <el-input v-model="hsCodeModelData.height" disabled ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="'体积(M³)'">
              <el-input v-model="packageVolume" disabled ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveHSCode()">保存</el-button>
        <el-button type="primary" @click="hsCodeModelFlag=false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="品名" @close="closeHsCodeDialog" @open="openHsCodeDialog" :visible.sync="hsCodeFlag" width="559px" v-drag>
      <el-form inline="inline" label-position="top" :model="hsCodeData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="品名">
          <el-input v-model="hsCodeData.hsCode" clearable style="width: 110px"></el-input>
        </el-form-item>
        <el-form-item label=" ">
          <el-button type="primary" style="padding: 3px 12px" @click="searchHsCodeList()">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :height="height + 110"
        :data="hsCodeList"
        stripe
        highlight-current-row
        border
        @row-dblclick="hsCodeRowDblclick"
        style="width: 100%;">
        <el-table-column
          prop="BuNo"
          header-align="center"
          align="center"
          label="Bu">
        </el-table-column>
        <el-table-column
          prop="hsCodeDesc"
          header-align="center"
          align="center"
          label="品名">
        </el-table-column>
        <el-table-column
          prop="HsCode"
          header-align="center"
          align="center"
          label="HS Code">
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button @click="hsCodeFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="栈板" @close="closePalletDialog" @open="openPalletDialog" :visible.sync="palletFlag" width="559px" v-drag>
      <el-form inline="inline" label-position="top" :model="palletData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="栈板类型">
          <el-input v-model="palletData.palletType" clearable style="width: 110px"></el-input>
        </el-form-item>
        <el-form-item label=" ">
          <el-button type="primary" style="padding: 3px 12px" @click="searchPalletList()">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :height="height + 110"
        :data="palletList"
        stripe
        highlight-current-row
        border
        @row-dblclick="palletRowDblclick"
        style="width: 100%;">
        <el-table-column
          prop="BuNo"
          header-align="center"
          align="center"
          label="BuNo">
        </el-table-column>
        <el-table-column
          prop="palletType"
          header-align="center"
          align="center"
          label="栈板类型">
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button @click="palletFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <el-dialog title="包装箱" @close="closePackageDialog" @open="openPackageDialog" :visible.sync="packageFlag" width="559px" v-drag>
      <el-form inline="inline" label-position="top" :model="packageData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="包装箱类型">
          <el-input v-model="packageData.packageType" clearable style="width: 110px"></el-input>
        </el-form-item>
        <el-form-item label=" ">
          <el-button type="primary" style="padding: 3px 12px" @click="searchPackageList()">查询</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :height="height + 110"
        :data="packageList"
        stripe
        highlight-current-row
        border
        @row-dblclick="packageRowDblclick"
        style="width: 100%;">
        <el-table-column
          prop="BuNo"
          header-align="center"
          align="center"
          label="BuNo">
        </el-table-column>
        <el-table-column
          prop="packageType"
          header-align="center"
          align="center"
          label="包装箱类型">
        </el-table-column>
        <el-table-column
          prop="packageNo"
          header-align="center"
          align="center"
          width="140"
          label="包装箱编码">
        </el-table-column>
        <el-table-column
          prop="length"
          header-align="center"
          align="center"
          label="长(M)">
        </el-table-column>
        <el-table-column
          prop="width"
          header-align="center"
          align="center"
          label="宽(M)">
        </el-table-column>
        <el-table-column
          prop="height"
          header-align="center"
          align="center"
          label="高(M)">
        </el-table-column>
      </el-table>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button @click="packageFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 导入弹窗 -->
    <part-hs-code-import ref="partHsCodeImport" @refreshTable="searchTable"></part-hs-code-import>

  </div>
</template>

<script>
  import {
    partInformationHsCode,savePartHSCode,
    searchHsCodeList,searchPalletList,searchPackageList
  }from "@/api/ecss/ecss.js"
  import {} from "@/api/sysLanguage.js"
  import {getBuList}from  '@/api/factory/site.js'
  import orderAttribute from "./orderProperties"
  import partHsCodeImport from "./partHsCodeImport"
  export default {
    name: "null",
    components:{
      orderAttribute,
      partHsCodeImport,
    },
    data() {
      return {
        activeName:'attribute',
        hsCodeFlag:false,
        palletFlag:false,
        packageFlag:false,
        hsCodeData:{},
        palletData:{},
        packageData:{},
        hsCodeList:[],
        palletList:[],
        packageList:[],
        buList:[],
        // 导出
        exportData: [],
        exportName: '物料HsCode' + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ['物料HsCode'],
        exportFooter: [],
        pageIndex: 1,
        pageSize: 100,
        totalPage: 0,
        height: 200,
        dataList:[],
        dataListLoading: false,
        searchData: {
          site: '',
          userName: this.$store.state.user.name,
          buNo: '',
          partNo: '',
          startDate: '',
          endDate: '',
          partDesc: '',
          page: 1,
          limit: 10

        },
        buttons:{
          search:'查询',
        },
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1Bu',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'buDesc',
            headerAlign: 'center',
            align: 'center',
            columnLabel: 'BU',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1PartNo',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'partNo',
            headerAlign: 'center',
            align: 'left',
            columnLabel: 'ERP物料编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1PartNo',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'sku',
            headerAlign: 'center',
            align: 'left',
            columnLabel: 'SKU',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 120
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1PartDesc',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'partDesc',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '物料描述',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 300
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1HsCode',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'hsCode',
            headerAlign: 'center',
            align: 'left',
            columnLabel: 'HS Code',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1HsCodeDesc',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'hsCodeDesc',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '品名',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 200
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1PartDesceEn',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'partDesceEn',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '物料描述（英文）',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 300
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1Spec',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'spec',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '规格',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 300
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1ActiveDesc',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'activeDesc',
            headerAlign: 'center',
            align: 'center',
            columnLabel: '是否在用',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 80
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1PartType2Desc',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'partType2Desc',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '零件类型',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1UmId',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'umId2',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '计量单位编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1UmName',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'umName',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '计量单位名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1FamilyID',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'familyID',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '物料分类编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1FamilyName',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'familyName',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '物料分类名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1OtherGroup1',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'productGroupId1',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '商品组1编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1OtherGroupName1',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'productGroupName1',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '商品组1名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1OtherGroup2',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'productGroupId2',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '商品组2编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1OtherGroupName2',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'productGroupName2',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '商品组2名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1OtherGroup3',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'productGroupId3',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '商品组3编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 100
          },
          {
            userId: this.$store.state.user.name,
            functionId: 801005,
            serialNumber: '801005Table1OtherGroupName3',
            tableId: '801005Table1',
            tableName: '物料信息表',
            columnProp: 'productGroupName3',
            headerAlign: 'center',
            align: 'left',
            columnLabel: '商品组3名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 150
          },
        ],
        hsCodeModelFlag:false,
        hsCodeModelData:{
          site: '',
          buNo: '',
          buDesc: '',
          partNo: '',
          partDesc: '',
          hsCode:'',
          hsCodeDesc:'',
          packageNo:'',
          length: '',
          width: '',
          height: ''
        },
        currentRow:{
          site:'',
          partNo:'',
          buNo:'',
          recordType:'',
          hsCodeNo:''
        }
      }
    },
    computed: {
      /**
       * 计算包装箱体积 (长 * 宽 * 高)
       */
      packageVolume() {
        const length = parseFloat(this.hsCodeModelData.length) || 0
        const width = parseFloat(this.hsCodeModelData.width) || 0
        const height = parseFloat(this.hsCodeModelData.height) || 0

        if (length > 0 && width > 0 && height > 0) {
          return (length * width * height).toFixed(6)
        }
        return ''
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.height = (window.innerHeight - 240)/2;
      })
    },
    methods: {
      openHsCodeDialog () {
        //请求
        this.searchHsCodeList();
      },
      closeHsCodeDialog () {
        this.hsCodeList = []
        this.hsCodeFlag = false
      },
      searchHsCodeList () {
        this.hsCodeData.buNo = this.hsCodeModelData.buNo
        searchHsCodeList(this.hsCodeData).then(({data}) => {
          if (data && data.code === 0){
            this.hsCodeList = data.rows;
          }
        })
      },
      hsCodeRowDblclick (row) {
        this.hsCodeModelData.hsCodeDesc = row.hsCodeDesc
        this.hsCodeModelData.hsCode = row.HsCode
        this.hsCodeFlag = false
      },

      openPalletDialog () {
        //请求
        this.searchPalletList();
      },
      closePalletDialog () {
        this.palletList = []
        this.palletFlag = false
      },
      searchPalletList () {
        this.palletData.buNo = this.hsCodeModelData.buNo
        searchPalletList(this.palletData).then(({data}) => {
          if (data && data.code === 0){
            this.palletList = data.rows;
          }
        })
      },
      palletRowDblclick (row) {
        this.hsCodeModelData.palletId = row.palletId
        this.hsCodeModelData.palletType = row.palletType
        this.palletFlag = false
      },

      openPackageDialog () {
        //请求
        this.searchPackageList();
      },
      closePackageDialog () {
        this.packageList = []
        this.packageFlag = false
      },
      searchPackageList () {
        this.packageData.buNo = this.hsCodeModelData.buNo
        searchPackageList(this.packageData).then(({data}) => {
          if (data && data.code === 0){
            this.packageList = data.rows;
          }
        })
      },
      packageRowDblclick (row) {
        this.hsCodeModelData.packageNo = row.packageNo
        this.packageFlag = false
      },

      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.searchTable()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.searchTable()
      },
      tabClick (tab, event) {
        // 刷新列表数据
        this.refreshCurrentTabTable()
      },
      searchTable(){
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        partInformationHsCode(this.searchData).then(({data}) => {
          //区分请求成功和失败的状况
          if (data && data.code == 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
            if(this.dataList.length>0){
              this.$refs.mainTable.setCurrentRow(this.dataList[0]);
              this.changeData(this.dataList[0])
            }else {
              this.changeData(null)
            }
          } else {
            this.dataList = [];
          }
        });
      },
      refreshCurrentTabTable(){
        if(this.currentRow===''||this.currentRow===null){
          this.currentRow={site:'',partNo:'',buNo:'',recordType:''}
        }
        // 刷新基本信息组件
        if (this.activeName === 'attribute' && this.$refs.dialogAttribute) {
          this.$nextTick(() => {
            this.$refs.dialogAttribute.getProperties()
          })
        }
      },
      async createExportData () {
        this.searchData.limit = -1
        this.searchData.page = 1
        await partInformationHsCode(this.searchData).then(({data}) => {
          this.resultList = data.page.list
        })
        return this.resultList
      },

      startDownload () {},

      finishDownload () {},

      fields () {
        let json = '{'
        this.columnList.forEach((item, index) => {
          if (index == this.columnList.length - 1) {
            json += '"' + item.columnLabel + '"' + ':' + '"' + item.columnProp + '"'
          } else {
            json += '"' + item.columnLabel + '"' + ':' + '"' + item.columnProp + '"' + ','
          }
        })
        json += '}'
        let s = eval('(' + json + ')')
        return s
      },
      getBu () {
        let tempData = {
          username: this.$store.state.user.name,
        }
        getBuList(tempData).then(({data}) => {
          if (data.code === 0) {
            this.buList = data.row2
          }
        })
      },
      /**
       * 打开导入弹窗
       */
      openImportDialog() {
        this.$refs.partHsCodeImport.init()
      },
      hsCodeModel(row){
        this.hsCodeModelData=JSON.parse(JSON.stringify(row))
        this.hsCodeModelData.length = row.boxLength/100
        this.hsCodeModelData.width = row.boxWidth/100
        this.hsCodeModelData.height = row.boxHeight/100
        this.hsCodeModelFlag=true
      },
      changeData(row){
        this.currentRow = JSON.parse(JSON.stringify(row));
        this.refreshCurrentTabTable ();
      },
      saveHSCode(){
        if(this.hsCodeModelData.hsCode===''||this.hsCodeModelData.hsCode==null){
          this.$alert('请输入HS Code！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        if(this.hsCodeModelData.hsCodeDesc===''||this.hsCodeModelData.hsCodeDesc==null){
          this.$alert('请输入品名！', '错误', {
            confirmButtonText: '确定'
          })
          return false
        }
        savePartHSCode(this.hsCodeModelData).then(({data}) => {
          if (data && data.code === 0) {
            this.searchTable()
            this.hsCodeModelFlag=false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },
    },
    activated() {
      // 检查是否有新的sku参数
      if (this.$route.query.sku && this.$route.query.sku !== this.searchData.sku) {
        this.searchData.sku = this.$route.query.sku;
      }
      this.searchTable()
    },
    created() {
      this.getBu();
      // 接收来自路由的sku参数
      if (this.$route.query.sku) {
        this.searchData.sku = this.$route.query.sku;
      }
    }
  }
</script>

<style scoped>

</style>
