<!--
  @description: 发送短信-选择模板
  @Modifier: haofengxian
  @routerPath:
  @date: 2020-11-24-17:33
-->
<template>
  <el-dialog
    v-dialogDrag
    :visible.sync="dialog"
    :close-on-click-modal="false"
    title="选择模板"
    width="960px"
    append-to-body
    custom-class="el-dialog__body-p8 el-dialog_table"
  >
    <el-table
      ref="smallTable"
      v-loading="loading"
      :data="tableData"
      class="pointer"
      highlight-current-row
      size="mini"
      @current-change="currentChange"
    >
      <el-table-column
        type="index"
        label="序号"
        width="60px"
        align="center"
      />
      <el-table-column
        header-align="center"
        prop="templateCode"
        label="模板编号"
        min-width="120"
      />
      <el-table-column
        header-align="center"
        label="模板名称"
        prop="templateName"
        min-width="150"
      />
      <el-table-column
        header-align="center"
        label="模板内容"
        prop="templateContent"
        min-width="260"
      />
    </el-table>
    <!--分页组件-->
    <pagination :pagination-data="paginationData" @change="loadData" />
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="ensure">确 定</el-button>
      <el-button @click="dialog = false">取 消</el-button>
    </span>
  </el-dialog>
</template>

<script>
/* 接口*/
import { selectSmsSendTemplateList } from '@api/common/tools'
/* 组件*/
import pagination from '@comp/common/pagination/pagination' // 分页
/* 公用方法*/
import { filterObj } from '@/assets/js/utils'// 过滤空的key
/* 混合开发方法-参数字段*/
import { ListMixin } from '@/mixins/ListMixin'// 分页
export default {
  name: 'SelectSMSTemplateDialog',
  components: {
    pagination // 分页
  },
  mixins: [ListMixin],
  data() {
    return {
      loading: true, // 加载loading
      dialog: false,
      tableData: [], // 模板列表
      currentData: {}// 当前选择的信息
    }
  },
  methods: {
    // 打开弹框获取模板数据
    open() {
      this.dialog = true // 关闭弹框
      this.loadData()
    },
    // 查询短信模板
    loadData() {
      const params = this.getParams()// 查询条件
      selectSmsSendTemplateList(params).then(res => {
        this.loading = false
        this.tableData = res.data.records
        this.paginationData.total = res.data.total
      }).catch(() => {
        this.loading = false
      })
    },
    // 查询条件
    getParams() {
      const param = Object.assign({}, this.searchForm)
      param.pageNo = this.paginationData.pageNo
      param.pageSize = this.paginationData.pageSize
      return filterObj(param)// 过滤空的key
    },
    // 当前选择的信息
    currentChange(val) {
      this.currentData = val
    },
    // 选择模板-确定
    ensure() {
      if (this.currentData.templateParams) {
        this.$emit('call-back', this.currentData)
        this.dialog = false// 关闭弹框
      } else {
        this.$message({
          message: '请选择短信模板',
          type: 'warning'
        })
      }
    },
    // 搜索重置
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.search()
    },
    // 搜索
    search() {
      this.paginationData.pageNo = 1
      this.paginationData.pageSize = 10
      this.loadData()
    }
  }
}
</script>

<style scoped>

</style>
