123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- import { dynamicPageName, prefixPagePath } from "../../../../core/utils";
- import { orderDetail, cancelOrder } from "./service";
- import { cuttingDate } from "../../utils";
- import history from "../../utils/history";
- import { tradePay } from "../../utils/tradePay";
- import { reportApi } from "../../utils/cloudMonitorHelper";
- import { getSubscribeAuth } from "../../../../core/utils/ywtService";
- Component({
- props: {},
- data: {
- result: {
- id: "",
- // 就诊人id
- status: -1,
- // 预约状态 0-待支付 1-已支付(预约成功)2-排队中 7-已就诊 8-过期未就诊 9-已取消
- date: "",
- // 2022-09-20
- day: "",
- // 周一
- am: "",
- // 上午
- time: "", // 00:00
- },
- countown: "0",
- modalOpened: false,
- buttons: [
- {
- text: "不,先留着",
- },
- {
- text: "取消预约",
- extClass: "buttonBold",
- },
- ],
- viewItem: [
- {
- label: "就诊日期",
- key: "date",
- },
- {
- label: "就诊时间",
- key: "time",
- },
- {
- label: "就诊医院",
- key: "districtName",
- },
- {
- label: "就诊科室",
- key: "depName",
- },
- {
- label: "就诊人",
- key: "name",
- },
- {
- label: "预约医生",
- key: "doctor",
- },
- {
- label: "挂号费用",
- key: "price",
- },
- {
- label: "就诊卡",
- key: "card",
- },
- ],
- refund: [
- "https://gw.alipayobjects.com/mdn/rms_373ab8/afts/img/A*03IPSKd3OmkAAAAAAAAAAAAAARQnAQ",
- "https://gw.alipayobjects.com/mdn/rms_373ab8/afts/img/A*03IPSKd3OmkAAAAAAAAAAAAAARQnAQ",
- ],
- },
- didMount() {
- const { query } = this.$page.data;
- this.orderDetail();
- const { where } = query || {};
- if (where === "order-pay") {
- /* 服务办结,预约挂号 */
- reportApi("预约挂号");
- }
- },
- didUnmount() {
- if (this.timer) {
- clearTimeout(this.timer);
- }
- },
- methods: {
- saveRef(ref) {
- this.subscribe = ref;
- },
- orderDetail() {
- const {
- query = {
- orderId: "",
- },
- } = this.$page.data;
- const { where } = query;
- my.showLoading();
- orderDetail({
- orderId: query.orderId,
- }).then((data) => {
- this.setData({
- result: Object.assign(data, cuttingDate(data.startTime)),
- });
- const { status, expireTime = "", systemTime = "" } = this.data.result;
- if (status === 0) {
- console.log("未支付 ===>");
- // const now = new Date(systemTime.replace(/-/g, "/")).getTime();
- // const start = new Date(expireTime.replace(/-/g, "/")).getTime();
- // if (!this.timeEndFlag) {
- // this.doTimeout(start - now, () => {
- // this.orderDetail();
- // this.timeEndFlag = true;
- // });
- // }
- } else if (status === 1) {
- /* 如果是从下单页面过来的,拉起消息授权 */
- if (where === "order-pay") {
- this.grantSubscribe();
- }
- }
- my.hideLoading();
- });
- },
- // 打开取消预约弹出
- onCancel() {
- this.setData({
- modalOpened: true,
- });
- },
- // 确认取消预约
- async onButtonClick(e) {
- this.setData({
- modalOpened: false,
- });
- if (e.target.dataset.index === 1) {
- const {
- query = {
- orderId: "",
- },
- } = this.$page.data;
- await getSubscribeAuth();
- my.showLoading();
- cancelOrder({
- orderId: query.orderId,
- reason: "",
- }).then(() => {
- my.hideLoading();
- this.orderDetail();
- });
- }
- },
- // 再次预约
- reAppoint() {
- my.navigateTo({
- url: `${prefixPagePath}/${dynamicPageName}/index?pageCode=hospital-new-select-area`,
- });
- },
- toH5(e) {
- const { url } = e.target.dataset;
- history.toH5(url);
- },
- hrefTo() {
- my.ap.navigateToAlipayPage({
- path: "alipays://platformapi/startapp?appId=77700284&page=pages/medical/index?chInfo=YY_xiaochengxu",
- });
- },
- // 消息订阅授权
- async grantSubscribe() {
- // 获取智能消息推送授权
- await getSubscribeAuth();
- },
- // 发起倒计时
- doTimeout(val, cb = () => {}) {
- if (val > 0) {
- const timeout = 200;
- val -= timeout;
- this.timer = setTimeout(() => {
- this.doTimeout(val, cb);
- }, timeout);
- } else {
- val = 0;
- cb();
- }
- const second = Math.floor(val / 1000);
- const h = Math.floor(second / 3600);
- const m = Math.floor((second % 3600) / 60);
- const s = second % 60;
- this.setData({
- countown: `${h > 0 ? `${h}:` : ""}${
- h > 0 || m > 0 ? `${`0${m}`.slice(-2)}:` : ""
- }${h > 0 || m > 0 || s > 0 ? `0${s}`.slice(-2) : "0"}`,
- });
- },
- // onPay
- async onPay() {
- const { query = {} } = this.$page.data;
- const { result } = this.data;
- try {
- my.showLoading();
- await this.grantSubscribe(); // 授权需要前置
- tradePay(
- {
- type: 1,
- idNum: query.orderId,
- depName: this.data.result.depName,
- amount: result.amount,
- orderId: query.orderId,
- },
- {
- tradeType: "Appointment",
- }
- ).then(() => {
- this.orderDetail(); // 支付成功之后发起消息订阅授权
- // this.subscribe.subscribeMessage();
- });
- } catch (error) {
- } finally {
- my.hideLoading();
- }
- /* 服务办结,挂号缴费 */
- reportApi("挂号缴费");
- },
- toBackHome() {
- const len = getCurrentPages().length;
- my.navigateBack({
- delta: len + 1,
- });
- },
- },
- });
|