template-items-select2.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. var TemplateItemsSelect2 = {
  2. template: '<div style="height: 100%;">\
  3. <div class="title-name c-f16">\
  4. <span class="c-vam mr15">项目表</span><img @click="goBack" src="../../../images/fanhui02_icon.png" class="c-vam"/>\
  5. </div>\
  6. <div class="search-warp">\
  7. <input class="inp-search" v-model="searchName" placeholder="搜索项目名称" @input="debounceSearch"/>\
  8. </div>\
  9. <div class="mt10 pt10 pl10 ul-wrap">\
  10. <ul class="level-third">\
  11. <li v-for="(o, k) in serviceItems" class="ptb5">\
  12. <div class="list-item-name c-nowrap mr5" :class="{\'is-active\': o.isBlueBgc}">{{o.name}}</div>\
  13. <a href="javascript:void(0);" @click="addItem(o,k)" class="add-item-btn" :class="{\'disabled\': !o.enable}">\
  14. 添加\
  15. </a>\
  16. </li>\
  17. </ul>\
  18. </div>\
  19. </div>',
  20. props: [],
  21. data: function() {
  22. return {
  23. isNew: null,
  24. searchName: "",
  25. serviceItems: [],
  26. templateDetail: []
  27. }
  28. },
  29. beforeRouteEnter: function(to, from, next) {
  30. next(function(vm) {
  31. var query = vm.$route.query
  32. if(vm.isNew == true || vm.isNew === "true") {
  33. vm.isNew = true
  34. } else {
  35. vm.isNew = false
  36. }
  37. vm.templateId = query.templateId
  38. if((to.path == "/template-item-detail" || from.path == "/template-item-detail" ) && from.path != "/") {
  39. return
  40. }
  41. if(!vm.isNew) {
  42. vm.loading.show()
  43. vm.findTemplateDetail().then(function(res) {
  44. vm.loading.close()
  45. if(res.status == 200) {
  46. vm.templateDetail = res.data
  47. vm.getServiceItemList().then(function(){
  48. _.each(vm.templateDetail, function(o) {
  49. o.isInit=true
  50. EventBus.$emit("add-template-item", o)
  51. })
  52. })
  53. } else {
  54. toastr && toastr.error(res.msg)
  55. }
  56. })
  57. } else {
  58. vm.getServiceItemList()
  59. }
  60. })
  61. },
  62. created: function() {
  63. },
  64. mounted: function() {
  65. var vm = this
  66. EventBus.$on("delete-template-item", function(obj, i,arr){
  67. console.log('dd',vm.serviceItems)
  68. _.each(vm.serviceItems, function(item, index) {
  69. if(item.code==obj.code){
  70. if(item.code=='2'||item.code=='3'){
  71. item.enable = true
  72. }
  73. vm.$set(vm.serviceItems, index, item)
  74. // 判断左边服务项背景色是否显示蓝色
  75. if(item.code==obj.code){
  76. var isEast=_.some(arr,function(itemb){
  77. if(itemb.code==obj.code){
  78. return true
  79. }
  80. })
  81. item.isBlueBgc=isEast
  82. }
  83. }
  84. })
  85. })
  86. },
  87. methods: {
  88. goBack: function() {
  89. EventBus.$emit("refresh-index")
  90. this.$router.replace('/');
  91. },
  92. addItem: function(o, k) {
  93. o.isInit=false
  94. if(o.code=='2'||o.code=='3'){
  95. o.enable=false
  96. }
  97. o.isBlueBgc=true
  98. EventBus.$emit("add-template-item", o)
  99. this.$set(this.serviceItems, k, o)
  100. // this.templateDetail.push(o)
  101. },
  102. debounceSearch: _.debounce(function() {
  103. var vm = this
  104. vm.getServiceItemList()
  105. }, 500, false),
  106. getServiceItemList: function(){
  107. var vm = this
  108. return rehaAPI.getServiceItemList({
  109. name: vm.searchName
  110. }).then(function(res) {
  111. vm.serviceItems = res.data
  112. var selected = vm.templateDetail
  113. var selectedIds = _.pluck(selected, "code")
  114. _.each(vm.serviceItems, function(o) {
  115. if(_.contains(selectedIds, o.code) && (o.code=='2' || o.code=='3')) {
  116. o.enable = false
  117. } else {
  118. o.enable = true
  119. }
  120. _.contains(selectedIds, o.code)?o.isBlueBgc=true:o.isBlueBgc=false
  121. })
  122. })
  123. },
  124. findTemplateDetail: function() {
  125. var vm = this
  126. return rehaAPI.findTemplateDetail({
  127. templateId: vm.templateId
  128. }).then(function(res) {
  129. return res
  130. })
  131. },
  132. }
  133. }