var SystemSendPanel = { template: '
\
\ 指导模板\
\ 保存为个人模板\
\
\
\
\ 模板名称:\
\
\ \
{{count}}/{{words}}
\
\
\
\
插入图片({{imgs.length}}/9)
\
\
\ \
\
\ \
\
\
\ \ 预览\ \ \ 引用模板\ \ \ 发送\ \
\
', beforeRouteEnter: function(to, from, next) { next(function(vm) { var query = vm.$route.query if(query && query.modelCode && from.path != "/preview-panel") { vm.modelCode = query.modelCode vm.listDetail() } if(!storage.patient && !query.patient) { vm.sendMode = false } else { storage.patient = storage.patient || query.patient vm.sendMode = true } }) }, props: [], data: function() { return { words: 10000, count: 0, content: "", modelName: "", imgs: [], modelCode: "", sendMode: false // 根据url中是否携带patient来判断是否是"发送"模式 } }, mounted: function() { EventBus.$emit('active-nav-tab', 2) }, methods: { countWord: function() { if(this.content.length <= this.words) { this.count = this.content.length } else { this.content = this.content.slice(0, this.words) } }, listDetail: function() { var vm = this guidanceAPI.listDetail({ modelCode: vm.modelCode }).then(function(res) { var data = res.data if(data) { vm.content = data.content vm.modelName = data.modelName vm.imgs = _.map(data.imagesUrls, function(s) { return httpRequest.getImgUrl(s) }) } }) }, imgUploaded: function(url) { var vm = this vm.imgs.push(httpRequest.getImgUrl(url)) }, removeImg: function(url, idx) { var vm = this vm.imgs.splice(idx, 1) }, save: function() { var vm = this if(!vm.modelName) { toastr && toastr.error("模板名称不能为空") return } if(!vm.content) { toastr && toastr.error("模板内容不能为空") return } guidanceAPI.newTemplate({ content: vm.content, modelName: vm.modelName, imagesUrl: vm.imgs.join(',') }).then(function(res) { if(res.status == 200) { toastr && toastr.success("保存成功") } else { toastr && toastr.error(res.msg) } }).catch(function(e) { console.error(e) }) }, saveAsPersonTemplate: function() { var vm = this if(!vm.modelName) { toastr && toastr.error("模板名称不能为空") return } if(!vm.content) { toastr && toastr.error("模板内容不能为空") return } var param = { content: vm.content, modelName: vm.modelName } var img = vm.imgs.join(',').trim() if(img) { param.imagesUrl = img } guidanceAPI.newTemplate(param).then(function(res) { if(res.status == 200) { toastr && toastr.success("保存成功") EventBus.$emit('refresh-person-panel') } else { toastr && toastr.error(res.msg) } }).catch(function(e) { console.error(e) }) }, sendTemplate: function() { var vm = this if(!vm.modelName) { toastr && toastr.error("模板名称不能为空") return } if(!vm.content) { toastr && toastr.error("模板内容不能为空") return } var d = dialog({ width: 350, content: '发出后无法变更,是否确认发送给居民?', okValue: '继续发送', ok: function () { guidanceAPI.sendTemplate( { patient: storage.patient, content: vm.content, modelCode: vm.modelCode || "", images: vm.imgs.join(',') }).then(function(res) { toastr && toastr.success("发送成功") var obj = { rehabilitationDetailId: storage.planId, patientCode: storage.patient, // patientName: patientName, doctorCode: storage.docInfo.code, doctorName: storage.docInfo.name, relationRecordType: 2, //健康指导 relationRecordCode: res.data.id } guidanceAPI.saveRehabilitationOperateRecord({ dataJson: JSON.stringify(obj) }).then(function(res) { console.log(res) console.log(res.status) if(res.status == 200) { var index = parent.layer && parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引 parent.layer && parent.layer.close(index) } else { toastr && toastr.success(res.msg) } }) }).catch(function(e) { console.error(e) }) }, cancelValue: '取消', cancel: function () {} }); d.showModal(); }, preview: function() { var vm = this var query = { modelCode: vm.modelCode, patient: storage.patient||"", timestemp: $.now() } this.$router.push({path:'/preview-panel',query:query}) } }, watch: { '$route': function (to, from) { var vm = this var query = vm.$route.query if(query && query.modelCode && from.path == "/system-send-panel"&& to.path == "/system-send-panel") { vm.modelCode = query.modelCode vm.listDetail() } if(storage.patient) { vm.sendMode = true } else { vm.sendMode = false } if(to.path == "/preview-panel") { EventBus.$emit('preview-template', { content: vm.content, modelName: vm.modelName, imgs: vm.imgs }) } }, 'content': function(v) { this.countWord() } } }