let message_id = $('#message_id').val(); const App = { mixins: [sharedMixin],/////共用的方法///// data() { return { message_id: message_id, dialog: { addDialogStatus: false, }, loading: { loading: false, addLoading: false, }, loading_attachment: false, attachmentList: [], message_title: "新增商城消息", other: {}, clearable: false, searchdata: { page: 1, page_size: 20, kw: '', }, messageRules: { title: [ { required: true, message: '请输入消息标题', trigger: 'blur' } ], publish_time: [ { required: true, message: '请填写发布时间', trigger: 'blur' }, ], content: [ { required: true, message: '请输入消息内容', trigger: 'blur' } ], }, messageInfo: { title: '', publish_time: this.curentTime(), content: '', }, msgCategoryList: [], msgCategoryList: [], curr_category_id: '', }; }, mounted() { this.getMsgCategoryList(); this.getTinymce(); this.create(); }, created() { }, methods: { handleCategory(val) { const that = this; that.curr_category_id = val that.messageInfo.sub_msg_category_id = 0; }, // 新增与编辑 create() { const that = this; if (that.message_id > 0) { that.message_title = "编辑商城消息" let url = "/admin/" + viewPath + "/getMessageDetail.html" postRequest(url, { message_id: that.message_id }).then(res => { if (res.data.code === 200) { that.messageInfo = res.data.info that.getAttachmentList(); tinymce.get('tinymce-content').setContent(that.messageInfo.content); that.curr_category_id = that.messageInfo.msg_category_id } else { that.$notify.error({ title: '错误', position: 'top-left', message: res.data.message }); } }).catch((error) => { that.$notify.error({ title: "错误", position: "top-left", message: "请求发生错误,请稍后重试", }); }); } else { that.message_title = "新增商城消息" } }, // 删除消息 deleteMessage(index) { const that = this; let { id } = that.messageList[index]; that.$confirm( '确定删除吗?', '警告', { confirmButtonText: '删除', cancelButtonText: '取消', type: 'warning', center: true, } ).then(() => { let url = "/admin/" + viewPath + "/deleteMessage.html" postRequest(url, { id: id }).then(res => { if (res.data.code === 200) { that.$notify({ title: '成功', message: res.data.message, position: 'top-left', type: 'success' }); that.messageList.splice(index, 1) } else { that.$notify.error({ title: '错误', position: 'top-left', message: res.data.message }); } }).catch((error) => { that.$notify.error({ title: "错误", position: "top-left", message: "请求发生错误,请稍后重试", }); }); ///////////// }).catch(() => { //取消,不做处理 }) }, // 上传附件 uploadAttachment(param) { const that = this; var fileobj = param.file; var form = new FormData(); form.append('file', fileobj); form.append('message_id', that.messageInfo.id); const url = "/admin/" + viewPath + "/uploadAttachment.html"; axios.post(url, form).then((res) => { if (res.data.code === 200) { that.getAttachmentList(); } param.onSuccess(res) }).catch(({ err }) => { param.onError(err) }); }, // 获取附件列表 getAttachmentList() { const that = this; that.loading_attachment = true; const url = "/admin/" + viewPath + "/getAttachmentList.html"; postRequest(url, { message_id: that.messageInfo.id }).then((res) => { that.loading_attachment = false; if (res.data.code === 200) { that.attachmentList = res.data.list;////商品附件列表 } else { that.attachmentList = []; } }).catch((error) => { // 处理请求失败的情况 that.loading_attachment = false; }); }, // 删除附件 deleteAttachment(index) { const that = this; let { id } = that.attachmentList[index]; that.$confirm( '确定删除吗?', '警告', { confirmButtonText: '删除', cancelButtonText: '取消', type: 'warning', center: true, } ).then(() => { let url = "/admin/" + viewPath + "/deleteAttachment.html" postRequest(url, { id: id }).then(res => { if (res.data.code === 200) { that.$notify({ title: '成功', message: res.data.message, position: 'top-left', type: 'success' }); that.attachmentList.splice(index, 1) } else { that.$notify.error({ title: '错误', position: 'top-left', message: res.data.message }); } }).catch((error) => { that.$notify.error({ title: "错误", position: "top-left", message: "请求发生错误,请稍后重试", }); }); ///////////// }).catch(() => { //取消,不做处理 }) }, // 提交表单 submitForm() { let that = this; that.messageInfo.content = tinymce.get('tinymce-content').getContent() that.$refs['Form'].validate(valid => { if (valid) { if (that.loading.addLoading) { return; } that.loading.addLoading = true; const url = "/admin/" + viewPath + "/saveMessage.html"; postRequest(url, that.messageInfo).then((res) => { if (res.data.code === 200) { that.$notify({ title: "成功", message: res.data.message, position: "top-left", type: "success", }); that.messageInfo.id = res.data.id; } else { that.$notify.error({ title: "错误", position: "top-left", message: res.data.message, }); } that.loading.addLoading = false; // that.dialog.addDialogStatus = false; }).catch((error) => { // 处理请求失败的情况 that.$notify.error({ title: "错误", position: "top-left", message: "添加消息失败", }); that.loading.addLoading = false; }); } }); }, // 关闭表单 backForm() { document.location.href = "/admin/" + viewPath + "/index.html"; }, //获取消息分类信息列表 getMsgCategoryList() { const that = this; const url = "/admin/" + viewPath + "/getMsgCategoryList.html"; postRequest(url, {}).then((res) => { if (res.data.code === 200) { that.msgCategoryList = res.data.list;////商品附件列表 } else { that.msgCategoryList = []; } }).catch((error) => { // 处理请求失败的情况 }); }, // 初始化富文本编辑器 getTinymce() { tinymce.init({ selector: '.textarea', license_key: 'gpl', language: "zh_CN", entity_encoding: "raw", convert_urls: false, width: "100%", height: 500, fontsize_formats: "8pt 9pt 10pt 11pt 12pt 14pt 18pt 22pt 26pt 36pt", autoresize_min_height: 300, autoresize_max_height: 300, resize: false, statusbar: false, branding: false, promotion: false, }); }, } }; const app = Vue.createApp(App); for (const [key, component] of Object.entries(ElementPlusIconsVue)) { app.component(key, component) } app.use(ElementPlus, { locale: ElementPlusLocaleZhCn, }); app.mount("#vue_item");