person-edit-panel.js 7.9 KB

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