支付宝小程序总结

  1. 路由跳转 且传参
    A页面: const item = {
    userInfo: null,
    code: ‘’,
    openId: ‘’,
    userId: ‘’,
    userAccount: ‘’,
    planId: ‘’
    }
    const a = encodeURIComponent(JSON.stringify(item))
    my.navigateTo({
    url: /pages/my/my?item=${a}
    });

跳到B页面:
Page({
data: {
item: null
},
onLoad(option) {
if (option.item) {
this.setData({
item: JSON.parse(decodeURIComponent(option.item))
})
console.log(JSON.parse(decodeURIComponent(option.item)));
}
},
});

请求方法:
// 请求头配置
export const FlieHeader = {
‘Content-Type’: ‘application/x-www-form-urlencoded’
}
export const PostHeader = {
‘Content-Type’: ‘application/json’,
}

/**
*

  • 第一个参 为请求地址 url
  • 第二个参 为请求头 header
  • 第三个参 为请求传参 date
  • 第四个参 为请求主体 type
  • **/

const request = (url = ‘’, header = PostHeader, data = {}, type = ‘POST’) => {
return new Promise((resolve, reject) => {
// 展示加载loading
my.showLoading({
content: ‘加载中…’
})
// 发送请求
my.request({
// 请求类型
method: type,
// 请求地址
url: baseApi + url,
// 请求参数
data: data,
// 请求头配置
header: header,
// 数据格式
dataType: ‘json’,
}).then((response) => {
// 如果请求成功
// 关闭加载loading
setTimeout(function () {
my.hideLoading();
}, 0);
let [error, res] = response;
resolve(res.data);
}).catch(error => {
// 如果请求错误,关闭加载loading
setTimeout(function () {
my.hideLoading();
}, 0);
let [err, res] = error;
reject(err)
})
});
}
// 默认导出请求方法
export default request

使用:
import request from “/api”;

导航栏目:
我是手机状态栏
data: {
systemInfo: {} // 手机基础信息
},
onLoad(options) {
try {
// 获取手机基础信息(头状态栏和标题栏高度)
let systemInfo = my.getSystemInfoSync();
this.setData({ systemInfo });
} catch (e) {
console.log(e);
my.alert({
title: ‘温馨提示’,
content: ‘onLoad 执行异常’
});
}
},

ocr身份证识别:
在app.json 配置插件
“plugins”: {
“ocr-id”: {
“version”: “",
“provider”: "
************” // 此为小程序的appId
}
},
a. 首先在身份识别页面 配置一下文件
{
“usingComponents”: {
“ocr-id”: “plugin://ocr-id/ocr-id”
},
“defaultTitle”: “身份证识别”
}
2. 使用改插件


3. js逻辑
Page({
data: {
imageOutput: ‘roi’, //imageOutput参数为“global”或者“roi”
systemInfo: {} // 手机基础信息
},
onLoad(query) {
console.info(Page onLoad with query: ${JSON.stringify(query)});
const { type } = query;
this.setData({ type });
},
onCompleteOcr(data) {
const a = encodeURIComponent(JSON.stringify(data.result))
my.reLaunch({
url: /pages/transparent/index?result=${a}
});
},
});

4. 回显页面
data: {
item: {}
},
onLoad(option) {
if (option.result) {
const arr = JSON.parse(decodeURIComponent(option.result))
this.setData({
item: arr[0].body[0]
})
}
},
dianji() {
my.navigateTo({url: ‘/pages/my/my’})
},

for循环:


{{idx}}: {{itemName.message}}

.red {
background-color: red;
}
data: {
array: [{
message: ‘foo’,
idx: 1
}, {
message: ‘bar’,
idx: 2
}],
current: ‘’
},
onLoad() {},
dian(e) {
const { value } = e.target.dataset;
this.setData({
current: value
})
}

async getInfo(id) {
const requestPayload = {
userId: id.userId
}
const retult = await request(
“/api/patient/getPatientsByUserId”,
FlieHeader,
requestPayload,
“GET”
);
if (retult.code !== 200) return
if (retult.data) {
this.setData({
people: retult.data
})
}
},

// // 没有跳转到建档
// my.navigateTo({
// url: “/pages/toRecord/toRecord”
// });

  if (!retult.data.patient.patientId) {
    my.navigateTo({
      url: "/pages/toRecord/toRecord"
    });
    return false
  }

  // {
  //   "pagePath": "pages/index/index",
  //   "name": "电子社保卡",
  //   "icon": "/assets/tabr/dian.png",
  //   "activeIcon": "/assets/tabr/dian-active.png"
  // },

async getInfo() {
// 获取就诊人
let res = my.getStorageSync({
key: “userInfo”
});
const requestPayload = {
userId: res.data.userId
}
const retult = await request(
“/api/patient/getPatientsByUserId”,
FlieHeader,
requestPayload,
“GET”
);
if (retult.code !== 200) return
if (retult.data) {
if (!retult.data.patient.patientId) {
my.navigateTo({
url: “/pages/toRecord/toRecord”
});
return false
}
let arr = []
if (Array.isArray(retult.data.otherPatients)) {
arr.push(retult.data.patient)
arr = […arr, …retult.data.otherPatients]
arr.forEach((element, i) => {
element.index = i
});
this.setData({
people: arr,
peos: arr[0]
})
}
}
},
// 点击打开弹出层
changeMan() {
// 清空数据
this.setData({
isHoriShow: true,
peos1: {}
});
},
// 确认切换就诊人
handleButtonTap(index) {
if (index === 1) {
if (Object.keys(this.data.peos1).length !== 0) {
this.setData({
peos: this.data.peos1
});
}
} else {
if (this.data.current2) {
this.setData({
current1: this.data.current2
});
}
}
this.setData({
peos1: {},
isHoriShow: false
});
},
// 切换就诊人
qieMen(e) {
// 先保存上一次数据
this.setData({
current2: this.data.current1
})
const {
value
} = e.target.dataset;
this.setData({
current1: value.index,
peos1: value
})
},

// onPullDownRefresh() {
// console.log(“onPullDownRefresh”, new Date());
// setTimeout(() => {
// my.stopPullDownRefresh();
// }, 1000);
// },
// // 上拉触底
// onReachBottom() {
// if (this.data.list.length > 50) {
// this.setData({
// status: “nomore”
// });
// return false;
// }
// const list = [
// {
// isOk: false,
// name: “张艺二1”,
// time: “11月24日 上午”,
// pay: “¥0.00(医事服务费)”,
// subTime: “11月24日 9:00”
// },
// {
// isOk: false,
// name: “张艺二1”,
// time: “11月24日 上午”,
// pay: “¥0.00(医事服务费)”,
// subTime: “11月24日 9:00”
// },
// {
// isOk: false,
// name: “张艺二1”,
// time: “11月24日 上午”,
// pay: “¥0.00(医事服务费)”,
// subTime: “11月24日 9:00”
// }
// ];
// setTimeout(() => {
// this.setData({
// list: […this.data.list, …list]
// });
// }, 1000);
// this.setData({
// status: “loading”
// });
// // my.pageScrollTo({ scrollTop: 100 }); // 加入这个方法
// },

  <text a:if="{{ item.status == -1 }}" style="color: red">锁号失败</text>
  <text a:if="{{ item.status == 0 }}" style="color: #69C0FF">锁号成功</text>
  <text a:if="{{ item.status == 1 }}" style="color: #69C0FF">挂号成功</text>
  <text a:if="{{ item.status == 2 }}" style="color: red">挂号失败</text>

async close(e) {
const {
value
} = e.target.dataset;
my.getAuthCode({
scopes: [“mfrstre”, “hospital_order”], //获取用户信息的固定写法
success: async res => {
if (res.authCode) {
//发送请求
const requestPayload = {
authCode: res.authCode
};
const retult = await request(
“/api/login/getAccessToken”,
FlieHeader,
requestPayload,
“post”
);
if (retult.code !== 200) return;
this.getss(retult.data.accessToken,value.id)
}
},
complete: res => {
if (res.errorMessage == ‘用户取消授权’) {
}
}
});
},
async getss(token, id) {
console.log(token, id);
let res = my.getStorageSync({
key: “userInfo”
});
const requestPayload1 = {
accessToken: token,
appointId: id,
userId: res.data.userId
};
await request(
“/api/message/cancelSend”,
FlieHeader,
requestPayload1,
“post”
);
this.getList(0)
},

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值