index.vue 11.9 KB
<template>
    <div class="goods-list-cntr">
        <!-- <GLTabs v-model="activeName" :tabPaneList="tabPaneList" @tab-click="handleClick"></GLTabs> -->
        <div class="table-wrap">
            <GLCombiForm ref="showSearch" class="search-wrap" :rowNumber="1" :formObj="tableSearchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset">
              <div slot="categorySlot">
                <brandCascader ref="cascaderRef" @clickItem="selectCategory" class="category-slot-class"></brandCascader>
              </div>
            </GLCombiForm>
            <div class="operate-wrap">
                <span class="table-title">发现商品列表</span>
                <el-button class="operate-btn" type="primary" size="small" @click="handleAdd">新增商品</el-button>
            </div>
            <GLTable ref="channelRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm" :beforeSearchFn="beforeSearchFn" :tableParams="tableParams" :pageConf="pageConf" @setTableFinishFun="setTableFinishFun">
                <div slot="imageSlot" class="table-image" slot-scope="scope">
                    <el-popover placement="top" width="160" trigger="hover" popper-class="table-popover-block">
                        <img class="table-popover-img" :src="scope.scope.goodsImage" />
                        <img class="img-36 pointer" slot="reference" :src="scope.scope.goodsImage" />
                    </el-popover>
                </div>
                <div slot="statusSlot" slot-scope="scope">
                    <span :class="['status', scope.scope.goodsStatus==1 ? 'success-status': 'error-status']"></span>
                    <span>{{scope.scope.goodsStatus==1 ? '上架' : '下架' }}</span>
                </div>
                <div slot="merchantPriceSlot" slot-scope="scope">
                  <template v-if="scope.scope.merchantList && scope.scope.merchantList.length > 1">
                    <span>{{ filterData(scope.scope).slice(0, 1).join('、') }}</span>
                    <el-popover
                      placement="top"
                      width="400"
                      trigger="hover">
                      <div v-for="(item,index) in filterData(scope.scope)" :key="index">
                        {{item}}
                      </div>
                      <span class="more-info" slot="reference">...[{{ scope.scope.merchantList.length }}]</span>
                    </el-popover>
                  </template>
                  <template v-else>
                    <span v-if="!scope.scope.merchantList || !scope.scope.merchantList.length">--</span>
                    <span v-else>{{ filterData(scope.scope).join('、') }}</span>
                  </template>
                </div>
                <div class="table-btns" slot="auth-button" slot-scope="scope">
                    <GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="4"></GLTableButton>
                </div>
            </GLTable>
        </div>
    </div>
  </template>
  
  <script>
  import url from '@/assets/empty.png'
  import brandCascader from './components/brandCascader'
  export default {
    name: 'App',
    components: {
        brandCascader,
    },
    data() {
      return {
        tableSearchForm: {
          channelName: '',
          createDate: [],
          associationClassifyFirstId: '',
          associationClassifySecondId: '',
          merchantName: ''
        },
        tabPaneList: [{name: 'sa', label: '配置升级'}, {name: 'sa', label: '车主优选'}],
        buttonList: [
          {
            type: 'el-button',
            name: '查看',
            attrs: {
              type: 'text',
              fn: '查看'
            },
            listeners: {
              click: row => this.handleAdd(row.scope, 1)
            }
          },
          {
            type: 'el-button',
            name: '编辑',
            attrs: {
              type: 'text',
              fn: '编辑'
            },
            listeners: {
              click: row => this.handleAdd(row.scope, 2)
            }
          },
          {
            type: 'el-button',
            name: '上架',
            attrs: {
              type: 'text',
              fn: '上架'
            },
            condition: row => {
              return row.scope.goodsStatus!=1
            },
            listeners: {
              click: row => this.shelfGoodsFn(row.scope, 1)
            }
          },
          {
            type: 'el-button',
            name: '下架',
            attrs: {
              type: 'text',
              fn: '下架'
            },
            condition: row => {
              return row.scope.goodsStatus==1
            },
            listeners: {
              click: row => this.shelfGoodsFn(row.scope, 0)
            }
          },
          {
            type: 'el-button',
            name: '删除',
            attrs: {
              type: 'text',
              fn: '删除'
            },
            condition: row => {
              return row.scope.goodsStatus!=1
            },
            listeners: {
              click: row => this.delGoodsFn(row.scope)
            }
          }
        ],
        searchForm: {},
        url: url,
        searchFormData: [
          {
            label: '商品名称',
            name: 'goodsName',
            type: 'input'
          },
          {
            label: '创建日期',
            name: 'createDate',
            type: 'datePicker',
            isClear: true,
            customPickerOptions: {
              disabledDate(date) {
                const yesterday = new Date(new Date().setDate(new Date().getDate()))
                if (date > yesterday) {
                  return true
                }
                return false
              }
            }
          },
          {
            label: '商户名称',
            name: 'merchantName',
            type: 'input'
          },
          {
            label: '商品分类',
            name: 'goodsCategory',
            addHtml: 'categorySlot'
          },
        ],
        getListApi: this.$apis.goods.getGoodsListApi,
        tableParams: {
          listName: 'list',
          tableOption: {
            width: 200
          },
          tableColumns: [
            {
              label: '商品名称',
              prop: 'goodsName'
            },
            {
              label: '缩略图',
              addHtml: 'imageSlot'
            },
            {
              label: '收款方式',
              formatter: cellValue => {
                return cellValue.paymentType==1 ? '全款' : '定金+尾款'
              }
            },
            {
              label: '定金(元)',
              formatter: cellValue => {
                return cellValue.depositPrice ? Number((Number(cellValue.depositPrice)/100).toFixed(2)) : '--'
              }
            },
            {
              label: '门店活动价(元)',
              width: 200,
              addHtml: 'merchantPriceSlot'
            },
            {
              label: '分类',
              formatter: cellValue => {
                return `${cellValue.associationClassifyFirstName||''}-${cellValue.associationClassifySecondName||''}`
              }
            },
            {
              label: '状态',
              addHtml: 'statusSlot'
            },
            {
              label: '创建日期',
              prop: 'createdDate',
              width: 220
            },
            {
              label: '更新时间',
              prop: 'updatedDate',
              width: 220
            },
            {
              label: '操作人',
              prop: 'operator',
            },
          ]
        },
        pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' }
      }
    },
    created() {},
    mounted() {},
    methods: {
      selectCategory(e){
        this.tableSearchForm.associationClassifyFirstId = e?.parent?.id
        this.tableSearchForm.associationClassifySecondId = e?.data?.id
      },
      shelfGoodsFn(item, type){
        if(type==1){
          this.updateStatus(item.id, type)
        }else{
          this.$confirm(`确定下架该商品吗`, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
            callback: action => {
              if (action == 'confirm') {
                this.updateStatus(item.id, type)
              }
            }
          })
        }
      },
      delGoodsFn(item){
        this.$confirm(`确定删除该商品吗`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          callback: action => {
            if (action == 'confirm') {
              this.$apis.goods.delGoodsApi({id: item.id}).then(res =>{
                if(res){
                  this.$message.success('删除成功')
                  this.handleSearch()
                }
              })
            }
          }
        })
      },
      updateStatus(id, goodsStatus){
        this.$apis.goods.updateGoodsStatusApi({id, goodsStatus}).then(res =>{
          if(res){
            this.$message.success('操作成功')
            this.handleSearch()
          }
        })
      },
      filterData({merchantList: list}){
        return list?.map(item => {
          let activityPrice = item.activityPrice ? Number((Number(item.activityPrice)/100).toFixed(2)) : 0
          return `${item.merchantName || '--'}:${activityPrice || '0'}`
        }) || []
      },
      getParams() {
        var params = JSON.parse(JSON.stringify(this.tableSearchForm))
        if (this.tableSearchForm.createDate.length) {
          params.createdDateStrat = new Date(this.tableSearchForm.createDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
          params.createdDateEnd = new Date(this.tableSearchForm.createDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
        }
        return params
      },
      beforeSearchFn() {
        return new Promise(resolve => {
          this.searchForm = this.getParams()
          delete this.searchForm.createDate
          resolve()
        })
      },
      handleSearch() {
        this.$refs.channelRef.refreshTable()
      },
      handleReset() {
        this.tableSearchForm = {
          channelName: '',
          createDate: [],
          associationClassifyFirstId: '',
          associationClassifySecondId: '',
          merchantName: ''
        },
        this.$refs?.cascaderRef?.curBrand && (this.$refs.cascaderRef.curBrand = {})
        this.searchForm = {}
        this.handleSearch()
      },
      setTableFinishFun() {
        //接收到的数据为空
        this.$refs.channelRef.data.length ? (this.$refs.channelRef.tableHeightValues = '') : this.$refs.channelRef.setTableHeightFun()
      },
      handleAdd(row={},type){
        const params = {}
        let title = '新增商品'
        if(type){
          params.id = row.id
          params.type = type
          title = type == 1 ? '查看商品' : '编辑商品'
        }
        
        const queryStr = encodeURIComponent(JSON.stringify(params))
        this.$router.push({ path: `/goods/add/`+queryStr,query: { $title: title }})
      }
    }
  }
  </script>
  
<style scoped lang="scss">
.goods-list-cntr{
    .search-wrap{
      /deep/ .gl-search{
        overflow: unset;
        .tree-box{
          width: 300px;
        }
      }
    }
    .table-wrap{
        margin-top: 16px;
        padding: 20px;
        background-color: #fff;
        .status{
            width: 6px;
            height: 6px;
            border-radius: 50%;
            display: inline-block;
            vertical-align: middle;
            margin-right: 8px;
        }
        .success-status{
            background-color: #37C67F;
        }
        .error-status{
            background-color: #999999;
        }
        .more-info{
          white-space: nowrap;
          color: #5850FF;
          cursor: pointer;
        }
    }
}
</style>