index.vue 9.63 KB
<template>
  <div>
    <GLTabs v-model="tabId" @tab-click="changeTab" :tabPaneList="tabPaneList"></GLTabs>
    <div class="main-wrap">
      <GLCombiForm ref="pointerWriteOffSearch" :rowNumber="1" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
      <div class="exportBtn">
        <el-button :size="size" @click="handleExport" class="default-blue-btn" type="default">导出</el-button>
      </div>
      <GLTable v-loading="loading" ref="pointerWriteOffRef" :getListApi="getListApi" :noDataImg="url" :searchForm="searchForm" :tableParams="tableParams" :pageConf="pageConf" @setTableFinishFun="setTableFinishFun" :beforeSearchFn="beforeSearchFn">
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
        </div>
      </GLTable>
    </div>
    <GLDialog title="查看" mode="mid" :hasFooter="false" :visible.sync="dialogVisible" :before-close="handleClose" @onOk="handleConfirm" @onCancel="handleClose">
      <ul class="detail-wrap">
        <template v-for="item in detailList">
          <li class="detail-li" v-if="!item.hasOwnProperty('include') || item.include.indexOf(tabId) != -1" :key="item.key">
            <label class="detail-label" for="">{{ item.label }}:</label>
            <span v-if="item.key !== 'merchantId'" class="detail-key">{{ detailObj[item.key] || '--' }}</span>
            <span v-else class="detail-key">{{ getMerchantName(detailObj[item.key]) }}</span>
          </li>
        </template>
      </ul>
    </GLDialog>
  </div>
</template>

<script>
import { exportFn } from '@/common/constant'
const TABLE_COL = [
  {
    label: '批次号',
    prop: 'batchNo',
    show: '1,2,3'
  },
  {
    label: '门店名称',
    prop: 'merchantName',
    show: '1,2,3'
  },
  {
    label: '客户姓名',
    prop: 'customerName',
    show: '1,3'
  },
  {
    label: '客户姓名',
    prop: 'userName',
    show: '2'
  },
  {
    label: '客户手机号',
    prop: 'customerPhone',
    show: '1,3'
  },
  {
    label: '客户手机号',
    prop: 'phone',
    show: '2'
  },
  {
    label: '保单号',
    prop: 'policyNo',
    width: 200,
    line: 1,
    show: '1,2,3'
  },
  {
    label: '油卡面值',
    prop: 'faceValue',
    width: 150,
    show: '2'
  },
  {
    label: '油卡数量',
    prop: 'couponNumber',
    width: 150,
    show: '2'
  },
  {
    label: '商品名称',
    prop: 'goodsName',
    width: 150,
    show: '3'
  },
  {
    label: '商品价格/元',
    prop: 'retailPrice',
    width: 150,
    show: '3',
    formatter: cell => {
      return cell.retailPrice ? Number((cell.retailPrice / 100).toFixed(2)) : 0
    }
  },
  {
    label: '商品数量',
    prop: 'goodsNumber',
    width: 150,
    show: '3'
  },
  {
    label: '消耗积分',
    prop: 'integralValue',
    show: '1'
  },
  {
    label: '消耗积分',
    prop: 'redeemPoints',
    show: '2,3'
  },
  {
    label: '消耗积分时间',
    prop: 'createdDate',
    show: '1'
  },
  {
    label: '消耗积分时间',
    prop: 'payDate',
    show: '2,3'
  }
]

const DETAIL_LIST = [
  { label: '门店名称', key: 'merchantName' },
  { label: '批次号', key: 'batchNo' },
  { label: '消耗积分', key: 'integralValue', include: '1' },
  { label: '消耗积分', key: 'redeemPoints', include: '2,3' },
  { label: '客户名称', key: 'customerName', include: '1,3' },
  { label: '客户手机号', key: 'customerPhone', include: '1,3' },
  { label: '客户名称', key: 'userName', include: '2' },
  { label: '客户手机号', key: 'phone', include: '2' },
  { label: '保单号', key: 'policyNo' },
  { label: '商品名称', key: 'goodsName', include: '3' },
  { label: '商品数量', key: 'goodsNumber', include: '3' },
  { label: '商品价格/元', key: 'retailPrice', include: '3' },
  { label: '油卡面值', key: 'faceValue', include: '2' },
  { label: '油卡数量', key: 'couponNumber', include: '2' },
  { label: '收款人身份证', key: 'idCardNo', include: '1' },
  { label: '收款银行卡号', key: 'recvBankCardNo', include: '1' },
  { label: '收款银行', key: 'recvBank', include: '1' },
  { label: '消耗积分类型', key: 'ruleDesc' },
  { label: '消耗积分时间', key: 'createdDate', include: '1' },
  { label: '消耗积分时间', key: 'payDate', include: '2,3' }
]
export default {
  name: 'index',
  data() {
    return {
      size: 'small',
      loading: false,
      tabId: '1',
      tabPaneList: [
        { name: '1', label: '积分转出明细' },
        { name: '2', label: '油卡兑换明细' },
        { name: '3', label: '商品兑换明细' }
      ],
      detailList: DETAIL_LIST,
      detailObj: {},
      dialogVisible: false,
      merchantList: [],
      searchForm: {
        ruleType: 'TRANSFER_OUT',
        merchantId: '',
        customerName: '',
        customerPhone: '',
        createDate: '',
        batchNo: '',
        policyNo: ''
      },
      searchFormData: [
        {
          label: '批次号',
          name: 'batchNo',
          type: 'input'
        },
        {
          label: '客户手机号',
          name: 'customerPhone',
          isClear: true,
          type: 'input'
        },
        {
          label: '客户姓名',
          name: 'customerName',
          isClear: true,
          type: 'input'
        },
        {
          label: '保单号',
          name: 'policyNo',
          type: 'input'
        },
        {
          label: '门店名称',
          name: 'merchantId',
          type: 'select',
          optionList: [],
          isClear: true,
          optionId: 'merchantId',
          optionLabel: 'merchantName'
        },
        {
          label: '消耗积分时间',
          name: 'createDate',
          type: 'datePicker',
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        }
      ],
      getListApi: this.$apis.pointWriteOff.payPointsListApi,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: []
      },
      tableButtonList: [
        {
          type: 'el-button',
          name: '查看',
          attrs: {
            type: 'text'
          },
          // condition: row => {
          //   return row.sopStatus != 1
          // },
          listeners: {
            click: row => this.viewDetail(row)
          }
        }
      ],
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' }
    }
  },
  watch: {
    tabId: {
      handler: function(nVal, oVal) {
        this.tableParams.tableColumns = TABLE_COL.filter(item => item.show.indexOf(nVal) != -1)
      },
      immediate: true
    }
  },
  created() {
    this.getMerchantList()
  },
  mounted() {},
  methods: {
    changeTab() {
      this.handleReset()
      this.getMerchantList()
    },
    getMerchantName(merchantId) {
      const _target = this.merchantList.find(item => item.merchantId == merchantId)
      return _target ? _target.merchantName : '--'
    },
    getMerchantList() {
      this.$apis.pointWriteOff
        .getMerchantList({
          parameterType: 2,
          type: this.tabId
        })
        .then(res => {
          if (res?.length) {
            const _target = this.searchFormData.find(e => e.name == 'merchantId')
            _target && (_target.optionList = res)
            this.merchantList = res
          }
        })
    },
    viewDetail(item) {
      this.detailObj = { ...item }
      this.detailObj.ruleDesc = this.tabId == 1 ? '积分转出' : this.tabId == 2 ? '油卡兑换' : '商品兑换'
      this.detailObj.retailPrice = item.retailPrice ? Number((item.retailPrice / 100).toFixed(2)) : 0
      this.dialogVisible = true
    },
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      if (this.searchForm.createDate?.length) {
        params.createdDateBegin = new Date(this.searchForm.createDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.createdDateEnd = new Date(this.searchForm.createDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      }
      if (this.tabId != 1) delete params.ruleType
      delete params.createDate
      return params
    },
    handleReset() {
      this.searchForm = {
        ruleType: 'TRANSFER_OUT',
        customerName: '',
        customerPhone: '',
        merchantId: '',
        createDate: '',
        batchNo: '',
        policyNo: ''
      }
      this.handleSearch()
    },
    handleSearch() {
      this.$refs.pointerWriteOffRef.refreshTable()
    },
    setTableFinishFun() {
      this.loading = false
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.loading = true
        let _api = this.tabId == 1 ? 'payPointsListApi' : this.tabId == 2 ? 'exchangeOilListApi' : 'exchangeGoodListApi'
        this.getListApi = this.$apis.pointWriteOff[_api]
        this.searchForm = this.getParams()
        resolve()
      })
    },
    handleExport() {
      var params = this.getParams()
      let _api = this.tabId == 1 ? 'payPointsExportApi' : this.tabId == 2 ? 'exchangeOilExportApi' : 'exchangeGoodExportApi'
      this.$apis.pointWriteOff[_api](params).then(res => {
        exportFn(res)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.main-wrap {
  background-color: #fff;
  padding: 20px;
  margin-top: 16px;
}

.detail-wrap {
  padding: 0 12px;
  font-size: 14px;
  line-height: 20px;
  .detail-li {
    &:first-child {
      margin-top: 0;
    }
    margin-top: 20px;
  }
  .detail-label {
    width: 154px;
    display: inline-block;
    text-align: right;
    color: #666666;
  }
  .detail-key {
    color: #333;
  }
}
.exportBtn {
  float: right;
  margin-bottom: 10px;
}
</style>