index.vue 6.71 KB
<template>
  <div>
    <div class="container">
      <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
      <div class="table-header">
        <GLButton type="primary" size="small" @click="handleEdit('add')" fn="新增">新增商品</GLButton>
        <el-button type="primary" size="small" @click="handleExport">导出</el-button>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="commofityRef" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>

<script>
import url from '@/assets/empty.png'
import constData from './constant/data'
import baseList from './constant/baseList'
import * as dayjs from 'dayjs'
export default {
  name: 'commodity',
  data() {
    return {
      size: 'small',
      url: url,
      searchForm: {
        goodsName: '',
        goodsCode: '',
        merchantIdList: [],
        type: '',
        goodsType: ''
      },
      tableSearchForm: {},
      searchFormData: constData.commodityObj.searchFormData,
      // 表格
      getListApi: this.$apis.commodity.getListApi,
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: {
          width: '170'
        },
        tableColumns: [
          {
            label: '商品名称',
            prop: 'goodsName',
            width: '200'
          },
          {
            label: '商品编码',
            prop: 'type',
            width: '110'
          },
          {
            label: '所属系列',
            prop: 'goodsCodeName',
            width: '100'
          },
          {
            label: '产品类型',
            prop: 'baseProductFlag',
            formatter: cellValue => {
              let list = []
              cellValue.baseProductFlag == 'Y' ? list.push('基础产品') : ''
              cellValue.upgradeProductFlag == 'Y' ? list.push('升级产品') : ''
              return list.join(',')
            }
          },
          {
            label: '售价/元',
            prop: 'sellPrice'
          },
          {
            label: '最低售价/元',
            prop: 'minSellPrice'
          },
          {
            label: '赠送成本',
            prop: 'giftCost'
          },
          {
            label: '产品成本',
            prop: 'productCost'
          },
          {
            label: '使用门店',
            prop: '',
            formatter: cellValue => {
              return cellValue.merchantList?.map(item => item.merchantName).join(',')
            },
            width: 200,
            line: 1
          },
          {
            label: '创建日期',
            prop: 'createDate',
            width: '155px',
            formatter: cellValue => {
              return cellValue.createdDate ? dayjs(cellValue.createdDate).format('YYYY-MM-DD') : ''
            }
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      // 表格按钮
      tableButtonList: [
        {
          type: 'GLButton',
          name: '查看',
          attrs: {
            type: 'text',
            fn: '查看'
          },
          listeners: {
            click: row => this.handleEdit('detail', row)
          }
        },
        {
          type: 'GLButton',
          name: '编辑',
          attrs: {
            type: 'text',
            fn: '编辑'
          },
          listeners: {
            click: row => this.handleEdit('edit', row)
          }
        },
        {
          type: 'GLButton',
          name: '删除',
          attrs: {
            type: 'text',
            fn: '删除'
          },
          listeners: {
            click: row => this.handleDelete(row)
          }
        }
      ],
      // 基本数据
      baseData: {
        merchantList: [],
        brandList: [],
        typeList: baseList.typeList,
        goodsSeriesList: []
      },
      imgVisible: false,
      previewImgUrl: ''
    }
  },

  mounted() {
    this.getGoodsSeries()
    this.getMerchantList()
    this.$utils.getOptionsList(this, 'searchFormData')
  },
  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      switch (params.goodsType) {
        case 1:
          params.baseProductFlag = 'Y'
          break
        case 2:
          params.upgradeProductFlag = 'Y'
          break
      }
      return params
    },
    beforeSearchFn() {
      return new Promise(async (resolve, reject) => {
        this.tableSearchForm = this.getParams()
        resolve()
      })
    },
    /**
     * @param {Sting} editType add/edit/detail
     * @param {Object} info
     */
    handleEdit(editType, info) {
      var titleObj = {
        add: '新建商品',
        edit: '编辑商品',
        detail: '查看商品'
      }
      let params = {
        editType,
        info,
        $title: encodeURI(titleObj[editType])
      }
      this.$router.push({
        path: editType == 'detail' ? '/commodity/commodityDetail' : '/commodity/editCommodity',
        query: params
      })
    },

    getGoodsSeries() {
      this.$apis.commodity.getGoodsSeries({}).then(res => {
        this.baseData.goodsSeriesList = res
        this.$utils.getOptionsList(this, 'searchFormData', true, 'goodsCode')
      })
    },

    getMerchantList() {
      let params = {
        currentPage: 1,
        pageSize: 99999
      }
      this.$apis.commodity.getSimpleMerchantList(params).then(res => {
        this.baseData.merchantList = res.list
        this.$utils.getOptionsList(this, 'searchFormData', true, 'merchantIdList')
      })
    },

    // 删除
    handleDelete(info) {
      this.$utils.secondConfirm(this, '删除提示', '删除后不可恢复,是否确定删除?', 'commodity', 'deleteGoods', { upgradeGoodsId: info.upgradeGoodsId })
    },

    // 导出
    handleExport() {
      let params = this.getParams()
      this.$apis.commodity.exportGoods(params).then(res => {
        this.$utils.aToExport(res.data)
      })
    },

    handleSearch() {
      this.$refs.commofityRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        goodsName: '',
        goodsCode: '',
        merchantIdList: [],
        type: '',
        goodsType: ''
      }
      this.handleSearch()
    }
  }
}
</script>
<style scoped></style>