sceneList.vue 5.77 KB
<!-- 场景配置 -->
<template>
  <d2-container class="m-t-40">
    <div class="header"
         slot="header">
      <d2-search ref="showSearch"
                 class="show-search"
                 :search-form="searchForm"
                 :form-data="showFormData" />
      <div class="up-btns">
        <el-button :id="tableParams.btnId"
                   size="small"
                   type="primary">
          查询
        </el-button>
        <el-button size="small"
                   @click="handleReset">
          重置
        </el-button>
      </div>
    </div>
    <div class="d2-container-content">
      <d2-table ref="sceneListTable"
                :search-form="searchForm"
                :table-params="tableParams"
                :get-list-api="getListApi"
                :has-num="false"
                :before-search-fn="beforeSearchFn">
        <div slot="auth-button"
             slot-scope="scope">
          <auth-button slot="auth-button"
                       :show-btn-ids="['9061201']"
                       :data="scope.scope" />
        </div>
      </d2-table>
    </div>
    <relation-category-dialog :category-visible="categoryVisible"
                              v-if="categoryVisible"
                              :info="recordInfo"
                              @dialogClose="dialogClose" />
  </d2-container>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import relationCategoryDialog from './relationCategoryDialog'
import { featuredGoodsList, getCategoryList } from '@api/sceneCategory'
import { sceneCodeList } from '@/common/constants.js'
export default {
  name: 'SceneList',
  data() {
    return {
      searchForm: {
        sceneType: '',
        featuredGoodsName: '',
        categoryName: ''
      },
      showFormData: [{
        label: '场景名',
        name: 'sceneType',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'sceneTypeList'
      }, {
        label: '特色产品',
        name: 'featuredGoodsName',
        type: 'input',
        maxlength: '30',
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '类目名',
        name: 'categoryName',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'id',
        optionLabel: 'categoryName',
        optionsName: 'categoryList'
      }],
      // maxLength: 10,
      getListApi: featuredGoodsList,
      // 表格参数
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '代号',
          prop: 'sceneType',
          width: '100',
          formatter: (cellValue) => {
            return this.baseData.numList.find(item => item.confId === cellValue.sceneType)?.confLabel
          }
        }, {
          label: '场景名',
          prop: 'sceneName'
        }, {
          label: '类别',
          prop: 'typeName'
        }, {
          label: '特色产品',
          prop: 'featuredGoodsName'
        }, {
          label: '关联类目',
          prop: 'categoryName'
        }, {
          label: '最近更新日期',
          prop: 'updatedDate',
          // width: '160',
          formatter: (cellValue) => {
            return Util.dateFormate(cellValue.updatedDate, 'YYYY-MM-DD HH:mm:ss')
          }
        }]
      },
      baseData: {
        numList: [
          {
            confId: 0,
            confLabel: '2.0'
          }, {
            confId: 1,
            confLabel: '1.1'
          }, {
            confId: 2,
            confLabel: '1.2'
          }, {
            confId: 3,
            confLabel: '1.3'
          }
        ],
        sceneTypeList: deepClone(sceneCodeList),
        categoryList: []
      },
      categoryVisible: false,
      recordInfo: {}
    }
  },

  components: {
    relationCategoryDialog
  },

  mounted() {
    this.getBaseData()
  },

  methods: {
    async getBaseData() {
      this.getOptionsList()
      this.queryCategoryList()
    },

    beforeSearchFn() {
      return new Promise(resolve => {
        if (this.searchForm.categoryName) {
          this.searchForm.categoryName = this.baseData.categoryList.find(item => item.id == this.searchForm.categoryName).categoryName
        }
        resolve()
      })
    },
    keyDowmGetList() {
      this.$refs.sceneListTable.refreshTable()
    },
    handleReset() {
      this.searchForm = {
        sceneType: '',
        featuredGoodsName: '',
        categoryName: ''
      }
    },
    getOptionsList() {
      this.showFormData.forEach((item, index) => {
        if (item.type === 'select') {
          if (
            this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this.showFormData[index].optionLabel] !== '全部'
          ) {
            const temp = {}
            temp[this.showFormData[index].optionId] = ''
            temp[this.showFormData[index].optionLabel] = '全部'
            this.baseData[item.optionsName].unshift(temp)
          }
          this.$set(
            this.showFormData[index],
            'optionList',
            this.baseData[item.optionsName]
          )
        }
      })
    },

    queryCategoryList() {
      const params = { currentPage: 1, pageSize: 10000 }
      getCategoryList(params).then((res) => {
        this.baseData.categoryList = res.list
        this.getOptionsList()
      })
    },

    relationCategory(row) {
      this.recordInfo = row
      this.categoryVisible = true
    },

    dialogClose(flag) {
      this.categoryVisible = !this.categoryVisible
      if (flag) {
        this.$refs.sceneListTable.refreshTable()
      }
    }
  }
}

</script>
<style scoped>
.m-t-40 {
  margin-top: 40px;
}
</style>