manage.vue 8.05 KB
<!-- 成长等级管理 -->
<template>
  <d2-container class="points-config">
    <div class="header"
         slot="header">
      <d2-search ref="showSearch"
                 class="show-search"
                 :search-form="searchForm"
                 :form-data="showFormData"
                 label-width="100px" />
      <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-header>
      </d2-table-header>
      <d2-table ref="detailListTable"
                :search-form="searchForm"
                :table-params="tableParams"
                :get-list-api="getListApi"
                :before-search-fn="beforeSearchFn">
        <div slot="auth-button"
             slot-scope="scope">
          <!-- 编辑 -->
          <span style="margin-right: 10px;">
            <auth-button :data="scope.scope"
                         :show-btn-ids="['9121404']" />
          </span>
          <!-- 启用/停用 -->
          <span style="margin-right: 10px;">
            <auth-button :data="scope.scope"
                         :show-btn-ids="['9121405']" />
          </span>
        </div>
      </d2-table>
    </div>

    <!-- 编辑积分配置 -->
    <edit-dialog :edit-visible="editVisible"
                 v-if="editVisible"
                 :params-obj="recordInfo"
                 @dialogClose="editDialogClose" />
  </d2-container>
</template>

<script>
import { mapActions, mapState } from 'vuex'
import { Util, deepClone } from '@/common/util'
import editDialog from './components/editDialog'
import { levelConfigPage, levelConfigSwitche } from '@api/inStorePoints'
import { levelTypeOpt, openStateOpt } from '@/common/constants.js'
export default {
  name: 'Manage',
  props: {

  },
  data() {
    return {
      searchForm: {
        levelName: '',
        staffPhone: '',
        openState: ''
      },
      showFormData: [{
        label: '奖励名称',
        name: 'levelName',
        type: 'input',
        maxlength: '20',
        isClear: true
      }, {
        label: '奖励类型',
        name: 'levelType',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'levelTypeOpt'
      }, {
        label: '状态',
        name: 'openState',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'openStateOpt'
      }],
      getListApi: levelConfigPage,
      // 表格参数
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        // tableOption: true,
        tableOption: { width: '150px' },
        tableColumns: [
          {
            label: '奖励类型',
            prop: 'levelType',
            width: '150',
            formatter: (cellValue) => {
              return cellValue.levelType ? this.baseData.levelTypeOpt.find(item => item.confId === cellValue.levelType).confValue : '--'
            }
          }, {
            label: '奖励名称',
            prop: 'levelName'
          }, {
            label: '评级项目',
            prop: "ratingProjectType"
          }, {
            label: '最低积分/排名',
            prop: 'minRanking',
            width: '150'
          }, {
            label: '最高积分',
            prop: 'highRanking',
            width: '150'
          }, {
            label: '等级结算周期',
            prop: 'ratingCycle',
            width: '150',
            formatter: (cellValue) => {
              return cellValue.ratingCycle ? cellValue.ratingCycle + '个月' : '--'
            }
          }, {
            label: '状态',
            prop: 'openState',
            width: '150',
            formatter: (cellValue) => {
              return (cellValue.openState === true || cellValue.openState === false) ? this.baseData.openStateOpt.find(item => item.confId === cellValue.openState).confValue : '--'
            },
            className: (cellValue) => {
              return {
                true: 'greenSpot',
                false: 'redSpot'
              }[cellValue.openState]
            }
          }, {
            label: '最后更新时间',
            prop: 'updatedDate',
            width: '150',
            formatter: (cellValue) => {
              return Util.dateFormate(cellValue.updatedDate, 'YYYY-MM-DD HH:mm:ss')
            }
          }
        ]
      },
      baseData: {
        levelTypeOpt: deepClone(levelTypeOpt),
        openStateOpt: deepClone(openStateOpt)
      },
      recordInfo: {},
      editVisible: false
    }
  },

  components: {
    editDialog
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },
  mounted() {
    this.getBaseData()
  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get',
      close: 'd2admin/page/close'
    }),
    ...mapActions('d2admin/user', ['actionSetDownloadList']),

    async getBaseData() {
      this.getOptionsList()
    },

    beforeSearchFn() {
      return new Promise(resolve => {
        console.log('this.searchForm.warnCycle', this.searchForm.warnCycle)
        if (this.searchForm.warnCycle) {
          this.searchForm.warningStartDate = Util.dateFormate(this.searchForm.warnCycle[0], 'YYYY-MM-DD')
          this.searchForm.warningEndDate = Util.dateFormate(this.searchForm.warnCycle[1], 'YYYY-MM-DD')
          // delete this.searchForm.warnCycle
        } else {
          delete this.searchForm.warningStartDate
          delete this.searchForm.warningEndDate
        }
        if (this.searchForm.createTime) {
          this.searchForm.startDate = Util.dateFormate(this.searchForm.createTime[0], 'YYYY-MM-DD')
          this.searchForm.endDate = Util.dateFormate(this.searchForm.createTime[1], 'YYYY-MM-DD')
          // delete this.searchForm.createTime
        } else {
          delete this.searchForm.startDate
          delete this.searchForm.endDate
        }
        resolve()
      })
    },
    keyDowmGetList() {
      this.$refs.detailListTable.refreshTable()
    },
    handleReset() {
      this.searchForm = {
        levelName: '',
        staffPhone: '',
        openState: ''
      }
      this.$refs.detailListTable.refreshTable()
    },
    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]
          )
        }
      })
    },

    handleEdit(row) {
      this.recordInfo = row
      this.editVisible = !this.editVisible
    },

    editDialogClose(flag) {
      this.editVisible = !this.editVisible
      if (flag) {
        this.$refs.detailListTable.refreshTable()
      }
    },

    handleUpOrDown(row) {
      var html = row.openState == false ? '是否启用该等级?' : '是否停用该等级?'
      this.$confirm(html, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const selfStatus = !row.openState
        levelConfigSwitche({ id: row.id, openState: selfStatus }).then(res => {
          this.notice.okTips()
          this.$refs.detailListTable.refreshTable()
        })
      }).catch(err => {
        console.log(err)
      })
    }

  }
}

</script>
<style lang="scss" scoped>
.points-config {
  margin-top: 40px;
  .m-l-md {
    margin-left: 20px;
  }
}
</style>