index.vue 9.36 KB
<template>
  <div>
    <ownerPreference></ownerPreference>
  </div>
  <!-- <div class="category-list-ctnr">
    <GLTabs ref='GLTabs' class="tabs" v-model="activeName" :tabPaneList="tabPaneList"
            @tab-click="handleClick" removeTab="removeTab"></GLTabs>

    <template v-if="activeName =='1'">
      <pullDownNav @confirmDialog="handleEdit" @inputBlur="inputBlur" @delete="delCategory" v-model="curMainCategoryId"
                   :tabList="mainCategoryList" :defaultProps="{id: 'id', name: 'categoryName'}"></pullDownNav>
      <div class="main-wrap">
        <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="editCategory">新增二级分类</el-button>
        </div>
        <GLTable ref="categoryRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm"
                 :beforeSearchFn="beforeSearchFn" :tableParams="tableParams" :pageConf="pageConf"
                 @setTableFinishFun="setTableFinishFun">
          <div slot="brandSlot">
            <span>{{ brandList.slice(0, 3).join('、') }}</span>
            <el-popover
                placement="top"
                width="400"
                trigger="hover">
                <span>
                {{ brandList.join('、') }}
                </span>
              <span class="more-brand" slot="reference">...[{{ brandList.length }}]</span>
            </el-popover>
          </div>
          <div class="table-btns" slot="auth-button" slot-scope="scope">
            <GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
          </div>
        </GLTable>
      </div>
    </template>

    <template v-if="activeName=='2'">
      <ownerPreference></ownerPreference>
    </template>
  </div> -->
</template>

<script>
import url from '@/assets/empty.png'
import * as dayjs from 'dayjs'
// import pullDownNav from './components/pullDownNav'
import ownerPreference from "views/category/ownerPreference";

export default {
  name: 'App',
  components: {
    // pullDownNav,
    ownerPreference
  },
  data() {
    return {
      activeName: '1',
      curMainCategoryId: '',
      tabPaneList: [],
      mainCategoryList: [],
      brandList: ['丰田', '本田', '一汽大众', '奔驰', '宝马', '奥迪', '比亚迪'],
      buttonList: [
        {
          type: 'el-button',
          name: '编辑',
          attrs: {
            type: 'text',
            fn: '编辑'
          },
          listeners: {
            click: row => this.editCategory(row.scope)
          }
        },
        {
          type: 'el-button',
          name: '删除',
          attrs: {
            type: 'text',
            fn: '删除'
          },
          listeners: {
            click: row => this.delCategory(row.scope, 1)
          }
        }
      ],
      tableSearchForm: {
        categoryName: '',
        createDate: []
      },
      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: 'createdDate'
          },
          {
            label: '更新时间',
            prop: 'updatedDate'
          },
          {
            label: '操作人',
            prop: 'updatedBy'
          },
        ]
      },
      pageConf: {pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total'}
    }
  },
  created() {
    // this.getChannelList()
  },

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (from.path.indexOf('/category/ownerPreference/add') == 0) {
        vm.activeName = '2'
      }
    })
  },
  watch: {
    curMainCategoryId: {
      handler() {
        this.handleSearch()
      },
      deep: true
    },
    activeName: {
      handler(val) {
        if (val == '1') {
          this.getMainCategory()
        }
      },
      immediate: true,
      deep: true
    },
  },
  mounted() {
  },

  methods: {
    //获取频道名称
    getChannelList() {
      this.$apis.channel
          .getChannelListApi({
            pageSize: 100,
            pageNum: 1
          })
          .then(res => {
            if (res?.list?.length) {
              let tabPaneList = []
              res.list.forEach(item => {
                if (item.channelType == 5 || item.channelType == 6) {
                  tabPaneList.push({
                    label: item.channelName,
                    name: item.channelType == 5 ? '1' : '2',
                    merchantChannelId: item.id
                  })
                }
              })
              this.tabPaneList = tabPaneList

              // 处理返回的tab值
              // let tagName = sessionStorage.getItem('tagActive')
              // this.activeName = tagName  '' || tabPaneList[0].name
              // this.activeName = _name
            }
          })
    },
    getMainCategory() {
      const params = {
        pageSize: 1000,
        pageNum: 1,
        categoryLevel: 1,
        categoryType: this.activeName
      }
      this.$apis.category.getCategoryListApi(params).then(res => {
        if (res?.list?.length) {
          this.mainCategoryList = res.list
          this.curMainCategoryId = res.list[0].id
        } else {
          this.curMainCategoryId = ''
        }
      })
    },
    inputBlur(e) {
      this.addCategory(e.value)
    },
    handleEdit(e) {
      this.addCategory(e.categoryName, e.id)
    },
    delCategory(e, type) {
      this.$confirm(`删除后数据将无法恢复,是否确认删除${e.categoryName}?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: action => {
          if (action == 'confirm') {
            this.$apis.category.delCategoryApi({id: e.id}).then(res => {
              if (res) {
                this.$message.success('删除成功')
                this.getMainCategory()
                if (type) {
                  this.handleSearch()
                }
              }
            })
          }
        }
      })
    },
    addCategory(val, id) {
      let params = {
        categoryType: this.activeName,
        categoryLevel: 1,
        categoryName: val
      }
      if (id) params.id = id
      this.$apis.category.addCategoryApi(params).then(res => {
        if (res) {
          this.$message.success('新增成功')
          this.getMainCategory()
        }
      })
    },
    getParams() {
      var params = JSON.parse(JSON.stringify(this.tableSearchForm))
      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'
      }
      params.categoryType = 1
      params.categoryLevel = 2
      params.parentCategoryId = this.curMainCategoryId
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchForm = this.getParams()
        delete this.searchForm.createDate
        resolve()
      })
    },
    handleSearch() {
      this.$refs.categoryRef.refreshTable()
    },
    handleReset() {
      this.tableSearchForm = {
        channelName: '',
        createDate: []
      }
      this.searchForm = {}
      this.handleSearch()
    },
    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.categoryRef.data.length ? (this.$refs.categoryRef.tableHeightValues = '') : this.$refs.categoryRef.setTableHeightFun()
    },
    editCategory(row = {}) {
      if (!this.activeName) return this.$message.error('暂无频道')
      const target = this.mainCategoryList.find(item => item.id == this.curMainCategoryId)
      if (!target) return this.$message.error('请选择一级分类')
      const params = {
        categoryType: this.activeName,
        parentCategoryId: target.id,
        parentCategoryName: target.categoryName
      }
      if (row.id) {
        params.id = row.id
        params.name = row.categoryName
      }
      const queryStr = encodeURIComponent(JSON.stringify(params))
      this.$router.push({path: `/category/add/` + queryStr, query: {$title: row.id ? '编辑二级分类' : '新增二级分类'}})
    }
  }
}
</script>

<style scoped lang="scss">
.category-list-ctnr {
  .tabs {
    margin-bottom: 16px;
  }

  .main-wrap {
    background-color: #fff;
    padding: 20px;
  }

  .more-brand {
    color: #5850FF;
    cursor: pointer;
  }
}
</style>