index.js 4.9 KB

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