team-edit-panel.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. var TeamEditPanel = {
  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 class="delete-btn ml10" v-if="isLeader && editable && !sendMode" @click="deleteTemplate">\
  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="team-name pl10 ptb10">\
  17. 所属团队:<select class="c-f14" style="border:0;">\
  18. <option v-for="(team, i) in teams" :value="i">{{team.teamName}}</option>\
  19. </select>\
  20. </div>\
  21. <div class="label-name pl10 ptb10 list-arrow-r" :class="{\'list-arrow-r\': !labelsDropdown, \'list-arrow-d\': labelsDropdown}">\
  22. <div @click="labelsDropdown = !labelsDropdown">指导标签:{{selectedLabel && selectedLabel.name}}</div>\
  23. <ul v-show="labelsDropdown" class="c-list msg-list clearfix">\
  24. <li @click="selectLabel(label)" v-for="(label, i) in labelList" :class="{\'active-icon\': label.active}" class="c-list-li ">\
  25. <div>\
  26. <span>{{label.name}}</span>\
  27. </div>\
  28. </li>\
  29. </ul>\
  30. </div>\
  31. <div class="c-position-r">\
  32. <textarea @input="countWord" v-model="content" class="ptb10 plr10" style="border: 0;width: 100%;box-sizing: border-box;height: 180px;"></textarea>\
  33. <div class="c-t-right mr10 mb5 c-909090">{{count}}/{{words}}</div>\
  34. </div>\
  35. </div>\
  36. <div class="img-wrap mt20 c-f14">\
  37. <div>插入图片<span class="c-909090">({{imgs.length}}/9)</span></div>\
  38. <div class="clearfix">\
  39. <div class="c-position-r fl mr15 mt20" v-for="(url,i) in imgs">\
  40. <img class="upload_img" :src="url" width="65" height="65">\
  41. <div class="delete-icon" @click="removeImg(url,i)"><img src="../../../images/delete_icon.png" width="18"></div>\
  42. </div>\
  43. <img-upload @uploaded="imgUploaded" v-show="imgs.length<9"></img-upload>\
  44. </div>\
  45. </div>\
  46. <div class="foot-btns">\
  47. <a class="preview-btn c-t-center mr15" @click="preview" v-show="editable || sendMode">\
  48. 预览\
  49. </a>\
  50. <a class="send-btn c-t-center" @click="save" v-show="isLeader && editable && !sendMode">\
  51. 保存\
  52. </a>\
  53. <a class="send-btn c-t-center" @click="sendTeamTemplate" v-show="sendMode">\
  54. 发送\
  55. </a>\
  56. </div>\
  57. </div>',
  58. props: [],
  59. data: function() {
  60. return {
  61. words: 1000,
  62. count: 0,
  63. content: "",
  64. modelName: "",
  65. imgs: [],
  66. modelCode: "",
  67. teamId: "",
  68. teamTemplateCode: "",
  69. teams: [],
  70. labelsDropdown: false,
  71. selectedLabel: null,
  72. labelList: [],
  73. editable: true,
  74. sendMode: false // 根据url中是否携带patient来判断是否是"发送"模式
  75. }
  76. },
  77. beforeRouteEnter: function(to, from, next) {
  78. next(function(vm) {
  79. var query = vm.$route.query
  80. if(!storage.patient && !query.patient) {
  81. vm.sendMode = false
  82. } else {
  83. storage.patient = storage.patient || query.patient
  84. vm.sendMode = true
  85. }
  86. if(query && query.teamTemplateCode && from.path != "/preview-panel") {
  87. vm.modelCode = query.modelCode
  88. vm.teamId = query.teamId
  89. vm.teamTemplateCode = query.teamTemplateCode
  90. vm.editable = true
  91. vm.getTeamGuidanceDetail().then(function() {
  92. vm.findAllLabelList()
  93. })
  94. }
  95. })
  96. },
  97. computed: {
  98. isLeader: function() {
  99. var vm = this
  100. var leaderCode = storage.docInfo.adminTeamCode
  101. if(!vm.teams || !vm.teams.length || !leaderCode) {
  102. return 0
  103. }
  104. var team = _.filter(vm.teams, function(o) {
  105. return o.teamId == leaderCode
  106. })
  107. if(team.length) {
  108. vm.teams = team
  109. return 1
  110. }
  111. return 0
  112. }
  113. },
  114. created: function() {
  115. },
  116. mounted: function() {
  117. EventBus.$emit('active-nav-tab', 1)
  118. },
  119. methods: {
  120. countWord: function() {
  121. if(this.content.length <= this.words) {
  122. this.count = this.content.length
  123. } else {
  124. this.content = this.content.slice(0, this.words)
  125. }
  126. },
  127. findAllLabelList: function() {
  128. var vm = this
  129. return guidanceAPI.findAllLabelList({
  130. teamId: vm.teamId
  131. }).then(function(res) {
  132. var selected = null
  133. var label = vm.selectedLabel? vm.selectedLabel.name: '未分组'
  134. selected = _.filter(res.data, function(o) {
  135. return o.name == label
  136. })
  137. if(selected[0]) {
  138. selected[0].active = true
  139. vm.selectedLabel = selected[0]
  140. }
  141. vm.labelList = res.data
  142. }).catch(function(e){
  143. console.error(e)
  144. })
  145. },
  146. selectLabel: function(label) {
  147. var vm = this
  148. vm.selectedLabel && (vm.selectedLabel.active = false)
  149. label.active = true
  150. vm.selectedLabel = label
  151. vm.labelsDropdown = false
  152. },
  153. getTeamGuidanceDetail: function() {
  154. var vm = this
  155. return guidanceAPI.getTeamGuidanceDetail({teamTemplateCode: vm.teamTemplateCode,teamId:vm.teamId}).then(function(res) {
  156. if(res.status == 200) {
  157. var detail = res.guidanceDetail
  158. vm.teams = detail.teamList
  159. vm.modelName = detail.title
  160. vm.content = detail.content
  161. vm.imgs = detail.imagesUrl && detail.imagesUrl.split(',') || []
  162. vm.selectedLabel = {
  163. name: detail.labelName,
  164. code: detail.labelCode
  165. }
  166. }
  167. })
  168. },
  169. imgUploaded: function(url) {
  170. var vm = this
  171. vm.imgs.push(httpRequest.getImgUrl(url))
  172. },
  173. removeImg: function(url, idx) {
  174. var vm = this
  175. vm.imgs.splice(idx, 1)
  176. },
  177. save: function() {
  178. var vm = this
  179. if(!vm.modelName) {
  180. toastr && toastr.error("模板名称不能为空")
  181. return
  182. }
  183. if(!vm.content) {
  184. toastr && toastr.error("模板内容不能为空")
  185. return
  186. }
  187. guidanceAPI.modifyTeamGuidance({
  188. content: vm.content,
  189. title: vm.modelName,
  190. labelCode: vm.selectedLabel.code,
  191. images: vm.imgs.join(','),
  192. teamInfo: vm.teams&&JSON.stringify(vm.teams)||"",
  193. saveAsGuidance:0,
  194. guidanceCode: vm.teamTemplateCode,
  195. isLeader: vm.isLeader || 0
  196. }).then(function(res) {
  197. if(res.status == 200) {
  198. toastr && toastr.success("保存成功")
  199. EventBus.$emit('refresh-team-panel')
  200. }
  201. }).catch(function(e) {
  202. console.error(e)
  203. })
  204. },
  205. deleteTemplate: function() {
  206. var vm = this
  207. var d = dialog({
  208. width: 350,
  209. title: '删除模板',
  210. content: '删除后无法恢复,是否确认删除?',
  211. okValue: '确定',
  212. ok: function () {
  213. guidanceAPI.deleteTeamGuidance( { deleteAll: 0, guidanceCode: vm.teamTemplateCode, teamId:vm.teamId}).then(function(res) {
  214. toastr && toastr.success("删除成功")
  215. vm.editable = false
  216. EventBus.$emit('refresh-team-panel')
  217. }).catch(function(e) {
  218. console.error(e)
  219. })
  220. },
  221. cancelValue: '取消',
  222. cancel: function () {}
  223. });
  224. d.showModal();
  225. },
  226. sendTeamTemplate: function() {
  227. var vm = this
  228. if(!vm.modelName) {
  229. toastr && toastr.error("模板名称不能为空")
  230. return
  231. }
  232. if(!vm.content) {
  233. toastr && toastr.error("模板内容不能为空")
  234. return
  235. }
  236. var team = _.filter(vm.teams, function(o) {
  237. return o.teamId == vm.teamId
  238. })
  239. if(!team.length) {
  240. // 匹配不了说明医生修改了指导所属的 团队,并且入口团队并不在选中的列表中。则默认选择选中团队中的第一个团队来发送
  241. team = [vm.teams[0]]
  242. }
  243. var d = dialog({
  244. width: 350,
  245. content: '发出后无法变更,是否确认发送给居民?',
  246. okValue: '继续发送',
  247. ok: function () {
  248. guidanceAPI.sendTemplate( {
  249. patient: storage.patient,
  250. content: vm.content,
  251. guidanceCode: vm.teamTemplateCode,
  252. images: vm.imgs.join(','),
  253. teamId: JSON.stringify(team)
  254. }).then(function(res) {
  255. toastr && toastr.success("发送成功")
  256. var obj = {
  257. rehabilitationDetailId: storage.planId,
  258. patientCode: storage.patient,
  259. // patientName: patientName,
  260. doctorCode: storage.docInfo.code,
  261. doctorName: storage.docInfo.name,
  262. relationRecordType: 2, //健康指导
  263. relationRecordCode: res.data.id
  264. }
  265. guidanceAPI.saveRehabilitationOperateRecord({
  266. dataJson: JSON.stringify(obj)
  267. }).then(function(res) {
  268. if(res.status == 200) {
  269. var index = top.layer && top.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
  270. top.layer && top.layer.close(index)
  271. } else {
  272. toastr && toastr.success(res.msg)
  273. }
  274. })
  275. }).catch(function(e) {
  276. console.error(e)
  277. })
  278. },
  279. cancelValue: '取消',
  280. cancel: function () {}
  281. });
  282. d.showModal();
  283. },
  284. saveAsPersonTemplate: function() {
  285. var vm = this
  286. if(!vm.modelName) {
  287. toastr && toastr.error("模板名称不能为空")
  288. return
  289. }
  290. if(!vm.content) {
  291. toastr && toastr.error("模板内容不能为空")
  292. return
  293. }
  294. var param = {
  295. content: vm.content,
  296. modelName: vm.modelName
  297. }
  298. var img = vm.imgs.join(',').trim()
  299. if(img) {
  300. param.imagesUrl = img
  301. }
  302. guidanceAPI.newTemplate(param).then(function(res) {
  303. if(res.status == 200) {
  304. toastr && toastr.success("保存成功")
  305. EventBus.$emit('refresh-person-panel')
  306. } else {
  307. toastr && toastr.error(res.msg)
  308. }
  309. }).catch(function(e) {
  310. console.error(e)
  311. })
  312. },
  313. preview: function() {
  314. var vm = this
  315. var query = {
  316. modelCode: vm.modelCode,
  317. patient: storage.patient||"",
  318. timestemp: $.now()
  319. }
  320. this.$router.push({path:'/preview-panel',query:query})
  321. }
  322. },
  323. watch: {
  324. '$route': function (to, from) {
  325. var vm = this
  326. var query = vm.$route.query
  327. if(query && query.teamTemplateCode && from.path == "/team-edit-panel"&& to.path == "/team-edit-panel") {
  328. vm.modelCode = query.modelCode
  329. vm.teamId = query.teamId
  330. vm.editable = true
  331. vm.teamTemplateCode = query.teamTemplateCode
  332. vm.getTeamGuidanceDetail().then(function() {
  333. vm.findAllLabelList()
  334. })
  335. }
  336. if(storage.patient) {
  337. vm.sendMode = true
  338. } else {
  339. vm.sendMode = false
  340. }
  341. if(to.path == "/preview-panel") {
  342. EventBus.$emit('preview-template', {
  343. content: vm.content,
  344. modelName: vm.modelName,
  345. imgs: vm.imgs
  346. })
  347. }
  348. },
  349. 'content': function(v) {
  350. this.countWord()
  351. }
  352. }
  353. }