record.vue 7.83 KB
<!-- 成长等级记录 -->
<template>
  <d2-container class="points-record">
    <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>
        <auth-button category="Button"
                     :show-btn-ids="['9121401']" />
      </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>
            <auth-button :data="scope.scope"
                         :show-btn-ids="['9121402']" />
          </span>
        </div>
      </d2-table>
    </div>
  </d2-container></template>

<script>
import { mapActions, mapState } from 'vuex'
import { Util, deepClone, downLoadFile } from '@/common/util'
import { levelManagePage, levelManageDelete, levelManageExport, levelNameList } from '@api/inStorePoints'
import { levelTypeOpt, levelNameOpt } from '@/common/constants.js'
export default {
  name: 'Record',
  props: {
  },
  data() {
    return {
      searchForm: {
        staffName: '',
        staffPhone: '',
        levelType: '',
        levelName: '',
        grantTime: ''
      },
      showFormData: [{
        label: '员工姓名',
        name: 'staffName',
        type: 'input',
        maxlength: '20',
        isClear: true
      }, {
        label: '电话号码',
        name: 'staffPhone',
        type: 'input',
        inputType: "number",
        maxlength: '11',
        isClear: true
      }, {
        label: '奖励类型',
        name: 'levelType',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'levelTypeOpt',
        changeAttr: (value, targetItem) => {
          this.getLevelNameList(value)
          // this.baseData.levelNameOpt = []
          // const nameOpt = deepClone(levelNameOpt)
          // if (value) {
          //   if (value == 1) {
          //     this.baseData.levelNameOpt = nameOpt.slice(0, 4)
          //   } else if (value == 2) {
          //     this.baseData.levelNameOpt = nameOpt.slice(4, 8)
          //   }
          // }
          // this.searchForm.levelName = ""
          // this.getOptionsList()
        }
      }, {
        label: '奖励名称',
        name: 'levelName',
        type: 'select',
        isClear: true,
        noDataText: "请先选择奖励类型",
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'levelNameOpt'
      }, {
        label: "发放时间",
        name: "grantTime",
        type: "datePicker",
        isClear: true,
        pickerOptions: "rangePickerOptions"
      }],
      getListApi: levelManagePage,
      // 表格参数
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: { width: '100px' },
        tableColumns: [
          {
            label: '姓名',
            prop: 'staffName'
          }, {
            label: '电话号码',
            prop: 'staffPhone',
            width: '150'
          }, {
            label: '月份',
            prop: "month",
            width: '150',
            formatter: (cellValue) => {
              return Util.dateFormate(cellValue.distributionTime, 'YYYY年MM月')
            }
          }, {
            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: 'distributionTime',
            width: '150',
            formatter: (cellValue) => {
              return Util.dateFormate(cellValue.distributionTime, 'YYYY-MM-DD HH:mm:ss')
            }
          }
        ]
      },
      baseData: {
        levelTypeOpt: deepClone(levelTypeOpt),
        levelNameOpt: []
      }
    }
  },

  components: {

  },
  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.grantTime', this.searchForm.grantTime)
        if (this.searchForm.grantTime) {
          this.searchForm.grantTimeBegin = Util.dateFormate(this.searchForm.grantTime[0], 'YYYY-MM-DD HH:mm:ss')
          this.searchForm.grantTimeEnd = Util.dateFormate(this.searchForm.grantTime[1], 'YYYY-MM-DD') + ' 23:59:59'
          // delete this.searchForm.grantTime
        } else {
          delete this.searchForm.grantTimeBegin
          delete this.searchForm.grantTimeEnd
        }
        resolve()
      })
    },
    keyDowmGetList() {
      this.$refs.detailListTable.refreshTable()
    },
    handleReset() {
      this.searchForm = {
        staffName: '',
        staffPhone: '',
        levelType: '',
        levelName: '',
        grantTime: ''
      }
      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]
          )
        }
      })
    },

    handleExport() {
      var params = this.searchForm

      levelManageExport(params).then((res) => {
        res && downLoadFile(res)
      })
    },

    handleDelete(row) {
      var html = '是否确认删除该条记录?'
      this.$confirm(html, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        levelManageDelete({ id: row.id }).then(res => {
          this.notice.okTips()
          this.$refs.detailListTable.refreshTable()
        })
      }).catch(err => {
        console.log(err)
      })
    },

    getLevelNameList(type) {
      this.baseData.levelNameOpt = []
      this.searchForm.levelName = ""
      if (type) {
        levelNameList({ levelType: type }).then(res => {
          const list = deepClone(res)
          this.baseData.levelNameOpt = list.map(item => {
            return {
              confId: item,
              confValue: item
            }
          })
          this.getOptionsList()
        })
      } else {
        this.getOptionsList()
      }
    }

  }
}

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