messageModel.vue 10.9 KB
<template>
  <div class="square-main">
    <el-dialog title="选择模板" :visible.sync="dialogVisible" width="1142px" :before-close="handleClose" :close-on-click-modal="false">
      <div class="model-panel">
        <el-form :inline="true" class="message-form" :model="searchForm" ref="searchForm">
          <el-form-item label="模板标题">
            <el-input v-model="searchForm.title" :size="size" placeholder="请输入模板名称搜索"></el-input>
          </el-form-item>
          <el-form-item label="创建者">
            <el-select v-model="searchForm.createdBy" :size="size" placeholder="全部">
              <el-option v-for="item in createdList" :key="item.id" :label="item.createdName" :value="item.createdBy"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" :size="size" @click="search">查询</el-button>
          </el-form-item>
          <el-form-item style="float: right;margin-right: 0;">
            <el-button :size="size" icon="el-icon-plus" @click="createModel">新增模板</el-button>
          </el-form-item>
        </el-form>
        <!-- <div class="model-panel-tab">
          <label>模板类型:</label>
          <el-tabs v-model="activeName" @tab-click="handleClick" type="card">
            <el-tab-pane label="售前" name="1"></el-tab-pane>
            <el-tab-pane label="售中" name="2"></el-tab-pane>
            <el-tab-pane label="售后" name="3"></el-tab-pane>
          </el-tabs>
        </div>-->
        <div class="model-item-panel" v-if="!loading && modelList.length > 0" v-loading="loading">
          <div class="model-item" v-for="item in modelList" :key="item.id">
            <div class="model-item-radio">
              <el-radio v-model="messageRadio" :label="item"></el-radio>
            </div>
            <div class="model-item-title">
              <div class="model-title-h1">{{ item.title }}</div>
              <div class="model-title-h2">{{ item.content }}</div>
            </div>
            <div class="model-item-content">
              <div class="model-content">创建人:{{ item.createdName }}</div>
              <div class="model-content">创建日期:{{ item.createdTime }}</div>
            </div>
            <div class="model-item-btn">
              <el-button v-if="item.createdBy == userId" type="text" :size="size" @click="editModel(item.id)">编辑</el-button>
            </div>
          </div>
        </div>
        <div class="model-item-panel" v-else>
          <img src="@/assets/empty.png" />
          <div class="empty-item">暂无数据</div>
        </div>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNum" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" :total="tableTotal" :layout="layout"></el-pagination>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="handleClose">取 消</el-button>
        <el-button size="small" type="primary" @click="selectModelItem">复制文本</el-button>
      </span>
    </el-dialog>
    <el-dialog :title="modelTitle" :visible.sync="createVisible" width="547px" :before-close="handleCreateClose" :close-on-click-modal="false">
      <el-form :model="templateForm" :rules="templateRules" ref="templateForm" label-width="100px" class="templateForm">
        <el-form-item label="标题" prop="title">
          <el-input v-model="templateForm.title" maxlength="10" show-word-limit placeholder="输入10个字以内的标题,如活动促销"></el-input>
        </el-form-item>
        <el-form-item label="内容说明" prop="content">
          <el-input type="textarea" v-model="templateForm.content" maxlength="600" :rows="7" show-word-limit placeholder="输入不超过600字内的文字说明"></el-input>
        </el-form-item>
      </el-form>
      <div class="template-footer">
        <el-button size="small" @click="createModel">取 消</el-button>
        <el-button size="small" type="primary" :loading="createLoading" @click="handleCreate">立即创建</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'MessageModel',
  data() {
    return {
      dialogVisible: false,
      createVisible: false,
      loading: false,
      activeName: '1',
      messageRadio: {},
      modelList: [
        // {
        //   title: '121',
        //   content: 'jlkjl就离开家离开家离开jlkjl就离开家离开家离开jlkjl就离开家离开家离开jlkjl就离开家离开家离开jlkjl就离开家离开家离开jlkjl就离开家离开家离开jlkjl就离开家离开家离开',
        //   createdTime: '2022-01-04'
        // }
      ],
      pageNum: 1,
      pageSize: 10,
      tableTotal: 0,
      layout: '',
      searchForm: {},
      templateForm: {},
      templateRules: {
        title: [{ required: true, message: '请输入标题', trigger: 'blur' }],
        content: [{ required: true, message: '请输入标题', trigger: 'blur' }]
      },
      createLoading: false,
      createdList: [],
      modelTitle: '创建群发模板',
      userId: ''
    }
  },
  mounted() {
    console.log(this.$globalState, '222323')
    if (this.$globalState) {
      this.userId = this.$globalState.session.id
    }
  },
  methods: {
    init() {
      this.pageNum = 1
      this.messageRadio = {}
      this.dialogVisible = true
      this.dracImMessage()
      this.getCreatedList()
    },
    selectModelItem() {
      this.dialogVisible = false
      this.$emit('selectItem', this.messageRadio)
    },
    handleClick() {
      this.dracImMessage()
    },
    search() {
      this.dracImMessage(this.searchForm)
    },
    handleClose() {
      this.dialogVisible = false
      this.modelList = []
      this.tableTotal = 0
    },
    dracImMessage(searcher) {
      this.modelList = []
      this.loading = true
      let params = {
        pageSize: this.pageSize,
        pageNum: this.pageNum
      }
      if (searcher) {
        params.title = searcher.title
        params.createdBy = searcher.createdBy
      }
      this.$apis.customerTransform.templatePage(params).then(res => {
        console.log(res)
        if (res) {
          this.modelList = res.data
          this.tableTotal = res.count
          if (res.count > 10) {
            this.layout = 'pager'
          }
        }
        this.loading = false
      })
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange(val) {
      this.pageNum = val
      this.dracImMessage()
      console.log(`当前页: ${val}`)
    },
    createModel() {
      this.createVisible = !this.createVisible
      if (!this.createVisible) {
        this.templateForm = {}
      }
    },
    handleCreate() {
      this.$refs.templateForm.validate(valid => {
        if (valid) {
          console.log(this.templateForm)
          this.createLoading = true
          const params = {
            title: this.templateForm.title,
            content: this.templateForm.content
          }
          let api = 'templateSave'
          if (this.templateForm.id) {
            api = 'templateUpdate'
            params.id = this.templateForm.id
          }
          console.log(params)
          this.$apis.customerTransform[api](params).then(res => {
            console.log(res)
            this.createLoading = false
            if (res) {
              this.$message({
                type: 'success',
                message: '操作成功!'
              })
              this.pageNum = 1
              this.createModel()
              this.dracImMessage()
            }
          })
        }
      })
    },
    editModel(id) {
      this.createModel()
      this.modelTitle = '编辑群发模板'
      this.getTemplateDetail(id)
    },
    getCreatedList() {
      this.$apis.customerTransform.createdNameList({}).then(res => {
        this.createdList = res
      })
    },
    getTemplateDetail(id) {
      this.$apis.customerTransform.templateDetail({ id }).then(res => {
        console.log(res)
        if (res) {
          this.templateForm = res
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.model-panel {
  padding: 0 20px;
  .model-panel-tab {
    display: flex;
    align-items: center;
    margin-bottom: 18px;
    label {
      font-size: 16px;
      font-weight: 400;
      color: #000000;
      line-height: 24px;
    }
    /deep/ {
      .el-checkbox:last-of-type {
        margin-right: 8px;
      }
      .el-tabs__nav {
        border: 0;
      }
      .el-tabs__header {
        border: 0;
        background-color: #f4f6fc;
        margin: 0px;
      }
      .el-tabs__item {
        border: none;
        width: 180px;
        height: 32px;
        line-height: 32px;
        margin: 2px;
        text-align: center;
      }
      .el-tabs__item.is-active {
        background-color: #fff;
        border-radius: 4px;
      }
    }
  }
  .model-item-panel {
    max-height: 400px;
    overflow: auto;
    > img {
      display: block;
      margin: 50px auto 0px;
      width: 60px;
      height: auto;
    }
    .empty-item {
      text-align: center;
      font-size: 14px;
      font-weight: 400;
      color: #000000;
      line-height: 22px;
      margin-bottom: 30px;
    }
    .model-item {
      display: flex;
      padding: 20px;
      border-bottom: 1px solid #e9e9e9;
      &:last-child {
        border-bottom: none;
      }
      &-radio {
        width: 60px;
        /deep/ {
          .el-radio__input {
            margin-top: 10px;
          }
          .el-radio__label {
            display: none;
          }
        }
      }
      &-content {
        min-width: 210px;
        margin-right: 50px;
        .model-content {
          font-size: 14px;
          font-weight: 400;
          color: #999999;
          line-height: 20px;
        }
      }
      &-title {
        flex: 1;
        .model-title-h1 {
          font-size: 14px;
          font-weight: 400;
          max-width: 658px;
          color: #333333;
          line-height: 20px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .model-title-h2 {
          font-size: 14px;
          font-weight: 400;
          color: #999999;
          line-height: 20px;
          max-width: 658px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
      }
      &-btn {
        width: 30px;
        height: 40px;
      }
    }
  }
}
.message-form .el-form-item {
  margin-bottom: 0 !important;
}
/deep/ .el-pager {
  height: 30px;
}
.el-pagination {
  margin-top: 21px;
}
.templateForm {
  padding: 0 20px;
  /deep/ {
    .el-textarea__inner {
      background-color: #fff;
    }
    .el-textarea .el-input__count {
      background-color: #fff;
    }
  }
}
.template-footer {
  text-align: center;
  border-top: 1px solid #e6e6e6;
  padding-top: 16px;
  margin-bottom: -14px;
}
/deep/ {
  .el-dialog__body {
    padding: 30px 0;
  }
}
</style>