pointsConfig.vue 8.48 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="['9121304']" />
          </span>
          <!-- 启用/停用 -->
          <span style="margin-right: 10px;"
                v-if="scope.scope.configStatus == 1 || scope.scope.configStatus == 0">
            <auth-button :data="scope.scope"
                         :show-btn-ids="['9121305']" />
          </span>
        </div>
      </d2-table>
    </div>

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

<script>
import { Util, deepClone } from '@/common/util'
import editDialog from './components/editDialog'
import { findAllCategory, findAllTypeByCategoryId, storePointsConfigurationPage, updateStorePointsConfiguration } from '@api/inStorePoints'
import { pointStatusOpt } from '@/common/constants.js'
export default {
  name: 'PointsConfig',
  props: {

  },
  data() {
    return {
      searchForm: {
        categoryId: '',
        typeId: '',
        description: '',
        configStatus: ''
      },
      showFormData: [{
        label: '积分分类',
        name: 'categoryId',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'id',
        optionLabel: 'pointsCategoryName',
        optionsName: 'pointClassificationOpt',
        changeAttr: (value, targetItem) => {
          if (value) {
            // 获取积分类型
            this.findAllTypeByCategoryId(value)
          } else {
            this.baseData.pointTypeOpt = []
          }
          this.searchForm.typeId = ""
          this.getOptionsList()
        }
      }, {
        label: '积分类型',
        name: 'typeId',
        type: 'select',
        isClear: true,
        noDataText: "请先选择积分分类",
        optionList: [],
        optionId: 'id',
        optionLabel: 'pointsTypeName',
        optionsName: 'pointTypeOpt'
      }, {
        label: '积分描述',
        name: 'description',
        type: 'input',
        maxlength: '20',
        isClear: true
      }, {
        label: '状态',
        name: 'configStatus',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'pointStatusOpt'
      }],
      getListApi: storePointsConfigurationPage,
      // 表格参数
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        // tableOption: true,
        tableOption: { width: '150px' },
        tableColumns: [
          {
            label: '积分分类',
            prop: 'categoryName',
            width: '150'
          }, {
            label: '积分类型',
            prop: 'typeName',
            width: '150'
          }, {
            label: '积分描述',
            prop: "description"
          }, {
            label: '积分规则',
            prop: 'ruleDescription'
          }, {
            label: '积分值',
            prop: 'pointsValue',
            width: '100'
          }, {
            label: '状态',
            prop: 'configStatus',
            width: '100',
            formatter: (cellValue) => {
              return (cellValue.configStatus || cellValue.configStatus == 0) ? this.baseData.pointStatusOpt.find(item => item.confId === cellValue.configStatus).confValue : '--'
            },
            className: (cellValue) => {
              return {
                1: 'greenSpot',
                0: 'redSpot'
              }[cellValue.configStatus]
            }
          }, {
            label: '最后更新时间',
            prop: 'updatedDate',
            width: '150',
            formatter: (cellValue) => {
              return Util.dateFormate(cellValue.updatedDate, 'YYYY-MM-DD HH:mm:ss')
            }
          }
        ]
      },
      baseData: {
        pointClassificationOpt: [],
        pointTypeOpt: [],
        pointStatusOpt: deepClone(pointStatusOpt)
      },
      recordInfo: {},
      editVisible: false
    }
  },

  components: {
    editDialog
  },
  computed: {

  },
  mounted() {
    this.getBaseData()
  },

  methods: {
    async getBaseData() {
      this.findAllCategory()
      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()
      })
    },
    findAllCategory() {
      findAllCategory({}).then((res) => {
        this.baseData.pointClassificationOpt = res
        this.getOptionsList()
      })
    },
    findAllTypeByCategoryId(id) {
      findAllTypeByCategoryId({ categoryId: id }).then((res) => {
        this.baseData.pointTypeOpt = res || []
        this.getOptionsList()
      })
    },
    handleReset() {
      this.searchForm = {
        categoryId: '',
        typeId: '',
        description: '',
        configStatus: ''
      }
      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.configStatus == '0' ? '是否启用该积分项?' : '是否停用该积分项?'
      this.$confirm(html, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const selfStatus = row.configStatus == 1 ? 0 : 1
        updateStorePointsConfiguration({ id: row.id, configStatus: 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>