system-send-panel.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. width: 350,
  166. content: '发出后无法变更,是否确认发送给居民?',
  167. okValue: '继续发送',
  168. ok: function () {
  169. guidanceAPI.sendTemplate( {
  170. patient: storage.patient,
  171. content: vm.content,
  172. modelCode: vm.modelCode || "",
  173. images: vm.imgs.join(',')
  174. }).then(function(res) {
  175. toastr && toastr.success("发送成功")
  176. var obj = {
  177. rehabilitationDetailId: storage.planId,
  178. patientCode: storage.patient,
  179. // patientName: patientName,
  180. doctorCode: storage.docInfo.code,
  181. doctorName: storage.docInfo.name,
  182. relationRecordType: 2, //健康指导
  183. relationRecordCode: res.data.id
  184. }
  185. guidanceAPI.saveRehabilitationOperateRecord({
  186. dataJson: JSON.stringify(obj)
  187. }).then(function(res) {
  188. console.log(res)
  189. console.log(res.status)
  190. if(res.status == 200) {
  191. var index = parent.layer && parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  192. parent.layer && parent.layer.close(index)
  193. } else {
  194. toastr && toastr.success(res.msg)
  195. }
  196. })
  197. }).catch(function(e) {
  198. console.error(e)
  199. })
  200. },
  201. cancelValue: '取消',
  202. cancel: function () {}
  203. });
  204. d.showModal();
  205. },
  206. preview: function() {
  207. var vm = this
  208. var query = {
  209. modelCode: vm.modelCode,
  210. patient: storage.patient||"",
  211. timestemp: $.now()
  212. }
  213. this.$router.push({path:'/preview-panel',query:query})
  214. }
  215. },
  216. watch: {
  217. '$route': function (to, from) {
  218. var vm = this
  219. var query = vm.$route.query
  220. if(query && query.modelCode && from.path == "/system-send-panel"&& to.path == "/system-send-panel") {
  221. vm.modelCode = query.modelCode
  222. vm.listDetail()
  223. }
  224. if(storage.patient) {
  225. vm.sendMode = true
  226. } else {
  227. vm.sendMode = false
  228. }
  229. if(to.path == "/preview-panel") {
  230. EventBus.$emit('preview-template', {
  231. content: vm.content,
  232. modelName: vm.modelName,
  233. imgs: vm.imgs
  234. })
  235. }
  236. },
  237. 'content': function(v) {
  238. this.countWord()
  239. }
  240. }
  241. }