measureTable.vue 9.33 KB
<template>
  <div class="">
    <d2-container class="m-t-40">
    <div class="header" slot="header" style="padding: 10px 20px;">
      <d2-search ref="showSearch" class="show-search" :search-form="searchForm" :label-width="labelWidth"
        :form-data="showFormData" />
        <div class="up-btns">
        <el-button @click="handleSearch" size="small" type="primary">
          查询
        </el-button>
        <el-button size="small" @click="handleReset"> 重置 </el-button>
      </div>
    </div>
    <div class="d2-container-content" style="height: 450px; overflow: auto;">
        <d2-table-header>
          <el-button type="primary" @click="handleExport">导出</el-button>
        </d2-table-header>
      <d2-table ref="measurementTable" :before-search-fn="beforeSearchFn" :get-list-api="getListApi" :search-form="searchFormSearch" :table-params="measurementTableParams"></d2-table>
    </div>
  </d2-container>
  </div>
</template>

<script>
import { deepClone } from "@/common/util"
import { mapActions, mapState } from 'vuex'
import { listGoodsType, getIncomePage } from '@api/resident'
import { jobTypeEnum, sceneTypeEnum, carTypeEnum } from './contant'
import dayjs from 'dayjs';
export default {
  name: 'MeasureTable',
  data() {
    return {
      // 收入测算
      searchForm: {
        sceneType: '',
        configCarType: ''
      },
      searchFormSearch: {},
      labelWidth: '110px',
      showFormData: [
        {
          label: '员工姓名',
					name: 'staffName',
          type: 'input'
        },
        {
          label: '电话号码',
          name: 'staffPhone',
          type: 'input'
        },
        {
          label: '门店名称',
          name: 'merchantName',
          type: 'input'
        },
        {
          label: '所属业务',
          name: 'sceneType',
          type: 'select',
          optionId: 'value',
					optionLabel: 'label',
          optionList: [
            {
              label: '全部',
              value: ''
            },
            {
              label: '会员权益/升级',
              value: '0'
            },
            {
              label: '轻改',
              value: '1'
            }
          ]
        },
        {
          label: '产品名称',
          name: 'showGoodsTypeName',
          type: 'select',
          optionId: 'goodsId',
					optionLabel: 'goodsName',
          optionList: [],
          isClear: true
        },
        {
          label: '品牌',
          name: 'configCarType',
          type: 'select',
          optionId: 'value',
					optionLabel: 'label',
          optionList: [
            {
              label: '全部',
              value: ''
            },
            {
              label: '问界',
              value: '1'
            },
            {
              label: '其他',
              value: '2'
            }
          ]
        },
        {
          label: '测算收入日期',
          name: 'calculationDay',
          type: 'datePicker',
          dateType: 'date',
          isClear: true,
          pickerOptions: 'yesterdayPicker'
        }
      ],
      getListApi: getIncomePage,
      measurementTableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableColumns: [
          {
            label: '员工姓名',
            prop: 'staffName',
            width: '150px'
          },
          {
            label: '电话号码',
            prop: 'staffPhone',
            width: '120px'
          },
          {
            label: '职级',
            prop: 'jobType',
            width: '120px',
            formatter: (cellValue) => {
              return jobTypeEnum[cellValue.jobType] || '-'
            }
          },
          {
            label: '服务门店',
            prop: 'merchantName',
            width: '120px'
          },
          {
            label: '所属业务',
            prop: 'sceneType',
            width: '100px',
            formatter: (cellValue) => {
              return sceneTypeEnum[cellValue.sceneType] || '-'
            }
          },
          {
            label: '品牌',
            prop: 'configCarType',
            formatter: (cellValue) => {
              return carTypeEnum[cellValue.configCarType] || '-'
            }
          },
          {
            label: '产品名称',
            prop: 'showGoodsTypeName'
          },
          {
            label: '应触客台数',
            prop: 'shouldToShopCount',
            width: '100px',
          },
          {
            label: '产值',
            prop: 'orderTotalPrice'
          },
          {
            label: '成交量',
            prop: 'orderCount'
          },
          {
            label: '渗透率',
            prop: 'penetrationRate',
            formatter: (cellValue) => {
              return cellValue.penetrationRate ? cellValue.penetrationRate + '%' : '-'
            }
          },
          {
            label: '提成系数',
            prop: 'calculateValue'
          },
          {
            label: '提成比例',
            prop: 'commissionRatio',
            formatter: (cellValue) => {
              return cellValue.commissionRatio ? cellValue.commissionRatio + '%' : '-'
            }
          },
          {
            label: '客单价',
            prop: 'avgCustomerOrderPrice'
          },
          {
            label: '客单价提成系数',
            prop: 'avgCustomerOrderPriceCalculateValue',
            width: '150px',
          },
          {
            label: '提成金额',
            prop: 'commissionPrice'
          },
          {
            label: '测算收入日期',
            prop: 'calculationDay',
            width: '120px',
          },
        ]
      },
    }
  },
  created() {
    this.getProduct()
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },
  methods: {
    ...mapActions('d2admin/user', ['actionSetDownloadList']),
    getProduct() {
      listGoodsType().then(res => {
        console.log(res, '获取商品');
        const list = []
        if (res) {
          res.forEach(item => {
            const _shop = {...item}
            if (item.thirdLevelGoodsTypeName) {
              _shop.goodsName = item.thirdLevelGoodsTypeName
              _shop.goodsId = item.thirdLevelGoodsType
              _shop.type = 3
            } else if (item.secondaryGoodsTypeName) {
              _shop.goodsName = item.secondaryGoodsTypeName
              _shop.goodsId = item.secondaryGoodsType
              _shop.type = 2
            } else {
              _shop.goodsName = item.goodsTypeName
              _shop.goodsId = item.goodsType
              _shop.type = 1
            }
            list.push(_shop)
            console.log(_shop);
          })
          this.showFormData[4].optionList = list
        } else {
          this.showFormData[4].optionList = []
        }
      })
    },
    beforeSearchFn() {
      return new Promise((resolve) => {
        this.searchFormSearch = deepClone(this.getParams())
        resolve()
      })
    },
    handleSearch() {
      const params = this.getParams()
      console.log(params, '-==-=');
      this.$refs.measurementTable.refreshTable(true, true)
    },
    getParams() {
      let params = deepClone(this.searchForm)
      const { showGoodsTypeName, calculationDay } = this.searchForm
      if (showGoodsTypeName) {
        const _goods = this.showFormData[4].optionList.find(item => item.goodsId == showGoodsTypeName)
        //  delete _goods.goodsId
        //  delete _goods.goodsName
        delete params.showGoodsTypeName
        const { type } = _goods
        if (type == 1) {
          params.goodsType = _goods.goodsType
          params.goodsTypeName = _goods.goodsTypeName
        } else if (type == 2) {
          params.secondaryGoodsType = _goods.secondaryGoodsType
          params.secondaryGoodsTypeName = _goods.secondaryGoodsTypeName
        } else if (type ==3 ) {
          params.thirdLevelGoodsType = _goods.thirdLevelGoodsType
          params.thirdLevelGoodsTypeName = _goods.thirdLevelGoodsTypeName
        }
        // params = Object.assign({}, _goods)
      }
      if (calculationDay) {
        params.calculationDayBegin = dayjs(calculationDay).format('YYYY-MM-DD')
        params.calculationDayEnd = dayjs(calculationDay).format('YYYY-MM-DD')
        // delete params.calculationDay
      } else {
        if (params.calculationDayBegin) delete params.calculationDayBegin
        if (params.calculationDayEnd) delete params.calculationDayEnd
      }
      return params
    },
    handleReset() {
      this.searchForm = {
        sceneType: '',
        configCarType: ''
      }
      this.$refs.measurementTable.refreshTable(true, true)
    },
    handleExport() {
      var params = this.getParams()
      // 去除为null的值
			for (const key in params) {
				if (params[key] === null || params[key] === '' || params[key].length == 0) {
					delete params[key]
				}
			}
			params.method = 'dj.api.smartcarlife.staff.incomeCalculation.exportAsync'
			const list = [
				...this.dowloadList,
				{
					name: '收入测算',
					exportParam: JSON.stringify(params),
					status: 'waiting',
					timeid: new Date().getTime()
				}
			]
			this.actionSetDownloadList({ list, type: 'dowloadList' })
    }
  }
}
</script>

<style lang="scss" scoped>
.header {
  background-color: #fff;
}
.m-t-40 {
  margin-top: 40px;
}
</style>