index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. import { dynamicPageName, prefixPagePath } from "../../../../core/utils";
  2. import { orderDetail, cancelOrder } from './service';
  3. import { cuttingDate } from '../../utils';
  4. import history from '../../utils/history';
  5. import { tradePay } from '../../utils/tradePay';
  6. import { reportApi } from '../../utils/cloudMonitorHelper';
  7. Component({
  8. props: {},
  9. data: {
  10. result: {
  11. id: '',
  12. // 就诊人id
  13. status: -1,
  14. // 预约状态 0-待支付 1-已支付(预约成功)2-排队中 7-已就诊 8-过期未就诊 9-已取消
  15. date: '',
  16. // 2022-09-20
  17. day: '',
  18. // 周一
  19. am: '',
  20. // 上午
  21. time: '' // 00:00
  22. },
  23. countown: '0',
  24. modalOpened: false,
  25. buttons: [{
  26. text: '不,先留着'
  27. }, {
  28. text: '取消预约',
  29. extClass: 'buttonBold'
  30. }],
  31. viewItem: [{
  32. label: '就诊日期',
  33. key: 'date'
  34. }, {
  35. label: '就诊时间',
  36. key: 'time'
  37. }, {
  38. label: '就诊医院',
  39. key: 'districtName'
  40. }, {
  41. label: '就诊科室',
  42. key: 'depName'
  43. }, {
  44. label: '就诊人',
  45. key: 'name'
  46. }, {
  47. label: '预约医生',
  48. key: 'doctor'
  49. }, {
  50. label: '挂号费用',
  51. key: 'price'
  52. }, {
  53. label: '就诊卡',
  54. key: 'card'
  55. }],
  56. refund: ['https://gw.alipayobjects.com/mdn/rms_373ab8/afts/img/A*03IPSKd3OmkAAAAAAAAAAAAAARQnAQ', 'https://gw.alipayobjects.com/mdn/rms_373ab8/afts/img/A*03IPSKd3OmkAAAAAAAAAAAAAARQnAQ']
  57. },
  58. didMount() {
  59. const {
  60. query
  61. } = this.$page.data;
  62. this.orderDetail();
  63. const {
  64. where
  65. } = query || {};
  66. if (where === 'order-pay') {
  67. /* 服务办结,预约挂号 */
  68. reportApi('预约挂号');
  69. }
  70. },
  71. didUnmount() {
  72. if (this.timer) {
  73. clearTimeout(this.timer);
  74. }
  75. },
  76. methods: {
  77. saveRef(ref) {
  78. this.subscribe = ref;
  79. },
  80. orderDetail() {
  81. const {
  82. query = {
  83. orderId: ''
  84. }
  85. } = this.$page.data;
  86. const {
  87. where
  88. } = query;
  89. my.showLoading();
  90. orderDetail({
  91. orderId: query.orderId
  92. }).then(data => {
  93. this.setData({
  94. result: Object.assign(data, cuttingDate(data.startTime))
  95. });
  96. const {
  97. status,
  98. expireTime = '',
  99. systemTime = ''
  100. } = this.data.result;
  101. if (status === 0) {
  102. const now = new Date(systemTime.replace(/-/g, '/')).getTime();
  103. const start = new Date(expireTime.replace(/-/g, '/')).getTime();
  104. if (!this.timeEndFlag) {
  105. this.doTimeout(start - now, () => {
  106. this.orderDetail();
  107. this.timeEndFlag = true;
  108. });
  109. }
  110. } else if (status === 1) {
  111. /* 如果是从下单页面过来的,拉起消息授权 */
  112. if (where === 'order-pay') {
  113. this.grantSubscribe();
  114. }
  115. }
  116. my.hideLoading();
  117. });
  118. },
  119. // 打开取消预约弹出
  120. onCancel() {
  121. this.setData({
  122. modalOpened: true
  123. });
  124. },
  125. // 确认取消预约
  126. onButtonClick(e) {
  127. this.setData({
  128. modalOpened: false
  129. });
  130. if (e.target.dataset.index === 1) {
  131. const {
  132. query = {
  133. orderId: ''
  134. }
  135. } = this.$page.data;
  136. cancelOrder({
  137. orderId: query.orderId,
  138. reason: ''
  139. }).then(() => {
  140. this.orderDetail();
  141. });
  142. }
  143. },
  144. // 再次预约
  145. reAppoint() {
  146. my.navigateTo({
  147. url: `${prefixPagePath}/${dynamicPageName}/index?pageCode=hospital-new-select-area`
  148. });
  149. },
  150. toH5(e) {
  151. const {
  152. url
  153. } = e.target.dataset;
  154. history.toH5(url);
  155. },
  156. hrefTo() {
  157. my.ap.navigateToAlipayPage({
  158. path: 'alipays://platformapi/startapp?appId=77700284&page=pages/medical/index?chInfo=YY_xiaochengxu'
  159. });
  160. },
  161. // 消息订阅授权
  162. grantSubscribe() {
  163. this.subscribe.subscribeMessage();
  164. },
  165. // 发起倒计时
  166. doTimeout(val, cb = () => {}) {
  167. if (val > 0) {
  168. const timeout = 200;
  169. val -= timeout;
  170. this.timer = setTimeout(() => {
  171. this.doTimeout(val, cb);
  172. }, timeout);
  173. } else {
  174. val = 0;
  175. cb();
  176. }
  177. const second = Math.floor(val / 1000);
  178. const h = Math.floor(second / 3600);
  179. const m = Math.floor(second % 3600 / 60);
  180. const s = second % 60;
  181. this.setData({
  182. countown: `${h > 0 ? `${h}:` : ''}${h > 0 || m > 0 ? `${`0${m}`.slice(-2)}:` : ''}${h > 0 || m > 0 || s > 0 ? `0${s}`.slice(-2) : '0'}`
  183. });
  184. },
  185. // onPay
  186. onPay() {
  187. tradePay({
  188. type: 1,
  189. idNum: this.data.result.orderId,
  190. depName: this.data.result.depName
  191. }, {
  192. tradeType: 'Appointment'
  193. }).then(() => {
  194. this.orderDetail(); // 支付成功之后发起消息订阅授权
  195. this.subscribe.subscribeMessage();
  196. });
  197. /* 服务办结,挂号缴费 */
  198. reportApi('挂号缴费');
  199. },
  200. toBackHome() {
  201. const len = getCurrentPages().length;
  202. my.navigateBack({
  203. delta: len + 1
  204. });
  205. }
  206. }
  207. });