template-items.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. var docInfo = JSON.parse(window.localStorage.getItem('wlyyAgent'));
  2. function showSuccessMessage(msg) {
  3. layer.msg(msg, {
  4. icon: 1
  5. })
  6. }
  7. function showErrorMessage(msg) {
  8. layer.msg(msg, {
  9. icon: 5
  10. })
  11. }
  12. function showWarningMessage(msg) {
  13. layer.msg(msg, {
  14. icon: 2
  15. })
  16. }
  17. function showInfoMessage(msg) {
  18. layer.msg(msg, {
  19. icon: 6
  20. })
  21. }
  22. var TemplateItems = {
  23. template: '<div style="height: 100%;">\
  24. <div class="title-name c-f16">\
  25. <span class="c-vam">{{name}}</span>\
  26. </div>\
  27. <div v-show="!items.length" class="c-t-center" style="margin-top: 200px;">\
  28. <img src="../../../images/fanhui_icon.png" class="c-vam"/>请在左侧“服务项”列表中选择\
  29. </div>\
  30. <div class="template-items" v-show="items.length">\
  31. <div class="item-card ptb10 plr15 mt10" v-for="(o, i) in items">\
  32. <div class="c-nowrap">{{o.name}}</div>\
  33. <div class="c-row c-f14 mt5">\
  34. <div class="c-50">\
  35. <span class="c-909090">医&emsp;&emsp;院:</span>\
  36. <span>待选择</span>\
  37. </div>\
  38. <div class="c-50">\
  39. <span class="c-909090">执行人员:</span>\
  40. <span class="c-909090">待选择</span>\
  41. </div>\
  42. </div>\
  43. <div class="c-row c-f14 mt5">\
  44. <div class="c-50">\
  45. <span class="c-909090">计划时间:</span>\
  46. <span class="c-909090">待选择</span>\
  47. </div>\
  48. <div class="c-50">\
  49. <span class="c-909090">费&emsp;&emsp;用:</span>\
  50. <span>0.00元</span>\
  51. </div>\
  52. </div>\
  53. <img v-if="name!=\'系统模板\'" src="../../../images/qingchu_icon.png" class="item-delete-btn" @click.stop="deleteItem(o, i)"/>\
  54. </div>\
  55. </div>\
  56. <div class="foot-btns">\
  57. <a class="delete-btn c-t-center mr50" @click="deleteTemplate">\
  58. 删除模板\
  59. </a>\
  60. <a class="save-btn c-t-center" @click="saveTemplate">\
  61. 保存模板\
  62. </a>\
  63. </div>\
  64. </div>',
  65. props: [],
  66. data: function() {
  67. return {
  68. name: '',
  69. items: [],
  70. isNew: null,
  71. templateId: "",
  72. item: null
  73. }
  74. },
  75. beforeRouteEnter: function (to, from, next) {
  76. next(function(vm) {
  77. var query = vm.$route.query
  78. vm.name = query.name || '模板未命名',
  79. vm.templateId = query.templateId
  80. if(from.path != "/template-item-detail" || from.path == "/") {
  81. vm.items = []
  82. }
  83. if(vm.isNew == true || vm.isNew === "true") {
  84. vm.isNew = true
  85. } else {
  86. vm.isNew = false
  87. }
  88. })
  89. },
  90. created: function() {
  91. var vm = this
  92. EventBus.$on("add-template-item", function(o) {
  93. vm.items.push(o)
  94. })
  95. },
  96. mounted: function() {
  97. var vm = this
  98. },
  99. methods: {
  100. deleteItem: function(o, i) {
  101. var vm = this
  102. o.enable = true
  103. vm.items.splice(i, 1)
  104. EventBus.$emit("delete-template-item", o, i)
  105. },
  106. saveTemplate: function() {
  107. var vm = this
  108. if(this.name=='系统模板'){
  109. showErrorMessage('不能编辑系统模板!')
  110. return false
  111. }
  112. vm.loading.showModal()
  113. rehaAPI.createTemplateDetail({
  114. doctor: docInfo.uid,
  115. json: JSON.stringify({
  116. templateId: vm.templateId,
  117. hospitalServiceItemId: _.pluck(vm.items, 'code').join(',')
  118. }),
  119. type: vm.isNew?"create":"edit"
  120. }).then(function(res) {
  121. if(res.status == 200) {
  122. vm.loading.close()
  123. showSuccessMessage('保存成功')
  124. EventBus.$emit("refresh-index")
  125. vm.$router.replace("/")
  126. } else {
  127. vm.loading.close()
  128. showErrorMessage(res.msg)
  129. }
  130. }).catch(function(e) {
  131. vm.loading.close()
  132. console.error(e)
  133. })
  134. },
  135. deleteTemplate: function() {
  136. var vm = this
  137. if(this.name=='系统模板'){
  138. showErrorMessage('不能删除系统模板!')
  139. return false
  140. }
  141. layer.confirm('确定删除该模板?', {
  142. btn: ['确认','取消'] //按钮
  143. }, function(){
  144. vm.loading.showModal()
  145. rehaAPI.deleteTemplate({
  146. templateId: vm.templateId
  147. }).then(function(res) {
  148. vm.loading.close()
  149. if(res.status == 200) {
  150. showSuccessMessage('删除成功')
  151. } else {
  152. showErrorMessage(res.msg)
  153. }
  154. EventBus.$emit("refresh-index")
  155. vm.$router.replace("/")
  156. }).catch(function(e) {
  157. vm.loading.close()
  158. console.error(e)
  159. })
  160. }, function(){
  161. });
  162. },
  163. toDetail: function(o) {
  164. var vm = this
  165. vm.item = o
  166. vm.$router.push({
  167. path:"/template-item-detail",
  168. query: {
  169. templateId: vm.templateId,
  170. itemId: o.code
  171. }
  172. })
  173. }
  174. },
  175. // watch: {
  176. // '$route': function (to, from) {
  177. // var vm = this
  178. //// if(to.path == "/template-item-detail" && (from.path != "/template-item-detail" || from.path == "/")) {
  179. //// EventBus.$emit("show-item-detail", vm.item)
  180. //// }
  181. // if(to.path == "/template-item-detail") {
  182. // EventBus.$emit("show-item-detail", vm.item)
  183. // }
  184. // }
  185. // }
  186. }