Przeglądaj źródła

Merge branch 'feature/预支付流程开发' into develop

Zhenghanjv 2 miesięcy temu
rodzic
commit
2fa9e25f4c

+ 13 - 2
app.json

@@ -12,8 +12,11 @@
     "components/orderItem/orderItem",
     "components/orderInfo/orderInfo",
     "components/orderItemInfo/orderItemInfo",
+    "components/prepayOrderItemInfo/prepayOrderItemInfo",
     "components/pay/pay",
-    "pages/payResult/payResult"
+    "pages/payStatus/payStatus",
+    "pages/payResult/payResult",
+    "pages/AuthorizationTransactionPage/AuthorizationTransactionPage"
   ],
   "window": {
     "navigationBarTextStyle": "black",
@@ -23,5 +26,13 @@
   "style": "v2",
   "componentFramework": "glass-easel",
   "sitemapLocation": "sitemap.json",
-  "lazyCodeLoading": "requiredComponents"
+  "lazyCodeLoading": "requiredComponents",
+  "permission": {
+    "scope.userLocation": {
+      "desc": "你的位置信息将用于判断当前下单操作是否合法"
+    }
+  },
+  "requiredPrivateInfos": [
+    "getLocation"
+  ]
 }

+ 75 - 0
components/prepayOrderItemInfo/prepayOrderItemInfo.js

@@ -0,0 +1,75 @@
+// components/orderItemInfo/orderItemInfo.js
+Component({
+
+  /**
+   * 组件的属性列表
+   */
+  properties: {
+    order:{
+      type:Object,
+      value:{
+        nozzle:5,
+        status:'已授权',
+        statusColor:'#a6d53f',
+        oilName:'92#汽油',
+        volume:30,
+        amount:224.7,
+        payAmount:209.4,
+        discount:15.3,
+        refund:0,
+        orderId:'20251111111111',
+        time:'2025-01-20 18:33'
+      }
+    },
+    buttonText1:{
+      type:String,
+      value:"按钮一"
+    },
+    buttonText2:{
+      type:String,
+      value:"按钮二"
+    }
+  },
+
+  /**
+   * 组件的初始数据
+   */
+  data: {
+    contentHeight: 21,
+    isHide:false,
+    rotateDeg:0
+  },
+
+  /**
+   * 组件的方法列表
+   */
+  methods: {
+    
+    showOrHide(){
+      
+      const height = this.data.isHide?21:38;
+      console.log("点击了",this.data.isHide,height)
+      
+      this.setData({
+        contentHeight:height,
+        isHide:!this.data.isHide,
+        rotateDeg:this.data.rotateDeg+180
+      })
+    },
+
+    //第一个按钮的点击事件
+    buttonClick1(){
+      this.triggerEvent('bottonEvent1',{
+        order:this.properties.order,
+        event:this.properties.buttonText1
+      })
+    },
+    //第二个按钮的点击事件
+    buttonClick2(){
+      this.triggerEvent('bottonEvent2',{
+        order:this.properties.order,
+        event:this.properties.buttonText2
+      })
+    },
+  }
+})

+ 5 - 0
components/prepayOrderItemInfo/prepayOrderItemInfo.json

@@ -0,0 +1,5 @@
+{
+  "component": true,
+  "usingComponents": {},
+  "navigationBarTitleText": ""
+}

+ 77 - 0
components/prepayOrderItemInfo/prepayOrderItemInfo.wxml

@@ -0,0 +1,77 @@
+<view class="orderItemInfoContainer">
+  <!-- 订单信息 -->
+  <view class="orderInfoBox">
+    <!-- 油枪 -->
+    <view class="nozzleAndStatus">
+      <text class="nozzle">{{order.nozzle}} 号油枪</text>
+      <text class="status" style="color: {{order.statusColor}};">{{order.status}}</text>
+    </view>
+
+
+    <view class="orderInfo" style="height: {{contentHeight}}vh;" bind:tap="showOrHide">
+      <!-- 订单主要信息 -->
+      <view class="mainInfo">
+        <image src="../../images/oil.svg" mode="aspectFill" />
+        <view class="oilInfo">
+          <text class="oil">{{order.oilName}}</text>
+          <text class="volume">{{order.volume}}升数</text>
+        </view>
+        <view class="amountBox">
+          <text class="mainAmount">¥ {{order.payAmount}}</text>
+          <image src="../../images/down.png" mode="aspectFill" style="transform: rotate({{rotateDeg}}deg);" />
+        </view>
+      </view>
+
+      <!-- 分割线 -->
+      <view class="line"></view>
+
+      <!-- 其余信息 -->
+      <view class="orderDetailInfo">
+        <view>
+          <text>交易订单号</text>
+          <text>{{order.orderId}}</text>
+        </view>
+        <view>
+          <text>时间</text>
+          <text>{{order.time}}</text>
+        </view>
+      </view>
+
+      <!-- 分割线 -->
+      <view class="line"></view>
+
+      <!-- 详情信息 -->
+      <view class="orderDetailInfo">
+        <view>
+          <text>预支付金额</text>
+          <text>¥ {{order.payAmount}}</text>
+        </view>
+        <view>
+          <text>退款金额</text>
+          <text>-{{order.refund}}</text>
+        </view>
+        <view>
+          <text>优惠金额</text>
+          <text>¥ {{order.discount}}</text>
+        </view>
+        <view>
+          <text>实付金额</text>
+          <text>¥ {{order.amount}}</text>
+        </view>
+      </view>
+    </view>
+  </view>
+
+  <view class="buttonBox">
+    
+    <text wx:if="{{buttonText1 == '' && buttonText2 != ''}}" class="button1All" bind:tap="buttonClick2">{{buttonText2}}</text>
+
+    <text wx:if="{{buttonText1 != '' && buttonText2 != ''}}" class="button1" bind:tap="buttonClick1">{{buttonText1}}</text>
+
+    <text wx:if="{{buttonText1 != '' && buttonText2 != ''}}" class="button2" bind:tap="buttonClick2">{{buttonText2}}</text>
+  </view>
+  
+
+  
+
+</view>

+ 147 - 0
components/prepayOrderItemInfo/prepayOrderItemInfo.wxss

@@ -0,0 +1,147 @@
+.orderItemInfoContainer{
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  justify-content: center;
+  width: 100%;
+  border-radius: 15rpx;
+  background-color: #FFFFFF;
+  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
+}
+
+.orderInfoBox{
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  width: 90%;
+}
+.nozzleAndStatus{
+  display: flex;
+  justify-content: center;
+  width: 100%;
+}
+.nozzle{
+  font-weight: 600;
+  margin-top: 3%;
+}
+.status{
+  position: absolute;
+  font-weight: 600;
+  margin-left: 70%;
+  margin-top: 3%;
+}
+
+.orderInfo{
+  width: 100%;
+  overflow: hidden;
+  transition: height 0.3s ease-in-out; /* 添加过渡效果 */
+}
+
+.mainInfo{
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+  width: 100%;
+}
+
+.mainInfo image{
+  width: 150rpx;
+  height: 150rpx;
+  flex-grow: 1;
+}
+
+.oilInfo{
+  display: flex;
+  flex-direction: column;
+  flex-grow: 3;
+}
+.oil{
+  color: #d92610;
+  font-size: large;
+  font-weight: 550;
+  margin-bottom: 3%;
+}
+.volume{
+  color: #878787;
+  font-size: small;
+}
+
+.amountBox{
+  display: flex;
+  flex-direction: column;
+  align-items: flex-end;
+  flex-grow: 3;
+}
+.mainAmount{
+  font-size: larger;
+  font-weight: 600;
+  margin-bottom: 3%;
+}
+
+.amountBox image {
+  width: 40rpx;
+  height: 40rpx;
+  margin-top: 3%;
+  transition: transform 0.3s ease-in-out;
+}
+
+.line{
+  background-color: #e5e5e5;
+  height: 1rpx;
+  width: 105%;
+  margin: 3% 0%;
+}
+
+.orderDetailInfo{
+  display: flex;
+  flex-direction: column;
+  width: 100%;
+  margin-bottom: 3%;
+}
+.orderDetailInfo view{
+  display: flex;
+  justify-content: space-between;
+}
+.orderDetailInfo text{
+  color: #838383;
+  font-size: small;
+  margin: 1% 0%;
+}
+
+.buttonBox{
+  width: 100%;
+  height: 8vh;
+  display: flex;
+  align-items: center;
+  justify-content: space-around;
+  border-radius: 0 0 15rpx 15rpx ;
+}
+.button1All{
+  width: 100%;
+  height: 100%;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  background-color: #d81e07;
+  border-radius: 0 0 15rpx 15rpx ;
+  color: #FFFFFF;
+}
+.button1{
+  width: 38%;
+  height: 75%;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  border: #b2b2b2 solid 5rpx;
+  border-radius: 15rpx ;
+}
+.button2{
+  width: 38%;
+  height: 75%;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  background-color: #d81e07;
+  border-radius: 15rpx ;
+  color: #FFFFFF;
+}

+ 10 - 3
js/api.js

@@ -3,7 +3,8 @@ const SM4Exten = require('../js/SM4Exten');
 const miniprogramsm4 = require("../miniprogram_npm/miniprogram-sm-crypto/index").sm4;
 const secretId = "D2BCF8DE-AA24-4BF6-9C34-C8DD325E412B"; //小程序应用ID
 const Secret = "6C680A47B87740138DFB299FC69A64E1"; //小程序应用密钥
-const api_root = 'http://47.97.120.160:5006/'
+const api_root = 'http://47.97.120.160:5007/'
+// const api_root = 'http://172.31.2.202:5006/'
 // const api_root = 'http://192.168.0.202:5006/'
 const CurrentBuId = '12345678-9abc-def0-1234-56789abcdef0';
 
@@ -209,13 +210,18 @@ function request_RefundTrx(data) {
 
 //根据油枪id获取油枪信息
 function request_GetNozzleInfo(data) {
-  return request('api/Nozzle/GetFuelNozzleInfoById', 'GET', data)
+  return request('api/Nozzle/GetFuelNozzleInfoById?nozzleid='+data, 'GET', data)
 }
 
 //发送消息模板
 function request_sendMessage(data) {
   return request('api/Transactions/SendMessage','POST',data)
 }
+
+//创建订单
+function request_createOrder(data) {
+  return request('api/Transactions/CreateTransactions','POST',data)
+}
 export default {
   request_GetSiteInfo,
   request_wechatPay,
@@ -229,5 +235,6 @@ export default {
   request_RefundTrx,
   request_GetNozzleInfo,
   request_WXFindOrders,
-  request_sendMessage
+  request_sendMessage,
+  request_createOrder
 }

+ 1 - 0
package.json

@@ -1,5 +1,6 @@
 {
   "dependencies": {
+    "lottie-miniprogram": "^1.0.12",
     "miniprogram-sm-crypto": "^0.3.13",
     "sm-crypto": "^0.3.13"
   }

+ 183 - 0
pages/AuthorizationTransactionPage/AuthorizationTransactionPage.js

@@ -0,0 +1,183 @@
+const {
+  default: api
+} = require("../../js/api");
+const util = require('../../utils/util.js')
+
+// pages/orderConfirm/orderConfirm.js
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    nozzleId: 0,
+    type: '预支付',
+    order: null,
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad(options) {
+    this.setData({
+      nozzleId:options.nozzleId
+    })
+    const that = this;
+    const eventChannel = this.getOpenerEventChannel();
+    eventChannel.on('acceptDataFromQuantify', function (data) {
+      console.log("获取到下单页的订单",data)
+      that.setData({
+        order:data
+      })
+    });
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload() {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh() {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom() {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage() {
+
+  },
+
+  /** 支付按钮点击事件 */
+  toPay() {
+    var that = this;
+    api.request_wechatPay(this.data.order.orderId).then(res => {
+      console.log("支付结果", res)
+      that.subMessage()
+      // this.pay()
+    }).catch(err => {
+      console.log("支付失败", err)
+    })
+  },
+  /** 订阅消息模板 */
+  subMessage() {
+    const that = this;
+    wx.requestSubscribeMessage({
+      tmplIds: ['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'], // 最多支持3条
+      success(res) {
+        that.pay()
+        // 'accept'表示用户同意订阅该条id对应的模板消息
+        if (res['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'] === 'accept') {
+          // 用户同意订阅,调用云函数或服务器接口发送订阅消息
+          // wx.cloud.callFunction({
+          //   name: 'sendSubscribeMessage',
+          //   data: {
+          //     templateId: '配置好的模板ID',
+          //     openid: 'o8pFb5cWH1KkBDvGls2X7yMiFkGA',
+          //     data: {
+          //       thing1: {
+          //         value: '活动名称'
+          //       },
+          //       // 其他参数...
+          //     }
+          //   },
+          //   success(res) {
+          //     console.log('订阅消息发送成功', res)
+          //   },
+          //   fail(err) {
+          //     console.error('订阅消息发送失败', err)
+          //   }
+          // })
+
+        }
+      },
+      fail(err) {
+        that.pay()
+      }
+    })
+
+
+  },
+  pay() {
+    const that = this;
+    api.request_wechatPay(this.data.order.orderId)
+      .then(res => {
+        wx.requestPayment({
+          timeStamp: res.data.data.unifiedOrderResult.timeStamp,
+          nonceStr: res.data.data.unifiedOrderResult.nonceStr,
+          package: res.data.data.unifiedOrderResult.package,
+          signType: res.data.data.unifiedOrderResult.signType,
+          paySign: res.data.data.unifiedOrderResult.paySign,
+          success: res => {
+            wx.hideLoading()
+            that.sendMessage()
+            that.toPayResult(1)
+
+          },
+          fail: res => {
+            wx.hideLoading()
+            that.toPayResult(2)
+          }
+        })
+      });
+  },
+
+  /** 发送消息模板 */
+  sendMessage() {
+    const message = {
+      trxid: this.data.order.orderId,
+      orderType: '支付'
+    }
+    api.request_sendMessage(message).then(res => {
+      console.log("发送消息模板结果", res)
+    }).catch(err => {
+      console.log("发送消息模板失败", err)
+    })
+  },
+
+  /** 跳到支付结果页面 */
+  toPayResult(type){
+    const that = this;
+    setTimeout(() => {
+      wx.navigateTo({
+        url: '../payStatus/payStatus?id='+type+'&nozzleId='+that.data.nozzleId,
+        success:function(res){
+          res.eventChannel.emit('acceptDataFromAuthorization',that.data.order)
+        }
+      })
+    },500)
+  }
+})

+ 7 - 0
pages/AuthorizationTransactionPage/AuthorizationTransactionPage.json

@@ -0,0 +1,7 @@
+{
+  "usingComponents": {
+    "orderInfo":"../../components/orderItemInfo/orderItemInfo",
+    "pay":"../../components/pay/pay"
+  },
+  "navigationBarTitleText": "确认支付"
+}

+ 7 - 0
pages/AuthorizationTransactionPage/AuthorizationTransactionPage.wxml

@@ -0,0 +1,7 @@
+<view class="orderConfirmContainer">
+  <!-- 订单 -->
+  <orderInfo wx:if="{{order != null}}" class="orderInfo" order="{{order}}" bottonText2="{{oprationBtn2}}" bind:bottonEvent2="toMordOrderPage" />
+  
+  <!-- 支付按钮 -->
+  <pay class="payButton" amount="{{order.amount}}" bind:onPay="toPay" />
+</view>

+ 39 - 0
pages/AuthorizationTransactionPage/AuthorizationTransactionPage.wxss

@@ -0,0 +1,39 @@
+.orderConfirmContainer{
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  width: 100%;
+  height: 95vh;
+  background-color: #f2f2f2;
+}
+.tip{
+  display: flex;
+  align-self: flex-start;
+  margin: 3%;
+  width: 100%;
+}
+.tip text{
+  color: #fbac15;
+  margin-left: 3%;
+}
+
+.orderInfo{
+  width: 90%;
+  display: flex;
+  justify-content: center;
+}
+
+.moreOrderTip{
+  color: #d81e07;
+  margin-top: 5%;
+  font-weight: 600;
+}
+
+.anthorizationTip{
+  color: #9f9cb7;
+  margin: 3%;
+}
+.payButton{
+  width: 95%;
+  margin-top: auto;
+}

+ 0 - 5
pages/TransactionPage/TransactionPage.wxml

@@ -1,9 +1,4 @@
 <view class="orderConfirmContainer">
-  <!-- 提示 -->
-  <view class="tip">
-    <icon color="#fbac15" type="warn"/>
-    <text>请勿在油机旁使用手机</text>
-  </view>
 
   <!-- 订单 -->
   <orderInfo wx:if="{{order != null}}" class="orderInfo" order="{{order}}" bottonText2="{{oprationBtn2}}" bind:bottonEvent2="toMordOrderPage" />

+ 153 - 46
pages/historyOrder/historyOrder.js

@@ -17,60 +17,57 @@ Page({
     pageSize:5,//页数
     isHaveOrder:true,//是否还有订单
     paymentMode: -1,
-    /** 根据当前模式(后支付:0或预支付:1)+ 授权状态(未授权:0;已授权:1)
-     * + 订单状态(0:未支付; 1:已支付; 2:订单全额退款;3:订单部分退款;5:已完成)
-     * 获取订单状态及颜色 */
-    statusValue: [{
-        paymentMode: "0",
-        authorizationStatus: 0,
+    /** 后支付订单状态  订单状态(0:未支付; 1:已支付; 2:订单全额退款;3:订单部分退款;5:已完成)*/
+    payStatusValue: [{
         orderStatus: 0,
         status: '未支付',
         statusColor: '#ff8d1a'
       },
       {
-        paymentMode: "0",
-        authorizationStatus: 0,
         orderStatus: 1,
         status: '已完成',
         statusColor: '#a6a6a6'
       },
       {
-        paymentMode: "0",
-        authorizationStatus: 0,
         orderStatus: 5,
         status: '已完成',
         statusColor: '#a6a6a6'
+      }
+    ],
+    /** 预支付订单状态 授权状态(未授权:0;已授权:1)
+     * + 订单状态(0:未支付; 1:已支付; 2:订单全额退款;3:订单部分退款;5:已完成) */
+    prepayStatuValue:[
+      {
+        authorizationStatus: 0,
+        orderStatus: 0,
+        status: '支付失败',
+        statusColor: '#f1912f'
       },
       {
-        paymentMode: "1",
         authorizationStatus: 0,
         orderStatus: 1,
-        status: '已失效',
-        statusColor: '#a6a6a6'
+        status: '授权失败',
+        statusColor: '#f0d02e'
       },
       {
-        paymentMode: "1",
         authorizationStatus: 1,
         orderStatus: 1,
-        status: '授权',
-        statusColor: '#b1db5a'
+        status: '授权成功',
+        statusColor: '#a2cd4a'
       },
       {
-        paymentMode: "1",
         authorizationStatus: 0,
         orderStatus: 2,
         status: '已完成',
         statusColor: '#a6a6a6'
       },
       {
-        paymentMode: "1",
         authorizationStatus: 0,
         orderStatus: 3,
         status: '已完成',
         statusColor: '#a6a6a6'
       },
       {
-        paymentMode: "1",
         authorizationStatus: 0,
         orderStatus: 5,
         status: '已完成',
@@ -146,7 +143,7 @@ Page({
     const today = this.getNowDate();
     const lastMouthDay = this.getLastMouthDate();
     this.setData({
-      date: today,
+      // date: today,
       paymentMode: options.paymentMode,
       startDate: today,
       endDate: lastMouthDay
@@ -190,7 +187,7 @@ Page({
    * 页面相关事件处理函数--监听用户下拉动作
    */
   onPullDownRefresh() {
-
+    this.refreshOrder()
   },
 
   /**
@@ -225,11 +222,62 @@ Page({
   /** 组件按钮一点击事件 */
   onOrderButtonClick1(event) {
     console.log(event)
+    const order = event.detail.order;
+    const message = event.detail.event;
+    if(message == "退款") {
+      wx.showLoading({
+        title: '正在退款',
+      })
+      api.request_RefundTrx({"trxId":order.orderId}).then(res =>{
+        console.log("退款",res)
+        wx.hideLoading()
+        if(res.data.statusCode == 200) {
+          return util.subAndsendMessage(order.orderId,"退款")
+        } else {
+          wx.showToast({
+            title: res.data.message,
+          })
+        }
+      }).then(res => {
+        this.refreshOrder();
+      })
+      .catch(err => {
+        console.log("退款失败",err)
+        wx.hideLoading()
+      })
+    }
   },
 
   /** 组件按钮二点击事件 */
   onOrderButtonClick2(event) {
     console.log(event)
+    if(event.detail.event == "重新授权") {
+      this.toAuthorization(event.detail.order.orderId)
+    }
+  },
+
+  /** 授权 */
+  toAuthorization(orderId) {
+    const that = this;
+    wx.showLoading({
+      title: '授权中',
+    })
+    api.request_NozzleAuthorization(orderId).then(res => {
+      console.log("授权",res)
+      wx.hideLoading()
+      if(res.data.statusCode == 200) {
+        that.refreshOrder()
+      } else {
+        wx.showToast({
+          title: '授权失败',
+        })
+      }
+    }).catch(err => {
+      console.log("授权报错",err)
+      wx.showToast({
+        title: '授权失败',
+      })
+    })
   },
 
   /** 获取订单 */
@@ -238,28 +286,57 @@ Page({
     api.request_WXFindOrders(this.data.date, this.data.pageNum, this.data.pageSize).then(res => {
       // api.request_WXFindOrders(this.data.date, 3, 5).then(res => {
       console.log("获取历史订单", res)
-      const datas = res.data.data;
+      let datas = res.data.data;
       if(datas.length <= 0) {
         that.data.isHaveOrder = false;
         return
       }
-      var getOrders = datas.map(order => {
-        var times = [order.authorizationTime, order.createTime, order.fuelItemTransactionEndTime, order.transactionTime];
-        var timeFormate = times.find(t => t != undefined && t != null && t != '');
-        var time = util.formatDateNotSecond(timeFormate);
-        var volume = (order.originalQty != null && order.originalQty != undefined) ? order.originalQty : order.qty
-        var status = that.data.statusValue.find(state =>
-          state.paymentMode == this.data.paymentMode &&
+      var getOrders = that.turnOnOrder(datas)
+
+      var orderList = [...this.data.orders,...getOrders]
+      this.setData({
+        orders: orderList
+      })
+
+      console.log("转换后的订单", this.data.orders)
+    }).catch(err => {
+      console.log("获取历史订单失败", err)
+    })
+  },
+
+  /** 打包订单信息 */
+  turnOnOrder(orders){
+    const that = this;
+    var getOrders = orders.map(order => {
+      //获取订单时间
+      var times = [order.authorizationTime, order.createTime, order.fuelItemTransactionEndTime, order.transactionTime];
+      var timeFormate = times.find(t => t != undefined && t != null && t != '');
+      var time = util.formatDateNotSecond(timeFormate);
+
+      //获取订单升数
+      var volume = (order.originalQty != null && order.originalQty != undefined) ? order.originalQty : order.qty
+
+      //获取订单状态
+      var status = undefined;
+      //根据不同的模式获取订单状态值
+      if(that.data.paymentMode == 0) {
+        status = that.data.payStatusValue.find(state => state.orderStatus == order.orderStatus)
+      } else {
+        status = that.data.prepayStatuValue.find(state =>
           state.authorizationStatus == order.authorizationStatus &&
           state.orderStatus == order.orderStatus
         )
-        var stute = '';
-        var stateColor = '';
-        var bt2 = ''
-        if (status != undefined) {
-          stute = status.status
-          stateColor = status.statusColor
-        }
+      }
+      
+      var stute = '';
+      var stateColor = '';
+      var bt1 = ''
+      var bt2 = ''
+      if (status != undefined) {
+        stute = status.status
+        stateColor = status.statusColor
+      }
+      if(that.data.paymentMode == 0) {
         if(stute == '未支付') bt2 = '重新支付';
         return {
           order: {
@@ -276,16 +353,46 @@ Page({
           },
           bottonText2: bt2
         }
-      })
-
-      var orderList = [...this.data.orders,...getOrders]
-      this.setData({
-        orders: orderList
-      })
-
-      console.log("转换后的订单", this.data.orders)
-    }).catch(err => {
-      console.log("获取历史订单失败", err)
+      } else {
+        if(stute == "授权成功") bt2 = "请尽快提枪"
+        if(stute == "支付失败") {
+          bt1 = "取消"
+          bt2 = "继续支付"
+        }
+        if(stute == "授权失败") {
+          bt1 = "退款"
+          bt2 = "重新授权"
+        }
+        return {
+          order: {
+            status: stute,
+            statusColor: stateColor,
+            oilName: order.productName,
+            nozzle: order.nozzleId,
+            volume: volume,
+            amount: order.originalAmount,
+            payAmount: order.actualPaymentAmount,
+            discount: order.originalAmount - order.actualPaymentAmount,
+            refund:order.refundAmount,
+            orderId: order.id,
+            time: time
+          },
+          bottonText1:bt1,
+          bottonText2: bt2
+        }
+      }
     })
+    
+    return getOrders;
+  },
+
+  /** 刷新订单 */
+  refreshOrder(){
+    this.setData({
+      date: '',
+      orders:[]
+    });
+    console.log(this.data.date)
+    this.getOrder()
   }
 })

+ 2 - 1
pages/historyOrder/historyOrder.json

@@ -1,6 +1,7 @@
 {
   "usingComponents": {
-    "orderItem":"../../components/orderItemInfo/orderItemInfo"
+    "orderItem":"../../components/orderItemInfo/orderItemInfo",
+    "prepayOrderItem":"../../components/prepayOrderItemInfo/prepayOrderItemInfo"
   },
   "navigationBarTitleText": "历史订单"
 }

+ 14 - 2
pages/historyOrder/historyOrder.wxml

@@ -13,8 +13,8 @@
     </picker>
   </view>
 
-  <!-- 订单列表 -->
-  <view class="order">
+  <!-- 订单列表-后支付-->
+  <view class="order" wx:if="{{paymentMode == 0}}">
     <view class="orderItem" wx:for="{{orders}}" wx:key="index">
       <orderItem 
       order="{{item.order}}"
@@ -24,5 +24,17 @@
     </view>
   </view>
 
+  <!-- 订单列表-预支付-->
+  <view class="order" wx:if="{{paymentMode == 1}}">
+    <view class="orderItem" wx:for="{{orders}}" wx:key="index">
+      <prepayOrderItem 
+      order="{{item.order}}"
+      buttonText1="{{item.bottonText1}}"
+      buttonText2="{{item.bottonText2}}"
+      bind:bottonEvent1="onOrderButtonClick1"
+      bind:bottonEvent2="onOrderButtonClick2" />
+    </view>
+  </view>
+
   <text style="color: #a1a1a1; margin: 5%">仅保留一个月的交易记录</text>
 </view>

+ 1 - 1
pages/payResult/payResult.js

@@ -88,7 +88,7 @@ Page({
   /** 查看订单 */
   toHistoryOrder() {
     wx.redirectTo({
-      url: '../historyOrder/historyOrder',
+      url: '../historyOrder/historyOrder?paymentMode='+0,
     })
   },
   /** 完成 */

+ 163 - 0
pages/payStatus/payStatus.js

@@ -0,0 +1,163 @@
+const { default: api } = require("../../js/api");
+
+Page({
+  data: {
+    id: 1 , // 初始ID值
+    nozzleId:0,
+    order:null,
+    countdown: 120,
+    progressWidth: 100, // 初始进度条宽度为100%
+    totalSeconds: 60, // 总秒数
+    currentSeconds: 60, // 当前剩余秒数
+    countDownTimer:null, //倒计时定时器
+    checkNozzleStatuesTimer:null, //检查油枪状态定时器
+  },
+  onLoad(options) {
+    console.log("收到预支付确定页信息",options)
+    this.setData({
+      id:options.id,
+      nozzleId:options.nozzleId
+    })
+    
+    const that = this;
+    const eventChannel = this.getOpenerEventChannel();
+    eventChannel.on('acceptDataFromAuthorization', function (data) {
+      console.log(data)
+      that.setData({
+        order:data
+      })
+      //授权
+    if(options.id == 1) {
+      that.toAuthorization();
+    }
+    });
+
+  },
+
+  /** 返回重新支付 */
+  back(){
+    setTimeout(() => {
+      wx.navigateBack()
+    },500)
+  },
+  
+  /** 授权 */
+  toAuthorization() {
+    this.setData({
+      id:1
+    })
+    const that = this;
+    api.request_NozzleAuthorization(this.data.order.orderId).then(res => {
+      console.log("授权",res)
+      if(res.data.statusCode != 200) {
+        that.setData({
+          id:5
+        })
+        return
+      }
+      that.setData({
+        id:3
+      })
+      that.countDown()
+      that.startCheckNozzle()
+    }).catch(err => {
+      console.log("授权报错",err)
+      that.setData({
+        id:5
+      })
+    })
+  },
+
+  /** 取消授权 */
+  toUnAuthorization(){
+    const that = this;
+    api.request_CancelNozzleAuthorization(this.data.order.orderId).then(res => {
+      console.log("取消授权",res)
+      if(res.data.statusCode != 200) {
+        that.countDown()
+        that.startCheckNozzle()
+        return
+      }
+      that.setData({
+        id:5
+      })
+    })
+  },
+
+  /** 查看历史订单 */
+  toHistory() {
+    setTimeout(() => {
+      wx.reLaunch({
+        url: '../historyOrder/historyOrder?paymentMode='+1,
+      })
+    },500)
+  },
+
+  /** 授权成功倒计时 */
+  countDown() {
+    const that = this;
+    let timer = setInterval(() => {
+      let { currentSeconds, totalSeconds } = that.data;
+      currentSeconds--;
+      if (currentSeconds < 0) {
+        that.toUnAuthorization()
+        that.setData({
+          currentSeconds: 60,
+          progressWidth: 100
+        })
+        that.clearTimer()
+        return
+      }
+      let aprogressWidth = (currentSeconds / totalSeconds) * 100;
+      that.setData({
+        currentSeconds: currentSeconds,
+        progressWidth: aprogressWidth
+      });
+    }, 1000);
+    that.setData({
+      countDownTimer:timer
+    }) // 保存定时器,以便在onUnload中清除
+  },
+
+  /** 轮询检查油枪状态 */
+  startCheckNozzle(){
+    const that = this;
+    const timer = setInterval(() => {
+      that.checkNozzleInfo()
+    }, 3000);
+    that.setData({
+      checkNozzleStatuesTimer:timer
+    })
+  },
+  /** 检查油枪状态 */
+  checkNozzleInfo(){
+    const that = this;
+    api.request_GetNozzleInfo(this.data.nozzleId).then(res => {
+      if (res.data.content.length != 0) {
+        var nozzle = res.data.content[0];
+        //加油态,转加油中页面
+        if(nozzle.status == 8) {
+          that.setData({
+            id:4
+          })
+          that.clearTimer()
+        }
+      }
+    })
+  },
+
+  onUnload() {
+    this.clearTimer()
+  },
+
+  clearTimer(){
+    if (this.data.countDownTimer != null) {
+      clearInterval(this.data.countDownTimer);
+      this.data.countDownTimer = null;
+    }
+    if(this.data.checkNozzleStatuesTimer != null) {
+      clearInterval(this.data.checkNozzleStatuesTimer)
+      this.data.checkNozzleStatuesTimer = null;
+    }
+  }
+});

+ 4 - 0
pages/payStatus/payStatus.json

@@ -0,0 +1,4 @@
+{
+  "usingComponents": {},
+  "navigationBarTitleText": ""
+}

+ 116 - 0
pages/payStatus/payStatus.wxml

@@ -0,0 +1,116 @@
+<view class="container" wx:if="{{id === 1}}" style="position: relative; left: 0rpx; top: 0rpx">
+  <!-- 动画区域 -->
+  <view style="position: relative; left: 0rpx; top: 204rpx">
+    <view class="loading-circle" style="position: relative; left: 0rpx; top: 1rpx"></view>
+  </view>
+  <!-- 文本区域 -->
+  <view>
+    <view class="title" style="width: 122rpx; display: block; box-sizing: border-box; position: relative; left: 25rpx; top: -222rpx">授权中</view>
+    <view class="sub-title" style="position: relative; left: 0rpx; top: -200rpx; width: 170rpx; display: block; box-sizing: border-box; height: 50rpx">请勿退出页面</view>
+  </view>
+  <!-- 底部链接区域 -->
+  <view class="bottom-links" style="position: relative; left: 192rpx; top: -12rpx">
+    <text style="height: 56rpx; display: block; box-sizing: border-box; left: 0rpx; top: 0rpx; position: relative; width: 150rpx">客服帮助</text>
+    <text style="width: 72rpx; height: 56rpx; display: block; box-sizing: border-box; position: relative; left: -34rpx; top: 0rpx">|</text>
+    <text style="position: relative; left: -70rpx; top: 0rpx; width: 218rpx; display: block; box-sizing: border-box; height: 56rpx">隐私政策等</text>
+  </view>
+</view>
+
+
+<view class="page-container" wx:if="{{id === 2}}" style="position: relative; left: 0rpx; top: -39rpx">
+  <!-- 图标部分 -->
+  <view class="fail-icon-box">
+    <view class="orange-circle" style="position: relative; left: 0rpx; top: 154rpx">
+      <text class="close-icon" style="position: relative; left: 0rpx; top: 0rpx; height: 225rpx; display: block; box-sizing: border-box">×</text>
+    </view>
+  </view>
+  <!-- 提示文本部分 -->
+  <view class="prompt-text-area">
+    <text class="fail-title" style="position: relative; left: 0rpx; top: 143rpx">支付失败</text>
+  </view>
+  <!-- 操作按钮部分 -->
+  <view class="action-button-section">
+    <button class="retry-pay-btn" style="position: relative; left: 0rpx; top: 241rpx; width: 522rpx; display: block; box-sizing: border-box" bind:tap="back">重新支付</button>
+  </view>
+  <!-- 底部链接区域 -->
+  <view class="bottom-links" style="position: relative; left: 130rpx; top: -15rpx">
+    <text style="height: 56rpx; display: block; box-sizing: border-box; left: 86rpx; top: -26rpx; position: relative; width: 212rpx">客服帮助</text>
+    <text style="width: 72rpx; height: 56rpx; display: block; box-sizing: border-box; position: relative; left: -20rpx; top: -29rpx">|</text>
+    <text style="position: relative; left: -57rpx; top: -29rpx; width: 212rpx; display: block; box-sizing: border-box; height: 56rpx">隐私政策等</text>
+  </view>
+</view>
+
+<view class="a" wx:if="{{id === 3}}" style="position: relative; left: 0rpx; top: 0rpx">
+  <!-- 图标区域 -->
+  <view class="b" style="position: relative; left: 0rpx; top: 95rpx">
+    <view class="c">
+      <text class="d">√</text>
+    </view>
+  </view>
+  <!-- 提示文本区域 -->
+  <view class="e">
+    <text class="f" style="position: relative; left: 0rpx; top: -108rpx">授权成功</text>
+  </view>
+  <view class="g">
+    <text class="h" style="position: relative; left: 0rpx; top: -226rpx">请在两分钟内提枪加油</text>
+  </view>
+  <!-- 倒计时区域 -->
+  <view class="i" style="position: relative; left: 0rpx; top: -388rpx; width: 556rpx; height: 100rpx; display: block; box-sizing: border-box">
+    <view class="k" style="width: {{progressWidth}}%; position: relative; left: -58rpx; top: 0rpx"></view>
+    <text class="countdown-text" style="position: absolute; left: 85rpx; top: -105rpx; width: 368rpx; height: 291rpx; display: flex; box-sizing: border-box">{{currentSeconds}}s</text>
+  </view>
+  <!-- 底部链接区域 -->
+  <view class="bottom-links" style="position: relative; left: 57rpx; top: -15rpx">
+    <text style="height: 56rpx; display: block; box-sizing: border-box; left: 148rpx; top: -57rpx; position: relative; width: 186rpx">客服帮助</text>
+    <text style="width: 72rpx; height: 56rpx; display: block; box-sizing: border-box; position: relative; left: 77rpx; top: -57rpx">|</text>
+    <text style="position: relative; left: 40rpx; top: -57rpx; width: 186rpx; display: block; box-sizing: border-box; height: 56rpx">隐私政策等</text>
+  </view>
+</view>
+
+
+<view class="a" wx:if="{{id === 4}}" style="position: relative; left: 0rpx; top: 0rpx">
+  <!-- 图标区域 -->
+  <view class="b" style="position: relative; left: 0rpx; top: 95rpx">
+    <view class="c">
+      <text class="d">√</text>
+    </view>
+  </view>
+  <!-- 提示文本区域 -->
+  <view class="e">
+    <text class="f" style="position: relative; left: 0rpx; top: -160rpx">加油中</text>
+  </view>
+  <view class="button-container">
+    <button class="check-order-btn" style="position: relative; left: 2rpx; top: -266rpx; width: 464rpx; display: block; box-sizing: border-box; height: 83rpx" bind:tap="toHistory">查看订单</button>
+    <button class="complete-btn" style="position: relative; left: 0rpx; top: -254rpx; width: 468rpx; display: block; box-sizing: border-box; height: 83rpx" bind:tap="toHistory">完成</button>
+  </view>
+  <!-- 底部链接区域 -->
+  <view class="bottom-links" style="position: relative; left: 180rpx; top: -12rpx">
+    <text style="height: 56rpx; display: block; box-sizing: border-box; left: 12rpx; top: -62rpx; position: relative; width: 120rpx">客服帮助</text>
+    <text style="width: 72rpx; height: 56rpx; display: block; box-sizing: border-box; position: relative; left: 12rpx; top: -62rpx">|</text>
+    <text style="position: relative; left: -34rpx; top: -62rpx; width: 174rpx; display: block; box-sizing: border-box; height: 56rpx">隐私政策等</text>
+  </view>
+</view>
+
+<view class="page-container" wx:if="{{id === 5}}" style="position: relative; left: 0rpx; top: -37rpx">
+  <!-- 图标部分 -->
+  <view class="fail-icon-box">
+    <view class="orange-circle" style="position: relative; left: 0rpx; top: 154rpx">
+      <text class="close-icon" style="position: relative; left: 0rpx; top: 0rpx; height: 225rpx; display: block; box-sizing: border-box">×</text>
+    </view>
+  </view>
+  <!-- 提示文本部分 -->
+  <view class="prompt-text-area">
+    <text class="fail-title" style="position: relative; left: 0rpx; top: 143rpx">授权失败</text>
+  </view>
+  <!-- 操作按钮部分 -->
+  <view class="action-button-section">
+    <button class="retry-pay-btn" style="position: relative; left: 0rpx; top: 150rpx; width: 522rpx; display: block; box-sizing: border-box" bind:tap="toAuthorization">重新授权</button>
+    <button class="checkHistory" style="position: relative; left: 0rpx; top: 150rpx; width: 522rpx; display: block; box-sizing: border-box" bind:tap="toHistory">查看订单</button>
+  </view>
+  <!-- 底部链接区域 -->
+  <view class="bottom-links" style="position: relative; left: 24rpx; top: 0rpx">
+    <text style="height: 56rpx; display: block; box-sizing: border-box; left: 200rpx; top: -55rpx; position: relative; width: 104rpx">客服帮助</text>
+    <text style="width: 72rpx; height: 56rpx; display: block; box-sizing: border-box; position: relative; left: 201rpx; top: -55rpx">|</text>
+    <text style="position: relative; left: 164rpx; top: -55rpx; width: 138rpx; display: block; box-sizing: border-box; height: 55rpx">隐私政策等</text>
+  </view>
+</view>

+ 230 - 0
pages/payStatus/payStatus.wxss

@@ -0,0 +1,230 @@
+.container {
+  display: flex;
+  flex-direction: column;
+  justify-content: space-between;
+  align-items: center;
+  min-height: 100vh;
+  color: #f2f2f2;
+  padding: 20px;
+}
+
+.title {
+  color: #373737;
+  font-size: 20px;
+  font-weight: bold;
+  margin-bottom: 10px;
+}
+
+.sub-title {
+  font-size: 14px;
+  color: #7e7e7e;
+}
+
+.bottom-links {
+  width: 100%;
+  display: flex;
+  align-items: center;
+  font-size: 12px;
+  color: #808080;
+}
+
+.page-container {
+  display: flex;
+  flex-direction: column;
+  justify-content: space-between;
+  align-items: center;
+  min-height: 100vh;
+  padding: 20px;
+  background-color: #f2f2f2;
+}
+
+.fail-icon-box {
+  width: 100%;
+  display: flex;
+  justify-content: center;
+  margin-bottom: 40px;
+}
+
+.orange-circle {
+  width: 80px;
+  height: 80px;
+  border-radius: 50%;
+  background-color: #fe8d1b;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}
+
+.close-icon {
+  color: #eff3f2;
+  font-size: 80px;
+}
+
+.prompt-text-area {
+  text-align: center;
+  margin-bottom: 50px;
+  color: #353535;
+}
+
+.fail-title {
+  font-size: 20px;
+  font-weight: bold;
+  color: #3a3a3a;
+}
+
+.action-button-section {
+  width: 100%;
+  margin-bottom: auto;
+}
+
+.retry-pay-btn {
+  width: 100%;
+  height: 45px;
+  line-height: 30px;
+  background-color: #d81e07;
+  color: #fff3e9;
+  border: none;
+  border-radius: 12px;
+  font-size: 16px;
+}
+
+.checkHistory{
+  width: 100%;
+  height: 45px;
+  line-height: 30px;
+  background-color: #fff3e9;
+  color: #d81e07;
+  border: #d81e07 solid 3rpx;
+  border-radius: 12px;
+  font-size: 16px;
+  margin-top: 5%;
+}
+
+.a {
+  display: flex;
+  flex-direction: column;
+  justify-content: space-between;
+  align-items: center;
+  min-height: 100vh;
+  padding: 20px;
+  background-color: #f2f2f2;
+}
+
+.b {
+  width: 100%;
+  display: flex;
+  justify-content: center;
+  margin-bottom: 40px;
+}
+
+.c {
+  width: 80px;
+  height: 80px;
+  border-radius: 50%;
+  background-color: #1fb758;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+}
+
+.d {
+  color: #fefaff;
+  font-size: 40px;
+}
+
+.e {
+  text-align: center;
+  margin-bottom: 20px;
+}
+
+.f {
+  font-size: 20px;
+  font-weight: bold;
+  color: #383838;
+}
+
+.g {
+  text-align: center;
+  margin-bottom: 50px;
+}
+
+.h {
+  font-size: 17px;
+  color: #818181;
+}
+
+.i {
+  width: 120%;
+  background-color: #f2f2f2;
+  height: 45px;
+  border: 5px solid #d81e07;
+  border-radius: 20px;
+  overflow: hidden; 
+  box-sizing: border-box;
+  position: relative;
+}
+
+.k{
+  height: 100%;
+  background-color: #d81e07;
+  transition: width 1s ease; /* 添加过渡动画,让进度条变化更平滑 */
+}
+
+.countdown-text {
+  position: absolute;
+  top: 0;
+  left: 0;
+  right: 0;
+  bottom: 0;
+  display: flex;
+  justify-content: center;
+  align-items: center;
+  font-family:'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
+  color: rgb(0, 0, 0);
+  font-size: 24px;
+}
+
+.button-container {
+  display: flex;
+  flex-direction: column;
+  align-items: center;
+  gap: 15px; /* 设置按钮之间的间距 */
+}
+
+.check-order-btn {
+  width: 200px; /* 按钮宽度 */
+  height: 45px; /* 按钮高度 */
+  background-color: #d81e07; /* 背景颜色 */
+  color: #fffdfe; /* 文字颜色 */
+  border: none; /* 无边框 */
+  border-radius: 10px; /* 圆角 */
+  font-size: 16px; /* 文字大小 */
+}
+
+.complete-btn {
+  width: 200px;
+  height: 45px;
+  background-color: #f2f2f2; /* 背景颜色为白色 */
+  color: #c52818; /* 文字颜色为红色 */
+  border: 3px solid #c83523; /* 红色边框 */
+  border-radius: 10px;
+  font-size: 16px;
+}
+
+.loading-circle {
+  width: 65px;
+  height: 65px;
+  border: 4px solid #e0e0e0; /* 灰色边框 */
+  border-top-color: #ad1919; /* 绿色上边框,可根据喜好修改 */
+  border-radius: 50%; /* 圆形 */
+  animation: spin 1s linear infinite; /* 应用动画,1秒循环一次,线性变化,无限循环 */
+}
+
+@keyframes spin {
+  0% {
+    transform: rotate(0deg); /* 初始旋转角度 */
+  }
+  100% {
+    transform: rotate(360deg); /* 结束旋转角度 */
+  }
+}

+ 200 - 17
pages/quantify/quantify.js

@@ -1,32 +1,210 @@
-// pages/quantify/quantify.js
+const {
+  default: api
+} = require("../../js/api");
+const utils = require('../../utils/util');
+
 Page({
 
   /**
    * 页面的初始数据
    */
   data: {
-    nozzleId:'',
-    quantify:'元',
-    fastInputs:[10,20,50,100,200,500],
-    type:[
-      { name:'金额',checked:true},
-      { name:'升数',checked:false}
-    ]
+    nozzleId: '',
+    nozzleInfo: null,
+    quantify: '元',
+    fastInputs: [10, 20, 50, 100, 200, 500],
+    type: [{
+        name: '金额',
+        checked: true
+      },
+      {
+        name: '升数',
+        checked: false
+      }
+    ],
+    inputValue: '',
+    inputTip: '请输入金额',
+    amount: '',
+    latitude: 0, //用户当前经度
+    longitude: 0, //用户当前纬度
+    stationLatitude: 0, //站点经度
+    stationLongitude: 0, //站点纬度
   },
 
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
-    const id = decodeURIComponent(options.q) // 获取到二维码原始链接内容
+    const link = decodeURIComponent(options.q) // 获取到二维码原始链接
+    var id = link.split('yuwxapp?id=')[1];
+    if (id == undefined) {
+      id = options.id;
+    }
     this.setData({
-      nozzleId:id
+      nozzleId: id
     })
     wx.showToast({
       title: id,
     })
   },
 
+  /** 获取站点信息 */
+  getStationData() {
+    console.log("获取站点")
+    api.request_GetSiteInfo().then(res => {
+      if (res.data.statusCode == 203) {
+        //若为203,证明还未登录,跳转到登录页,这里可能刚从主页跳转过来,频繁的跳转可能会跳转页面超时,故而加上延时
+        setTimeout(() => {
+          wx.navigateTo({
+            url: '../login/login'
+          })
+        }, 500)
+        return
+      }
+      console.log("站点信息", res)
+      const stationLocation = res.data.data.site.gpsCoordinates.split(",");
+      if (stationLocation.length == 2) {
+        this.setData({
+          stationLatitude: stationLocation[0],
+          stationLongitude: stationLocation[1]
+        })
+      }
+      this.getLocation();
+    })
+  },
+
+  /** 获取用户经纬度 */
+  getLocation() {
+    const that = this;
+    wx.getLocation({
+      type: 'wgs84',
+      success(res) {
+        console.log("获取经纬度结果", res)
+        that.setData({
+          latitude: res.latitude,
+          longitude: res.longitude
+        })
+      }
+    })
+
+    this.getNozzleInfo();
+  },
+
+  /** 获取油枪信息 */
+  getNozzleInfo() {
+    const that = this;
+    api.request_GetNozzleInfo(this.data.nozzleId).then(res => {
+      console.log("获取油枪信息", res)
+      if (res.data.content.length != 0) {
+        var nozzle = res.data.content[0];
+        nozzle.productPrice = utils.formatDiNumber(nozzle.productPrice);
+        that.setData({
+          nozzleInfo: nozzle
+        })
+      }
+    })
+  },
+
+  /** 输入框监听 */
+  onInputChange(event) {
+    console.log("输入框变化", event)
+    this.setData({
+      inputValue: event.detail.value
+    })
+  },
+
+  /**
+   * 处理快速输入金额的点击事件
+   */
+  onFastInputClick(event) {
+    console.log("点击", event)
+    const amount = event.currentTarget.dataset.id;
+    this.setData({
+      inputValue: amount
+    });
+  },
+
+  /** 授权 */
+  toAuthorization() {
+    console.log(this.data)
+    // const distance = utils.haversine(this.data.stationLatitude,this.data.stationLongitude,this.data.latitude,this.data.longitude);
+    // if(distance > 500) {
+    //   wx.showToast({
+    //     title: '您不在油站范围内,请到油站时进行下单',
+    //   })
+    //   return
+    // }
+    this.createOrder()
+  },
+
+  /** 创建订单 */
+  createOrder() {
+    const nozzle = this.data.nozzleInfo;
+    const value = this.data.inputValue;
+    console.log("要授权的油枪信息", nozzle, value)
+    if(value <= 0){
+      wx.showToast({
+        title: '定量值非法',
+      })
+      return
+    }
+    var requestData = null
+    if (this.data.quantify == '元') {
+      requestData = {
+        externalGunNumber: nozzle.externalGunNumber,
+        originalAmount: value,
+        product: nozzle.productName,
+        price: parseFloat(nozzle.productPrice),
+        transactionNumber: ''
+      };
+    } else {
+      requestData = {
+        externalGunNumber: nozzle.externalGunNumber,
+        qty: value,
+        product: nozzle.productName,
+        price: nozzle.productPrice,
+        transactionNumber: ''
+      };
+    }
+
+    api.request_createOrder(requestData).then(res => {
+      console.log("创建订单", res)
+      if (res.data.statusCode != 200) {
+        wx.showToast({
+          icon: "none",
+          title: res.data.message == undefined ? res.data.notification : res.data.message,
+        })
+        return
+      }
+      utils.subAndsendMessage(res.data.data.id, "下单").then(response => {
+        this.toPayPage(res)
+      }).catch(err => {
+        this.toPayPage(res)
+      });
+    })
+  },
+
+  toPayPage(res) {
+    const order = res.data.data;
+    const time = utils.formatDateNotSecond(order.createTime)
+    setTimeout(() => {
+      wx.navigateTo({
+        url: '../AuthorizationTransactionPage/AuthorizationTransactionPage?nozzleId=' + this.data.nozzleId,
+        success: function (res) {
+          res.eventChannel.emit('acceptDataFromQuantify', {
+            oilName: order.productName,
+            nozzle: order.nozzleId,
+            volume: order.qty,
+            amount: order.originalAmount,
+            payAmount: order.actualPaymentAmount,
+            discount: order.originalAmount - order.actualPaymentAmount,
+            orderId: order.id,
+            time: time
+          })
+        }
+      })
+    }, 500)
+  },
   /**
    * 生命周期函数--监听页面初次渲染完成
    */
@@ -38,7 +216,8 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
-
+    console.log("页面显示")
+    this.getStationData();
   },
 
   /**
@@ -76,17 +255,21 @@ Page({
 
   },
 
-  /** 当选择定量类型 */
+  /**
+   * 当选择定量类型
+   */
   onTypeChange(event) {
     var type = event.detail.value;
-    if(type == '升数') {
+    if (type == '升数') {
       this.setData({
-        quantify:'升'
-      })
+        quantify: '升',
+        inputTip: '请输入升数'
+      });
     } else {
       this.setData({
-        quantify:'元'
-      })
+        quantify: '元',
+        inputTip: '请输入金额'
+      });
     }
   }
 })

+ 10 - 12
pages/quantify/quantify.wxml

@@ -1,18 +1,17 @@
-
 <view class="quantifyContainer">
   <!-- 提示 -->
-  <view class="tip">
+  <!-- <view class="tip">
     <icon color="#fbac15" type="warn" />
     <text>请勿在油机旁使用手机</text>
-  </view>
+  </view> -->
 
   <view class="quantifyBox">
     <!-- 油品信息 -->
     <view class="oilInfoBox">
       <image src="../../images/oil.svg" mode="aspectFill" />
       <view class="oilInfo">
-        <text class="oil">92#汽油</text>
-        <text class="price">¥7.49/升</text>
+        <text class="oil">{{nozzleInfo.productName}}油品</text>
+        <text class="price">¥{{nozzleInfo.productPrice}}/升</text>
       </view>
     </view>
 
@@ -20,8 +19,9 @@
     <view class="inputBox">
       <!-- 输入 -->
       <view class="input">
-        <text>请输入金额</text>
-        <input type="digit" placeholder="0.00{{quantify}}"/>
+        <text>{{inputTip}}</text>
+        <input type="digit" placeholder="0.00" value="{{inputValue}}" bindinput="onInputChange" />
+        <text>{{quantify}}</text>
       </view>
 
       <!-- 分割线 -->
@@ -29,17 +29,15 @@
 
       <!-- 快速输入 -->
       <view class="fastInput">
-        <text class="fastItem" wx:for="{{fastInputs}}" wx:key="{{index}}">{{item}}{{quantify}}</text>
+        <text class="fastItem" wx:for="{{fastInputs}}" wx:key="index" bindtap="onFastInputClick" data-id="{{item}}">{{item}}{{quantify}}</text>
       </view>
 
       <!-- 定量类型选择 -->
       <radio-group class="typeSelect" bindchange="onTypeChange">
-        <radio wx:for="{{type}}" checked="{{item.checked}}"
-        color="#d81e07" value="{{item.name}}">{{item.name}}</radio>
+        <radio wx:for="{{type}}" wx:key="index" checked="{{item.checked}}" color="#d81e07" value="{{item.name}}">{{item.name}}</radio>
       </radio-group>
     </view>
   </view>
 
-  <text class="anthorization">授权</text>
-
+  <text class="anthorization" bind:tap="toAuthorization">授权</text>
 </view>

+ 7 - 1
pages/quantify/quantify.wxss

@@ -20,6 +20,7 @@
   display: flex;
   flex-direction: column;
   width: 90%;
+  margin-top: 5%;
 }
 
 .oilInfoBox{
@@ -46,10 +47,15 @@
 }
 
 .price{
-  border: #d81e07 solid 1rpx;
+  border: #b7332e solid 5rpx;
   background-color: #ffebec;
   border-radius: 18rpx;
   margin-top: 5%;
+  padding: 10%;
+  font-size: larger;
+  font-weight: 600;
+  color: #b7332e;
+  width: 100%;
 }
 
 .inputBox{

+ 8 - 6
pages/scan/scan.js

@@ -67,10 +67,10 @@ Page({
       success(res) {
         console.log("扫码内容",res.result)
         const scanStr = res.result;
-        if(scanStr.includes('wxapp')) {
-          const id = scanStr.split('wxapp?id=')[1];
+        if(scanStr.includes('yuwxapp')) {
+          const id = scanStr.split('yuwxapp?id=')[1];
           wx.redirectTo({
-            url: '../TransactionPage/TransactionPage?id=' + id,
+            url: '../quantify/quantify?id=' + id,
             fail(err){
               wx.showToast({
                 title: '跳转页面失败',
@@ -78,11 +78,12 @@ Page({
               });
             }
           })
+          return
         }
-        if(scanStr.includes('yuwxapp')) {
-          const id = scanStr.split('yuwxapp?id=')[1];
+        if(scanStr.includes('wxapp')) {
+          const id = scanStr.split('wxapp?id=')[1];
           wx.redirectTo({
-            url: '../quantify/quantify?id=' + id,
+            url: '../TransactionPage/TransactionPage?id=' + id,
             fail(err){
               wx.showToast({
                 title: '跳转页面失败',
@@ -92,6 +93,7 @@ Page({
           })
         }
         
+        
       },
       fail(err) {
         console.error('扫码失败:', err);

+ 88 - 1
utils/util.js

@@ -1,3 +1,5 @@
+const { default: api } = require("../js/api")
+
 const formatTime = date => {
   const year = date.getFullYear()
   const month = date.getMonth() + 1
@@ -45,8 +47,93 @@ const formatPhone = phone => {
   return start + hidden + end;
 }
 
+// 格式化小数点数字
+const formatDiNumber = number => {
+  var numberStr = number.toString()
+  if(!numberStr.includes(".")){
+    numberStr += ".00"
+  }
+  return numberStr
+}
+
+//根据经纬度计算距离
+const haversine = (lat1, lon1, lat2, lon2) => {
+  const R = 6371; // 地球半径,单位:千米
+  const toRadians = (degrees) => degrees * (Math.PI / 180); // 将度数转换为弧度
+
+  // 将经纬度转换为弧度
+  const phi1 = toRadians(lat1);
+  const phi2 = toRadians(lat2);
+  const deltaPhi = toRadians(lat2 - lat1);
+  const deltaLambda = toRadians(lon2 - lon1);
+
+  // Haversine公式
+  const a = Math.sin(deltaPhi / 2) ** 2 + Math.cos(phi1) * Math.cos(phi2) * Math.sin(deltaLambda / 2) ** 2;
+  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
+
+  // 计算距离
+  const distance = R * c; // 单位:千米
+  return distance * 1000; // 转换为米
+}
+
+function subAndsendMessage(id,type) {
+  return new Promise((resolve,reject)=>{
+    wx.requestSubscribeMessage({
+      tmplIds: ['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'], // 最多支持3条
+      success(res) {
+        sendMessage(id,type,resolve,reject)
+        // 'accept'表示用户同意订阅该条id对应的模板消息
+        if (res['V0tl-4n-5hwNZc4SrEttvrmawAyM-SB0pQWZNwp54Ks'] === 'accept') {
+          // 用户同意订阅,调用云函数或服务器接口发送订阅消息
+          // wx.cloud.callFunction({
+          //   name: 'sendSubscribeMessage',
+          //   data: {
+          //     templateId: '配置好的模板ID',
+          //     openid: 'o8pFb5cWH1KkBDvGls2X7yMiFkGA',
+          //     data: {
+          //       thing1: {
+          //         value: '活动名称'
+          //       },
+          //       // 其他参数...
+          //     }
+          //   },
+          //   success(res) {
+          //     console.log('订阅消息发送成功', res)
+          //   },
+          //   fail(err) {
+          //     console.error('订阅消息发送失败', err)
+          //   }
+          // })
+          
+        }
+      },
+      fail(err) {
+        sendMessage(id,type,resolve,reject)
+      }
+    })
+  })
+  
+}
+
+function sendMessage(id,type,resolve,reject) {
+  const message = {
+    trxid:id,
+    orderType:type
+  }
+  api.request_sendMessage(message).then(res => {
+    console.log("发送消息模板结果",res)
+    resolve()
+  }).catch(err => {
+    console.log("发送消息模板失败",err)
+    reject()
+  })
+}
+
 module.exports = {
   formatTime,
   formatDateNotSecond,
-  formatPhone
+  formatPhone,
+  formatDiNumber,
+  haversine,
+  subAndsendMessage
 }