person-edit-panel.js 7.7 KB

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