template-items.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. var docInfo = JSON.parse(window.localStorage.getItem('wlyyAgent'));
  2. function showSuccessMessage(msg) {
  3. layer.msg(msg, {
  4. icon: 1
  5. })
  6. }
  7. function showErrorMessage(msg) {
  8. layer.msg(msg, {
  9. icon: 5
  10. })
  11. }
  12. function showWarningMessage(msg) {
  13. layer.msg(msg, {
  14. icon: 2
  15. })
  16. }
  17. function showInfoMessage(msg) {
  18. layer.msg(msg, {
  19. icon: 6
  20. })
  21. }
  22. var TemplateItems = {
  23. template: '<div style="height: 100%;">\
  24. <div class="title-name c-f16">\
  25. <span class="c-vam">{{name}}</span>\
  26. </div>\
  27. <div v-show="!items.length" class="c-t-center" style="margin-top: 200px;">\
  28. <img src="../../../images/fanhui_icon.png" class="c-vam"/>请在左侧“服务项”列表中选择\
  29. </div>\
  30. <div class="template-items" v-show="items.length">\
  31. <div v-for="(item, index) in items">\
  32. <div class="item-card ptb10 plr15 mt10" v-for="(o, i) in item.list">\
  33. <div class="c-nowrap">{{o.name}}</div>\
  34. <div class="c-row c-f14 mt5">\
  35. <div class="c-50">\
  36. <span class="c-909090">执行人员:</span>\
  37. <span v-if="!o.type" class="c-909090">家庭医生</span>\
  38. <span v-else class="c-909090">{{o.type==1?\'家庭医生\':\'专科医生\'}}</span>\
  39. </div>\
  40. <div class="c-50 c-hide">\
  41. <span class="c-909090">医&emsp;&emsp;院:</span>\
  42. <span class="c-909090">待选择</span>\
  43. </div>\
  44. </div>\
  45. <div class="c-row c-f14 mt5">\
  46. <div class="c-50">\
  47. <span class="c-909090">计划时间:</span>\
  48. <span class="c-909090" v-if="item.list.length==1 && !o.executeTimes">不限频次</span>\
  49. <span class="c-909090" v-else>{{o.frequencyName||\'待选择\'}}</span><img v-if="o.code!=2 && o.code!=3" class="ml15" @click="showDialog(o,index,i)" style="width:16px;height: 16px;vertical-align: middle;" src="../../../images/bianji_icon.png"></img>\
  50. </div>\
  51. <el-dialog\
  52. title="计划时间"\
  53. :visible.sync="dialogVisible"\
  54. width="34%"\
  55. :before-close="handleClose">\
  56. <div class="c-t-center">\
  57. <div class="c-t-left mb20">任务项目:{{seletc[\'name\']}}</div>\
  58. <div class="mb10 ui-grid ui-grid-middle">\
  59. <div class="ui-col-0">频&emsp;&emsp;次:</div>\
  60. <el-select class="ui-col-1" v-model="seletc[\'frequency\']" placeholder="请选择" @change="selectFrequency">\
  61. <el-option\
  62. v-for="item in frequencysList1"\
  63. :key="item.name"\
  64. :label="item.name"\
  65. :value="item.name">\
  66. </el-option>\
  67. </el-select>\
  68. </div>\
  69. <div v-show="seletc[\'frequency\']!=\'不限频次\'" class="mb10 ui-grid ui-grid-middle">\
  70. <div class="ui-col-0">执行时间:</div>\
  71. <el-select class="ui-col-1" v-model="seletc[\'time\']" placeholder="请选择" @focus="selectTime">\
  72. <el-option\
  73. v-for="item in multipleTimeArr"\
  74. :key="item.code"\
  75. :label="item.name"\
  76. :value="item.code">\
  77. </el-option>\
  78. </el-select>\
  79. </div>\
  80. <div v-show="seletc[\'frequency\']!=\'不限频次\'" class="mb10 ui-grid ui-grid-middle">\
  81. <div class="ui-col-0">执行人员:</div>\
  82. <el-select class="ui-col-1" v-model="seletc[\'doctor\']" placeholder="请选择">\
  83. <el-option\
  84. v-for="item in doctorList"\
  85. :key="item.name"\
  86. :label="item.name"\
  87. :value="item.code">\
  88. </el-option>\
  89. </el-select>\
  90. </div>\
  91. </div>\
  92. <span slot="footer" class="dialog-footer">\
  93. <el-button @click="dialogVisible = false">取 消</el-button>\
  94. <el-button type="primary" @click="confirmTaskItem(items[index].list[i])">确 定</el-button>\
  95. </span></el-dialog>\
  96. <div class="c-50 setSelect" v-if="i==0">\
  97. <span class="c-909090">费&emsp;&emsp;用:</span>\
  98. <el-input-number v-model="item.expense" :step="1" :min="0" size="mini"></el-input-number>&emsp;元\
  99. </div>\
  100. </div>\
  101. <img v-if="name!=\'系统模板\'" src="../../../images/qingchu_icon.png" class="item-delete-btn" @click.stop="deleteItem(o, i)"/>\
  102. </div>\
  103. </div>\
  104. </div>\
  105. <div class="foot-btns">\
  106. <a class="delete-btn c-t-center mr50" @click="deleteTemplate">\
  107. 删除模板\
  108. </a>\
  109. <a class="save-btn c-t-center" @click="saveTemplate">\
  110. 保存模板\
  111. </a>\
  112. </div>\
  113. </div>',
  114. props: [],
  115. data: function() {
  116. return {
  117. name: '',
  118. items: [],
  119. isNew: null,
  120. templateId: "",
  121. dialogVisible:false,
  122. item: null,
  123. seletc:{'frequency':'','time':'','doctor':'','name':'','index':'','i':''},
  124. selectFrequencyItem:null,
  125. multipleTimeList:{},
  126. multipleTimeArr:[],
  127. doctorList:[{name:'家庭医生',code:1},{name:'专科医生',code:2}], //执行人员列表
  128. frequencysList1:[{'code':'','name':'不限频次'},{"code":"qd_10-week1","name":"1周/次","type":1,mode:"week"},
  129. {"code":"qd_10-week1","name":"2周/次","type":2,mode:"week"},
  130. {"code":"qd_10-month1","name":"1月/次","type":1,mode:"month"},
  131. {"code":"qd_10-month1","name":"2月/次","type":2,mode:"month"},
  132. {"code":"qd_10-month1","name":"3月/次","type":3,mode:"month"}], //频次列表-multiple
  133. options:[{label:'0',value:'0'}]
  134. }
  135. },
  136. beforeRouteEnter: function (to, from, next) {
  137. next(function(vm) {
  138. var query = vm.$route.query
  139. vm.name = query.name || '模板未命名',
  140. vm.templateId = query.templateId
  141. if(from.path != "/template-item-detail" || from.path == "/") {
  142. vm.items = []
  143. }
  144. if(vm.isNew == true || vm.isNew === "true") {
  145. vm.isNew = true
  146. } else {
  147. vm.isNew = false
  148. }
  149. })
  150. },
  151. created: function() {
  152. var vm = this
  153. // 点击添加 初始化数据
  154. EventBus.$on("add-template-item", function(o) {
  155. if(o.isInit){
  156. vm.items.push(o)
  157. }else{
  158. var isEast=_.findIndex(vm.items,{code:o.code})
  159. if(isEast==-1){
  160. o.list=[{}]
  161. o.expense=0
  162. vm.items.push(o)
  163. }else{
  164. _.map(vm.items,function(item){
  165. if(item.code==o.code){
  166. item.list.push({})
  167. return item
  168. }
  169. })
  170. }
  171. }
  172. _.map(vm.items, function (item) {
  173. if(item.list.length>=1){
  174. _.map(item.list,function(it){
  175. !it.executeTimes?it.frequencyName='待选择':''
  176. return it
  177. })
  178. }
  179. return item
  180. })
  181. _.map(vm.items, function (item) {
  182. _.map(item.list,function(it){
  183. it.name=item.name
  184. it.code=item.code
  185. return it
  186. })
  187. return item
  188. })
  189. vm.$forceUpdate()
  190. })
  191. },
  192. mounted: function() {
  193. var vm = this
  194. vm.initTimeData()
  195. },
  196. methods: {
  197. deleteItem: function(o, i) {
  198. var vm = this
  199. o.enable = true
  200. _.some(vm.items,function(item,index){
  201. if(item.code==o.code){
  202. item.list.splice(i, 1)
  203. if(item.list.length==0){
  204. vm.items.splice(index,1)
  205. }
  206. return true
  207. }
  208. })
  209. vm.$forceUpdate()
  210. EventBus.$emit("delete-template-item", o,i,vm.items)
  211. },
  212. initTimeData:function(){
  213. var vm=this
  214. vm.multipleTimeList ={"week":[],"month":[]}
  215. for(var i=1;i<=28;i++){
  216. switch(i){
  217. case 1:vm.multipleTimeList.week.push({name:"周一",code:String(i)});break;
  218. case 2:vm.multipleTimeList.week.push({name:"周二",code:String(i)});break;
  219. case 3:vm.multipleTimeList.week.push({name:"周三",code:String(i)});break;
  220. case 4:vm.multipleTimeList.week.push({name:"周四",code:String(i)});break;
  221. case 5:vm.multipleTimeList.week.push({name:"周五",code:String(i)});break;
  222. case 6:vm.multipleTimeList.week.push({name:"周六",code:String(i)});break;
  223. case 7:vm.multipleTimeList.week.push({name:"周日",code:String(i)});break;
  224. default:break;
  225. }
  226. // if(i<=7){
  227. vm.multipleTimeList.month.push({name:i+"号",code:String(i)})
  228. // }
  229. }
  230. },
  231. // 编辑按钮
  232. showDialog:function(item,index,i){
  233. this.seletc['frequency']=item.frequencyName
  234. if(this.seletc['frequency']=='待选择'){
  235. this.seletc['frequency']='不限频次'
  236. }
  237. // 根据频率获取执行时间选择返回
  238. if(this.seletc['frequency']){
  239. this.selectFrequencyItem=_.find(this.frequencysList1,{'name':this.seletc['frequency']})
  240. this.multipleTimeArr=this.multipleTimeList[this.selectFrequencyItem.mode]
  241. }
  242. this.seletc['doctor']=item.type
  243. this.seletc['time']=item.dateCode
  244. this.seletc['name']=item.name
  245. this.seletc['index']=index
  246. this.seletc['i']=i
  247. this.dialogVisible = true
  248. },
  249. // 点击同意按钮
  250. confirmTaskItem:function(){
  251. var index=this.seletc['index'],
  252. i=this.seletc['i'],
  253. item=this.items[index].list[i];
  254. if(this.seletc['frequency']=='不限频次'){
  255. var list=[{'name':item.name,'code':item.code,'frequencyName':'不限频次'}]
  256. this.items.splice(index,1,{'code':item.code,'name':item.name,'expense':0,list})
  257. this.dialogVisible = false
  258. return
  259. }
  260. item.type=this.seletc['doctor']
  261. item.dateCode=this.seletc['time']
  262. item.dateCode?item.dateName=_.find(this.multipleTimeArr,{'code':this.seletc['time']}).name:''
  263. item.frequencyName=this.selectFrequencyItem.name
  264. item.frequencyCode=this.selectFrequencyItem.code
  265. if(item.dateCode){
  266. item.date=getFreDateArr(this.selectFrequencyItem.mode+this.selectFrequencyItem.type, Number(item.dateCode)).map(function(o) {return o.format("YYYY-MM-DD")})
  267. item.executeTimesArr = _.map(item.date,function(citem){
  268. return citem+" 00:00"
  269. })
  270. item.executeTimes=item.executeTimesArr.join(",")
  271. }
  272. this.dialogVisible = false
  273. },
  274. selectFrequency:function(){
  275. this.selectFrequencyItem=_.find(this.frequencysList1,{'name':this.seletc['frequency']})
  276. this.multipleTimeArr=this.multipleTimeList[this.selectFrequencyItem.mode]
  277. },
  278. selectTime:function(item){
  279. if(!this.seletc['frequency']){
  280. showErrorMessage('请先选择频次')
  281. return false
  282. }
  283. },
  284. handleClose:function(){
  285. this.dialogVisible = false
  286. },
  287. saveTemplate: function() {
  288. var vm = this
  289. //检查有频次时(同一个服务项超过1个)计划时间是否填写完整
  290. var ispass=_.every(vm.items,function(item){
  291. if(item.list.length>1){
  292. return _.every(item.list,function(it){
  293. return it.dateCode && it.type && it.frequencyCode
  294. })
  295. }else{
  296. return true
  297. }
  298. })
  299. if(!ispass){
  300. showErrorMessage('请完善计划时间')
  301. return false
  302. }
  303. var ispass1=_.every(vm.items,function(item){
  304. if(item.code!='2'&&item.code!='3'){
  305. return _.every(item.list,function(it,index){
  306. return _.every(item.list,function(i,ind){
  307. if(index!=ind){
  308. var same=_.intersection(it.executeTimesArr,i.executeTimesArr)
  309. if(same.length>0){
  310. return false
  311. }else{
  312. return true
  313. }
  314. }else{
  315. return true
  316. }
  317. })
  318. })
  319. }else{
  320. return true
  321. }
  322. })
  323. if(!ispass1){ //时间重复
  324. showErrorMessage('存在重复时间')
  325. return false
  326. }
  327. _.map(vm.items, function (item) {
  328. item.plan=[]
  329. // 过滤有执行时间的数组
  330. var arr=[]
  331. arr=_.filter(item.list,function(ee){
  332. return ee.executeTimes
  333. })
  334. item.num=arr.length
  335. _.map(item.list,function(it){
  336. it.name=item.name
  337. it.code=item.code
  338. return it
  339. })
  340. // 存在执行时间
  341. if(item.num){
  342. item.plan =item.list||[]
  343. item.remark=item.list[0].remark
  344. _.map(item.plan,function(item2){
  345. item2.executeTimes?item2.executeTimesArr=item2.executeTimes.split(','):''
  346. item2.mode='multiple' //模板
  347. item2.show=false
  348. if(item2.type){
  349. item2.doctorName=item2.type==1?'家庭医生':'专科医生'
  350. }else{
  351. item2.doctorName=''
  352. }
  353. item2.doctor=item2.type
  354. _.map(vm.frequencysList1,function(it){
  355. if(it.name==item2.frequencyName){
  356. item2.frequencyName?item2.frequencyCode=it.code:''
  357. }
  358. })
  359. item2.date=_.map(item2.executeTimesArr,function(item3){
  360. return item3.substring(0,item3.length-6)
  361. })
  362. return item2
  363. })
  364. }
  365. return item
  366. })
  367. var params = []
  368. _.each(vm.items, function (item, index) {
  369. if (item.plan && item.plan.length) {
  370. _.each(item.plan, function (citem, cindex) {
  371. var param = {
  372. 'templateId': vm.templateId,
  373. "hospitalServiceItemId": item.code,
  374. "type": citem.type, //1家医2专医
  375. "executeTimes": citem.executeTimes,
  376. "frequencyCode": citem.frequencyCode.split("-")[0],
  377. 'frequencyName':citem.frequencyName,
  378. 'dateName':citem.dateName,
  379. 'dateCode':citem.dateCode,
  380. "timeType": 0, //1白天2晚上0全天
  381. 'expense':item.expense||0,
  382. "remark": item.remark,
  383. }
  384. params.push(param)
  385. })
  386. } else {
  387. var param = {
  388. 'templateId': vm.templateId,
  389. "hospitalServiceItemId": item.code,
  390. "type": '', //1家医2专医
  391. "executeTimes": "",
  392. "frequencyCode": "",
  393. "timeType": 0, //1白天2晚上0全天
  394. 'expense':item.expense||0,
  395. "remark": ""
  396. }
  397. params.push(param)
  398. }
  399. })
  400. vm.loading.showModal()
  401. rehaAPI.createTemplateDetail({
  402. doctor: docInfo.uid,
  403. json:JSON.stringify(params),
  404. type: vm.isNew?"create":"edit"
  405. }).then(function(res) {
  406. if(res.status == 200) {
  407. vm.loading.close()
  408. showSuccessMessage('保存成功')
  409. EventBus.$emit("refresh-index")
  410. vm.$router.replace("/")
  411. } else {
  412. vm.loading.close()
  413. showErrorMessage(res.msg)
  414. }
  415. }).catch(function(e) {
  416. vm.loading.close()
  417. console.error(e)
  418. })
  419. },
  420. deleteTemplate: function() {
  421. var vm = this
  422. if(this.name=='系统模板'){
  423. showErrorMessage('不能删除系统模板!')
  424. return false
  425. }
  426. layer.confirm('确定删除该模板?', {
  427. btn: ['确认','取消'] //按钮
  428. }, function(){
  429. vm.loading.showModal()
  430. rehaAPI.deleteTemplate({
  431. templateId: vm.templateId
  432. }).then(function(res) {
  433. vm.loading.close()
  434. if(res.status == 200) {
  435. showSuccessMessage('删除成功')
  436. } else {
  437. showErrorMessage(res.msg)
  438. }
  439. EventBus.$emit("refresh-index")
  440. vm.$router.replace("/")
  441. }).catch(function(e) {
  442. vm.loading.close()
  443. console.error(e)
  444. })
  445. }, function(){
  446. });
  447. },
  448. toDetail: function(o) {
  449. var vm = this
  450. vm.item = o
  451. vm.$router.push({
  452. path:"/template-item-detail",
  453. query: {
  454. templateId: vm.templateId,
  455. itemId: o.code
  456. }
  457. })
  458. }
  459. },
  460. // watch: {
  461. // '$route': function (to, from) {
  462. // var vm = this
  463. //// if(to.path == "/template-item-detail" && (from.path != "/template-item-detail" || from.path == "/")) {
  464. //// EventBus.$emit("show-item-detail", vm.item)
  465. //// }
  466. // if(to.path == "/template-item-detail") {
  467. // EventBus.$emit("show-item-detail", vm.item)
  468. // }
  469. // }
  470. // }
  471. }