index.vue 9.19 KB
<template>
  <div class="equity-wrap">
    <el-button type="primary" icon="el-icon-plus" size="small" @click="showDialog('add')"><span style="margin-left: 5px">新增特别约定</span></el-button>
    <div class="equity-wrap contain" style="margin-top: 10px">
      <GLCombiForm :rowNumber="1" ref="showSearch" :formObj="appointmentForm" :formData="searchFormData" @handleOk="seletTable('select')" @handleRest="seletTable('reset')"></GLCombiForm>
      <el-button plain style="float:right;margin-bottom:10px;" size="small" @click="exportTable" class="selectBtn">导出</el-button>
      <GLTable ref="appointmentTable" :searchForm="appointmentForm" :tableParams="tableParams" :pageConf="tablePageConf" :getListApi="getAppointmentList">
        <span slot="auth-button" slot-scope="scope" :data="scope.scope">
          <!-- 批次管理详情弹窗按钮 -->
          <!-- <el-button type="text" @click="showDialog(scope.scope)">修改</el-button>
          <el-button type="text" @click="del(scope.scope)">删除</el-button> -->
          <GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
        </span>
      </GLTable>
      <!-- 修改界面弹窗 -->
      <GLDialog class="gl-form-page gl-form-min" :title="dialogTitle" mode="mid" v-if="modifyDialog" :visible.sync="modifyDialog" :before-close="handleClose" @onOk="submitForm('modifyForm')" @onCancel="cancelDialog">
        <glsx-combi-form ref="spaRef" labelWidth="154px" defaultWidth="284px" formRef="modifyForm" :formObj="modifyDialogForm" :formData="modifyDialogData" :formRules="modifyDialogRules"></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'
export default {
  name: '',
  components:{
    glsxCombiForm
  },
  data() {
    return {
      date_format,
      buttonList: [
        {
          type: 'el-button',
          name: row => {
            return '修改'
          },
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.showDialog(row.scope)
          }
        },
        {
          type: 'el-button',
          name: row => {
            return '删除'
          },
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.del(row.scope)
          }
        }
      ],
      searchFormData:[
        {
          label: '特约名称',
          name: 'spaName',
          type: 'input'
        },
        {
          label: '特约内容',
          name: 'spaContent',
          type: 'input'
        }
      ],
      modifyDialogData: [
        {
          type: 'input',
          label: '特约名称',
          name: 'spaName',
          isClear: true,
        },
        {
          type: 'input',
          label: '特约内容',
          name: 'spaContent',
          isClear: true,
          maxlength: 200,
          inputType:'textarea',
        }
      ],
      isAdd: false,
      getAppointmentList: this.$apis.appointmentApi.getAppointmentList,
      dialogTitle: '',
      tablePageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' },
      modifyDialog: false,
      appointmentForm: {
        spaName: '',
        spaContent: ''
      },
      modifyDialogForm: {
        spaName: '',
        spaContent: '',
        id: null
      },
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: {
          width: 120
        },
        tableColumns: [
          {
            label: '特约名称',
            prop: 'spaName',
            width: 400,
            line:1
          },
          {
            label: '特约内容',
            prop: 'spaContent',
            width: 400,
            line:1
          },

          {
            label: '操作人',
            prop: 'updatedBy',
            minWidth: 100,
          },

          {
            label: '创建时间',
            prop: 'createdDate',
            width:220,
            formatter: cellValue => {
              return this.date_format(cellValue.createdDate)
            }
          },

          {
            label: '更新时间',
            prop: 'updatedDate',
            width:220,
            formatter: cellValue => {
              return this.date_format(cellValue.updatedDate)
            }
          }
        ]
      },
      modifyDialogRules: {
        spaName: [{ required: true, message: '请输入名称', trigger: 'blur' }],
        spaContent: [{ required: true, message: '请输入特约内容', trigger: 'blur' }]
      }
    }
  },
  mounted() {},
  methods: {
    handleClose() {
      this.modifyDialog = false
      this.modifyDialogForm = {}
    },
    cancelDialog() {
      this.modifyDialog = false
      this.modifyDialogForm = {}
    },
    submitForm(formName) {
      this.$refs.spaRef.$refs[formName].validate(valid => {
        if (valid) {
          this.$apis.appointmentApi.modifyAppointment(this.modifyDialogForm).then(res => {
            if (res.code == '0') {
              this.$message({
                message: '操作成功',
                type: 'success'
              })
              this.modifyDialog = false
              this.modifyDialogForm = {}
              this.$refs.spaRef.$refs.modifyForm.clearValidate()
              this.$refs.appointmentTable.refreshTable()
            } else {
              this.$message({
                message: '该特约名称已存在,请修改',
                type: 'error'
              })
            }
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    showDialog(e) {
      if (e == 'add') {
        this.dialogTitle = '新增特别约定'
        this.isAdd = true
      } else {
        let obj = JSON.parse(JSON.stringify(e))
        this.dialogTitle = '修改特别约定'
        this.isAdd = false
        this.modifyDialogForm = obj
      }
      this.modifyDialog = true
    },
    del(e) {
      this.modifyDialogForm = e
      this.$apis.appointmentApi.delAppointment(this.modifyDialogForm).then(res => {
        if (res == '1') {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.appointmentTable.refreshTable()
          this.modifyDialogForm = {}
        } else {
          this.$message({
            message: '新增失败',
            type: 'error'
          })
        }
      })
    },
    seletTable(e) {
      let params = {
        spaName: '',
        spaContent: '',
        pageSize: this.$refs.appointmentTable.page.pageSize,
        pageNum: this.$refs.appointmentTable.page.pageNum
      }
      if (e == 'reset') {
        this.appointmentForm.spaName = ''
        this.appointmentForm.spaContent = ''
        this.$apis.appointmentApi.getAppointmentList(params).then(res => {
          this.$refs.appointmentTable.refreshTable()
        })
      } else if (e == 'select') {
        params.spaName = this.appointmentForm.spaName
        params.spaContent = this.appointmentForm.spaContent
        this.$apis.appointmentApi.getAppointmentList(params).then(res => {
          this.$refs.appointmentTable.refreshTable()
        })
      }
    },
    //导出
    exportTable() {
      let params = {
        spaName: this.appointmentForm.spaName,
        spaContent: this.appointmentForm.spaContent,
        pageSize: this.$refs.appointmentTable.page.pageSize,
        pageNum: this.$refs.appointmentTable.page.pageNum
      }
      this.$apis.appointmentApi.exportAppointment(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)
        }
      })
      // this.$apis.appointmentApi.exportAppointment(params).then(res => {
      //   if (res) {
      //     console.log(res, 'res')
      //     var a = document.createElement('a')
      //     a.setAttribute('href', res)
      //     a.setAttribute('target', '_blank')
      //     a.setAttribute('id', 'd2admin-link-temp')
      //     a.setAttribute('download', '无忧卡导出' + '.xlsx') // 设置下载文件名称
      //     window.open(a)
      //     document.body.appendChild(a)
      //     a.click()
      //     document.body.removeChild(document.getElementById('d2admin-link-temp'))
      //   } else {
      //     console.log('导出失败')
      //   }
      // })
    }
  }
}
</script>

<style lang="scss" scoped></style>