瀏覽代碼

修改问题

tangning 2 年之前
父節點
當前提交
fe610c9c09
共有 3 個文件被更改,包括 90 次插入31 次删除
  1. 1 2
      src/App.vue
  2. 9 0
      src/api/index.ts
  3. 80 29
      src/views/detail/payment.vue

+ 1 - 2
src/App.vue

@@ -6,7 +6,6 @@
   import { onMounted, computed } from 'vue';
   import { useUserStore } from '/@/store/modules/user';
   const userStore = useUserStore();
-  console.log('userStore', userStore);
   const wxOpenId = computed(() => {
     return userStore.getWxOpenId;
   });
@@ -35,7 +34,7 @@
     //获取code
     let urlNow = encodeURIComponent(window.location.href);
     let scope = 'snsapi_base'; //snsapi_userinfo   //静默授权 用户无感知
-    let appid = 'wxac3d59ea82d9b82a';
+    let appid = 'wx779dbafb46bab697';
     let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${urlNow}&response_type=code&scope=${scope}&state=${state}#wechat_redirect`;
     window.location.replace(url);
   }

+ 9 - 0
src/api/index.ts

@@ -136,6 +136,15 @@ export function wxLogin(code) {
     params: { code },
   });
 }
+
+// 申请开票
+export function wechatMobilePay(params) {
+  return request({
+    url: '/service/sale/order/pay/wechatPay',
+    method: 'post',
+    data:params,
+  });
+}
 export interface wxLoginRus {
   openid: string;
 }

+ 80 - 29
src/views/detail/payment.vue

@@ -3,7 +3,7 @@
     <div class="evaluate_top">
       <div class="cell">
         <span>维修费用</span>
-        <span class="colortext">¥{{detail.amount}}</span>
+        <span class="colortext">¥{{ detail.amount }}</span>
       </div>
       <div class="cell border">
         <span>单位</span>
@@ -17,36 +17,87 @@
 </template>
   
 <script lang="ts" setup name="detailPage">
-  import { ref, onMounted, unref } from 'vue';
-  import { useRouter } from 'vue-router';
-  import { repairDetails } from '/@/api';
-  const router = useRouter();
-  const { id } = unref(router.currentRoute)?.params;
-  const detail = ref({
-    // priceList: [],
-    amount: 0,
-  });
-  onMounted(async () => {
-    const { response } = await repairDetails(id);
-    let detaile = unref(response)?.data,amount = 0;
-    // detail.value.priceList = 
-    detaile.priceList.map(ele =>{
-      amount = amount + (ele.price * ele.count)
-      // return ele
-    })
-    detail.value.amount = amount
+import { ref, onMounted, unref, computed } from 'vue';
+import { useRouter } from 'vue-router';
+import { useUserStore } from '/@/store/modules/user';
+
+import { repairDetails, wechatMobilePay } from '/@/api';
+const router = useRouter();
+const userStore = useUserStore();
+const wxOpenId = computed(() => {
+  return userStore.getWxOpenId;
+});
+const { id } = unref(router.currentRoute)?.params;
+const detail = ref({
+  // priceList: [],
+  amount: 0,
+});
+onMounted(async () => {
+  const { response } = await repairDetails({id});
+  let detaile = unref(response)?.data,
+    amount = 0;
+  // detail.value.priceList =
+  detaile.priceList.map((ele) => {
+    amount = amount + ele.price * ele.count;
+    // return ele
   });
-  
-  function payOrder() {
-    //获取code
-    let urlNow = encodeURIComponent(window.location.href);
-    let scope = 'snsapi_base'; //snsapi_userinfo   //静默授权 用户无感知
-    let appid = 'wxac3d59ea82d9b82a';
-    let url = `https://open.weixin.qq.com/connect/oauth2/authorize?redirect_uri=${urlNow}&appid=${appid}&response_type=code&scope=${scope}&connect_redirect=1#wechat_redirect`;
-    window.location.replace(url);
-  }
-   // 判断是否在微信浏览器  1为微信浏览器 2为其他  这个方法定义在外面,后面也会用到
+  detail.value.amount = amount;
+});
 
+function payOrder() {
+  //获取code
+  let urlNow = encodeURIComponent(window.location.href);
+  let scope = 'snsapi_base'; //snsapi_userinfo   //静默授权 用户无感知
+  let appid = 'wxac3d59ea82d9b82a';
+  let url = `https://open.weixin.qq.com/connect/oauth2/authorize?redirect_uri=${urlNow}&appid=${appid}&response_type=code&scope=${scope}&connect_redirect=1#wechat_redirect`;
+  console.log('https://v4-uat.4dkankan.com/aftermarket/#/home', url);
+  if (typeof WeixinJSBridge == 'undefined') {
+    if (document.addEventListener) {
+      document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
+    } else if (document.attachEvent) {
+      document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
+      document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
+    }
+  } else {
+    onBridgeReady();
+  }
+  // window.location.replace(url);
+}
+async function onBridgeReady() {
+  const params = await wechatMobilePay({
+    openId:wxOpenId.value,
+    repairId:id,
+    wxPayType:'1',
+  });
+  console.log(params);
+  WeixinJSBridge.invoke(
+    'getBrandWCPayRequest',
+    {
+      appId: 'wx2421b1c4370ec43b', //公众号ID,由商户传入
+      timeStamp: '1395712654', //时间戳,自1970年以来的秒数
+      nonceStr: 'e61463f8efa94090b1f366cccfbbb444', //随机串
+      package: `prepay_id=${params.prepayId}`,
+      signType: 'RSA', //微信签名方式:
+      paySign:
+        'oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYD7rthRAZ/X+QBhcCYL21N7cHCTUxbQ+EAt6Uy+lwSN22f5YZvI45MLko8Pfso0jm46v5hqcVwrk6uddkGuT+Cdvu4WBqDzaDjnNa5UK3GfE1Wfl2gHxIIY5lLdUgWFts17D4WuolLLkiFZV+JSHMvH7eaLdT9N5GBovBwu5yYKUR7skR8Fu+LozcSqQixnlEZUfyE55feLOQTUYzLmR9pNtPbPsu6WVhbNHMS3Ss2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jq/xDg==', //微信签名
+    },
+    function (res) {
+      if (res.err_msg == 'get_brand_wcpay_request:ok') {
+        // 使用以上方式判断前端返回,微信团队郑重提示:
+        //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
+      }
+    },
+  );
+}
+function queryURLParams(url) {
+  let pattern = /(\w+)=(\w+)/gi; //定义正则表达式
+  let parames = {}; // 定义参数对象
+  url.replace(pattern, ($, $1, $2) => {
+    parames[$1] = $2;
+  });
+  return parames;
+}
+// 判断是否在微信浏览器  1为微信浏览器 2为其他  这个方法定义在外面,后面也会用到
 </script>
  <style lang="scss" >
 .evaluate {