// import { speeChcraft, serviceCate, addServiceCate, addSpeeChcraft, serviceCateUpdate, editServiceCate } from '@/api/kefu' define([ 'kefu-assets/api/kefu', 'text!./index.html', 'css!./index.css' ], function (kefuApi, template) { return { name: "words", props: { isWords: { type: Boolean, default: false } }, computed: { cateStatus() { if (this.cateData.name && this.cateData.sort) { return false } else { return true } }, msgStatus() { if (this.msgData.message) { return false } else { return true } } }, data() { return { isWordShow: false, // 编辑窗 wordsList: [], wordsTab: [ { title: '个人库', key: 1 }, { title: '公共库', key: 0 } ], wordsTabCur: 1, wordsData: { isScroll: true, ops: { vuescroll: { mode: 'slide', enable: false, tips: { deactive: 'Push to Load', active: 'Release to Load', start: 'Loading...', beforeDeactive: 'Load Successfully!' }, auto: false, autoLoadDistance: 0, pullRefresh: { enable: false }, pushLoad: { enable: true, auto: true, autoLoadDistance: 10 } }, bar: { background: '#393232', opacity: '.5', size: '2px' } }, page: 1, limit: 10, searchTxt: '', cate: [], // 分类 cateId: '' // 分类id }, // 分组数据 cateData: { status: 0, // 0 新增 1编辑 name: '', sort: '', isCate: false, // 分组状态开关 id: '' }, // 编辑分组列表 editList: { status: false }, // 话术添加数据 msgData: { isCateMeg: false, msgCateId: '', message: '', title: '', status: 0, // 0 新增 1修改 editId: '' }, selectData: '' } }, mounted() { // Promise.all([this.getServiceCate()]) }, methods: { // 关闭添加话术弹窗 closeMsgBox() { this.msgData.isCateMeg = false }, // 选择话术 selectWords(item) { this.$emit('selectMsg', item.message) }, // 关闭弹窗 closeBox() { this.$emit('closeBox') }, // 搜索 bindSearch() { this.wordsData.page = 1 this.wordsData.isScroll = true this.wordsList = [] this.getWordsList() }, // 顶部切换 bindTab(item) { this.wordsTabCur = item.key this.wordsData.isScroll = true this.wordsData.page = 1 this.wordsData.cate = [] this.wordsList = [] this.getServiceCate() }, // 选择话术分类 changeCate(item) { this.wordsData.isScroll = true this.wordsList = [] this.wordsData.page = 1 this.wordsData.cateId = item.id this.msgData.msgCateId = item.id this.getWordsList() }, // 获取话术分类 getServiceCate() { serviceCate({ type: this.wordsTabCur }).then(res => { let tempArr = JSON.parse(JSON.stringify(res.data.data)) this.wordsData.cateId = res.data.data.length ? res.data.data[0].id : '' this.msgData.msgCateId = this.wordsData.cateId this.wordsData.cate = res.data.data this.selectData = tempArr this.getWordsList() }) }, // 话术滚动到底部 handleWordsScroll(vm, refreshDom, done) { this.getWordsList() done(); }, // 常用语 getWordsList() { speeChcraft({ page: this.wordsData.page, limit: this.wordsData.limit, title: this.wordsData.searchTxt, cate_id: this.wordsData.cateId, type: this.wordsTabCur }).then(res => { this.wordsData.isScroll = res.data.length >= this.wordsData.limit this.wordsList = this.wordsList.concat(res.data) this.wordsData.page++ }) }, // 打开分组弹窗 openCate(key, item) { this.cateData.status = key this.cateData.isCate = true if (key == 1) { this.cateData.name = item.name this.cateData.id = item.id } }, // 关闭分组弹窗 closeCate() { this.cateData.isCate = false this.cateData.name = '' this.cateData.sort = '' }, // 分组添加 cateConfirm() { if (!this.cateData.status) { addServiceCate({ name: this.cateData.name, sort: this.cateData.sort }).then(res => { this.cateData.isCate = false this.cateData.name = '' this.cateData.sort = '' this.page = 1 this.wordsData.isScroll = true this.wordsList = [] this.$Message.success(res.msg) this.getServiceCate() }).catch(error => { this.$Message.error(error.msg) }) } else { editServiceCate(this.cateData.id, { name: this.cateData.name, sort: this.cateData.sort }).then(res => { this.cateData.isCate = false this.cateData.name = '' this.cateData.sort = '' this.cateData.id = "" this.page = 1 this.wordsData.isScroll = true this.wordsList = [] this.$Message.success(res.msg) this.getServiceCate() }) } }, // 话术打开 addMsg() { this.msgData.isCateMeg = true this.msgData.status = 0 }, // 话术添加 msgConfirm() { if (!this.msgData.status) { addSpeeChcraft({ title: this.msgData.title, cate_id: this.msgData.msgCateId, message: this.msgData.message }).then(res => { this.msgData.isCateMeg = false this.msgData.title = '' this.msgData.message = "" this.msgData.msgCateId = this.wordsData.cateId this.$Message.success(res.msg) this.wordsData.isScroll = true this.wordsData.page = 1 this.wordsList = [] this.getWordsList() }).catch(error => { this.$Message.error(error.msg) }) } else { serviceCateUpdate(this.msgData.editId, { title: this.msgData.title, cate_id: this.msgData.msgCateId, message: this.msgData.message }).then(res => { this.msgData.isCateMeg = false this.msgData.title = '' this.msgData.message = "" this.msgData.msgCateId = this.wordsData.cateId this.$Message.success(res.msg) this.wordsData.isScroll = true this.wordsData.page = 1 this.wordsList = [] this.getWordsList() }) } }, // 编辑话术 bindEdit(item) { this.msgData.status = 1 this.msgData.isCateMeg = true this.msgData.message = item.message this.msgData.title = item.title this.msgData.editId = item.id }, // 删除话术 delMsg(row, tit, num) { let delfromData = { title: tit, num: num, url: `/service/speechcraft/${row.id}`, method: 'DELETE', ids: '', kefu: true }; this.$modalSure(delfromData).then((res) => { this.wordsList.splice(num, 1) this.$Message.success(res.msg); }).catch(res => { this.$Message.error(res.msg); }); }, delCate(row, tit, num) { let delfromData = { title: tit, num: num, url: `/service/cate/${row.id}`, method: 'DELETE', ids: '', kefu: true }; this.$modalSure(delfromData).then((res) => { this.wordsData.cate.splice(num, 1) this.page = 1 this.wordsData.isScroll = true this.wordsList = [] this.$Message.success(res.msg) this.getServiceCate() }).catch(res => { this.$Message.error(res.msg); }); } } } });