var TeamEditPanel = { template: '
\
\ 指导模板\
\ 保存为个人模板\
\
\ 删除\
\
\
\
\ 模板名称:\
\
\ 所属团队:\
\
\
指导标签:{{selectedLabel && selectedLabel.name}}
\
    \
  • \
    \ {{label.name}}\
    \
  • \
\
\
\ \
{{count}}/{{words}}
\
\
\
\
插入图片({{imgs.length}}/9)
\
\
\ \
\
\ \
\
\
\ \ 预览\ \ \ 保存\ \ \ 发送\ \
\
', props: [], data: function() { return { words: 1000, count: 0, content: "", modelName: "", imgs: [], modelCode: "", teamId: "", teamTemplateCode: "", teams: [], labelsDropdown: false, selectedLabel: null, labelList: [], editable: true, sendMode: false // 根据url中是否携带patient来判断是否是"发送"模式 } }, 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 } if(query && query.teamTemplateCode && from.path != "/preview-panel") { vm.modelCode = query.modelCode vm.teamId = query.teamId vm.teamTemplateCode = query.teamTemplateCode vm.editable = true vm.getTeamGuidanceDetail().then(function() { vm.findAllLabelList() }) } }) }, computed: { isLeader: function() { var vm = this var leaderCode = storage.docInfo.adminTeamCode if(!vm.teams || !vm.teams.length || !leaderCode) { return 0 } var team = _.filter(vm.teams, function(o) { return o.teamId == leaderCode }) if(team.length) { vm.teams = team return 1 } return 0 } }, created: function() { }, mounted: function() { EventBus.$emit('active-nav-tab', 1) }, methods: { countWord: function() { if(this.content.length <= this.words) { this.count = this.content.length } else { this.content = this.content.slice(0, this.words) } }, findAllLabelList: function() { var vm = this return guidanceAPI.findAllLabelList({ teamId: vm.teamId }).then(function(res) { var selected = null var label = vm.selectedLabel? vm.selectedLabel.name: '未分组' selected = _.filter(res.data, function(o) { return o.name == label }) if(selected[0]) { selected[0].active = true vm.selectedLabel = selected[0] } vm.labelList = res.data }).catch(function(e){ console.error(e) }) }, selectLabel: function(label) { var vm = this vm.selectedLabel && (vm.selectedLabel.active = false) label.active = true vm.selectedLabel = label vm.labelsDropdown = false }, getTeamGuidanceDetail: function() { var vm = this return guidanceAPI.getTeamGuidanceDetail({teamTemplateCode: vm.teamTemplateCode,teamId:vm.teamId}).then(function(res) { if(res.status == 200) { var detail = res.guidanceDetail vm.teams = detail.teamList vm.modelName = detail.title vm.content = detail.content vm.imgs = detail.imagesUrl && detail.imagesUrl.split(',') || [] vm.selectedLabel = { name: detail.labelName, code: detail.labelCode } } }) }, 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.modifyTeamGuidance({ content: vm.content, title: vm.modelName, labelCode: vm.selectedLabel.code, images: vm.imgs.join(','), teamInfo: vm.teams&&JSON.stringify(vm.teams)||"", saveAsGuidance:0, guidanceCode: vm.teamTemplateCode, isLeader: vm.isLeader || 0 }).then(function(res) { if(res.status == 200) { toastr && toastr.success("保存成功") EventBus.$emit('refresh-team-panel') } }).catch(function(e) { console.error(e) }) }, deleteTemplate: function() { var vm = this var d = dialog({ width: 350, title: '删除模板', content: '删除后无法恢复,是否确认删除?', okValue: '确定', ok: function () { guidanceAPI.deleteTeamGuidance( { deleteAll: 0, guidanceCode: vm.teamTemplateCode, teamId:vm.teamId}).then(function(res) { toastr && toastr.success("删除成功") vm.editable = false EventBus.$emit('refresh-team-panel') }).catch(function(e) { console.error(e) }) }, cancelValue: '取消', cancel: function () {} }); d.showModal(); }, sendTeamTemplate: function() { var vm = this if(!vm.modelName) { toastr && toastr.error("模板名称不能为空") return } if(!vm.content) { toastr && toastr.error("模板内容不能为空") return } var team = _.filter(vm.teams, function(o) { return o.teamId == vm.teamId }) if(!team.length) { // 匹配不了说明医生修改了指导所属的 团队,并且入口团队并不在选中的列表中。则默认选择选中团队中的第一个团队来发送 team = [vm.teams[0]] } var d = dialog({ width: 350, content: '发出后无法变更,是否确认发送给居民?', okValue: '继续发送', ok: function () { guidanceAPI.sendTemplate( { patient: storage.patient, content: vm.content, guidanceCode: vm.teamTemplateCode, images: vm.imgs.join(','), teamId: JSON.stringify(team) }).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) { if(res.status == 200) { var index = top.layer && top.layer.getFrameIndex(window.name); //先得到当前iframe层的索引 top.layer && top.layer.close(index) } else { toastr && toastr.success(res.msg) } }) }).catch(function(e) { console.error(e) }) }, cancelValue: '取消', cancel: function () {} }); d.showModal(); }, 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) }) }, 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.teamTemplateCode && from.path == "/team-edit-panel"&& to.path == "/team-edit-panel") { vm.modelCode = query.modelCode vm.teamId = query.teamId vm.editable = true vm.teamTemplateCode = query.teamTemplateCode vm.getTeamGuidanceDetail().then(function() { vm.findAllLabelList() }) } 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() } } }