index.js 5.4 KB

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