system-send-panel.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. var SystemSendPanel = {
  2. template: '<div>\
  3. <div style="height: 34px;" >\
  4. 指导模板\
  5. <div @click="saveAsPersonTemplate" class="save-btn ml10" v-if="sendMode" style="width: 150px;">\
  6. 保存为个人模板\
  7. </div>\
  8. </div>\
  9. <div class="temp-info c-f14">\
  10. <div class="temp-name pl10 ptb10">\
  11. 模板名称:<input v-model="modelName" placeholder="请输入模板名称( 10字内 )" class="c-f14" maxlength="10"/>\
  12. </div>\
  13. <div class="c-position-r">\
  14. <textarea @input="countWord" v-model="content" class="ptb10 plr10" style="border: 0;width: 100%;box-sizing: border-box;height: 180px;"></textarea>\
  15. <div class="c-t-right mr10 mb5 c-909090">{{count}}/{{words}}</div>\
  16. </div>\
  17. </div>\
  18. <div class="img-wrap mt20 c-f14">\
  19. <div>插入图片<span class="c-909090">({{imgs.length}}/9)</span></div>\
  20. <div class="clearfix">\
  21. <div class="c-position-r fl mr15 mt20" v-for="(url,i) in imgs">\
  22. <img class="upload_img" :src="url" width="65" height="65">\
  23. <div class="delete-icon" @click="removeImg(url,i)"><img src="../../../images/delete_icon.png" width="18"></div>\
  24. </div>\
  25. <img-upload @uploaded="imgUploaded" v-show="imgs.length<9"></img-upload>\
  26. </div>\
  27. </div>\
  28. <div class="foot-btns">\
  29. <a class="preview-btn c-t-center mr15" @click="preview">\
  30. 预览\
  31. </a>\
  32. <a class="send-btn c-t-center" @click="save" v-show="!sendMode">\
  33. 引用模板\
  34. </a>\
  35. <a class="send-btn c-t-center" @click="sendTemplate" v-show="sendMode">\
  36. 发送\
  37. </a>\
  38. </div>\
  39. </div>',
  40. beforeRouteEnter: function(to, from, next) {
  41. next(function(vm) {
  42. var query = vm.$route.query
  43. if(query && query.modelCode && from.path != "/preview-panel") {
  44. vm.modelCode = query.modelCode
  45. vm.listDetail()
  46. }
  47. if(!storage.patient && !query.patient) {
  48. vm.sendMode = false
  49. } else {
  50. storage.patient = storage.patient || query.patient
  51. vm.sendMode = true
  52. }
  53. })
  54. },
  55. props: [],
  56. data: function() {
  57. return {
  58. words: 10000,
  59. count: 0,
  60. content: "",
  61. modelName: "",
  62. imgs: [],
  63. modelCode: "",
  64. sendMode: false // 根据url中是否携带patient来判断是否是"发送"模式
  65. }
  66. },
  67. mounted: function() {
  68. EventBus.$emit('active-nav-tab', 2)
  69. },
  70. methods: {
  71. countWord: function() {
  72. if(this.content.length <= this.words) {
  73. this.count = this.content.length
  74. } else {
  75. this.content = this.content.slice(0, this.words)
  76. }
  77. },
  78. listDetail: function() {
  79. var vm = this
  80. guidanceAPI.listDetail({
  81. modelCode: vm.modelCode
  82. }).then(function(res) {
  83. var data = res.data
  84. if(data) {
  85. vm.content = data.content
  86. vm.modelName = data.modelName
  87. vm.imgs = _.map(data.imagesUrls, function(s) {
  88. return httpRequest.getImgUrl(s)
  89. })
  90. }
  91. })
  92. },
  93. imgUploaded: function(url) {
  94. var vm = this
  95. vm.imgs.push(httpRequest.getImgUrl(url))
  96. },
  97. removeImg: function(url, idx) {
  98. var vm = this
  99. vm.imgs.splice(idx, 1)
  100. },
  101. save: function() {
  102. var vm = this
  103. if(!vm.modelName) {
  104. toastr && toastr.error("模板名称不能为空")
  105. return
  106. }
  107. if(!vm.content) {
  108. toastr && toastr.error("模板内容不能为空")
  109. return
  110. }
  111. guidanceAPI.newTemplate({
  112. content: vm.content,
  113. modelName: vm.modelName,
  114. imagesUrl: vm.imgs.join(',')
  115. }).then(function(res) {
  116. if(res.status == 200) {
  117. toastr && toastr.success("保存成功")
  118. } else {
  119. toastr && toastr.error(res.msg)
  120. }
  121. }).catch(function(e) {
  122. console.error(e)
  123. })
  124. },
  125. saveAsPersonTemplate: function() {
  126. var vm = this
  127. if(!vm.modelName) {
  128. toastr && toastr.error("模板名称不能为空")
  129. return
  130. }
  131. if(!vm.content) {
  132. toastr && toastr.error("模板内容不能为空")
  133. return
  134. }
  135. var param = {
  136. content: vm.content,
  137. modelName: vm.modelName
  138. }
  139. var img = vm.imgs.join(',').trim()
  140. if(img) {
  141. param.imagesUrl = img
  142. }
  143. guidanceAPI.newTemplate(param).then(function(res) {
  144. if(res.status == 200) {
  145. toastr && toastr.success("保存成功")
  146. EventBus.$emit('refresh-person-panel')
  147. } else {
  148. toastr && toastr.error(res.msg)
  149. }
  150. }).catch(function(e) {
  151. console.error(e)
  152. })
  153. },
  154. sendTemplate: function() {
  155. var vm = this
  156. if(!vm.modelName) {
  157. toastr && toastr.error("模板名称不能为空")
  158. return
  159. }
  160. if(!vm.content) {
  161. toastr && toastr.error("模板内容不能为空")
  162. return
  163. }
  164. var d = dialog({
  165. content: '发出后无法变更,是否确认发送给居民?',
  166. okValue: '继续发送',
  167. ok: function () {
  168. guidanceAPI.sendTemplate( {
  169. patient: storage.patient,
  170. content: vm.content,
  171. modelCode: vm.modelCode || "",
  172. images: vm.imgs.join(',')
  173. }).then(function(res) {
  174. toastr && toastr.success("发送成功")
  175. var obj = {
  176. rehabilitationDetailId: storage.planId,
  177. patientCode: storage.patient,
  178. // patientName: patientName,
  179. doctorCode: storage.docInfo.code,
  180. doctorName: storage.docInfo.name,
  181. relationRecordType: 2, //健康指导
  182. relationRecordCode: res.data.id
  183. }
  184. guidanceAPI.saveRehabilitationOperateRecord({
  185. dataJson: JSON.stringify(obj)
  186. }).then(function(res) {
  187. if(res.status == 200) {
  188. } else {
  189. toastr && toastr.success(res.msg)
  190. }
  191. })
  192. }).catch(function(e) {
  193. console.error(e)
  194. })
  195. },
  196. cancelValue: '取消',
  197. cancel: function () {}
  198. });
  199. d.showModal();
  200. },
  201. preview: function() {
  202. var vm = this
  203. var query = {
  204. modelCode: vm.modelCode,
  205. patient: storage.patient||"",
  206. timestemp: $.now()
  207. }
  208. this.$router.push({path:'/preview-panel',query:query})
  209. }
  210. },
  211. watch: {
  212. '$route': function (to, from) {
  213. var vm = this
  214. var query = vm.$route.query
  215. if(query && query.modelCode && from.path == "/system-send-panel"&& to.path == "/system-send-panel") {
  216. vm.modelCode = query.modelCode
  217. vm.listDetail()
  218. }
  219. if(storage.patient) {
  220. vm.sendMode = true
  221. } else {
  222. vm.sendMode = false
  223. }
  224. if(to.path == "/preview-panel") {
  225. EventBus.$emit('preview-template', {
  226. content: vm.content,
  227. modelName: vm.modelName,
  228. imgs: vm.imgs
  229. })
  230. }
  231. },
  232. 'content': function(v) {
  233. this.countWord()
  234. }
  235. }
  236. }