reconciliationList.vue 9.48 KB
<!-- 对账类目 -->
<template>
  <div>
    <div class="d2-container-content" style="padding: 10px 20px;">
      <d2-search ref="showSearch" class="show-search" :label-width="'110px'" :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-header>
        <span slot="left">
          <auth-button category="Button" :show-btn-ids="['9061604']" />
        </span>
      </d2-table-header>
      <d2-table ref="reconciliationListTable" :search-form="searchForm" :table-params="tableParams"
                :get-list-api="getListApi" :before-search-fn="beforeSearchFn">
        <template slot="applicationSceneTypes" slot-scope="scope">
          <el-popover placement="top" width="300" trigger="hover">
            <div class="merchant-name-box">
              {{ applicationSceneTypesFliter(scope.scope) }}
            </div>
            <div slot="reference">
              {{ applicationSceneTypesFliter(scope.scope, 20) }}
            </div>
          </el-popover>
        </template>
        <template slot="typeName" slot-scope="scope">
          <el-popover placement="top" width="300" trigger="hover" v-if="scope.scope.formType == 2">
            <div class="merchant-name-box">
              {{ formTypeFilter(scope.scope) }}
            </div>
            <div slot="reference">
              {{ formTypeFilter(scope.scope, 20) }}
            </div>
          </el-popover>
          <div v-else>-</div>
        </template>
        <div slot="auth-button" slot-scope="scope" v-if="filterEnableEdit(scope.scope.sourceType)">
          <auth-button slot="auth-button" :show-btn-ids="['9061605']" :data="scope.scope" />
          <auth-button slot="auth-button" :show-btn-ids="['9061606']" :data="scope.scope" />
        </div>
      </d2-table>
    </div>
  </div>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import { mapActions } from 'vuex'
import { selectFeeCategoryList, deleteFeeCategory } from '@api/costCategory'
import { sceneCodeList, sceneList, targetType } from '@/common/constants.js'
export default {
  name: 'ReconciliationList',
  data() {
    return {
      searchForm: {
        feeCategoryType: 2,
        applicationSceneType: '',
        applicationObjectType: '',
        feeCategoryName: '',
        formType: ''
      },
      showFormData: [{
        label: '费用类目名称',
        name: 'feeCategoryName',
        type: 'input',
        maxlength: '20',
        isClear: true,
        keyFn: this.keyDowmGetList
      }, {
        label: '应用场景',
        name: 'applicationSceneType',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'sceneTypeList'
      }, {
        label: '应用对象',
        name: 'applicationObjectType',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confLabel',
        optionsName: 'objList'
      }, {
        label: '费用类型',
        name: 'formType',
        type: 'select',
        isClear: true,
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confLabel',
        optionsName: 'formTypeList'
      }],
      getListApi: selectFeeCategoryList,
      // 表格参数
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '费用类目名称',
          prop: 'feeCategoryName',
          minWidth: '140'
        }, {
          label: '费用类型',
          width: '90',
          formatter: (cellValue) => {
            return cellValue.formType == 1 ? '普通' : '可拓展'
          }
        }, {
          label: '子类目',
          prop: 'typeName',
          addHtml: 'typeName',
          width: '300'
        }, {
          label: '应用场景',
          prop: 'feeCategorySceneList',
          addHtml: 'applicationSceneTypes',
          width: '300'

        }, {
          label: '应用对象',
          prop: 'applicationObjectName',
          formatter: (cellValue) => {
            return cellValue.applicationObjectType == 3 ? '平台方' : targetType[cellValue.applicationObjectType]
          }
        }, {
          label: '创建人',
          prop: 'createdBy'
        }, {
          label: '创建时间',
          prop: 'createdDate',
          // width: '160',
          formatter: (cellValue) => {
            return Util.dateFormate(cellValue.createdDate, 'YYYY-MM-DD HH:mm:ss')
          }
        }]
      },
      baseData: {
        objList: [
          {
            confId: 1,
            confLabel: '流量方'
          }, {
            confId: 2,
            confLabel: '服务商'
          }, {
            confId: 3,
            confLabel: '平台方'
          }
        ],
        sceneTypeList: deepClone(sceneCodeList),
        formTypeList: [
          {
            confId: 1,
            confLabel: '普通'
          }, {
            confId: 2,
            confLabel: '可拓展'
          }
        ],
      }
    }
  },

  components: {

  },

  mounted() {
    this.getBaseData()
    this.$nextTick(() => {
      // console.log(this.$refs.reconciliationListTable.page, 'this.$refs.reconciliationListTable.page')
      if (this.$refs.reconciliationListTable && this.$refs.reconciliationListTable.page) this.$refs.reconciliationListTable.page.pageSize = 10
    })
  },

  methods: {
    ...mapActions({ close: 'd2admin/page/close' }),
    async getBaseData() {
      this.getOptionsList()
    },

    filterEnableEdit(sourceType) {
      return sourceType != 2
    },

    formTypeFilter(ele, length) {
      if (ele.formType == 2 && ele.feeCategoryChildren.length) {
        let str = ''
        ele.feeCategoryChildren.map((item, index) => {
          // console.log(item.)
          const unit = ele.feeCategoryChildren.length - 1 == index ? '' : ','
          str += item.feeCategoryName + unit
        })
        return length ? (str?.length > length ? str.substring(0, length) + '\u2026' : str.substring(0, length)) : str
      } else {
        return '-'
      }
      // }
      // if (ele.formType == 2 && ele.feeCategoryChildren.length) {
      //   let str = ''
      //   ele.feeCategoryChildren.map((item, index) => {
      //     // console.log(item.)
      //     const unit = ele.feeCategoryChildren.length - 1 == index ? '' : ','
      //     str += item.feeCategoryName + unit
      //   })
      //   return lenght ? str.substring(0, lenght) : str
      // } else {
      //   return '-'
      // }
    },
    applicationSceneTypesFliter(cellValue, lenght) {
      // applicationSceneTypes
      const scenes = cellValue.applicationSceneTypes
      if (scenes && scenes.length > 0) {
        const list = scenes.map(item => {
          return sceneList[item]
        })
        return lenght ? (list.join(",")?.length > lenght ? list.join(",").substring(0, lenght) + '\u2026' : list.join(",").substring(0, lenght)) : list.join(",")
      } else {
        return '-'
      }
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        resolve()
      })
    },
    keyDowmGetList() {
      this.$refs.reconciliationListTable.refreshTable()
    },
    handleReset() {
      this.searchForm = {
        feeCategoryType: 2,
        applicationSceneType: '',
        applicationObjectType: '',
        feeCategoryName: '',
        formType: ''
      }
      this.$refs.reconciliationListTable.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]
          )
        }
      })
    },

    addReconciliationCategory() {
      this.close({ tagName: '/editReconciliation' })
      this.$router.push({
        name: 'editReconciliation',
        params: {
          addOrEdit: 'add',
          activeName: 'reconciliation'
        }
      })
    },

    editReconciliationCategory(row) {
      this.close({ tagName: '/editReconciliation' })
      this.$router.push({
        name: 'editReconciliation',
        params: {
          addOrEdit: 'edit',
          info: row,
          activeName: 'reconciliation'
        }
      })
    },

    // 删除
    delReconciliationCategory(row) {
      this.$confirm("删除后不可恢复,不影响原有已设置的对账规则。是否确定删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        closeOnClickModal: false
      })
        .then(() => {
          deleteFeeCategory({ id: row.id }).then((res) => {
            this.notice.okTips()
            this.$refs.reconciliationListTable.refreshTable()
          })
        })
        .catch((err) => {
          console.log(err)
        })
    }
  }
}

</script>
<style scoped></style>