<template> <el-dialog title="自动回复" center :visible.sync="dialogObj.show" width="800px"> <div class="focus-reply"> <div class="content"> <div class="inner" v-loading="loading"> <ul class="weui-desktop-msg-sender__tabs"> <li class="weui-desktop-msg-sender__tab weui-desktop-msg-sender__tab_text" :class="type === 'text' ? 'weui-desktop-msg-sender__tab_selected' : ''" @click="type = 'text'">文字</li> <li class="weui-desktop-msg-sender__tab weui-desktop-msg-sender__tab_img" :class="type === 'image' ? 'weui-desktop-msg-sender__tab_selected' : ''" @click="type = 'image'">图片</li> </ul> <div class="inner-bottom"> <div class="img-action" v-if="type === 'image'"> <template v-if="imageContent"> <div class="my-teacher" v-if="imageContent.variable">我的老师二维码</div> <img style="max-width: 80%" v-if="imageContent.content" :src="imageContent.content"/> </template> <div class="display-b"> <div class="img-create-access" v-if="!showMedia"> <a href="javascript:;" class="img-create-access__link" @click="getMediaList('image')">从素材库中选择</a> </div> <div class="img-create-access" v-if="!showMedia"> <a href="javascript:;" class="img-create-access__link" @click="addTeacherQrcode">添加老师二维码</a> </div> </div> <div v-if="showMedia && mediaList.length > 0"> <el-table :data="mediaList" @row-click="onChooseMedia" style="width: 100%"> <el-table-column prop="name" label="名称"> </el-table-column> <el-table-column prop="media_id" label="mediaId"> </el-table-column> <el-table-column label="URL"> <template slot-scope="scope"> <a :href="scope.row.url" target="_blank"> <img style="width: 60px;" :src="scope.row.url"/> </a> </template> </el-table-column> </el-table> <page :total="total" v-model="nowPage" :limit="limit" @pageChange="onPageChange"/> </div> </div> <div class="inner-emotion_editor" v-else-if="type === 'text'"> <div class="inner-edit_area"> <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 8}" placeholder="请输入内容" v-model="content"> </el-input> </div> <div style="float: right"> <el-popover placement="bottom-end" width="400" :offset="10" trigger="manual" v-model="showEmotion"> <div> <emotion @emotion="handleEmotion" :height="200" ></emotion> </div> <el-button @click="showEmotion = !showEmotion" slot="reference" type="text"> <span class="icon_emotion emotion_switch"></span> </el-button> </el-popover> <el-button @click="addTeacherName" type="warning" plain>添加老师名字</el-button> <el-button @click="addTeacherAlias" type="success" plain>添加老师别名</el-button> </div> </div> </div> <div class="tool_bar"> <el-button @click="close">取 消</el-button> <el-button class="weui-desktop-btn weui-desktop-btn_primary" @click="save">保存</el-button> <!--<div class="weui-desktop-popover__wrp">--> <!--<span class="weui-desktop-popover__target"><button class="weui-desktop-btn weui-desktop-btn_default">删除回复</button></span>--> <!--</div>--> </div> </div> </div> </div> </el-dialog> </template> <script> import {updateConfigApi,saveConfigApi,getMediaListApi,getConfigListApi,getTeacherListApi} from "../../service/api"; import page from '../framework/page' import emotion from '../framework/Emotion/index' export default { name: "focusReplyDialog", props:[ 'dialogObj' ], data(){ return{ show: false, loading:false, showEmotion: false, total:0, nowPage:1, limit: 5, id: null, list: [], index: -1, form:{ key:'', value:'', desc:'' }, content: '', imageContent: '', type: 'text', mediaList: [], mediaListMock: [], showMedia: false, pickerOptions1: { disabledDate(time) { return !(time.getTime() > Date.now()); } }, rules:{ value:[ { required: true, message: '请输入规则名称', trigger: 'change' } ], desc:[ { required: true, message: '请输入回复内容', trigger: 'change' } ], qr:[ { required: true, message: '请输入二维码', trigger: 'change' } ] } } }, components:{ page, emotion }, mounted(){ this.initDialog(); }, filters: { }, methods:{ addTeacherName(){ this.content += '{my_teacher_name}' }, addTeacherAlias(){ this.content += '{my_teacher_alias}' }, handleEmotion (i) { this.content += i }, initDialog(){ if (this.dialogObj.id) { this.id = this.dialogObj.id; } this.form.key=this.dialogObj.key; this.form.value=this.dialogObj.value; this.index = this.dialogObj.index this.list = this.dialogObj.list || [] if (this.index === -1) { this.type = 'text' this.content = '' } else { this.type = this.list[this.index].type; if (this.type === 'text') { this.content = this.list[this.index].content } else if (this.type === 'image') { let obj = { type: 'image' } if(this.list[this.index].content) { obj.content = this.list[this.index].content } if(this.list[this.index].media_id) { obj.media_id = this.list[this.index].media_id } if(this.list[this.index].variable) { obj.variable = this.list[this.index].variable } this.imageContent = obj } } }, close(){ this.$emit("changeShow", false); }, save(){ let json = this.form let _desc = this.list || []; if (this.type === 'text') { if (!this.content) { this.$message({ showClose: true, message: '请输入文本内容' }); return; } let obj = { type : this.type, content: this.content }; if (this.index > -1) { _desc[this.index] = obj } else { _desc.push(obj) } } else if (this.type === 'image') { if (!this.imageContent) { this.$message({ showClose: true, message: '请选择图片' }); return } if (this.index > -1) { _desc[this.index] = this.imageContent } else { _desc.push(this.imageContent) } } json.desc = JSON.stringify(_desc) if (this.id) { updateConfigApi(this.id,json).then(res=>{ this.$message({ type: 'success', message: '修改成功!' }); this.$emit("reflash"); this.$emit("changeShow", false); this.show = false; }) } else { saveConfigApi(json).then(res=>{ this.$message({ type: 'success', message: '保存成功!' }); this.$emit("reflash"); this.$emit("changeShow", false); }) } }, onPageChange(val){ this.nowPage = val this.getMediaList(this.type) }, getMediaList(type){ let json = { type: type, page: this.nowPage, limit: this.limit }; this.loading = true; getMediaListApi(json).then(res=>{ this.loading = false; this.type = type; this.total = res.total_count; if (res.item.length === 0 ) { this.$message({ showClose: true, message: '暂无数据' }); this.showMedia = false; } else { this.showMedia = true; this.mediaList = res.item; } }).catch(() => { this.loading = false; this.showMedia = false; }) }, onChooseMedia(val){ this.addContent(this.type, val.url, val.media_id); this.showMedia = false; }, addTeacherQrcode(){ this.imageContent = { type: 'image', variable:'my_teacher' } }, addContent(type, content, mediaId) { let obj = {}; if (content) { obj = { type: type, content: content }; } if (mediaId) { obj.media_id = mediaId; } this.imageContent = obj } } } </script> <style scoped> .focus-reply { padding: 30px; } ul, ol { padding-left: 0; list-style-type: none; } .title { color: #353535; font-size: 20px; font-weight: 400; line-height: 1; } .content { } .inner { position: relative; border: 1px solid #E4E8EB; background-color: #FFFFFF; } .inner-bottom { border-top: 1px solid #E4E8EB; } .img-action { padding: 17px 20px; min-height: 215px; text-align: center; } .img-create-access { position: relative; border: 2px dotted #E4E8EB; width: 48.6%; height: 211px; text-align: center; } /*.img-create-access:first-child {*/ /*float: left;*/ /*}*/ .img-create-access__link { display: inline-block; vertical-align: middle; color: #9A9A9A; margin: 0 10px; margin-top: 68px; text-decoration: none; } .img-create-access__link:before { content: " "; display: block; width: 36px; height: 36px; margin: 0 auto 5px; background: transparent url(https://res.wx.qq.com/mpres/en_US/htmledition/pages/modules/msg_sender/images/icon36_add_gray.png) no-repeat 0 0; } .weui-desktop-msg-sender__tabs { line-height: 38px; background-color: #FFFFFF; } .sender__tab_selected { color: #44B549; } .weui-desktop-msg-sender__tab:hover, .weui-desktop-msg-sender__tab_selected { color: #44B549; } .weui-desktop-msg-sender__tab { display: inline-block; padding: 0 20px; cursor: pointer; } .weui-desktop-msg-sender__tab:hover.weui-desktop-msg-sender__tab_text:before, .weui-desktop-msg-sender__tab_selected.weui-desktop-msg-sender__tab_text:before { background-image: url(https://res.wx.qq.com/mpres/en_US/htmledition/pages/modules/msg_sender/svg/default/sender_text_current.svg); } .weui-desktop-msg-sender__tab_img:before { background: transparent url(https://res.wx.qq.com/mpres/en_US/htmledition/pages/modules/msg_sender/svg/default/sender_img.svg) no-repeat 0 0; } .weui-desktop-msg-sender__tab:hover.weui-desktop-msg-sender__tab_img:before, .weui-desktop-msg-sender__tab_selected.weui-desktop-msg-sender__tab_img:before { background-image: url(https://res.wx.qq.com/mpres/en_US/htmledition/pages/modules/msg_sender/svg/default/sender_img_current.svg); } .weui-desktop-msg-sender__tab:before { content: " "; display: inline-block; width: 22px; height: 20px; vertical-align: middle; margin: -0.2em 5px 0 0; } .tool_bar { padding-top: 0; padding-bottom: 50px; /*margin-top: 40px;*/ margin-left: 20px; } .tool_bar > .weui-desktop-btn { margin-right: 1em; } .weui-desktop-btn_primary { background-color: #1AAD19; border-color: #1AAD19; color: #FFFFFF; } .weui-desktop-btn { display: inline-block; padding: 0 22px; min-width: 54px; line-height: 2.42857143; vertical-align: middle; text-align: center; text-decoration: none; border-radius: 3px; font-size: 14px; cursor: pointer; border-width: 1px; border-style: solid; box-sizing: content-box; } .weui-desktop-popover__wrp { display: inline; position: relative; font-size: 14px; } .weui-desktop-btn_default { background-color: #FBFBFB; border-color: #E4E8EB; color: #353535; } .inner-emotion_editor { margin: 2%; } .shotcut { width: 50px; } .emotion_switch { float: left; height: 28px; line-height: 999em; overflow: hidden; background: transparent url(https://res.wx.qq.com/mpres/en_US/htmledition/pages/modules/reply/images/icon_emotion_switch.png) no-repeat 0 0; width: 20px; height: 20px; vertical-align: middle; display: inline-block; } .display-b { display: flex; flex-flow: row nowrap; justify-content: space-between; align-items: center; } .my-teacher{ height: 150px; line-height: 150px; width: 50%; margin-left: 25%; border: 1px dashed #666; margin-bottom: 10px; } </style>