<template>
	<view v-cloak>
		<u-button shape="circle" @click="submit" :disabled="disabled">立即支付</u-button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				disabled: false,
				sweixin: null,
			}
		},
		onShow() {
			if (this.disabled) {
				uni.switchTab({
					url: '/wuye/index/index'
				});
			}
		},
		onLoad(item) {
			// #ifdef APP-PLUS  
			plus.share.getServices((s) => {
				let shares = {};
				for (let i = 0; i < s.length; i++) {
					let t = s[i];
					shares[t.id] = t;
				}
				let sweixin = shares['weixin'];
				this.sweixin = sweixin
				console.log(this.sweixin)
			}, function(e) {
				console.log("获取分享服务列表失败:" + e.message);
			});
			//#endif
		},
		methods: {
			submit() {
				this.disabled = true
				this.$u.post(this.postUrl, '业务参数')
					.then(res => {
						if (res.code === 0) {
							var data=res.data;
								this.sweixin ? this.sweixin.launchMiniProgram({
										path: `pages/orderDetail/orderDetail?${res.data}`, //  可带参数
										type: 0, //可取值: 0-正式版; 1-测试版; 2-体验版。 默认值为0。
										id: '小程序的原始id' //小程序的原始id
									},
									res => {
										uni.switchTab({
											url: '/wuye/index/index'
										});
									},
									err => {
										if (err.code == -8) {
											uni.showToast({
												title: "未安装微信客户端",
												duration: 2000
											});
											setTimeout(() => {
												uni.switchTab({
													url: '/wuye/index/index'
												});
											}, 2000)
											return
										} else {
											uni.switchTab({
												url: '/wuye/index/index'
											});
										}
									}
								) : plus.nativeUI.alert('当前环境不支持微信操作!');
								return
						} else {
							this.$msg(res.msg)
						}
					})
			}
		},
	}
</script>

<style lang="scss" scoped>
</style>

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐