index.js 5.4 KB

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