goodIndex.vue 10.7 KB
<template>
  <div class="container">
    <div class="find_wrap">
      <GLCombiForm ref="showSearch" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
    </div>
    <div class="table_wrapper">
      <div class="operate_wrap">
        <span class="table_title">合同列表</span>
        <div class="operate_btn">
          <el-button type="primary" fn="批量更换" plain :size="size" @click="batchChangeTmpl">批量更换</el-button>
          <el-button type="primary" fn="批量初始化" plain :size="size" @click="batchInitTmpl">批量初始化</el-button>
          <el-button type="primary" plain :size="size" @click="handleExport">导出</el-button>
        </div>
      </div>
      <GLTable ref="equityRef" :getListApi="getListApi" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn">
        <div slot="serviceContent" slot-scope="scope">
          <div v-html="scope.scope.serviceContent"></div>
        </div>
        <span slot="auth-button" slot-scope="scope" :data="scope.scope">
          <GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
        </span>
      </GLTable>
    </div>
    <pdf-dialog :isVisible="isPdfVisible" title="合同" :pdfUrl="pdfUrl" @closeDialog="handlePdfClose"></pdf-dialog>
    <changeContractDialog v-if="changeContractObj.visible" @closeDialog="closeTmplDialog" :changeContractObj="changeContractObj"></changeContractDialog>
    <GLDialog :visible.sync="tipObj.visible" :close-on-click-modal="false" mode="small" title="提示" @onOk="toInitTmpl" @onCancel="closeTipDialog" :before-close="closeTipDialog">
      <div class="tip-body">
        <i class="el-icon-warning icon"></i>
        <p class="title">是否确认初始化?</p>
        <p class="content">选中的商品合同模板将初始化,读取后台的最新配置</p>
      </div>
    </GLDialog>
  </div>
</template>

<script>
const throttle = function (fn, time) {
  let timer = null
  time = time || 1000
  return function (...args) {
    if (timer) {
      return
    }
    const _this = this
    timer = setTimeout(() => {
      timer = null
    }, time)
    fn.apply(_this, args)
  }
}
import * as dayjs from 'dayjs'
import utils from '../../util/util'
import pdfDialog from '@/views/beforeSale/pdfDialog'
import changeContractDialog from './components/changeContractDialog'
export default {
  name: 'goodIndex',
  components: {
    pdfDialog,
    changeContractDialog
  },
  data() {
    return {
      size: 'small',
      tipObj: {
        visible: false,
        ids: []
      },
      isPdfVisible: false,
      changeContractObj: {
        visible: false,
        id: ''
      },
      buttonList: [
        {
          type: 'el-button',
          name: row => {
            return '打印'
          },
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.handlePdf(row.scope)
          }
        },
        {
          type: 'el-button',
          name: row => {
            return '编辑'
          },
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.editContract(row.scope)
          }
        },
        {
          type: 'el-button',
          name: row => {
            return '更换合同'
          },
          attrs: {
            type: 'text',
            fn: '更换模板'
          },
          listeners: {
            click: row => this.changeContractTMPL(row.scope)
          }
        },
        {
          type: 'el-button',
          name: row => {
            return '模板初始化'
          },
          attrs: {
            type: 'text',
            fn: '模板初始化'
          },
          listeners: {
            click: row => this.initTmpl(row.scope)
          }
        }
      ],
      searchForm: {
        merchantName: '',
        packageName: '',
        createdDate: '',
        updatedDate: ''
      },
      tableSearchForm: {},
      searchFormData: [
        {
          label: '商户名称',
          name: 'merchantName',
          type: 'input',
          isClear: true
        },
        {
          label: '商品名称',
          name: 'packageName',
          type: 'input',
          isClear: true
        },
        {
          label: '创建时间',
          name: 'createdDate',
          type: 'datePicker',
          labelWidth: 95,
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        },
        {
          label: '更新时间',
          name: 'updatedDate',
          type: 'datePicker',
          labelWidth: 95,
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        }
      ],
      // 表格
      getListApi: this.$apis.contractManager.getContractListApi,
      tableParams: {
        listName: 'list',
        mutiSelectName: 'tmplIndex',
        mutiSelectUniqueKey: 'id',
        tableOption: true,
        tableColumns: [
          {
            label: '合同编号',
            prop: 'id'
          },
          {
            label: '商户名称',
            prop: 'merchantName'
          },
          {
            label: '商品名称',
            prop: 'packageName'
          },
          {
            label: '创建时间',
            prop: 'createdDate',
            formatter: cellValue => {
              return cellValue.createdDate ? dayjs(cellValue.createdDate).format('YYYY-MM-DD HH:mm:ss') : '--'
            }
          },
          {
            label: '更新时间',
            prop: 'updatedDate',
            formatter: cellValue => {
              return cellValue.updatedDate ? dayjs(cellValue.updatedDate).format('YYYY-MM-DD HH:mm:ss') : '--'
            }
          },
          {
            label: '操作人',
            prop: 'updatedBy',
            width: 140
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' }
    }
  },

  mounted() {},

  methods: {
    closeTmplDialog() {
      this.changeContractObj.visible = false
      this.handleSearch()
    },
    batchChangeTmpl() {
      const data = this.$refs.equityRef?.mutiSelectArr?.[this.tableParams.mutiSelectName] || []
      const ids = data.map(item => item.id)
      if (!ids.length) return this.$message.error('请选择需要变更模板的合同')
      this.changeContractObj = {
        visible: true,
        id: '',
        ids
      }
    },
    batchInitTmpl() {
      const data = this.$refs.equityRef?.mutiSelectArr?.[this.tableParams.mutiSelectName] || []
      const ids = data.map(item => item.id)
      if (!ids.length) return this.$message.error('请选择需要初始化的合同')
      this.tipObj = {
        visible: true,
        ids
      }
    },
    initTmpl(row) {
      this.tipObj = {
        visible: true,
        ids: [row.id]
      }
    },
    toInitTmpl() {
      const params = {
        templateIds: this.tipObj.ids
      }
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      this.$apis.contractManager
        .babchInitTemplateApi(params)
        .then(res => {
          if (res) {
            this.$message.success('初始化模板成功')
            this.closeTipDialog()
          }
        })
        .finally(end => {
          loading.close()
        })
    },
    closeTipDialog() {
      this.tipObj = {
        visible: false,
        ids: []
      }
      this.handleSearch()
    },
    changeContractTMPL(row) {
      this.changeContractObj = {
        visible: true,
        id: row.id
      }
    },
    getParams() {
      let params = JSON.parse(JSON.stringify(this.searchForm))
      if (this.searchForm?.createdDate?.length) {
        params.beginCreateDate = new Date(this.searchForm.createdDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.endCreateDate = new Date(this.searchForm.createdDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      }
      if (this.searchForm?.updatedDate?.length) {
        params.beginUpdateDate = new Date(this.searchForm.updatedDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.endUpdateDate = new Date(this.searchForm.updatedDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      }
      delete params.createdDate
      delete params.updatedDate
      return { ...params }
    },

    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        resolve()
      })
    },

    handlePdfClose() {
      this.isPdfVisible = !this.isPdfVisible
    },

    // 打印
    handlePdf(row) {
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      this.$apis.contractManager.printContractApi({ packageCode: row.packageCode, merchantId: row.merchantId }).then(res => {
        this.pdfUrl = res
        this.handlePdfClose()
        loading.close()
      })
    },

    // 导出
    handleExport: throttle(function () {
      var params = this.getParams()
      this.$apis.contractManager.exportContractApi(params).then(res => {
        // window.open(res)
        let tempaa = utils.getExplorer()
        if (tempaa == 'QQ') {
          window.open(res)
        } else {
          let iframe = document.createElement('iframe')
          iframe.style.display = 'none'
          iframe.src = res
          document.body.appendChild(iframe)
        }
      })
    }, 1000),

    handleSearch() {
      this.$refs.equityRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        serviceName: '',
        packageName: '',
        createdDate: '',
        updatedDate: ''
      }
      this.handleSearch()
    },

    editContract(row) {
      const { id, merchantId } = row || {}
      let query = {
        id
      }
      const queryStr = encodeURIComponent(JSON.stringify(query))
      this.$router.push('/ContractManager/addTmpl/' + queryStr)
    }
  }
}
</script>

<style lang="scss" scoped>
.find_wrap {
  background: #ffffff;
  padding: 20px 20px 2px 20px;
  .resetBtn {
    background: #ffffff;
    color: #2a58ad;
    border: 1px solid #2a58ad;
  }
  .m-r-l-20 {
    margin: 0 20px;
  }
}
.table_wrapper {
  background: #ffffff;
  padding: 0 20px 20px;
}

.tip-body {
  width: 100%;
  text-align: center;
  .icon {
    font-size: 48px;
    color: #2a58ad;
    margin-top: 18px;
  }
  .title {
    font-weight: 400;
    font-size: 16px;
    color: #333333;
    text-align: center;
    margin: 12px 0 8px;
  }
  .content {
    font-weight: 400;
    font-size: 14px;
    color: #666666;
    text-align: center;
  }
}
</style>