index.js 5.1 KB

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