index.vue 7.32 KB
<template>
  <div class="points">
    <div class="container">
      <GLCombiForm ref="showSearch" :rowNumber="1" :formObj="searchForm" :formData="showFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
      <div class="table-header">
        <h2>积分核销列表</h2>
        <div>
          <!-- <el-button size="small" @click="handleImport" type="primary">批量结算导入</el-button> -->
          <div class="flex">
            <div class="import-btn">
              批量结算导入
              <input id="fileUpload" type="file" style="opacity: 0;" ref="file" class="import-input" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.ms-excel" @change="e => handleImport(e)" />
            </div>
            <el-button size="small" @click="exportExcel" type="primary" plain>导出</el-button>
          </div>
        </div>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="pointRef" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <GLTableButton :buttonList="tableButtonList" :buttonItem="scope.scope" :buttonNum="3"></GLTableButton>
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import url from '@/assets/empty.png'
export default {
  data() {
    //这里存放数据
    return {
      size: 'small',
      url: url,
      searchForm: {
        settlementStatus: ''
      },
      tableSearchForm: {},
      showFormData: [
        {
          label: '项目名称',
          name: 'bizRelName',
          type: 'input',
          isClear: true,
          maxlength: 100
        },
        {
          label: '商户名称',
          name: 'merchantName',
          type: 'input',
          isClear: true,
          maxlength: 100
        },
        {
          label: '结算状态',
          name: 'settlementStatus',
          type: 'select',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confLabel',
          optionsName: 'settlementStatusList'
        },
        {
          label: '核销日期',
          name: 'verificationTimeStr',
          type: 'datePicker',
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        }
      ],
      tableButtonList: [
        {
          type: 'GLButton',
          name: '查看',
          attrs: {
            type: 'text',
            fn: '查看'
          },
          listeners: {
            click: this.handleDetail
          }
        },
        {
          type: 'GLButton',
          name: row => {
            return row.settlementStatus ? '取消结算' : '去结算'
          },
          attrs: {
            type: 'text',
            fn: '去结算'
          },
          listeners: {
            click: this.handleSettlement
          }
        }
      ],
      // 表格
      getListApi: this.$apis.points.getList,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '项目名称',
            prop: 'bizRelName'
          },
          {
            label: '消费积分',
            prop: 'integralValue'
          },
          {
            label: '客户昵称',
            prop: 'customerWechatName'
          },
          {
            label: '手机号',
            prop: 'customerPhone',
            width: '120px'
          },
          {
            label: '核销员工',
            prop: 'verificationStaffName'
          },
          {
            label: '商户名称',
            prop: 'merchantName'
          },
          {
            label: '核算状态',
            prop: 'settlementStatusStr',
            width: '90px'
          },
          {
            label: '核销日期',
            prop: 'verificationTime',
            width: '180px'
          },
          {
            label: '操作人',
            prop: 'updatedBy'
          },
          {
            label: '订单编号',
            prop: 'orderCode',
            width: '200px'
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      // 基本数据
      baseData: {
        settlementStatusList: [
          {
            confId: '0',
            confLabel: '未结算'
          },
          {
            confId: '1',
            confLabel: '已结算'
          }
        ]
      }
    }
  },
  mounted() {
    this.$utils.getOptionsList(this, 'showFormData')
  },
  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      if (this.searchForm.verificationTimeStr) {
        params.verificationStartTime = dayjs(this.searchForm.verificationTimeStr[0]).format('YYYY-MM-DD') + ' 00:00:01'
        params.verificationEndTime = dayjs(this.searchForm.verificationTimeStr[1]).format('YYYY-MM-DD') + ' 23:59:59'
      }

      delete params.verificationTimeStr
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        delete this.tableSearchForm.verificationTimeStr
        resolve()
      })
    },
    handleSearch() {
      this.$refs.pointRef.refreshTable()
    },
    handleReset() {
      this.searchForm = {
        settlementStatus: ''
      }
      this.handleSearch()
    },
    handleSettlement(row) {
      const params = {
        id: row.id,
        settlementStatus: row.settlementStatus ? 0 : 1
      }
      this.$utils.secondConfirm(this, '结算', '是否要' + (row.settlementStatus ? '取消结算' : '结算') + '?', 'points', 'integralorderSettle', params)
    },
    handleDetail(row) {
      console.log(row)
      this.$router.push({
        path: '/pointsList/orderDetail',
        query: {
          id: row.id
        }
      })
    },
    handleImport(e) {
      var reader = new FileReader()
      var file = e.srcElement.files[0]
      const isLt = file.size / 1024 / 1024 < 10
      if (isLt > 10) {
        this.$message({
          message: '文件大小不能超过10M',
          type: 'error'
        })
        return true
      }
      reader.readAsDataURL(file)
      reader.onload = e => {
        const imgFile = e.target.result
        const base64 = file.name.split('.')[file.name.split('.').length - 1] + '@' + imgFile.split(',')[1]
        this.$apis.points.orderImport({ file: base64 }).then(res => {
          this.$message({
            message: res.code == '0' ? '操作成功' : res.message,
            type: res.code == '0' ? 'success' : 'error'
          })
          document.getElementById('fileUpload').value = ''
          this.handleSearch()
        })
      }
    },
    exportExcel() {
      const params = this.getParams()
      this.$apis.points.orderExport(params).then(res => {
        this.$utils.aToExport(res)
      })
    }
  }
}
</script>
<style scoped>
.import-btn {
  position: relative;
  width: 116px;
  height: 32px;
  text-align: center;
  background: #5850ff;
  border-radius: 4px;
  color: #ffffff;
  font-size: 14px;
  margin-right: 8px;
}

.import-input {
  opacity: 0;
  position: absolute;
  right: 0;
  top: 0;
  width: 98px;
  height: 36px;
  cursor: pointer;
  font-size: 0;
}
</style>