ledgerList.vue 10.6 KB
<!-- 分账类目 -->
<template>
  <div>
    <div class="d2-container-content" style="padding: 10px 20px;">
      <d2-search ref="showSearch" class="show-search" :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="['9061601']" />
        </span>
      </d2-table-header>
      <d2-table ref="ledgerListTable" :search-form="searchForm" :table-params="tableParams" :get-list-api="getListApi"
                :before-search-fn="beforeSearchFn">
        <template slot="formType" 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>
        <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>
        <div slot="auth-button" slot-scope="scope" v-if="filterEnableEdit(scope.scope.sourceType)">
          <auth-button slot="auth-button" :show-btn-ids="['9061602']" :data="scope.scope" />
          <auth-button slot="auth-button" :show-btn-ids="['9061603']" :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: 'LedgerList',
  data() {
    return {
      searchForm: {
        feeCategoryType: 1,
        feeCategoryName: '',
        applicationSceneType: '',
        applicationObjectType: '',
        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'
      }
      ],
      // maxLength: 10,
      getListApi: selectFeeCategoryList,
      // 表格参数
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [{
          label: '费用类目名称',
          prop: 'feeCategoryName',
          minWidth: '140'
        }, {
          label: '费用类型',
          // prop: 'feeCategoryNameList',
          width: '90',
          formatter: (cellValue) => {
            return cellValue.formType == 1 ? '普通' : '可拓展'
          }
        }, {
          label: '子类目',
          width: '300',
          addHtml: 'formType',
          formatter: (cellValue) => {
            if (cellValue.formType == 2) {
              let str = ''
              cellValue.feeCategoryChildren.map((item, index) => {
                const unit = cellValue.feeCategoryChildren.length - 1 == index ? '' : ','
                str += item.feeCategoryName + unit
              })
              return str
            } else {
              return '-'
            }
          }
        }, {
          label: '应用场景',
          prop: 'applicationSceneTypes',
          addHtml: 'applicationSceneTypes',
          width: '300',
          formatter: (cellValue) => {
            // applicationSceneTypes
            const scenes = cellValue.applicationSceneTypes
            if (scenes && scenes.length > 0) {
              const list = scenes.map(item => {
                return sceneList[item]
              })
              return list.join(",")
            } else {
              return ''
            }
          }
        }, {
          label: '应用对象',
          prop: 'applicationObjectType',
          width: '90',
          formatter: (cellValue) => {
            return targetType[cellValue.applicationObjectType]
          }
        }, {
          label: '创建人',
          prop: 'createdBy',
          width: '100'
        }, {
          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: '公共'
          }
        ],
        formTypeList: [
          {
            confId: 1,
            confLabel: '普通'
          }, {
            confId: 2,
            confLabel: '可拓展'
          }
        ],
        sceneTypeList: deepClone(sceneCodeList)
      },
      hideOptList: [1, 2, 3, 4, 5]
    }
  },
  // // 定义组件过滤器
  // filters: {
  //   filterEnableEdit(sourceType) {
  //     console.log('sourceType', sourceType)
  //     return sourceType != 1
  //   }
  // },
  filters: {
    // formTypeFilter(ele, lenght) {
    //   console.log(ele)
    //   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 str
    //   } else {
    //     return '-'
    //   }
    // }
  },
  components: {
    // relationCategoryDialog
  },

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

  methods: {
    ...mapActions({ close: 'd2admin/page/close' }),
    formTypeFilter(ele, lenght) {
      // console.log(ele)
      // console.log(lenght)
      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?.length > lenght ? str.substring(0, lenght) + '\u2026' : 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 '-'
      }
    },
    async getBaseData() {
      this.getOptionsList()
    },
    // 1是自建 2是系统内置 (不允许修改)
    filterEnableEdit(sourceType) {
      // console.log('sourceType', sourceType)
      return sourceType != 2
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        resolve()
      })
    },
    keyDowmGetList() {
      this.$refs.ledgerListTable.refreshTable()
    },
    handleReset() {
      this.searchForm = {
        feeCategoryType: 1,
        feeCategoryName: '',
        applicationSceneType: '',
        applicationObjectType: '',
        formType: ''
      }
      this.$refs.ledgerListTable.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]
          )
        }
      })
    },

    addLedgerCategory() {
      this.close({ tagName: '/editLedger' })
      this.$router.push({
        name: 'editLedger',
        params: {
          addOrEdit: 'add',
          activeName: 'ledger'
        }
      })
    },

    editLedgerCategory(row) {
      this.close({ tagName: '/editLedger' })
      this.$router.push({
        name: 'editLedger',
        params: {
          addOrEdit: 'edit',
          info: row,
          activeName: 'ledger'
        }
      })
    },

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

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