Просмотр исходного кода

fix: 修复wx.chooseInvoiceTitle抬头类型映射反了(type='0'为企业),增加授权拒绝引导

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 1 день назад
Родитель
Сommit
c48bf25642

+ 14 - 3
charge-front/src/pages-common/invoice/invoice-form.vue

@@ -162,7 +162,7 @@ const importWechatTitle = () => {
   // #ifdef MP-WEIXIN
   wx.chooseInvoiceTitle({
     success: (res: any) => {
-      form.invoiceType = res.type === '1' ? 'ORGANIZATION' : 'INDIVIDUAL';
+      form.invoiceType = res.type === '0' ? 'ORGANIZATION' : 'INDIVIDUAL';
       form.invoiceTitle = res.title || '';
       form.taxId = res.taxNumber || '';
       form.address = res.companyAddress || '';
@@ -171,9 +171,20 @@ const importWechatTitle = () => {
       form.bankAccount = res.bankAccount || '';
     },
     fail: (err: any) => {
-      if (err && err.errMsg && !/cancel/.test(err.errMsg)) {
-        uni.showToast({ title: "同步失败,请重试", icon: "none" });
+      const msg = err && err.errMsg ? err.errMsg : '';
+      if (/cancel/.test(msg)) return;
+      if (/auth deny/.test(msg)) {
+        uni.showModal({
+          title: "需要授权",
+          content: "请在设置中开启「发票抬头」权限",
+          confirmText: "去设置",
+          success: (res: any) => {
+            if (res.confirm) wx.openSetting({});
+          }
+        });
+        return;
       }
+      uni.showToast({ title: "同步失败,请重试", icon: "none" });
     }
   });
   // #endif

+ 14 - 3
charge-front/src/pages-user/invoice-title.vue

@@ -216,7 +216,7 @@ const importWechatTitle = () => {
   // #ifdef MP-WEIXIN
   wx.chooseInvoiceTitle({
     success: (res: any) => {
-      editForm.invoiceType = res.type === '1' ? 'ORGANIZATION' : 'INDIVIDUAL';
+      editForm.invoiceType = res.type === '0' ? 'ORGANIZATION' : 'INDIVIDUAL';
       editForm.invoiceTitle = res.title || '';
       editForm.taxId = res.taxNumber || '';
       editForm.address = res.companyAddress || '';
@@ -225,9 +225,20 @@ const importWechatTitle = () => {
       editForm.bankAccount = res.bankAccount || '';
     },
     fail: (err: any) => {
-      if (err && err.errMsg && !/cancel/.test(err.errMsg)) {
-        uni.showToast({ title: "同步失败,请重试", icon: "none" });
+      const msg = err && err.errMsg ? err.errMsg : '';
+      if (/cancel/.test(msg)) return;
+      if (/auth deny/.test(msg)) {
+        uni.showModal({
+          title: "需要授权",
+          content: "请在设置中开启「发票抬头」权限",
+          confirmText: "去设置",
+          success: (res: any) => {
+            if (res.confirm) wx.openSetting({});
+          }
+        });
+        return;
       }
+      uni.showToast({ title: "同步失败,请重试", icon: "none" });
     }
   });
   // #endif