template-items-select.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. var TemplateItemsSelect = {
  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>\
  11. <li v-for="(s,i) in items" class="list-item c-f16" :class="{\'arrow-r\': !s.dropdown, \'arrow-d\': s.dropdown}" >\
  12. <span @click.stop="s.dropdown=!s.dropdown">{{itemType[s.itemType]}}</span>\
  13. <ul class="level-sec" v-show="s.dropdown">\
  14. <li v-for="(g, j) in s.item" class="list-item c-f14 ml15 mt15" :class="{\'arrow-r\': !g.dropdown, \'arrow-d\': g.dropdown}">\
  15. <span @click.stop="g.dropdown=!g.dropdown">{{g.itemName}}</span>\
  16. <ul class="level-third" v-show="g.dropdown" >\
  17. <li v-for="(o, k) in g.hospitalServiceItems" class="mt15" v-show="o.show">\
  18. <div class="list-item-name pl10 c-nowrap mr5">{{o.specialistServiceItemDO.title}}</div>\
  19. <a href="javascript:void(0);" @click="addItem(o)" class="add-item-btn" :class="{\'disabled\': !o.enable}">\
  20. 添加\
  21. </a>\
  22. </li>\
  23. </ul>\
  24. </li>\
  25. </ul>\
  26. </li>\
  27. </ul>\
  28. </div>\
  29. </div>',
  30. props: [],
  31. data: function() {
  32. return {
  33. isNew: null,
  34. searchName: "",
  35. itemType: ["", "诊疗服务", "健康服务"],
  36. items: [
  37. // {
  38. // name: "健康服务",
  39. // dropdown: false,
  40. // items: [
  41. // {
  42. // name: "门诊",
  43. // dropdown: false,
  44. // items: [
  45. // {
  46. // name: "专科医师每周两次查房,指导药物调整和诊疗",
  47. // enable: true
  48. // },
  49. // {
  50. // name: "专科医师每周两次查房,指导药物调整和诊疗",
  51. // enable: false
  52. // }
  53. // ]
  54. // }
  55. // ]
  56. // }
  57. ]
  58. }
  59. },
  60. beforeRouteEnter: function(to, from, next) {
  61. next(function(vm) {
  62. var query = vm.$route.query
  63. if(vm.isNew == true || vm.isNew === "true") {
  64. vm.isNew = true
  65. } else {
  66. vm.isNew = false
  67. }
  68. vm.templateId = query.templateId
  69. // if((to.path == "/template-items" || to.path=="/template-item-detail")
  70. // && (from.path != "/template-item-detail" || from.path == "/")) {
  71. //
  72. // }
  73. if((to.path == "/template-item-detail" || from.path == "/template-item-detail" ) && from.path != "/") {
  74. return
  75. }
  76. if(!vm.isNew) {
  77. vm.loading.show()
  78. vm.findTemplateDetail().then(function(res) {
  79. if(res.status == 200) {
  80. var selected = res.data
  81. var selectedIds = _.pluck(selected, "id")
  82. vm.findServiceItemsByHospital().then(function() {
  83. _.each(vm.items, function(o) {
  84. _.each(o.item,function(g) {
  85. _.each(g.hospitalServiceItems, function(v) {
  86. if(_.contains(selectedIds, v.id)) {
  87. v.enable = false
  88. EventBus.$emit("add-template-item", v)
  89. } else {
  90. v.enable = true
  91. }
  92. })
  93. })
  94. })
  95. vm.loading.close()
  96. }).catch(function(e) {
  97. vm.loading.close()
  98. console.error(e)
  99. })
  100. } else {
  101. vm.loading.close()
  102. toastr && toastr.error(res.msg)
  103. }
  104. })
  105. } else {
  106. vm.findServiceItemsByHospital()
  107. }
  108. })
  109. },
  110. created: function() {
  111. },
  112. mounted: function() {
  113. var vm = this
  114. },
  115. methods: {
  116. goBack: function() {
  117. this.$router.replace('/');
  118. },
  119. addItem: function(o) {
  120. o.enable = false
  121. EventBus.$emit("add-template-item", o)
  122. },
  123. debounceSearch: _.debounce(function() {
  124. var vm = this
  125. if(vm.searchName.trim()) {
  126. _.each(vm.items, function(o) {
  127. o.dropdown = true
  128. _.each(o.item,function(g) {
  129. g.dropdown = true
  130. _.each(g.hospitalServiceItems, function(v) {
  131. if(v.specialistServiceItemDO.title.indexOf(vm.searchName)>-1) {
  132. v.show = true
  133. } else {
  134. v.show = false
  135. }
  136. })
  137. })
  138. })
  139. } else {
  140. _.each(vm.items, function(o) {
  141. _.each(o.item,function(g) {
  142. _.each(g.hospitalServiceItems, function(v) {
  143. v.show = true
  144. })
  145. })
  146. })
  147. }
  148. }, 500, false),
  149. findServiceItemsByHospital: function(){
  150. var vm = this
  151. return rehaAPI.findServiceItemsByHospital({
  152. doctor: storage.docInfo.code
  153. }).then(function(res) {
  154. var items = res.data[0]
  155. vm.items = _.map(items, function(o) {
  156. o.dropdown = false
  157. o.item = _.map(o.item,function(g) {
  158. g.dropdown = false
  159. _.each(g.hospitalServiceItems, function(v) {
  160. v.enable = true
  161. v.show = true
  162. })
  163. return g
  164. })
  165. return o
  166. })
  167. })
  168. },
  169. findTemplateDetail: function() {
  170. var vm = this
  171. return rehaAPI.findTemplateDetail({
  172. templateId: vm.templateId
  173. }).then(function(res) {
  174. return res
  175. })
  176. },
  177. }
  178. }