messageModel.vue 11.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
<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>