expenseList.vue 6.95 KB
<!-- 激励池 - 支出 -->
<template>
  <div class="expense-list">
    <d2-table ref="expenseTable" 
              :has-num="false"
              :search-form="searchFormSearch"
              :table-params="tableParams"
              :get-list-api="getListApi"
              :before-search-fn="beforeSearchFn">
      <template slot="remark" slot-scope="scope">
        <template v-if="scope.scope.remark.length > 20">
          <el-popover placement="top" width="300" trigger="hover">
            <div class="merchant-name-box">
              {{ remarkFilter(scope.scope) }}
            </div>
            <div slot="reference">
              {{ remarkFilter(scope.scope, 20) }}
            </div>
          </el-popover>
        </template>
        <span v-else>{{ scope.scope.remark || '-' }}</span>
      </template>
      <template slot="auth-button" slot-scope="scope">
        <auth-button :data="scope.scope" :show-btn-ids="['9121208']" />
      </template>
    </d2-table>
    <add-expense-dialog :expense-visible="expenseVisible" v-if="expenseVisible" :expense-pool-info="staticData" @expenseClose="expenseClose"></add-expense-dialog>
    <d2-dialog title="修改备注"
              :is-visible="remarkVisible"
              width="720px"
              @confirmDialog="handleConfirm"
              @closeDialog="handleClose">
      <div class="form-content">
        <el-form ref="remarkForm" :model="remarkForm" :rules="rules" label-width="154px">
          <el-form-item label="备注:" prop="remark">
            <el-input type="textarea" v-model="remarkForm.remark" :rows="4" maxlength="100" class="wid_432" show-word-limit placeholder="请输入备注"></el-input>
          </el-form-item>
          <el-form-item label="历史备注:">
            <div v-for="item in remarkForm.historyRemark" :key="item.id" class="history-remark">
              <el-input type="textarea" v-model="item.remark" :rows="4" maxlength="500" class="wid_432" show-word-limit disabled></el-input>
              <div class="time">{{ item.createTimeStr }}</div>
            </div>
          </el-form-item>
        </el-form>
      </div>
    </d2-dialog>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
import { Util, deepClone } from '@/common/util'
import addExpenseDialog from './addExpenseDialog.vue'
import { staffLevelList } from '@/common/constants.js'
import { editIncentivePoolRemarkApi, getIncentivePoolExpendListApi, getIncentivePoolRemarkRecordApi } from '@api/resident'
import { filterStr } from '../../inStoreManage/util.js'
export default {
  name: 'ExpenseList',
  components: {
    addExpenseDialog
  },
  data() {
    return {
      searchFormSearch: {},
      getListApi: getIncentivePoolExpendListApi,
      // 表格参数
      tableParams: {
        needUnique: true,
        mutiSelectUniqueKey: 'uniqueVal',
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: {
          width: '100'
        },
        tableColumns: [{
          label: '序号',
          prop: 'ownSerialNum',
          type: 'ownSerialNum',
          width: '60'
        }, {
          label: '员工姓名',
          prop: 'staffName'
        }, {
          label: '职级',
          prop: 'jobType',
          formatter: (cellValue) => {
            return filterStr(cellValue.jobType, this.baseData.jobTypeList, cellValue.hireType)
          }
        }, {
          label: '支出时间',
          prop: 'createdDate',
          formatter: (cellValue) => {
            return cellValue.createdDate ? Util.dateFormate(cellValue.createdDate, 'YYYY-MM-DD HH:mm:ss') : '-'
          }
        }, {
          label: '金额',
          prop: 'expensePrice',
          formatter: (cellValue) => {
            return cellValue.expensePrice ? `¥${cellValue.expensePrice}` : '-'
          }
        }, {
          label: '操作人',
          prop: 'updatedBy'
        }, {
          label: '备注',
          prop: 'remark',
          width: '300',
          addHtml: 'remark'
        }]
      },
      expenseVisible: false,
      baseData: {
        jobTypeList: deepClone(staffLevelList)
      },
      remarkForm: {historyRemark: []},
      remarkVisible: false,
      rules: {
        remark: [
          { required: true, message: '请输入备注', trigger: 'blur' }
        ]
      }
    }
  },

  props: {
    parentSearchForm: {
      type: Object,
      default: () => { }
    },
    staticData: {
      type: Object,
      default: () => { }
    }
  },

  mounted() {
  },

  methods: {
    ...mapActions({
      get: 'd2admin/base/get'
    }),

    remarkFilter(ele, lenght) {
      if (ele.remark) {
        return lenght ? (ele.remark?.length > lenght ? ele.remark.substring(0, lenght) + '\u2026' : ele.remark.substring(0, lenght)) : ele.remark
      } else {
        return '-'
      }
    },
    
    keyDowmGetList() {
      this.$refs.expenseTable.refreshTable(true, true)
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        if (this.parentSearchForm.time && this.parentSearchForm.time?.length) {
          this.parentSearchForm.startTime = Util.dateFormate(
            this.parentSearchForm.time[0],
            "YYYY-MM-DD HH:mm:ss"
          )
          this.parentSearchForm.endTime =
            Util.dateFormate(this.parentSearchForm.time[1], "YYYY-MM-DD") + " 23:59:59"
        }
        delete this.parentSearchForm.time
        this.searchFormSearch = {
          ...this.parentSearchForm
        }
        resolve()
      })
    },
    // 编辑备注
    handleToNote(row) {
      this.remarkRow = row
      getIncentivePoolRemarkRecordApi({ id: row.id }).then(res => {
        res?.remarkRecordList?.forEach(v => {
          v.createTimeStr = Util.dateFormate(v.createdDate, 'YYYY-MM-DD HH:mm:ss')
        })
        this.remarkForm.historyRemark = res?.remarkRecordList || []
        this.handleClose()
      })
      
    },
    handleConfirm() {
      this.$refs.remarkForm.validate((valid) => {
        if (valid) {
          editIncentivePoolRemarkApi({ id: this.remarkRow.id, remark: this.remarkForm.remark }).then(res => {
            this.$message.success('备注成功')
            this.handleClose()
            this.$refs.expenseTable.refreshTable(true, true)
          })
        }
      })
    },
    handleClose() {
      this.remarkVisible = !this.remarkVisible
      this.$nextTick(() => {
        this.$set(this.remarkForm, 'remark', '')
      })
    },
    // 新增支出
    handleAddExpenditure() {
      this.expenseClose()
    },
    expenseClose(confirm) {
      if (confirm) {
        this.expenseVisible = !this.expenseVisible
        // 刷新列表数据
        this.$refs.expenseTable.refreshTable(true, true)
        // 刷新统计数据
        this.$emit('refreshStatic')
      } else {
        this.expenseVisible = !this.expenseVisible
      }
    }
  }
}

</script>
<style lang="scss" scoped>
.wid_432{
  width: 432px;
}
.time{
  font-size: 14px;
  color: #999999;
}
.form-content{
  max-height: calc(65vh - 60px);
  overflow: auto;
}
</style>