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