index.vue 8.95 KB
<template>
  <div class="equity-wrap">
    <div class="equity-wrap contain">
      <el-button type="primary" @click="add" size="small" class="addButtom">生成</el-button>
      <div class="blank"></div>
      <GLTable ref="detailTable" :searchForm="addForm" :tableParams="addParams" :pageConf="addPageConf" style="margin-top: 10px" :getListApi="getWorryBatcnList">
        <span slot="auth-button" slot-scope="scope" :data="scope.scope">
          <!-- <el-button type="text" @click="download(scope.scope)">批量下载</el-button> -->
          <GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
        </span>
      </GLTable>
      <!-- 生成弹窗 -->
      <GLDialog class="gl-form-page gl-form-min" title="生成无忧卡" mode="mid" v-if="addDialog" :visible.sync="addDialog" :before-close="handleClose" @onOk="submitForm('detailForm')" @onCancel="cancelDetailDialog">
        <glsx-combi-form ref="productCard" labelWidth="154px" defaultWidth="284px" formRef="detailForm" :formObj="addDialogForm" :formData="addDialogFormData" :formRules="addDialogRules"></glsx-combi-form>
      </GLDialog>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import glsxCombiForm from '@/components/glsx-combi-form'
function date_format(date) {
  var date2 = new Date(date)
  var YY = date2.getFullYear() + '-'
  var MM = (date2.getMonth() + 1 < 10 ? '0' + (date2.getMonth() + 1) : date2.getMonth() + 1) + '-'
  var DD = date2.getDate() < 10 ? '0' + date2.getDate() : date2.getDate()
  var hh = (date2.getHours() < 10 ? '0' + date2.getHours() : date2.getHours()) + ':'
  var mm = (date2.getMinutes() < 10 ? '0' + date2.getMinutes() : date2.getMinutes()) + ':'
  var ss = date2.getSeconds() < 10 ? '0' + date2.getSeconds() : date2.getSeconds()
  return YY + MM + DD + ' ' + hh + mm + ss
}
import utils from '../../util/util'
const validatorActualPrice = (rule, value, callback) => {
  if (value) {
    var reg = /^[1-9]\d*$/
    if (reg.test(value)) {
      if (value > 200) {
        callback('请输入200万以内的价格')
      } else {
        callback()
      }
    } else {
      callback('请输入正整数')
    }
  } else {
    callback('请输入具体价格')
  }
}
const validatorQuantity = (rule, value, callback) => {
  if (value) {
    var reg = /^[1-9]\d*$/
    if (reg.test(value)) {
      if (value > 5000) {
        callback('请输入5000以内的数字')
      } else {
        callback()
      }
    } else {
      callback('请输入正整数')
    }
  } else {
    callback('请输入数量')
  }
}
export default {
  name: '',
  components:{
    glsxCombiForm
  },
  data() {
    return {
      date_format,
       buttonList: [
        {
          type: 'el-button',
          name: row => {
            return '批量下载'
          },
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.download(row.scope)
          }
        }
      ],
      getWorryBatcnList: this.$apis.addWorryFree.getWorryBatcnList,
      addDialogForm: {
        batchType: '',
        packageCode:'',
        quantity: '',
        actualPrice:'',
        servicePeriod: '',
        remark: ''
      },
      addDialogFormData: [
        {
          label: '版本',
          name: 'batchType',
          type: 'select',
          optionList: [
            {
              value: '1',
              label: '尊享版'
            },
            {
              value: '2',
              label: '畅享版'
            }
          ],
          optionId: 'value',
          optionLabel: 'label'
        },
        {
          label: '适用类型',
          name: 'packageCode',
          type: 'select',
          optionList: [],
          optionId: 'packageCode',
          optionLabel: 'packageName'
        },
        {
          type: 'input',
          label: '数量',
          placeholder:'请输入1-5000的数字',
          name: 'quantity',
          isClear: true
        },
        {
          type: 'input',
          label: '具体价格/万',
          name: 'actualPrice',
          isClear: true
        },
        {
          label: '使用年限',
          name: 'servicePeriod',
          type: 'select',
          isClear: true,
          optionList: [
            {
              value: '1',
              label: '1年'
            },
            {
              value: '2',
              label: '2年'
            },
            {
              value: '3',
              label: '3年'
            },
            {
              value: '4',
              label: '4年'
            },
            {
              value: '5',
              label: '5年'
            }
          ],
          optionId: 'value',
          optionLabel: 'label'
        },
        {
          type: 'input',
          label: '备注',
          inputType:'textarea',
          name: 'remark',
          isClear: true,
          placeholder:'请输入活动详情或规则',
          maxlength: 200
        }
      ],
      addDialog: false,
      addPageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      addDialogRules: {
        batchType: [{ required: true, message: '请选择版本', trigger: 'change' }],
        packageCode: [{ required: true, message: '请选择适应类型', trigger: 'change' }],
        actualPrice: [{ validator: validatorActualPrice, trigger: 'blur' }],
        servicePeriod: [{ required: true, message: '请选择使用年限', trigger: 'change' }],
        quantity: [{ validator: validatorQuantity, trigger: 'blur' }],
        remark: [{ required: true, message: '请输入备注', trigger: 'blur' }]
      },
      addParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: {
          width: 100
        },
        tableColumns: [
          {
            label: '批次号',
            prop: 'id'
          },
          {
            label: '生成时间',
            prop: 'createdDate',
            formatter: cellValue => {
              return this.date_format(cellValue.createdDate)
            }
          },

          {
            label: '数量',
            prop: 'quantity'
          },
          {
            label: '备注',
            prop: 'remark'
            // minWidth: '200'
          }
        ]
      }
    }
  },
  created() {
    this.getTypelist()
  },
  mounted() {},
  methods: {
    getTypelist(){
      this.$apis.addWorryFree.getTypelistApi({}).then(res => {
        if(!res?.length) return;
        let target = this.addDialogFormData.find(item => item.name == 'packageCode')
        target.optionList = res
      })
    },
    // changePgCode(e){
    //   const arr = [{
    //       value: '1',
    //       label: '1年'
    //     },
    //     {
    //       value: '2',
    //       label: '2年'
    //     },
    //     {
    //       value: '3',
    //       label: '3年'
    //     }]
    //   const moreArr = [{
    //       value: '4',
    //       label: '4年'
    //     },
    //     {
    //       value: '5',
    //       label: '5年'
    //     }]
    //   const target = this.addDialogFormData.find(item => item.name=='servicePeriod')
    //   target.optionList = (e=='PC0005' || e=='PC0007') ? [ ...arr, ...moreArr] : [...arr]
    //   this.addDialogForm.servicePeriod = ''
    // },
    //批量下载
    download(e) {
      this.$apis.addWorryFree.downLoads({ id: e.id }).then(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)
        }
      })
    },
    add() {
      this.addDialog = true
    },
    // 关闭弹窗界面
    cancelDetailDialog() {
      this.addDialog = false
      this.addDialogForm = {
        batchType: '',
        packageCode:'',
        quantity: '',
        actualPrice:'',
        servicePeriod: '',
        remark: ''
      }
    },
    submitForm(formName) {
      this.$refs.productCard.$refs[formName].validate(valid => {
        if (valid) {
          this.$apis.addWorryFree.addCards(this.addDialogForm).then(res => {
            if (res.code == '0') {
              this.$message({
                message: '操作成功',
                type: 'success'
              })
              this.cancelDetailDialog()
              this.$refs.detailTable.refreshTable()
            } else {
              this.$message({
                message: '新增失败',
                type: 'error'
              })
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.equity-wrap {
}
.addGood {
  margin-bottom: 20px;
  margin-left: 40px;
  padding: 8px 16px;
  // margin-bottom: 20px;
}
.row-btns {
  margin-top: 5px;
  margin-bottom: 10px;
}
.addButtom {
  float: right;
  margin-bottom: 10px;
}
/deep/ .el-pagination {
  margin-top: 20px;
}
</style>