<template>
  <div>
    <a-card size="small" :bordered="false" class="productInfoList-wrap searchBoxNormal">
      <!-- 搜索条件 -->
      <div ref="tableSearch" class="table-page-search-wrapper">
        <a-form layout="inline" id="productInfoList-form" @keyup.enter.native="$refs.table.refresh(true)">
          <a-row :gutter="15">
            <a-col :md="6" :sm="24">
              <a-form-item label="最近修改时间">
                <rangeDate id="productInfoList-rangeDate" ref="rangeDate" @change="dateChange" />
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="产品编码/原厂编码">
                <a-input id="productInfoList-queryWord" v-model.trim="queryParam.queryWord" allowClear placeholder="请输入产品编码/原厂编码"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="24">
              <a-form-item label="产品名称">
                <a-input id="productInfoList-name" v-model.trim="queryParam.name" allowClear placeholder="请输入产品名称"/>
              </a-form-item>
            </a-col>
            <template v-if="advanced">
              <a-col :md="6" :sm="24">
                <a-form-item label="品牌">
                  <ProductBrand id="productInfoList-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="产品分类">
                  <productTypeAll placeholder="请选择产品分类" @change="changeProductType" v-model="productType" id="productInfoList-productType"></productTypeAll>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="产品状态">
                  <v-select code="PRODUCT_STATUS" id="productInfoList-state" v-model="queryParam.state" allowClear placeholder="请选择产品状态"></v-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="定价状态">
                  <v-select code="PRICING_STATUS" id="productInfoList-pricingState" v-model="queryParam.pricingState" allowClear placeholder="请选择定价状态"></v-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="停产状态">
                  <a-select v-model="queryParam.haltProdFlag" id="productInfoList-haltProdFlag" placeholder="请选择停产状态" allowClear>
                    <a-select-option value="0">
                      启用
                    </a-select-option>
                    <a-select-option value="1">
                      停产
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="是否有产品图片">
                  <a-select id="productInfoList-picFlag" v-model="queryParam.picFlag" allowClear placeholder="请选择是否有产品图片">
                    <a-select-option value="1">
                      有图片
                    </a-select-option>
                    <a-select-option value="0">
                      无图片
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-model-item label="出库仓库">
                  <chooseWarehouse ref="outWarehouse" id="productInfoList-outWarehouse" isPermission v-model="queryParam.outWarehouseSn"></chooseWarehouse>
                </a-form-model-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-model-item label="退货仓库">
                  <chooseWarehouse ref="returnWarehouse" id="productInfoList-returnWarehouse" isPermission v-model="queryParam.returnWarehouseSn"></chooseWarehouse>
                </a-form-model-item>
              </a-col>
            </template>
            <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
              <a-button type="primary" @click="$refs.table.refresh(true)" :disabled="disabled" id="productInfoList-refresh">查询</a-button>
              <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="productInfoList-reset">重置</a-button>
              <a-button
                v-if="$hasPermissions('B_productInfo_export')"
                style="margin-left: 5px"
                type="primary"
                class="button-warning"
                @click="handleExport"
                :disabled="disabled"
                :loading="exportLoading"
                id="productInfoList-export">导出</a-button>
              <a @click="advanced=!advanced" id="productInfoList-isAdvanced" style="margin-left: 5px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card size="small" :bordered="false">
      <a-spin :spinning="spinning" tip="Loading...">
        <!-- 操作按钮 -->
        <div class="table-operator">
          <a-button type="primary" id="productInfoList-add" v-if="$hasPermissions('B_productInfo_add')" @click="handleEdit()">新增</a-button>
          <a-button type="primary" id="productInfoList-addProduct" class="button-info" @click="handleMenuClick({key:'1'})" v-if="$hasPermissions('B_productInfo_batchImport')"> 新增产品导入</a-button>
          <a-button type="primary" id="productInfoList-unline-import" class="button-info" @click="handleMenuClick({key:'3'})" v-if="$hasPermissions('B_onlineProduct_import')"> 上线产品导入</a-button>
          <a-button type="primary" id="productInfoList-import" class="button-info" @click="handleMenuClick({key:'2'})" v-if="$hasPermissions('B_offlineProduct_import')"> 下线产品导入</a-button>
          <a-button
            id="productInfoList-batchAudit"
            type="primary"
            v-if="$hasPermissions('B_productInfo_batchAudit')"
            ghost
            class="button-info"
            :loading="loadingAudit"
            @click="handleBatchAudit"
            style="margin: 0 5px;">批量审核</a-button>
          <a-button
            id="productInfoList-batchLaunch"
            type="primary"
            v-if="$hasPermissions('B_productInfo_batchLaunch')"
            ghost
            :loading="loadingLaunch"
            @click="handleBatchLaunch"
            style="margin: 0 5px;">批量上线</a-button>
          <a-button
            id="productInfoList-batchDownline"
            type="primary"
            v-if="$hasPermissions('B_productInfo_batchDownline')"
            ghost
            :loading="loadingDownline"
            @click="handleBatchDownline"
            style="margin: 0 5px;">批量下线</a-button>
          <span style="margin-left: 8px" v-if="$hasPermissions('B_productInfo_batchAudit') || $hasPermissions('B_productInfo_batchLaunch') || $hasPermissions('B_productInfo_batchDownline')">
            <template v-if="rowSelectionInfo && rowSelectionInfo.selectedRowKeys.length>0">{{ `已选 ${rowSelectionInfo.selectedRowKeys.length} 项` }}</template>
          </span>
        </div>
        <s-table
          class="sTable fixPagination"
          ref="table"
          :style="{ height: tableHeight+70+'px' }"
          size="small"
          :row-selection=" showSelect?{ columnWidth: 40 }:null"
          :rowKey="(record) => record.id"
          @rowSelection="rowSelectionFun"
          :columns="columns"
          :data="loadData"
          :scroll="{ y: tableHeight }"
          :defaultLoadData="false"
          bordered>
          <!-- 自定义表头 -->
          <template slot="arrowFalgTitle">
            <a-tooltip placement="top">
              <template slot="title">
                <span>自有即箭冠产品，非自有即非箭冠产品</span>
              </template>
              自有<a-icon type="question-circle" :style="{ marginLeft: '10px' }" />
            </a-tooltip>
          </template>
          <!-- 判断是否是自有产品 -->
          <template slot="arrowFalg" slot-scope="text, record">
            <span v-if="record.arrowFalg">{{ record.arrowFalg == 1 ? '是' : '否' }}</span>
            <span v-else>--</span>
          </template>
          <!-- 产品分类 -->
          <template slot="productType" slot-scope="text, record">
            <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
            <span v-else>--</span>
          </template>
          <!-- 停产状态 -->
          <template slot="stopStatus" slot-scope="text, record">
            <a-switch
              checkedChildren="启用"
              unCheckedChildren="停产"
              :id="'productInfoList-isEnable'+record.id"
              v-model="record.stopFlag"
              @change="changeFlagHandle(record)" />
          </template>
          <!-- 产品图片 -->
          <template slot="imageUrl" slot-scope="text, record">
            <div v-if="record.productPicList && record.productPicList.length>0">
              <img
                :id="'productInfoList-img'+record.id"
                :src="record.productPicList[0].imageUrl+'?x-oss-process=image/resize,h_30,m_lfit' || ''"
                width="30"
                height="30"
                class="imageUrl"
                @click="inited(record.productPicList)" />
            </div>
            <span v-else>--</span>
          </template>
          <!-- 操作 -->
          <template slot="action" slot-scope="text, record">
            <a-button
              size="small"
              type="link"
              v-if="record.state=='WAIT' && $hasPermissions('B_productInfo_audit')"
              class="button-warning"
              @click="handleAudit(record)"
              :id="'productInfoList-audit-btn'+record.id">审核</a-button>
            <a-button
              size="small"
              type="link"
              v-if="(record.state=='WAIT_ONLINE'||record.state=='OFFLINE') && $hasPermissions('B_productInfo_launch')"
              class="button-primary"
              @click="handleLaunch(record)"
              :id="'productInfoList-launch-btn'+record.id">上线</a-button>
            <a-button
              size="small"
              type="link"
              v-if="record.state=='ONLINE' && $hasPermissions('B_productInfo_downline')"
              class="button-grey"
              @click="handleDownline(record)"
              :id="'productInfoList-downline-btn'+record.id">下线</a-button>
            <a-button
              size="small"
              type="link"
              v-if="$hasPermissions('B_productInfo_edit')"
              class="button-info"
              @click="handleEdit(record)"
              :id="'productInfoList-edit-btn'+record.id">编辑</a-button>
            <a-button
              size="small"
              type="link"
              v-if="$hasPermissions('B_productInfo_detail')"
              class="button-success"
              @click="handleDetail(record)"
              :id="'productInfoList-detail-btn'+record.id">详情</a-button>
            <a-button
              size="small"
              type="link"
              v-if="record.state=='WAIT' && $hasPermissions('B_productInfo_del')"
              class="button-error"
              @click="handleDel(record)"
              :id="'productInfoList-del-btn'+record.id">删除</a-button>
            <span v-if="!(record.state=='WAIT' && $hasPermissions('B_productInfo_audit')) && !((record.state=='WAIT_ONLINE'||record.state=='OFFLINE') && $hasPermissions('B_productInfo_launch')) && !(record.state=='ONLINE' && $hasPermissions('B_productInfo_downline')) && !$hasPermissions('B_productInfo_edit') && !$hasPermissions('B_productInfo_detail') && !(record.state=='WAIT' && $hasPermissions('B_productInfo_del'))">--</span>
          </template>
        </s-table>
      </a-spin>
      <!-- 产品详情 -->
      <product-info-detail-modal v-drag :openModal="openModal" :itemSn="itemSn" @close="closeModal" />
      <!-- 产品下线 -->
      <product-info-offline-modal v-drag :openModal="openOfflineModal" :offlineProductList="offlineProductList" @close="closeOfflineModal" @ok="$refs.table.refresh()" />
      <!-- 导入产品 -->
      <importGuideModal :guideType="guideModalType" :openModal="openGuideModal" @close="openGuideModal=false" @ok="hanldeOk" />
    </a-card>
  </div>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { exportExcel } from '@/libs/JGPrint.js'
// 组件
import { STable, VSelect } from '@/components'
import productInfoDetailModal from './detailModal.vue'
import productInfoOfflineModal from './offlineModal.vue'
import ProductBrand from '@/views/common/productBrand.js'
import productTypeAll from '@/views/common/productTypeAll.js'
import rangeDate from '@/views/common/rangeDate.vue'
import importGuideModal from './importGuideModal.vue'
import chooseWarehouse from '@/views/common/chooseWarehouse'
// 接口
import { productList, productAudit, productBatchAudit, productDel, productOnline, productBatchOnline, productExport, saveBatchImportProduct, saveBatchImportOnlineProduct, importSaveBatch, updateHaltProdFlag } from '@/api/product'
export default {
  name: 'ProductInfoList',
  mixins: [commonMixin],
  components: { STable, VSelect, productInfoDetailModal, productInfoOfflineModal, ProductBrand, productTypeAll, rangeDate, importGuideModal, chooseWarehouse },
  data () {
    return {
      spinning: false,
      advanced: true, // 高级搜索 展开/关闭
      tableHeight: 0, // 表格高度
      disabled: false, //  查询、重置按钮是否可操作
      exportLoading: false, // 导出按钮加载状态
      //  查询条件
      queryParam: {
        haltProdFlag: undefined, // 停产状态
        updateBeginDate: '', // 最近修改时间 开始日期
        updateEndDate: '', // 最近修改时间 结束日期
        name: '', //  产品名称
        queryWord: '', // 产品编码/原厂编码
        productBrandSn: undefined, //  产品品牌
        productTypeSn1: '', //  产品一级分类
        productTypeSn2: '', //  产品二级分类
        productTypeSn3: '', //  产品三级分类
        state: undefined, //  产品状态
        pricingState: undefined, //  定价状态
        picFlag: undefined, // 产品图片
        outWarehouseSn: undefined, // 出库仓库
        returnWarehouseSn: undefined// 退货仓库
      },
      productType: [], // 产品类型

      openGuideModal: false, // 导入产品 弹窗
      columns: [
        { title: '序号', dataIndex: 'no', width: '4%', align: 'center' },
        { title: '创建时间', dataIndex: 'createDate', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品名称', dataIndex: 'name', align: 'left', width: '12%', ellipsis: true, customRender: function (text) { return text || '--' } },
        { title: '产品编码', dataIndex: 'code', width: '10%', align: 'left', customRender: function (text) { return text || '--' } },
        { title: '原厂编码', dataIndex: 'origCode', width: '10%', align: 'left', customRender: function (text) { return text || '--' } },
        { title: '品牌', dataIndex: 'productBrandName', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品分类', scopedSlots: { customRender: 'productType' }, width: '12%', align: 'left' },
        { slots: { title: 'arrowFalgTitle' }, scopedSlots: { customRender: 'arrowFalg' }, width: '5%', align: 'center' },
        { title: '最近修改时间', dataIndex: 'updateDate', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '最新定价时间', dataIndex: 'pricingTime', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '产品状态', dataIndex: 'stateDictValue', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '定价状态', dataIndex: 'pricingStateDictValue', width: '6%', align: 'center', customRender: function (text) { return text || '--' } },
        { title: '停产状态', width: '6%', align: 'center', scopedSlots: { customRender: 'stopStatus' } },
        { title: '产品图片', scopedSlots: { customRender: 'imageUrl' }, width: '5%', align: 'center' },
        { title: '出库仓库', dataIndex: 'outWarehouseName', width: '8%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '退货仓库', dataIndex: 'returnWarehouseName', width: '8%', align: 'center', customRender: function (text) { return text || '--' }, ellipsis: true },
        { title: '操作', scopedSlots: { customRender: 'action' }, width: '10%', align: 'center' }
      ],
      loadingAudit: false, // 审核按钮加载状态
      loadingLaunch: false, // 上线按钮加载状态
      loadingDownline: false, // 下线按钮加载状态
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        this.disabled = true
        this.spinning = true
        // 获取列表数据  有分页
        return productList(Object.assign(parameter, this.queryParam)).then(res => {
          let data
          if (res.status == 200) {
            data = res.data
            // 计算列表序号
            const no = (data.pageNo - 1) * data.pageSize
            for (var i = 0; i < data.list.length; i++) {
              data.list[i].no = no + i + 1
              data.list[i].stopFlag = data.list[i].haltProdFlag == 0
            }
            this.disabled = false
          }
          this.spinning = false
          return data
        })
      },
      openModal: false, //  查看详情  弹框
      itemSn: '', //  当前sn
      openOfflineModal: false, //  下线  弹框
      offlineProductList: [], //  下线 当前所选数据
      pageFromInfo: null, // 页面跳转来源  productInfoAdd
      rowSelectionInfo: null, // 表格选中数据
      guideModalType: ''// 1 新增产品批量导入 2下线产品批量导入
    }
  },
  computed: {
    // 是否显示table选择框
    showSelect () {
      return this.$hasPermissions('B_productInfo_batchAudit') || this.$hasPermissions('B_productInfo_batchLaunch') || this.$hasPermissions('B_productInfo_batchDownline')
    }
  },
  methods: {
    // 批量导入
    handleMenuClick (e) {
      this.guideModalType = e.key
      this.openGuideModal = true
    },
    //  最近修改时间  change
    dateChange (date) {
      this.queryParam.updateBeginDate = date[0] || ''
      this.queryParam.updateEndDate = date[1] || ''
    },
    // 表格选中项
    rowSelectionFun (obj) {
      this.rowSelectionInfo = obj || null
    },
    // 批量导入产品
    hanldeOk (obj) {
      this.spinning = true
      // importSaveBatch 下线导入
      const ajaxName = obj && obj.type && obj.type == 'offline' ? importSaveBatch : (obj && obj.type && obj.type == 'online' ? saveBatchImportOnlineProduct : saveBatchImportProduct)
      ajaxName(obj).then(res => {
        if (res.status == 200) {
          this.resetSearchForm()
        }
        this.spinning = false
      })
    },
    // 审核
    handleAudit (row) {
      const _this = this
      this.$confirm({
        title: '提示',
        content: '确认要审核吗？',
        centered: true,
        onOk () {
          _this.spinning = true
          productAudit({ sn: row.productSn }).then(res => {
            if (res.status == 200) {
              _this.$message.success(res.message)
              _this.$refs.table.refresh()
            }
            _this.spinning = false
          })
        }
      })
    },
    // 批量审核
    handleBatchAudit () {
      const _this = this
      if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
        _this.$message.warning('请在列表勾选后再进行批量操作！')
        return
      }
      let num = 0
      const obj = []
      _this.rowSelectionInfo && _this.rowSelectionInfo.selectedRows.map(item => {
        if (item.state == 'WAIT') {
          num++
          obj.push(item.productSn)
        }
      })
      if (num < 1) {
        _this.$message.warning('当前数据不可操作！')
        return
      }
      this.$confirm({
        title: '提示',
        content: '已选有效数据' + num + '条，确认要批量审核吗？',
        centered: true,
        onOk () {
          _this.loadingAudit = true
          _this.spinning = true
          productBatchAudit(obj).then(res => {
            _this.loadingAudit = false
            if (res.status == 200) {
              _this.$refs.table.clearSelected() // 清空表格选中项
              _this.$message.success(res.message)
              _this.$refs.table.refresh()
            }
            _this.spinning = false
          })
        }
      })
    },
    // 预览图片
    inited (viewer) {
      if (viewer) {
        const imageUrl = []
        viewer.map(item => {
          imageUrl.push(item.imageUrl)
        })
        this.$viewerApi({
          images: imageUrl
        })
      }
    },
    // 改变停产状态
    changeFlagHandle (row) {
      const _this = this
      _this.spinning = true
      updateHaltProdFlag({ productSn: row.productSn, haltProdFlag: row.stopFlag ? 0 : 1 }).then(res => {
        if (res.status == 200) {
          _this.$message.success(res.message)
          _this.$refs.table.refresh()
        }
        _this.spinning = false
      })
    },
    // 批量上线
    handleBatchLaunch () {
      const _this = this
      if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
        _this.$message.warning('请在列表勾选后再进行批量操作！')
        return
      }
      let num = 0
      const obj = []
      _this.rowSelectionInfo && _this.rowSelectionInfo.selectedRows.map(item => {
        if (item.state == 'WAIT_ONLINE' || item.state == 'OFFLINE') {
          num++
          obj.push(item.productSn)
        }
      })
      if (num < 1) {
        _this.$message.warning('当前数据不可操作！')
        return
      }
      this.$confirm({
        title: '提示',
        content: '已选有效数据' + num + '条，确认要批量上线吗？',
        centered: true,
        onOk () {
          _this.loadingLaunch = true
          _this.spinning = true
          productBatchOnline(obj).then(res => {
            _this.loadingLaunch = false
            if (res.status == 200) {
              _this.$refs.table.clearSelected() // 清空表格选中项
              _this.$message.success(res.message)
              _this.$refs.table.refresh()
            }
            _this.spinning = false
          })
        }
      })
    },
    // 批量下线
    handleBatchDownline () {
      const _this = this
      if (!_this.rowSelectionInfo || (_this.rowSelectionInfo && _this.rowSelectionInfo.selectedRowKeys.length < 1)) {
        _this.$message.warning('请在列表勾选后再进行批量操作！')
        return
      }
      let num = 0
      _this.offlineProductList = []
      _this.rowSelectionInfo && _this.rowSelectionInfo.selectedRows.map(item => {
        if (item.state == 'ONLINE') {
          num++
          _this.offlineProductList.push({ productSn: item.productSn, code: item.code, commonProductList: [] })
        }
      })
      if (num < 1) {
        _this.$message.warning('当前数据不可操作！')
        return
      }
      this.openOfflineModal = true
    },
    //  重置
    resetSearchForm () {
      this.queryParam.name = ''
      this.queryParam.queryWord = ''
      this.queryParam.productBrandSn = undefined
      this.queryParam.productTypeSn1 = ''
      this.queryParam.productTypeSn2 = ''
      this.queryParam.productTypeSn3 = ''
      this.queryParam.state = undefined
      this.queryParam.pricingState = undefined
      this.queryParam.picFlag = undefined
      this.queryParam.haltProdFlag = undefined
      this.queryParam.outWarehouseSn = undefined
      this.queryParam.returnWarehouseSn = undefined
      this.productType = []
      if (this.advanced) {
        this.$refs.rangeDate.resetDate()
        this.queryParam.updateBeginDate = ''
        this.queryParam.updateEndDate = ''
      }
      this.$refs.table.refresh(true)
    },
    //  新增/编辑
    handleEdit (row) {
      if (row) { //  编辑
        this.$router.push({ path: `/productManagement/productInfo/edit/${row.id}/${row.productSn}` })
      } else { //  新增
        this.$router.push({ path: '/productManagement/productInfo/add' })
      }
    },
    // 上线
    handleLaunch (row) {
      const _this = this
      this.$confirm({
        title: '提示',
        content: '确认要上线吗？',
        centered: true,
        onOk () {
          _this.spinning = true
          productOnline({ sn: row.productSn }).then(res => {
            if (res.status == 200) {
              _this.$message.success(res.message)
              _this.$refs.table.refresh()
            }
            _this.spinning = false
          })
        }
      })
    },
    // 下线
    handleDownline (row) {
      this.offlineProductList.push({ productSn: row.productSn, code: row.code, commonProductList: [] })
      this.openOfflineModal = true
    },
    // 删除
    handleDel (row) {
      const _this = this
      this.$confirm({
        title: '提示',
        content: '确认要删除吗？',
        centered: true,
        onOk () {
          _this.spinning = true
          productDel({ sn: row.productSn }).then(res => {
            if (res.status == 200) {
              _this.$message.success(res.message)
              _this.$refs.table.refresh()
            }
            _this.spinning = false
          })
        }
      })
    },
    //  详情
    handleDetail (row) {
      this.itemSn = row.productSn
      this.openModal = true
    },
    //  关闭弹框
    closeModal () {
      this.itemSn = ''
      this.openModal = false
    },
    //  关闭下线弹框
    closeOfflineModal () {
      this.$refs.table.clearSelected() // 清空表格选中项
      this.offlineProductList = []
      this.openOfflineModal = false
    },
    //  导出
    handleExport () {
      const _this = this
      const params = this.queryParam
      this.spinning = true
      exportExcel(productExport, params, '产品列表', function () {
        _this.spinning = false
      })
    },
    //  产品分类  change
    changeProductType (val, opt) {
      this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
      this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
      this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
    },
    // 初始化
    pageInit () {
      const _this = this
      this.$nextTick(() => { // 页面渲染完成后的回调
        _this.setTableH()
      })
    },
    // 计算表格高度
    setTableH () {
      const tableSearchH = this.$refs.tableSearch.offsetHeight
      this.tableHeight = window.innerHeight - tableSearchH - 240
    }
  },
  watch: {
    // 监听 展开关闭时表格高度变化
    advanced (newValue, oldValue) {
      const _this = this
      this.$nextTick(() => { // 页面渲染完成后的回调
        _this.setTableH()
      })
    },
    '$store.state.app.winHeight' (newValue, oldValue) { //  窗口变更时，需同时更改表格高度
      this.setTableH()
    }
  },
  mounted () {
    if (!this.$store.state.app.isNewTab) { // 页签刷新时调用
      this.pageInit()
      this.resetSearchForm()
    }
  },
  activated () {
    const _this = this
    // 如果是新页签打开，则重置当前页面
    if (this.$store.state.app.isNewTab) {
      this.pageInit()
      this.resetSearchForm()
    }
    // 仅刷新列表，不重置页面
    if (this.$store.state.app.updateList) {
      this.pageInit()
      setTimeout(() => { //  解决 编辑页 返回列表 请求先前页的数据。新增页 返回列表 请求第一页的数据。延迟是为了解决先执行activated 后执行beforeRouteEnter的问题
        if (_this.pageFromInfo && _this.pageFromInfo.name == 'productInfoAdd') {
        	_this.resetSearchForm()
        } else {
        	_this.$refs.table.refresh()
        }
      }, 100)
    }
  },
  beforeRouteEnter (to, from, next) {
    next(vm => {
      vm.pageFromInfo = from
    })
  }
}
</script>
