guide_the_message.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. var httpData = GetRequest()
  2. var docInfo = JSON.parse(window.localStorage.getItem('wlyyAgent'))
  3. var tempwindow
  4. var previewLayerIndex, followupLayerIndex, KFZDlayerIndex
  5. function closeGuidancePreview() {
  6. layer.close(previewLayerIndex)
  7. }
  8. function closeFollowUpLayer(planDetaiId, relationCode) {
  9. if ($.isArray(relationCode)) {
  10. $.each(relationCode, function (index, item) {
  11. top.rehabilitationGuideVue.saveRehabilitationOperateRecord(planDetaiId, 6, item)
  12. })
  13. } else {
  14. top.rehabilitationGuideVue.saveRehabilitationOperateRecord(planDetaiId, 6, relationCode)
  15. }
  16. layer.close(followupLayerIndex)
  17. }
  18. function closeKFZDlayer(planDetaiId) {
  19. top.rehabilitationGuideVue.saveRehabilitationOperateRecord(planDetaiId, 5)
  20. layer.close(KFZDlayerIndex)
  21. }
  22. function showSuccessMessage(msg) {
  23. layer.msg(msg, {
  24. icon: 1
  25. })
  26. }
  27. function showErrorMessage(msg) {
  28. layer.msg(msg, {
  29. icon: 5
  30. })
  31. }
  32. top.rehabilitationGuideVue = new Vue({
  33. el: '#app',
  34. data: {
  35. doctorlevel: docInfo.doctorlevel,
  36. imgData: {
  37. accept: 'image/gif, image/jpeg, image/png, image/jpg'
  38. },
  39. isCollapse: false,
  40. selectCheckTyperadio: 0,
  41. showAppointHelpCheckBtn: true, //点击预约协诊按钮结束变为false
  42. showRecordFinished: false, //点击完成记录按钮变为true
  43. appointTime: '',
  44. appointDate: '',
  45. appointHour: '',
  46. upImgs: [],
  47. upImgArr: [],
  48. planid: httpData['planid'], // 服务项id
  49. service: {
  50. relationRecordImg: {},
  51. messageList: {}
  52. },
  53. startTime: '',
  54. pickerOptions: {
  55. disabledDate: function (time) {
  56. return time.format('yyyy-MM-dd') < new Date().format('yyyy-MM-dd')
  57. }
  58. },
  59. pId: httpData['pId'], // 康复计划id
  60. patient: httpData['patient'],
  61. patientName: decodeURI(httpData['patientName']),
  62. layerIndex: undefined,
  63. recordId: httpData['recordId'] || undefined,
  64. islimit: false
  65. },
  66. watch: {
  67. appointDate: function () {
  68. if (this.appointDate == new Date().format('yyyy-MM-dd')) {
  69. this.startTime = new Date(new Date().getTime()).format('hh:mm')
  70. } else {
  71. this.startTime = ''
  72. }
  73. }
  74. },
  75. mounted: function () {
  76. this.getServiceItem()
  77. },
  78. methods: {
  79. // 提醒患者 num 1康复指导2康复下转3复诊提醒4上门服务提醒5家签提醒
  80. sendSpecialistWeixinMessage: function (type) {
  81. var vm = this
  82. var text = ''
  83. if (type == 4) {
  84. // 上门服务
  85. text = '请问您是否确认提醒' + vm.patientName + '居民预约上门护理服务?'
  86. } else if (type == 7) {
  87. // 康复复诊
  88. text = '请问您是否确认提醒' + vm.patientName + '居民进行复诊?'
  89. }
  90. var current = layer.confirm(
  91. text,
  92. {
  93. btn: ['确定', '取消'],
  94. title: '提示'
  95. },
  96. function (index) {
  97. var reservationTypeObj = { 0: 2, 1: 3, 2: 1 }
  98. var _type = type == 4 ? 4 : type == 7 ? 3 : ''
  99. var loading = layer.load(0, { shade: false })
  100. var params = {
  101. patient: vm.patient,
  102. doctor: docInfo.uid,
  103. type: _type,
  104. relationCode: vm.planid,
  105. planId: vm.pId,
  106. reservationType: reservationTypeObj[vm.selectCheckTyperadio] //复诊类型:1线上,2线下,3远程
  107. }
  108. rehaAPI.sendSpecialistWeixinMessage(params).then(function (res) {
  109. layer.close(loading)
  110. if (res.status == 200) {
  111. showSuccessMessage('提交成功!')
  112. if (_type == 3 || _type == 4) {
  113. // 提醒患者后,即认为是已完成
  114. vm.saveRehabilitationOperateRecord(vm.planid, type)
  115. }
  116. } else {
  117. showErrorMessage(res.msg)
  118. }
  119. })
  120. layer.close(current) //再执行关闭
  121. }
  122. )
  123. },
  124. appointHelpCheck: function (data) {
  125. var vm = this
  126. vm.showAppointHelpCheckBtn = false
  127. vm.appointTime = vm.appointDate + ' ' + vm.appointHour
  128. var params = {
  129. patient: vm.patient,
  130. doctor: data.familyDoctorCode,
  131. doctorName: data.familyDoctorName, //家签医生
  132. sendTime: vm.appointTime,
  133. planDetailId: vm.planid,
  134. appointmentDoctor: data.specialistDoctorCode,
  135. appointmentDoctorName: data.specialistDoctorName //专科医生
  136. }
  137. var loading = layer.load(0, { shade: false })
  138. rehaAPI.appointmentConsultation(params).then(function (res) {
  139. layer.close(loading)
  140. if (res.status == 200) {
  141. showSuccessMessage('操作成功')
  142. setTimeout(function () {
  143. vm.getServiceItem()
  144. }, 400)
  145. } else {
  146. showErrorMessage(res.msg)
  147. }
  148. })
  149. },
  150. encryptCode: function (docCode) {
  151. var publicKey =
  152. 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC4lT0JWcv9xx6Q1hsxMal2F1AmKti/xVbBeh8jrD5CiYsFTH0DO1Mpyvv8YtkGdnDSLRjOQOA1PiaYvZoHIhml/jTvEMsvFlAD5i1BsHa5blLlJxQNp/XI7wpMZPfczqO+I/JONrV6ib+6Ci/1FyTjPQfHaiT2ehGyM/CFzOW1PQIDAQAB'
  153. var encrypt = new JSEncrypt()
  154. encrypt.setPublicKey(publicKey)
  155. return encodeURIComponent(encrypt.encrypt(docCode))
  156. },
  157. openWindow(url, p1, p2) {
  158. try {
  159. if (tempwindow) tempwindow.close()
  160. } catch (e) {
  161. console.log(e)
  162. }
  163. if (p1) {
  164. tempwindow = window.open('_blank', p1, p2)
  165. } else {
  166. tempwindow = window.open('_blank')
  167. }
  168. tempwindow.location = url
  169. },
  170. openHelpCheck: function () {
  171. var encryptCode = this.encryptCode(docInfo.uid)
  172. var url = httpRequest.teamworkService + '/#/teamwork/login?_code=' + encryptCode
  173. this.openWindow(url)
  174. },
  175. recordFinished: function () {
  176. this.showRecordFinished = true
  177. },
  178. //康复指导
  179. kfzd: function () {
  180. var vm = this,
  181. str = '../../rehabilitation/html/rehabilitation_guidance.html?patient=' + vm.patient + '&planDetaiId=' + vm.planid + '&planId=' + vm.pId
  182. KFZDlayerIndex = layer.open({
  183. type: 2,
  184. // offset: ['100px'], //右下角弹出
  185. area: ['660px', '650px'],
  186. shade: 0.5,
  187. title: '康复指导',
  188. fixed: true, //不固定
  189. maxmin: true,
  190. closeBtn: 1,
  191. shift: 5,
  192. shadeClose: false, //点击遮罩关闭层
  193. content: str,
  194. end: function () {
  195. // 未点击确定按钮,点击关闭按钮
  196. vm.getServiceItem()
  197. }
  198. })
  199. },
  200. // 康复随访计划
  201. sfjh: function () {
  202. var vm = this
  203. followupLayerIndex = layer.open({
  204. type: 2,
  205. // offset: ['100px'], //右下角弹出
  206. area: ['80%', '650px'],
  207. shade: 0.5,
  208. title: '随访计划',
  209. fixed: true, //不固定
  210. maxmin: true,
  211. closeBtn: 1,
  212. shift: 5,
  213. shadeClose: false, //点击遮罩关闭层
  214. content: '../../followup/html/followup_newplan.html?patient=' + vm.patient + '&planDetaiId=' + vm.planid + '&planId=' + vm.pId,
  215. end: function () {
  216. // 未点击确定按钮,点击关闭按钮
  217. this.getServiceItem()
  218. }
  219. })
  220. },
  221. zwkf: function () {
  222. top.layer.msg('此功能暂未开放', {
  223. icon: 1
  224. })
  225. },
  226. //康复指导
  227. jkzd: function (planId, patient) {
  228. var vm = this
  229. top.layer.open({
  230. type: 2,
  231. // offset: ['100px'], //右下角弹出
  232. area: ['80%', '648px'],
  233. shade: 0.5,
  234. title: '健康教育',
  235. fixed: true, //不固定
  236. maxmin: true,
  237. closeBtn: 1,
  238. shift: 5,
  239. shadeClose: false, //点击遮罩关闭层
  240. content: '../../guidance/html/index.html#/person-edit-panel?patient=' + patient + '&planId=' + planId
  241. })
  242. },
  243. // openFollowResult() {
  244. // top.layer.open({
  245. // type: 2,
  246. // area: ['600px', '700px'],
  247. // shade: 0.5,
  248. // title: '查看随访表单',
  249. // fixed: true, //不固定
  250. // maxmin: true,
  251. // closeBtn: 1,
  252. // // shift: 5,
  253. // shadeClose: false, //点击遮罩关闭层
  254. // content: '../html/followResult.html'
  255. // })
  256. // },
  257. rehabilitationReservation() {
  258. // 如果是康复复诊过去预约挂号,在就诊信息页面少一个字段显示,1隐藏字段,0正常显示
  259. sessionStorage.setItem('isFuzhen', 1)
  260. top.layer.open({
  261. type: 2,
  262. closeBtn: 1, // 显示关闭按钮
  263. area: ['800px', '90%'],
  264. title: '预约挂号',
  265. content: '../../jbsc/html/appointment/appoint-select.html?patient=' + this.patient
  266. })
  267. },
  268. openFollowRecordForm() {
  269. var vm = this
  270. if (vm.service.disease != '3') {
  271. top.layer.msg('请到app上操作!')
  272. return false
  273. }
  274. top.layer.open({
  275. type: 2,
  276. area: ['600px', '700px'],
  277. shade: 0.5,
  278. title: '记录随访表单',
  279. fixed: true, //不固定
  280. maxmin: true,
  281. closeBtn: 1,
  282. // shift: 5,
  283. shadeClose: false, //点击遮罩关闭层
  284. content: '../../rehabilitation/html/followRecord.html?serviceInfo=' + encodeURIComponent(JSON.stringify(this.service)) + '&planDetailId=' + this.planid,
  285. end: function () {
  286. // 未点击确定按钮,点击关闭按钮
  287. vm.getServiceItem()
  288. }
  289. })
  290. },
  291. qwapp: function () {
  292. top.layer.msg('请前往app处理', {
  293. icon: 5
  294. })
  295. },
  296. toDoorDialog() {
  297. var vm = this
  298. top.layer.open({
  299. type: 2,
  300. area: ['850px', '700px'],
  301. shade: 0.5,
  302. title: '代预约',
  303. fixed: true, //不固定
  304. maxmin: true,
  305. closeBtn: 1,
  306. // shift: 5,
  307. shadeClose: false, //点击遮罩关闭层
  308. // content: `/app/rehabilitation/html/toDoorService.html?patient=${this.patient}&detailId=${this.planid}&relationCode=${this.planid}`,
  309. content: `../../rehabilitation/html/toDoorService.html?patient=${this.patient}&detailId=${this.planid}&relationCode=${this.planid}`,
  310. end: function () {
  311. vm.getServiceItem()
  312. }
  313. })
  314. },
  315. viewGuidance: function (o) {
  316. var vm = this
  317. previewLayerIndex = layer.open({
  318. type: 2,
  319. area: ['380px', '600px'],
  320. shade: 0.5,
  321. title: '预览',
  322. fixed: true, //不固定
  323. maxmin: true,
  324. closeBtn: 1,
  325. shift: 5,
  326. shadeClose: false, //点击遮罩关闭层
  327. content: '../../rehabilitation/html/rehabilitation_guidance_preview.html?modelCode=' + o.article
  328. })
  329. },
  330. getServiceItem: function () {
  331. var vm = this
  332. var loginDoctor = JSON.parse(window.localStorage.getItem('wlyyAgent'))
  333. var loadding = top.layer.load(0, {
  334. shade: false
  335. }) //0代表加载的风格,支持0-2
  336. var params = {
  337. planDetailId: vm.planid
  338. }
  339. if (vm.recordId) {
  340. params['recordId'] = vm.recordId
  341. }
  342. rehaAPI.serviceItem(params).then(function (res) {
  343. top.layer.close(loadding)
  344. if (res.status == 200) {
  345. vm.service = res.data
  346. var isZK = loginDoctor.doctorType == 1 ? true : false
  347. vm.service.isZK = isZK
  348. if (vm.service.completeTime) {
  349. var l = vm.service.completeTime.length
  350. vm.service.shortCompleteTime = vm.service.completeTime.substr(l - 5, l - 1)
  351. }
  352. if (vm.service.isMyTask == 1) {
  353. //执行者
  354. vm.service.isCK = true //无法显示按钮
  355. if (loginDoctor.uid == vm.service.specialistDoctorCode) {
  356. //说明我自己是创建者
  357. vm.service.isCK = false
  358. vm.service.isCreate = true
  359. }
  360. } else {
  361. if (loginDoctor.uid == vm.service.specialistDoctorCode) {
  362. //说明我自己是创建者
  363. vm.service.isCreate = true
  364. }
  365. }
  366. if (vm.service.type == 4 || vm.service.type == 5 || vm.service.type == 7) {
  367. vm.getRelationRecord(vm.service.type, vm.planid).then(function (result) {
  368. if (result.status == 200) {
  369. vm.service.relationList = result.data && result.data.length > 0 ? result.data : undefined
  370. vm.$forceUpdate()
  371. }
  372. })
  373. }
  374. if (vm.service.frequencyCode) {
  375. vm.islimit = true
  376. } else {
  377. vm.islimit = false
  378. }
  379. } else {
  380. top.layer.msg(res.msg, {
  381. icon: 5
  382. })
  383. }
  384. if (vm.service.status == 1) {
  385. var index = top.layer.getFrameIndex(window.name) //先得到当前iframe层的索引
  386. top.layer.title('服务记录详情', index) //再改变当前层的标题
  387. }
  388. })
  389. },
  390. getRelationRecord: function (type, planDetaiId) {
  391. // 1.电话短信 2.康复咨询 3.远程监控检测 4.上门服务 5.康复指导 6 康复随访 7.复诊)
  392. var vm = this
  393. var url = ''
  394. if (type == 5) {
  395. url = 'doctor/specialist/rehabilitation/selectByRelationCode'
  396. } else if (type == 7) {
  397. url = 'third/guahao/selectByRelationCode'
  398. } else if (type == 4) {
  399. url = '/doctor/specialist/rehabilitation/selectRelationCode'
  400. }
  401. var vm = this
  402. var params = {
  403. relationCode: vm.recordId ? vm.recordId : planDetaiId
  404. }
  405. return httpRequest.get(url, { data: params })
  406. },
  407. zdly: function (data) {
  408. var vm = this
  409. var loginDoctor = JSON.parse(window.localStorage.getItem('wlyyAgent'))
  410. var otherCode, otherName
  411. if (loginDoctor.doctorType == 1) {
  412. otherCode = data.familyDoctorCode
  413. otherName = data.familyDoctorName
  414. } else {
  415. otherCode = data.specialistDoctorCode
  416. otherName = data.specialistDoctorName
  417. }
  418. top.layer.open({
  419. type: 2,
  420. // offset: ['100px'], //右下角弹出
  421. area: ['660px', '600px'],
  422. shade: 0.5,
  423. title: '指导留言',
  424. fixed: true, //不固定
  425. maxmin: true,
  426. closeBtn: 1,
  427. shift: 5,
  428. shadeClose: false, //点击遮罩关闭层
  429. content: '../../consulting/html/consulting.html?otherCode=' + otherCode + '&otherName=' + encodeURI(otherName) + '&planDetailId=' + vm.planid,
  430. end: function () {
  431. // 未点击确定按钮,点击关闭按钮
  432. vm.getServiceItem()
  433. }
  434. })
  435. },
  436. deleteImg: function (idx) {
  437. console.log(idx)
  438. this.upImgs.splice(idx, 1)
  439. },
  440. chakan: function () {
  441. this.isCollapse = !this.isCollapse
  442. },
  443. upLoadImgToBase64: function () {
  444. var vm = this
  445. var img1 = event.target.files[0]
  446. var reader = new FileReader()
  447. var type = img1.type //文件的类型,判断是否是图片
  448. var size = img1.size //文件的大小,判断图片的大小
  449. if (this.imgData.accept.indexOf(type) == -1) {
  450. alert('请选择我们支持的图片格式!')
  451. return false
  452. }
  453. if (size > 3145728) {
  454. alert('请选择3M以内的图片!')
  455. return false
  456. }
  457. reader.readAsDataURL(img1)
  458. reader.onload = function (e) {
  459. vm.upImgs.push({
  460. baseUrl: e.target.result
  461. })
  462. vm.upImgArr.push(img1)
  463. console.log('e', e, 'vm.upImgs', vm.upImgs, 'vm.upImgArr', vm.upImgArr)
  464. //vm.uploadImg(vm.upImgArr);
  465. }
  466. },
  467. qrwc: function (patient, type) {
  468. var vm = this
  469. if (!vm.service.node) {
  470. showErrorMessage('请填写服务记录')
  471. return
  472. }
  473. if (!vm.upImgs.length) {
  474. showErrorMessage('请上传相关记录')
  475. return
  476. }
  477. vm.saveRehabilitationOperateRecord(vm.planid, type)
  478. },
  479. saveRehabilitationOperateRecord: function (planDetailId, type, relationCode, flag) {
  480. var vm = this
  481. var params = {
  482. rehabilitationDetailId: planDetailId,
  483. node: null,
  484. patientCode: vm.patient,
  485. doctorCode: docInfo.uid,
  486. relationRecordType: type,
  487. relationRecordCode: '',
  488. relationRecordImg: null,
  489. status: 0
  490. }
  491. rehaAPI.saveRehabilitationOperateRecord({ dataJson: JSON.stringify(params) }).then(function (res) {
  492. if (res.status == 200) {
  493. if (type == 1 || type == 7) {
  494. vm.uploadImg(vm.upImgArr)
  495. } else if (type == 6) {
  496. vm.updateRelationCodeByDetailId(planDetailId, relationCode)
  497. } else {
  498. vm.updateNoteAndImageRehabilitationOperate(planDetailId)
  499. }
  500. } else {
  501. layer.msg(res.msg, {
  502. icon: 5
  503. })
  504. }
  505. })
  506. },
  507. //上传图片
  508. uploadImg: function (data) {
  509. var vm = this
  510. var len = data.length
  511. if (len == 0) {
  512. vm.updateNoteAndImageRehabilitationOperate(vm.planid)
  513. } else {
  514. var file = data[len - 1]
  515. var formData = new FormData()
  516. formData.append('file', file)
  517. rehaAPI.upload(formData).then(function (res) {
  518. if (res.status == 200) {
  519. vm.upImgs[len - 1].img = res.data
  520. data.pop()
  521. vm.$forceUpdate()
  522. vm.uploadImg(data)
  523. } else {
  524. layer.msg(res.msg, {
  525. icon: 5
  526. })
  527. }
  528. })
  529. }
  530. },
  531. updateNoteAndImageRehabilitationOperate: function (planDetailId, relationCode) {
  532. var vm = this
  533. var _image = []
  534. $.each(vm.upImgs, function (index, obj) {
  535. _image.push(obj.img)
  536. })
  537. var params = {
  538. planDetailId: planDetailId,
  539. node: vm.service && vm.service.node ? vm.service.node : null,
  540. image: JSON.stringify(_image) || ''
  541. }
  542. if (relationCode) {
  543. params['relationCode'] = relationCode
  544. }
  545. var loadding = top.layer.load(0, {
  546. shade: false
  547. }) //0代表加载的风格,支持0-2
  548. rehaAPI.updateNoteAndImageRehabilitationOperate(params).then(function (res) {
  549. top.layer.close(loadding)
  550. if (res.status == 200) {
  551. vm.getServiceItem()
  552. top.rehabilitationVue.refresh()
  553. }
  554. })
  555. },
  556. updateRelationCodeByDetailId: function (planDetailId, relationCode) {
  557. var vm = this
  558. var params = {
  559. planDetailId: planDetailId,
  560. relationCode: relationCode
  561. }
  562. rehaAPI.updateRelationCodeByDetailId(params).then(function (res) {
  563. if (res.status == 200) {
  564. vm.getServiceItem()
  565. top.rehabilitationVue.refresh()
  566. } else {
  567. showErrorMessage(res.msg)
  568. }
  569. })
  570. },
  571. viewDetial: function (type, code) {
  572. var vm = this
  573. if (type == 3) {
  574. top.layer.msg('客户端暂不支持查询健康指导记录')
  575. } else if (type == 4) {
  576. top.layer.msg('客户端暂不支持查询随访记录')
  577. } else {
  578. top.layer.open({
  579. type: 2,
  580. // offset: ['100px'], //右下角弹出
  581. area: ['80%', '600px'],
  582. shade: 0.5,
  583. title: '指导教育',
  584. fixed: true, //不固定
  585. maxmin: true,
  586. closeBtn: 1,
  587. shift: 5,
  588. shadeClose: false, //点击遮罩关闭层
  589. content: '../../article/html/article-info.html?articleId=' + code,
  590. end: function () {
  591. // 未点击确定按钮,点击关闭按钮
  592. vm.getServiceItem()
  593. }
  594. })
  595. }
  596. },
  597. getContent: function (value, type) {
  598. var res = value
  599. if (type == 2 || type == 9) {
  600. res = "<img src='" + httpRequest.getImgUrl(res) + "'>"
  601. } else if (type == 3) {
  602. res = '【语音】'
  603. } else if (type == 19) {
  604. res = '【聊天记录】'
  605. } else if (type == 12) {
  606. res = '【视频】'
  607. }
  608. return res
  609. }
  610. },
  611. filters: {
  612. formatDate: function (value, format) {
  613. if (!value) return
  614. var fmt = format || 'yyyy-MM-dd hh:mm'
  615. var date = new Date(value)
  616. if (/(y+)/.test(fmt)) {
  617. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
  618. }
  619. let o = {
  620. 'M+': date.getMonth() + 1,
  621. 'd+': date.getDate(),
  622. 'h+': date.getHours(),
  623. 'm+': date.getMinutes(),
  624. 's+': date.getSeconds()
  625. }
  626. for (let k in o) {
  627. if (new RegExp(`(${k})`).test(fmt)) {
  628. let str = o[k] + ''
  629. fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : ('00' + str).substr(str.length))
  630. }
  631. }
  632. return fmt
  633. },
  634. getImgUrl: function (value) {
  635. var url = httpRequest.getImgUrl(value)
  636. return url
  637. }
  638. }
  639. })
  640. $('body').on('click', 'img', function () {
  641. var _this = $(this) //将当前的img元素作为_this传入函数
  642. imgShow('#outerdiv', '#innerdiv', '#bigimg', _this)
  643. })
  644. function imgShow(outerdiv, innerdiv, bigimg, _this) {
  645. var src = _this.attr('src') //获取当前点击的pimg元素中的src属性
  646. $(bigimg).attr('src', src) //设置#bigimg元素的src属性
  647. /*获取当前点击图片的真实大小,并显示弹出层及大图*/
  648. $('<img/>')
  649. .attr('src', src)
  650. .load(function () {
  651. var windowW = $(window).width() //获取当前窗口宽度
  652. var windowH = $(window).height() //获取当前窗口高度
  653. var realWidth = this.width //获取图片真实宽度
  654. var realHeight = this.height //获取图片真实高度
  655. var imgWidth, imgHeight
  656. var scale = 0.8 //缩放尺寸,当图片真实宽度和高度大于窗口宽度和高度时进行缩放
  657. if (realHeight > windowH * scale) {
  658. //判断图片高度
  659. imgHeight = windowH * scale //如大于窗口高度,图片高度进行缩放
  660. imgWidth = (imgHeight / realHeight) * realWidth //等比例缩放宽度
  661. if (imgWidth > windowW * scale) {
  662. //如宽度扔大于窗口宽度
  663. imgWidth = windowW * scale //再对宽度进行缩放
  664. }
  665. } else if (realWidth > windowW * scale) {
  666. //如图片高度合适,判断图片宽度
  667. imgWidth = windowW * scale //如大于窗口宽度,图片宽度进行缩放
  668. imgHeight = (imgWidth / realWidth) * realHeight //等比例缩放高度
  669. } else {
  670. //如果图片真实高度和宽度都符合要求,高宽不变
  671. imgWidth = realWidth
  672. imgHeight = realHeight
  673. }
  674. $(bigimg).css('width', imgWidth) //以最终的宽度对图片缩放
  675. var w = (windowW - imgWidth) / 2 //计算图片与窗口左边距
  676. var h = (windowH - imgHeight) / 2 //计算图片与窗口上边距
  677. $(innerdiv).css({ 'top': h, 'left': w }) //设置#innerdiv的top和left属性
  678. $(outerdiv).fadeIn('fast') //淡入显示#outerdiv及.pimg
  679. })
  680. $(outerdiv).click(function () {
  681. //再次点击淡出消失弹出层
  682. $(this).fadeOut('fast')
  683. })
  684. }