var docInfo = JSON.parse(window.localStorage.getItem('wlyyAgent')); function showSuccessMessage(msg) { layer.msg(msg, { icon: 1 }) } function showErrorMessage(msg) { layer.msg(msg, { icon: 5 }) } function showWarningMessage(msg) { layer.msg(msg, { icon: 2 }) } function showInfoMessage(msg) { layer.msg(msg, { icon: 6 }) } var TemplateItems = { template: '
\
\ {{name}}\
\
\ 请在左侧“服务项”列表中选择\
\
\
\
{{o.name}}
\
\
\ 医  院:\ 待选择\
\
\ 执行人员:\ 待选择\
\
\
\
\ 计划时间:\ 待选择\
\
\ 费  用:\ 0.00元\
\
\ \
\
\
\ \ 删除模板\ \ \ 保存模板\ \
\
', props: [], data: function() { return { name: '', items: [], isNew: null, templateId: "", item: null } }, beforeRouteEnter: function (to, from, next) { next(function(vm) { var query = vm.$route.query vm.name = query.name || '模板未命名', vm.templateId = query.templateId if(from.path != "/template-item-detail" || from.path == "/") { vm.items = [] } if(vm.isNew == true || vm.isNew === "true") { vm.isNew = true } else { vm.isNew = false } }) }, created: function() { var vm = this EventBus.$on("add-template-item", function(o) { vm.items.push(o) }) }, mounted: function() { var vm = this }, methods: { deleteItem: function(o, i) { var vm = this o.enable = true vm.items.splice(i, 1) EventBus.$emit("delete-template-item", o, i) }, saveTemplate: function() { var vm = this if(this.name=='系统模板'){ showErrorMessage('不能编辑系统模板!') return false } vm.loading.showModal() rehaAPI.createTemplateDetail({ doctor: docInfo.uid, json: JSON.stringify({ templateId: vm.templateId, hospitalServiceItemId: _.pluck(vm.items, 'code').join(',') }), type: vm.isNew?"create":"edit" }).then(function(res) { if(res.status == 200) { vm.loading.close() showSuccessMessage('保存成功') EventBus.$emit("refresh-index") vm.$router.replace("/") } else { vm.loading.close() showErrorMessage(res.msg) } }).catch(function(e) { vm.loading.close() console.error(e) }) }, deleteTemplate: function() { var vm = this if(this.name=='系统模板'){ showErrorMessage('不能删除系统模板!') return false } layer.confirm('确定删除该模板?', { btn: ['确认','取消'] //按钮 }, function(){ vm.loading.showModal() rehaAPI.deleteTemplate({ templateId: vm.templateId }).then(function(res) { vm.loading.close() if(res.status == 200) { showSuccessMessage('删除成功') } else { showErrorMessage(res.msg) } EventBus.$emit("refresh-index") vm.$router.replace("/") }).catch(function(e) { vm.loading.close() console.error(e) }) }, function(){ }); }, toDetail: function(o) { var vm = this vm.item = o vm.$router.push({ path:"/template-item-detail", query: { templateId: vm.templateId, itemId: o.code } }) } }, // watch: { // '$route': function (to, from) { // var vm = this //// if(to.path == "/template-item-detail" && (from.path != "/template-item-detail" || from.path == "/")) { //// EventBus.$emit("show-item-detail", vm.item) //// } // if(to.path == "/template-item-detail") { // EventBus.$emit("show-item-detail", vm.item) // } // } // } }