var TemplateItemsSelect2 = { template: '
\
\ 项目表\
\
\ \
\
\ \
\
', props: [], data: function() { return { isNew: null, searchName: "", serviceItems: [], templateDetail: [] } }, beforeRouteEnter: function(to, from, next) { next(function(vm) { var query = vm.$route.query if(vm.isNew == true || vm.isNew === "true") { vm.isNew = true } else { vm.isNew = false } vm.templateId = query.templateId if((to.path == "/template-item-detail" || from.path == "/template-item-detail" ) && from.path != "/") { return } if(!vm.isNew) { vm.loading.show() vm.findTemplateDetail().then(function(res) { vm.loading.close() if(res.status == 200) { vm.templateDetail = res.data vm.getServiceItemList().then(function(){ _.each(vm.templateDetail, function(o) { EventBus.$emit("add-template-item", o) }) }) } else { toastr && toastr.error(res.msg) } }) } else { vm.getServiceItemList() } }) }, created: function() { }, mounted: function() { var vm = this EventBus.$on("delete-template-item", function(obj, i){ _.each(vm.serviceItems, function(item, index) { if(item.code==obj.code){ item.enable = true vm.$set(vm.serviceItems, index, item) vm.templateDetail.splice(i, 1) } }) }) }, methods: { goBack: function() { this.$router.replace('/'); }, addItem: function(o, k) { if(!o.enable){ return } o.enable = false EventBus.$emit("add-template-item", o) this.$set(this.serviceItems, k, o) this.templateDetail.push(o) }, debounceSearch: _.debounce(function() { var vm = this vm.getServiceItemList() }, 500, false), getServiceItemList: function(){ var vm = this return rehaAPI.getServiceItemList({ name: vm.searchName }).then(function(res) { vm.serviceItems = res.data var selected = vm.templateDetail var selectedIds = _.pluck(selected, "code") _.each(vm.serviceItems, function(o) { if(_.contains(selectedIds, o.code)) { o.enable = false } else { o.enable = true } }) }) }, findTemplateDetail: function() { var vm = this return rehaAPI.findTemplateDetail({ templateId: vm.templateId }).then(function(res) { return res }) }, } }