index.vue 6.65 KB
<template>
  <div class="owner-ctnr">
    <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="tableSearchForm" :formData="searchFormData"
                 @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
    <div class="operate-wrap">
      <span class="table-title">分类列表</span>
      <el-button class="operate-btn" type="primary" size="small" @click="addClassify()">新建分类</el-button>
    </div>
    <GLTable ref="categoryRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm"
             :beforeSearchFn="beforeSearchFn" :tableParams="tableParams" :pageConf="pageConf"
             @setTableFinishFun="setTableFinishFun">

      <div slot="categoryImage" 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.categoryImage"/>
          <img class="img-36 pointer" slot="reference" :src="scope.scope.categoryImage"/>
        </el-popover>
      </div>

      <div slot="categoryStyle" slot-scope="scope">
        <div class="category-style" v-if="scope.scope.categoryStyle == 0">
          <img src="@/assets/category/vertical.png">
          <span>商品-竖向排列</span>
        </div>
        <div class="category-style" v-if="scope.scope.categoryStyle == 1">
          <img src="@/assets/category/transverse.png">
          <span>商品-横向排列</span>
        </div>
        <div class="category-style" v-if="scope.scope.categoryStyle == 2">
          <img src="@/assets/category/recommend.png">
          <span>种草模式A</span>
        </div>
        <div class="category-style" v-if="scope.scope.categoryStyle == 3">
          <img src="@/assets/category/recommend2.png">
          <span>种草模式B</span>
        </div>
      </div>
      <div class="table-btns" slot="auth-button" slot-scope="scope">
        <GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
      </div>
    </GLTable>
  </div>
</template>

<script>
import url from 'assets/empty.png'
import bigView from 'components/big-view'

export default {
  name: 'App',
  components: {
    // bigView
  },
  data() {
    return {
      tableSearchForm: {
        // categoryType: 2,
        // caseName: '',
        // brandName: '',
        // createDate: []
      },
      buttonList: [
        {
          type: 'el-button',
          name: '编辑',
          attrs: {
            type: 'text',
            fn: '编辑'
          },
          listeners: {
            click: row => this.addClassify(row.scope, 0)
          }
        },
        {
          type: 'el-button',
          name: '删除',
          attrs: {
            type: 'text',
            fn: '删除'
          },
          listeners: {
            click: row => this.delCate(row.scope)
          }
        }
      ],
      searchForm: {},
      url: url,
      searchFormData: [
        {
          label: '分类名称',
          name: 'categoryName',
          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
            }
          }
        },
      ],
      getListApi: this.$apis.category.getCategoryListApi,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '分类名称',
            prop: 'categoryName'
          },
          {
            label: '分类归属',
            prop: 'categoryType',
            formatter: cellValue => {
              return cellValue.categoryType==1 ? '配置升级' : '车主优选' 
            }
          },
          {
            label: '分类图标',
            addHtml: 'categoryImage',
            width: 150
          },
          {
            label: '布局样式',
            addHtml: 'categoryStyle',
            width: 220
          },
          {
            label: '创建日期',
            prop: 'createdDate'
          },
          {
            label: '更新日期',
            prop: 'updatedDate'
          },
          {
            label: '操作人',
            prop: 'updatedBy',
            width: 150
          },
        ]
      },
      pageConf: {pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total'}
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.tableSearchForm))
      params.categoryLevel = 1
      if (this.tableSearchForm.createDate?.length) {
        params.beginCreateTime = new Date(this.tableSearchForm.createDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.endCreateTime = 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.categoryRef.refreshTable()
    },

    handleReset() {
      this.tableSearchForm = {
        categoryName: '',
        createDate: []
      }
      this.searchForm = {}
      this.handleSearch()
    },
    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.categoryRef.data.length ? (this.$refs.categoryRef.tableHeightValues = '') : this.$refs.categoryRef.setTableHeightFun()
    },
    addClassify(row = {}, type) {
      this.$router.push({
        path: `/category/ownerPreference/add?id=${row.id || ''}&$title=${type ? '编辑' : '新增'}分类`
      })
    },
    delCate({id, categoryName}) {
      this.$confirm(`是否确认删除${categoryName} ?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: action => {
          if (action == 'confirm') {
            this.$apis.category.delCategoryApi({id}).then(res => {
              if (res) {
                this.$message.success('删除成功')
                this.handleSearch()
              }
            })
          }
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
.owner-ctnr {
  background-color: #fff;
  padding: 20px;

  .more-brand {
    white-space: nowrap;
    color: #5850FF;
    cursor: pointer;
  }
}

.category-style {
  display: flex;
  align-items: center;

  img {
    width: 36px;
    margin-right: 8px;
  }
}
</style>