index.vue 6.46 KB
<template>
  <div>
    <GLDialog bigTitle="选择合同" mode="big" :visible.sync="changeContractObj.visible" :before-close="handleClose" :close-on-click-modal="false" @onOk="handleConfirm" @onCancel="handleClose">
      <glsx-combi-form ref="showSearch" labelWidth="105px" :formObj="searchForm" :formData="searchFormData">
        <span slot="footer">
          <el-button :size="size" type="primary" @click="getTable">查询</el-button>
        </span>
      </glsx-combi-form>
      <GLTable :hasNum="false" ref="contractTableRef" :noDataImg="url" :getListApi="getListApi" :searchForm="searchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn">
        <div slot="radioSlot" slot-scope="scope">
          <el-radio v-model="curId" :label="scope.scope.id">&nbsp;</el-radio>
        </div>
        <span slot="auth-button" slot-scope="scope" :data="scope.scope">
          <GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
        </span>
      </GLTable>
    </GLDialog>
    <pdf-dialog :isVisible="isPdfVisible" title="合同" :pdfUrl="pdfUrl" @closeDialog="handlePdfClose"></pdf-dialog>
  </div>
</template>
<script>
const TABLE_HEAD = [
  {
    label: '',
    prop: 'radioSlot',
    addHtml: 'radioSlot',
    width: '50'
  },
  {
    label: '合同编号',
    prop: 'id'
  }
]
import url from '@/assets/empty.png'
import pdfDialog from '@/views/beforeSale/pdfDialog'
import glsxCombiForm from '@/components/glsx-combi-form'
export default {
  name: 'changeContract',
  components: {
    pdfDialog,
    glsxCombiForm
  },
  props: {
    changeContractObj: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      size: 'small',
      isPdfVisible: false,
      pdfUrl: '',
      curId: '',
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      getListApi: this.$apis.contractManager.getContractListApi,
      searchForm: {
        id: '',
        templateName: ''
      },
      buttonList: [
        {
          type: 'el-button',
          name: row => {
            return '预览'
          },
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.handlePdf(row.scope)
          }
        }
      ],
      searchFormData: [
        {
          label: '合同编号',
          name: 'id',
          type: 'input',
          maxlength: 9,
          isClear: true,
          isHide: this.changeContractObj.isBase == 1
        },
        {
          label: '合同名称',
          name: 'templateName',
          type: 'input',
          maxlength: 20,
          isClear: true,
          isHide: this.changeContractObj.isBase != 1
        }
      ],
      tableParams: {
        listName: 'list',
        tableOption: {
          width: '100px'
        },
        tableColumns: []
      }
    }
  },
  created() {
    if (this.changeContractObj.isBase == 1) {
      this.tableParams.tableColumns = [
        ...TABLE_HEAD,
        {
          label: '合同名称',
          prop: 'templateName'
        }
      ]
    } else {
      this.tableParams.tableColumns = [
        ...TABLE_HEAD,
        {
          label: '关联商品',
          prop: 'packageName'
        }
      ]
    }
  },
  mounted() {},
  methods: {
    handlePdfClose() {
      this.isPdfVisible = !this.isPdfVisible
    },

    // 预览
    handlePdf(row) {
      if (this.changeContractObj.isBase == 1) {
        this.pdfUrl = row.previewUrl
        this.handlePdfClose()
        return
      }
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      let params = {
        packageCode: this.changeContractObj.isParent ? row.parentId : row.packageCode,
        merchantId: row.merchantId || '',
        baseFlag: this.changeContractObj.isParent ? 2 : (this.changeContractObj.isBase == 2 ? 1 : 0)
      }
      this.$apis.contractManager.printContractApi(params).then(res => {
        loading.close()
        if (res) {
          this.pdfUrl = res
          this.handlePdfClose()
        }
      })
    },
    beforeSearchFn() {
      const _apiStr = this.changeContractObj.isParent ? 'getProdPackageListApi' : (this.changeContractObj.isBase == 1 ? 'getBaseContractListApi' : this.changeContractObj.isBase == 2 ? 'getBaseTempListApi' : 'getContractListApi')
      this.getListApi = this.$apis.contractManager[_apiStr]
      return new Promise(resolve => {
        resolve()
      })
    },
    getTable() {
      this.$refs.contractTableRef.refreshTable()
    },
    handleConfirm() {
      if (!this.curId)
        return this.$message({
          message: '请选择变更模板的合同',
          type: 'error',
          customClass: 'msgHierarchy'
        })
      let params = {}
      let API = 'babchCopyTemplateApi' //默认为商品合同批量更换接口
      if (this.changeContractObj.isBase == 1) {
        //产品合同
        API = 'copyBaseTemplateApi'
        params = {
          baseTemplateId: this.curId,
          skuPackageCode: this.changeContractObj.skuPackageCode,
          skuId: this.changeContractObj.skuId
        }
      } else {
        params = {
          sourceId: this.curId,
          baseFlag: this.changeContractObj.isParent ? 2 : (this.changeContractObj.isBase == 2 ? 1 : 0)
        }
        if (this.changeContractObj.id) {
          //单个商品合同更换
          params.targetId = this.changeContractObj.id
          API = 'copyTemplateApi'
        } else {
          //商品合同批量
          params.targetIds = this.changeContractObj.ids
        }
        // 产品合同批量
        if (this.changeContractObj.isProdBatch) {
          params.targetIds = this.changeContractObj.ids
          API = 'copyTemplateApi'
        }
      }
      const loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.3)'
      })
      this.$apis.contractManager[API](params)
        .then(res => {
          if (res.data) {
            this.$message.success('变更模板成功')
            this.handleClose()
          } else {
            this.$message({
              message: res.message,
              type: 'error',
              customClass: 'msgHierarchy'
            })
          }
        })
        .finally(end => {
          loading.close()
        })
    },
    handleClose() {
      this.$emit('closeDialog')
    }
  }
}
</script>
<style lang="scss"></style>