|
|
@@ -26,7 +26,7 @@
|
|
|
<uv-radio-group v-model="payType" placement="column" iconPlacement="right" shape="square" size="24"
|
|
|
iconSize="18">
|
|
|
<uv-radio :name="payType">
|
|
|
- <view class="flex items-center" slot="label">
|
|
|
+ <view class="flex items-center">
|
|
|
<image class="channel-icon" mode="widthFix" src="@/static/image/wechat-pay.png" />
|
|
|
<text>微信支付</text>
|
|
|
</view>
|
|
|
@@ -37,18 +37,56 @@
|
|
|
<ie-button type="primary" :loading="loading" @click="handlePay">{{ `确认支付 ¥${formatPrice}` }}</ie-button>
|
|
|
</view>
|
|
|
</view>
|
|
|
+ <ie-popup ref="popupRef" mode="center">
|
|
|
+ <view class="w-[70vw] px-50 pt-50 pb-80">
|
|
|
+ <view class="text-center text-30 text-fore-title font-bold mb-50">请先绑定微信</view>
|
|
|
+ <uv-button type="primary" icon-color="white" @click="handleBindWechat" icon-size="24"
|
|
|
+ icon="weixin-fill">点击绑定微信</uv-button>
|
|
|
+ </view>
|
|
|
+ </ie-popup>
|
|
|
</ie-page>
|
|
|
</template>
|
|
|
<script lang="ts" setup>
|
|
|
import { usePay } from '@/hooks/usePay';
|
|
|
import { useUserStore } from '@/store/userStore';
|
|
|
+import { bindOpenId } from '@/api/modules/login';
|
|
|
|
|
|
const userStore = useUserStore();
|
|
|
const { ready, formatPrice, pay, setCallback, loading } = usePay();
|
|
|
const isIOS = ref(false);
|
|
|
const payType = ref('wechat');
|
|
|
|
|
|
+
|
|
|
+async function getWxCode() {
|
|
|
+ const { code, errMsg } = await uni.login();
|
|
|
+ if (errMsg === 'login:ok' && code) {
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+}
|
|
|
+
|
|
|
+const popupRef = ref();
|
|
|
+const handleBindWechat = async (e: any) => {
|
|
|
+ uni.$ie.showLoading();
|
|
|
+ const code = await getWxCode();
|
|
|
+ if (code) {
|
|
|
+ bindOpenId(code).then(async res => {
|
|
|
+ popupRef.value?.close();
|
|
|
+ await userStore.getUserInfo();
|
|
|
+ uni.$ie.hideLoading();
|
|
|
+ handlePay();
|
|
|
+ }).catch(err => {
|
|
|
+ console.error(err);
|
|
|
+ uni.$ie.hideLoading();
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
const handlePay = () => {
|
|
|
+ if (!userStore.isBindWechat) {
|
|
|
+ popupRef.value?.open();
|
|
|
+ return;
|
|
|
+ }
|
|
|
loading.value = true
|
|
|
setCallback({
|
|
|
onSuccess: () => {
|