person-new-panel.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. var PersonNewPanel = {
  2. template: '<div>\
  3. <div style="height: 34px;" >\
  4. 指导模板\
  5. <div @click="save" 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="new-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. props: [],
  41. beforeRouteEnter: function(to, from, next) {
  42. next(function(vm) {
  43. var query = vm.$route.query
  44. if(!storage.patient && !query.patient) {
  45. vm.sendMode = false
  46. } else {
  47. storage.patient = storage.patient || query.patient
  48. vm.sendMode = true
  49. }
  50. })
  51. },
  52. data: function() {
  53. return {
  54. words: 1000,
  55. count: 0,
  56. content: "",
  57. modelName: "",
  58. imgs: [],
  59. sendMode: false // 根据url中是否携带patient来判断是否是"发送"模式
  60. }
  61. },
  62. mounted: function() {
  63. EventBus.$emit('active-nav-tab', 0)
  64. },
  65. methods: {
  66. countWord: function() {
  67. if(this.content.length <= this.words) {
  68. this.count = this.content.length
  69. } else {
  70. this.content = this.content.slice(0, this.words)
  71. }
  72. },
  73. imgUploaded: function(url) {
  74. var vm = this
  75. vm.imgs.push(url)
  76. },
  77. save: function() {
  78. var vm = this
  79. if(!vm.modelName) {
  80. toastr && toastr.error("模板名称不能为空")
  81. return
  82. }
  83. if(!vm.content) {
  84. toastr && toastr.error("模板内容不能为空")
  85. return
  86. }
  87. var param = {
  88. content: vm.content,
  89. modelName: vm.modelName
  90. }
  91. var img = vm.imgs.join(',').trim()
  92. if(img) {
  93. param.imagesUrl = img
  94. }
  95. guidanceAPI.newTemplate(param).then(function(res) {
  96. if(res.status == 200) {
  97. toastr && toastr.success("保存成功")
  98. EventBus.$emit('refresh-person-panel')
  99. } else {
  100. toastr && toastr.error(res.msg)
  101. }
  102. }).catch(function(e) {
  103. console.error(e)
  104. })
  105. },
  106. sendTemplate: function() {
  107. var vm = this
  108. if(!vm.modelName) {
  109. toastr && toastr.error("模板名称不能为空")
  110. return
  111. }
  112. if(!vm.content) {
  113. toastr && toastr.error("模板内容不能为空")
  114. return
  115. }
  116. var d = dialog({
  117. width: 350,
  118. content: '发出后无法变更,是否确认发送给居民?',
  119. okValue: '继续发送',
  120. ok: function () {
  121. guidanceAPI.sendTemplate( {
  122. patient: storage.patient,
  123. content: vm.content,
  124. modelCode: vm.modelCode,
  125. images: vm.imgs.join(',')
  126. }).then(function(res) {
  127. toastr && toastr.success("发送成功")
  128. }).catch(function(e) {
  129. console.error(e)
  130. })
  131. },
  132. cancelValue: '取消',
  133. cancel: function () {}
  134. });
  135. d.showModal();
  136. },
  137. preview: function() {
  138. var vm = this
  139. var query = {
  140. modelCode: vm.modelCode,
  141. patient: storage.patient || "",
  142. timestemp: $.now()
  143. }
  144. this.$router.push({path:'/preview-panel',query:query})
  145. }
  146. },
  147. watch: {
  148. '$route': function (to, from) {
  149. var vm = this
  150. var query = vm.$route.query
  151. if(storage.patient) {
  152. vm.sendMode = true
  153. } else {
  154. vm.sendMode = false
  155. }
  156. if(to.path == "/preview-panel") {
  157. EventBus.$emit('preview-template', {
  158. content: vm.content,
  159. modelName: vm.modelName,
  160. imgs: vm.imgs
  161. })
  162. }
  163. },
  164. 'content': function(v) {
  165. this.countWord()
  166. }
  167. }
  168. }