123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- var TemplateItemsSelect2 = {
- template: '<div style="height: 100%;">\
- <div class="title-name c-f16">\
- <span class="c-vam mr15">项目表</span><img @click="goBack" src="../../../images/fanhui02_icon.png" class="c-vam"/>\
- </div>\
- <div class="search-warp">\
- <input class="inp-search" v-model="searchName" placeholder="搜索项目名称" @input="debounceSearch"/>\
- </div>\
- <div class="mt10 pt10 pl10 ul-wrap">\
- <ul class="level-third">\
- <li v-for="(o, k) in serviceItems" class="ptb5">\
- <div class="list-item-name c-nowrap mr5" :class="{\'is-active\': !o.enable}">{{o.name}}</div>\
- <a href="javascript:void(0);" @click="addItem(o,k)" class="add-item-btn" :class="{\'disabled\': !o.enable}">\
- 添加\
- </a>\
- </li>\
- </ul>\
- </div>\
- </div>',
- 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
- })
- },
- }
- }
|