person-edit-panel.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. var PersonEditPanel = {
  2. template:
  3. '<div v-loading="isloading">\
  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. isloading:false,
  74. }
  75. },
  76. mounted: function () {
  77. var vm = this
  78. EventBus.$emit('active-nav-tab', 0)
  79. },
  80. methods: {
  81. countWord: function () {
  82. if (this.content.length <= this.words) {
  83. this.count = this.content.length
  84. } else {
  85. this.content = this.content.slice(0, this.words)
  86. }
  87. },
  88. listDetail: function () {
  89. var vm = this
  90. guidanceAPI
  91. .listDetail({
  92. modelCode: vm.modelCode
  93. })
  94. .then(function (res) {
  95. var data = res.data
  96. if (data) {
  97. vm.content = data.content
  98. vm.modelName = data.modelName
  99. vm.imgs = _.map(data.imagesUrls, function (s) {
  100. return httpRequest.getImgUrl(s)
  101. })
  102. }
  103. })
  104. },
  105. imgUploaded: function (url) {
  106. var vm = this
  107. vm.imgs.push(httpRequest.getImgUrl(url))
  108. },
  109. removeImg: function (url, idx) {
  110. var vm = this
  111. vm.imgs.splice(idx, 1)
  112. },
  113. save: function () {
  114. var vm = this
  115. if (!vm.modelCode) {
  116. toastr && toastr.error('请选择模板')
  117. return
  118. }
  119. if (!vm.modelName) {
  120. toastr && toastr.error('模板名称不能为空')
  121. return
  122. }
  123. if (!vm.content) {
  124. toastr && toastr.error('模板内容不能为空')
  125. return
  126. }
  127. guidanceAPI
  128. .modifyTemplate({
  129. content: vm.content,
  130. modelName: vm.modelName,
  131. imagesUrl: vm.imgs.join(','),
  132. code: vm.modelCode
  133. })
  134. .then(function (res) {
  135. if (res.status == 200) {
  136. toastr && toastr.success('保存成功')
  137. EventBus.$emit('refresh-person-panel')
  138. }
  139. })
  140. .catch(function (e) {
  141. console.error(e)
  142. })
  143. },
  144. deleteTemplate: function () {
  145. var vm = this
  146. var d = dialog({
  147. width: 350,
  148. title: '删除模板',
  149. content: '删除后无法恢复,是否确认删除?',
  150. okValue: '确定',
  151. ok: function () {
  152. guidanceAPI
  153. .deleteTemplate({ code: vm.modelCode })
  154. .then(function (res) {
  155. toastr && toastr.success('删除成功')
  156. vm.editable = false
  157. EventBus.$emit('refresh-person-panel')
  158. })
  159. .catch(function (e) {
  160. console.error(e)
  161. })
  162. },
  163. cancelValue: '取消',
  164. cancel: function () {}
  165. })
  166. d.showModal()
  167. },
  168. sendTemplate: function () {
  169. var vm = this
  170. if (!vm.modelName) {
  171. toastr && toastr.error('模板名称不能为空')
  172. return
  173. }
  174. if (!vm.content) {
  175. toastr && toastr.error('模板内容不能为空')
  176. return
  177. }
  178. var d = dialog({
  179. width: 350,
  180. content: '发出后无法变更,是否确认发送给居民?',
  181. okValue: '继续发送',
  182. ok: function () {
  183. vm.isloading = true
  184. guidanceAPI
  185. .sendTemplate({
  186. patient: storage.patient,
  187. content: vm.content,
  188. modelCode: vm.modelCode,
  189. images: vm.imgs.join(',')
  190. })
  191. .then(function (res) {
  192. vm.isloading = false
  193. toastr && toastr.success('发送成功')
  194. var obj = {
  195. rehabilitationDetailId: storage.planId,
  196. patientCode: storage.patient,
  197. // patientName: patientName,
  198. doctorCode: storage.docInfo.code,
  199. doctorName: storage.docInfo.name,
  200. relationRecordType: 2, //健康指导
  201. relationRecordCode: res.data.id
  202. }
  203. guidanceAPI
  204. .saveRehabilitationOperateRecord({
  205. dataJson: JSON.stringify(obj)
  206. })
  207. .then(function (res) {
  208. if (res.status == 200) {
  209. var index = parent.layer && parent.layer.getFrameIndex(window.name) //先得到当前iframe层的索引
  210. parent.layer && parent.layer.close(index)
  211. } else {
  212. // toastr && toastr.success(res.msg)
  213. }
  214. })
  215. })
  216. .catch(function (e) {
  217. console.error(e)
  218. })
  219. },
  220. cancelValue: '取消',
  221. cancel: function () {}
  222. })
  223. d.showModal()
  224. },
  225. preview: function () {
  226. var vm = this
  227. var query = {
  228. modelCode: vm.modelCode,
  229. patient: storage.patient || '',
  230. timestemp: $.now()
  231. }
  232. this.$router.push({ path: '/preview-panel', query: query })
  233. }
  234. },
  235. watch: {
  236. '$route': function (to, from) {
  237. var vm = this
  238. var query = vm.$route.query
  239. if (query && query.modelCode && from.path == '/person-edit-panel' && to.path == '/person-edit-panel') {
  240. vm.modelCode = query.modelCode
  241. vm.editable = true
  242. vm.listDetail()
  243. }
  244. if (storage.patient) {
  245. vm.sendMode = true
  246. } else {
  247. vm.sendMode = false
  248. }
  249. if (to.path == '/preview-panel') {
  250. EventBus.$emit('preview-template', {
  251. content: vm.content,
  252. modelName: vm.modelName,
  253. imgs: vm.imgs
  254. })
  255. }
  256. },
  257. 'content': function (v) {
  258. this.countWord()
  259. }
  260. }
  261. }