index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. my.showLoading();
  145. cancelOrder({
  146. orderId: query.orderId,
  147. reason: "",
  148. }).then(() => {
  149. my.hideLoading();
  150. this.orderDetail();
  151. });
  152. }
  153. },
  154. // 再次预约
  155. reAppoint() {
  156. my.navigateTo({
  157. url: `${prefixPagePath}/${dynamicPageName}/index?pageCode=hospital-new-select-area`,
  158. });
  159. },
  160. toH5(e) {
  161. const { url } = e.target.dataset;
  162. history.toH5(url);
  163. },
  164. hrefTo() {
  165. my.ap.navigateToAlipayPage({
  166. path: "alipays://platformapi/startapp?appId=77700284&page=pages/medical/index?chInfo=YY_xiaochengxu",
  167. });
  168. },
  169. // 消息订阅授权
  170. async grantSubscribe() {
  171. // 获取智能消息推送授权
  172. await getSubscribeAuth();
  173. },
  174. // 发起倒计时
  175. doTimeout(val, cb = () => {}) {
  176. if (val > 0) {
  177. const timeout = 200;
  178. val -= timeout;
  179. this.timer = setTimeout(() => {
  180. this.doTimeout(val, cb);
  181. }, timeout);
  182. } else {
  183. val = 0;
  184. cb();
  185. }
  186. const second = Math.floor(val / 1000);
  187. const h = Math.floor(second / 3600);
  188. const m = Math.floor((second % 3600) / 60);
  189. const s = second % 60;
  190. this.setData({
  191. countown: `${h > 0 ? `${h}:` : ""}${
  192. h > 0 || m > 0 ? `${`0${m}`.slice(-2)}:` : ""
  193. }${h > 0 || m > 0 || s > 0 ? `0${s}`.slice(-2) : "0"}`,
  194. });
  195. },
  196. // onPay
  197. async onPay() {
  198. const { query = {} } = this.$page.data;
  199. const { result } = this.data;
  200. try {
  201. my.showLoading();
  202. await this.grantSubscribe(); // 授权需要前置
  203. tradePay(
  204. {
  205. type: 1,
  206. idNum: query.orderId,
  207. depName: this.data.result.depName,
  208. amount: result.amount,
  209. orderId: query.orderId,
  210. },
  211. {
  212. tradeType: "Appointment",
  213. }
  214. ).then(() => {
  215. this.orderDetail(); // 支付成功之后发起消息订阅授权
  216. // this.subscribe.subscribeMessage();
  217. });
  218. } catch (error) {
  219. } finally {
  220. my.hideLoading();
  221. }
  222. /* 服务办结,挂号缴费 */
  223. reportApi("挂号缴费");
  224. },
  225. toBackHome() {
  226. const len = getCurrentPages().length;
  227. my.navigateBack({
  228. delta: len + 1,
  229. });
  230. },
  231. },
  232. });