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

      <!-- 表格区域 开始 -->
      <GLTable ref="commofityRef" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <div slot="merchantName" slot-scope="scope">
          <el-tooltip v-if="scope.scope.merchantList.length > 0" placement="top" effect="light">
            <div slot="content">
              <div class="text-3 font-12 weight-6" style="line-height:24px">上家门店</div>
              <div class="merchant-wrap">
                <div class="text-6 font-12" style="line-height:24px" v-for="item in scope.scope.merchantList" :key="item">{{ item.merchantName }}</div>
              </div>
            </div>
            <div class="use-store">
              <img src="@/assets/store.png" />
              x {{ scope.scope.merchantList.length }}
            </div>
          </el-tooltip>
          <span v-else>--</span>
        </div>
        <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: '',
        proType: '',
        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: '150',
            line: 1
          },
          {
            label: '商品编码',
            prop: 'type',
            width: '110',
            line: 1
          },
          {
            label: '所属分类',
            prop: 'goodsTypeName',
            width: '150'
          },
          {
            label: '品牌方',
            prop: 'brandMerchantName'
          },
          {
            label: '供应方',
            prop: 'supplierName'
          },
          {
            label: '产品类型',
            prop: 'baseProductFlag',
            width: 120,
            formatter: cellValue => {
              let list = []
              cellValue.baseProductFlag == 'Y' ? list.push('基础产品') : ''
              cellValue.upgradeProductFlag == 'Y' ? list.push('升级产品') : ''
              return list.join(',')
            }
          },
          {
            label: '售价/元',
            prop: 'sellPrice',
            width: 100
          },
          {
            label: '最低售价/元',
            prop: 'minSellPrice',
            width: 120
          },
          {
            label: '赠送成本',
            prop: 'giftCost',
            width: 120
          },
          {
            label: '产品成本',
            prop: 'productCost',
            width: 120
          },
          {
            label: '质保年限/年',
            prop: 'warrantyPeriod',
            width: 120
          },
          {
            label: '使用门店',
            prop: '',
            addHtml: 'merchantName',
            // formatter: cellValue => {
            //   return cellValue.merchantList.length==1?cellValue.merchantList?.map(item => item.merchantName).join(','):cellValue.merchantList.length
            // },
            width: 150
            // 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: [],
        goodsCategoryList: []
      },
      imgVisible: false,
      previewImgUrl: ''
    }
  },

  mounted() {
    this.getGoodsSeries()
    this.getMerchantList()
    this.getGoodsCategory()
    this.$utils.getOptionsList(this, 'searchFormData')
  },
  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      switch (params.proType) {
        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')
      })
    },

    getGoodsCategory() {
      this.$apis.commodity.getGoodsCategory({}).then(res => {
        this.baseData.goodsCategoryList = res
        this.$utils.getOptionsList(this, 'searchFormData', true, 'goodsType')
      })
    },
    // 删除
    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: '',
        proType: '',
        goodsType: ''
      }
      this.handleSearch()
    }
  }
}
</script>
<style scoped lang="scss">
.container {
  padding: 20px;
}
.use-store {
  display: flex;
  font-size: 14px;
  color: #5850ff;
  align-items: center;
  img {
    width: 14px;
    height: 12.98px;
    margin-right: 8px;
  }
}
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  margin-top: 20px;
  h2 {
    font-weight: 600;
    font-size: 16px;
    color: #333;
  }
}
.merchant-wrap {
  max-height: 200px;
  overflow: scroll;
}
</style>