var PersonNewPanel = { template: '
\
\ 指导模板\
\ 保存为个人模板\
\
\
\
\ 模板名称:\
\
\ \
{{count}}/{{words}}
\
\
\
\
插入图片({{imgs.length}}/9)
\
\
\ \
\
\ \
\
\
\ \ 预览\ \ \ 新增\ \ \ 发送\ \
\
', props: [], beforeRouteEnter: function(to, from, next) { next(function(vm) { var query = vm.$route.query if(!storage.patient && !query.patient) { vm.sendMode = false } else { storage.patient = storage.patient || query.patient vm.sendMode = true } }) }, data: function() { return { words: 1000, count: 0, content: "", modelName: "", imgs: [], sendMode: false // 根据url中是否携带patient来判断是否是"发送"模式 } }, mounted: function() { EventBus.$emit('active-nav-tab', 0) }, methods: { countWord: function() { if(this.content.length <= this.words) { this.count = this.content.length } else { this.content = this.content.slice(0, this.words) } }, imgUploaded: function(url) { var vm = this vm.imgs.push(httpRequest.getImgUrl(url)) }, save: 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("发送成功") }).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(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() } } }