hzd 2 éve
szülő
commit
e8ba974659

+ 157 - 1
app.js

@@ -1,2 +1,158 @@
 // app.js
-App({})
+App({
+  //全局变量
+  globalData: {
+    //服务器地址
+    serverUrl: 'https://wy.dazhengyun.com/api/h5/',
+    h5Url: 'https://wy.dazhengyun.com/public/wap/ph2',
+    appVersion: '1.0.0',
+    platform: 'wxapp',
+    userinfo:{}
+  },
+
+  onLaunch: function (options) {
+    // let orgId = 3
+    // wx.setStorageSync("orgId", orgId);
+    this.getScene(options);
+  },
+  
+  getScene(options){
+    const scene = decodeURIComponent(options.scene);
+    let ss = scene.split('-');
+    if(ss.length == 2){
+      var orgId = wx.getStorageSync("orgId");
+      if(!orgId || (orgId && Number(orgId) != Number(ss[1]))){
+        wx.setStorageSync("orgId", ss[1]);
+        this.logout();
+      }
+    }
+
+    var orgId = wx.getStorageSync("orgId");
+    if(!orgId){
+      var orgId = 3;
+      wx.setStorageSync("orgId", 3);
+    }
+  },
+
+  getCommonParam(){
+    var orgId = wx.getStorageSync("orgId");
+    var userId = wx.getStorageSync("userId");
+    var token = wx.getStorageSync("token");
+    return "orgId="+orgId+"&userId="+userId+"&token="+token;
+  },
+
+  logout(){
+    wx.removeStorageSync("token");
+    wx.removeStorageSync("userId");
+  },
+
+  checkCode:function(code){
+    if(code == -100){
+      wx.showToast({
+        title: '登录超时,请重新登录',
+        icon: 'none',
+        duration: 2000
+      })
+      this.logout();
+      setTimeout(function(){
+        wx.reLaunch({ //关闭所有页面,打开到应用内的某个页面
+          url: '/pages/splash/splash'
+        })
+      },2000);
+      return false;
+    }
+    return true;
+  },
+
+  ajax:function(params){
+    console.log('params',params)
+    if (!params.type) {
+      var type = 'POST';
+    }else{
+      var type = params.type;
+    }
+    if (!params.apiname) {
+      var apiname = '1';
+    } else {
+      var apiname = params.apiname;
+    }
+    if (!params.data) {
+      var data = [];
+    }else{
+      var data = params.data;
+    }
+    var app = getApp();
+    var userId = wx.getStorageSync("userId");
+    var token = wx.getStorageSync("token");
+    var orgId = wx.getStorageSync("orgId");
+    console.log('params2',userId,token,token);
+    if (!userId || userId == undefined) { //未登录
+      wx.showToast({
+        title: '未登录',
+        icon: 'none',
+        duration: 2000
+      });
+      this.logout();
+      setTimeout(function () {
+        wx.reLaunch({ //关闭所有页面,跳转到闪屏页
+          url: '/pages/splash/splash'
+        })
+      }, 2000);
+      return false;
+    }
+    data['userId'] = userId;
+    data['token'] = token;
+    data['orgId'] = orgId;
+    console.log('params3',data);
+    wx.showLoading({
+      title: '加载中',
+      mask: true
+    });
+    
+    wx.request({
+      url: params.url,
+      data: data,
+      method: type,
+      header: {
+        'content-type': 'application/x-www-form-urlencoded'
+      },
+      success: function (res) {
+        console.log('params4',res);
+        wx.hideLoading();
+        wx.stopPullDownRefresh();
+        var ret = app.checkCode(res.data.code); //检查token是否失效
+        if(ret == false){
+          return false;
+        }
+
+        if (res.data.code == 0) {
+          if (app.ajaxReadyCallback) { //在onShow中调用数据的,添加在onShow方法内,防止不同页面覆盖
+            res.data['apiname'] = apiname;
+            app.ajaxReadyCallback(res)
+          }
+        } else {
+          let showMsg = true;
+          if(params.showMsg != undefined){
+            showMsg = params.showMsg;
+          }
+          if(showMsg){
+            wx.showToast({
+              title: res.data.message,
+              icon: 'none',
+              duration: 2000
+            })
+          }
+        }
+      },
+      fail: function (err) {
+        wx.hideLoading();
+        wx.showToast({
+          title: '请求失败',
+          icon: 'none',
+          duration: 2000
+        })
+      }
+    })
+  },
+
+})

+ 35 - 12
app.json

@@ -1,13 +1,36 @@
 {
-    "pages": [
-        "pages/index/index"
-    ],
-    "window": {
-        "backgroundTextStyle": "light",
-        "navigationBarBackgroundColor": "#fff",
-        "navigationBarTitleText": "大正陪护",
-        "navigationBarTextStyle": "black"
-    },
-    "style": "v2",
-    "sitemapLocation": "sitemap.json"
-}
+  "pages": [
+    
+    "pages/index/index",
+    "pages/pay/index",
+    "pages/user/index",
+    "pages/webview/index"
+  ],
+  "window": {
+    "backgroundTextStyle": "light",
+    "navigationBarBackgroundColor": "#fff",
+    "navigationBarTitleText": "大正陪护",
+    "navigationBarTextStyle": "black"
+  },
+  "style": "v2",
+  "sitemapLocation": "sitemap.json",
+  "tabBar": {
+    "color": "#777777",
+    "selectedColor": "#148d8f",
+    "backgroundColor": "#FFFFFF",
+    "list": [
+      {
+        "pagePath": "pages/index/index",
+        "text": "首页",
+        "iconPath": "images/home1.png",
+        "selectedIconPath": "images/home2.png"
+      },
+      {
+        "pagePath": "pages/user/index",
+        "text": "我的",
+        "iconPath": "images/user1.png",
+        "selectedIconPath": "images/user2.png"
+      }
+    ]
+  }
+}

BIN
images/avatar.png


BIN
images/home1.png


BIN
images/home2.png


BIN
images/jiantouyou.png


BIN
images/user1.png


BIN
images/user2.png


+ 98 - 30
pages/index/index.js

@@ -1,36 +1,104 @@
 // index.js
+var app = getApp();
 Page({
-    data:{
-        src:"https://wy.dazhengyun.com/public/wap/ph?orgId="
-    },
+  data:{
+    loading: true,
+    src: "",
+    msg: ""
+  },
 
-    onLoad:function(options){
-       this.getScene(options);
-        var orgId = wx.getStorageSync("orgId");
-        var orgId = orgId?orgId:3;
-        console.log(this.data.src+orgId);
-        this.setData({
-            'src':this.data.src+orgId
-        })
-    },
-    getScene(options){
-        if(options.hasOwnProperty('scene')){
-            const scene = decodeURIComponent(options.scene);
-            let ss = scene.split('_');
-            if(ss.length == 2){
-                wx.setStorageSync("orgId", ss[1]);
-            }else {
-                wx.showToast({
-                    title: '项目id不存在',
-                    icon: 'none',
-                    duration: 2000
-                });
-                return false;
-            }
-        }else {
-            wx.setStorageSync("orgId", 3);
+    
+
+  onLoad:function(options){
+    console.log(1111111111,encodeURIComponent("org_3"));
+    app.getScene(options);
+
+    var userId = wx.getStorageSync("userId");
+    var token = wx.getStorageSync("token");
+    if (!userId || token) { //未登录
+      this.autologin();
+    }else{
+      this.setData({
+        src: app.globalData.h5Url + "/#/pages/index/index?"+app.getCommonParam()
+      })
+      console.log(this.data.src);
+    }
+  },
 
-        }
+  onShow: function () {
+    var that = this;
+    app.ajaxReadyCallback = res => {  //各个接口统一回调方法
+      var apiname = res.data.apiname;
+      if(apiname == 'icon'){
+        
+      }
+    }
+  },
 
-    },
+  autologin(){
+    let that = this;
+    wx.login({
+      success: function (ret) {
+        wx.showLoading({
+          title: '加载中',
+          mask: true
+        });
+        wx.request({
+          url: app.globalData.serverUrl + 'Oauth/checkCode',
+          data: {
+              type: 2,
+              code: ret.code,
+          },
+          method: 'POST',
+          header: {
+              'content-type': 'application/x-www-form-urlencoded'
+          },
+          success: function (res) {
+              wx.hideLoading();
+              if (res.data.code == 0) {
+                  try {
+                    app.logout();
+                    wx.setStorageSync("userId", res.data.data.userId);
+                    wx.setStorageSync("token", res.data.data.token);
+                  } catch (e) { };
+
+                  var userinfo = {
+                      userId: res.data.data.userId,
+                      token: res.data.data.token,
+                  };
+                  app.globalData.userinfo = userinfo;
+              
+                  that.setData({
+                    src: app.globalData.h5Url + "/#/pages/index/index?"+app.getCommonParam()
+                  })
+                  console.log(that.data.src);
+              }else{
+                  wx.showModal({
+                      title: '提示',
+                      content: res.data.message,
+                      showCancel: false
+                  })
+              }
+          },
+          fail:function(e){
+              wx.hideLoading();
+              wx.showModal({
+                  title: '提示',
+                  content: '登录失败,请重试',
+                  showCancel: false
+              })
+              }
+          })
+      },
+      fail:function(e){
+        wx.hideLoading();
+        wx.showModal({
+            title: '提示',
+            content: '登录失败,请重试',
+            showCancel: false
+        })
+      }
+    });
+  }
+    
 })

+ 2 - 1
pages/index/index.json

@@ -1,3 +1,4 @@
 {
-  "usingComponents": {}
+  "usingComponents": {},
+  "navigationStyle": "custom"
 }

+ 4 - 2
pages/index/index.wxml

@@ -1,5 +1,7 @@
 <!--index.wxml-->
 <view class="container">
-  <web-view  src="{{src}}"></web-view>
-
+  <web-view wx:if="{{src}}" src="{{src}}"></web-view>
+  <view wx:if="{{msg}}">
+    {{msg}}
+  </view>
 </view>

+ 175 - 0
pages/pay/index.js

@@ -0,0 +1,175 @@
+// pages/pay/index.js
+var app = getApp();
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    id: 106,
+    info: null,
+    temps: [],
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad(options) {
+    var that = this;
+    console.log(options);
+    this.setData({
+      id: options.id
+    })
+
+    this.getTemps();
+
+    this.getData();
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow() {
+    var that = this;
+    app.ajaxReadyCallback = res => {  //各个接口统一回调方法
+      var apiname = res.data.apiname;
+      if(apiname == 'pay'){
+        console.log(res.data.data);
+        that.setData({
+          info: res.data.data
+        })
+      }else if(apiname == 'temps'){
+        if(res.data.data.temps.length > 0){
+          that.setData({
+            temps: res.data.data.temps
+          });
+          wx.showModal({
+            title: '温馨提示',
+            content: res.data.data.tips,
+            confirmText: "同意",
+            cancelText: "拒绝",
+            complete: (res) => {
+              if (res.cancel) {
+                
+              }
+          
+              if (res.confirm) {
+                that.paySubscribe();
+              }
+            }
+          })
+        }
+        
+      }
+    };
+
+    
+    
+  },
+
+  paySubscribe(){
+    let that = this;
+    if(that.data.temps.length > 0){
+      wx.requestSubscribeMessage({
+        tmplIds: that.data.temps,
+        success (res) {
+          console.log('temp',res);
+        },
+        fail(res){
+          console.log('fail',res);
+        },
+        complete(){
+          // that.pay();
+        }
+      });
+    }  
+  },
+
+  getData:function(){
+    app.ajax({
+      url: app.globalData.serverUrl + 'PhOrders/pay',
+      type: 'POST',
+      apiname: 'pay',
+      data: {
+        payId: this.data.id
+      }
+    });
+  },
+
+  getTemps:function(){
+    app.ajax({
+      url: app.globalData.serverUrl + 'PhOrders/temps',
+      type: 'POST',
+      apiname: 'temps',
+    });
+  },
+
+  pay(){
+    // let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam());
+    // wx.navigateTo({
+    //   url: '/pages/webview/index?url='+url
+    // }); 
+    wx.requestPayment({
+      timeStamp: this.data.info.timestamp,
+      nonceStr: this.data.info.noncestr,
+      package: this.data.info.package,
+      signType: this.data.info.signtype,
+      paySign: this.data.info.paysign,
+      success (res) { 
+        let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam());
+        wx.navigateTo({
+          url: '/pages/webview/index?url='+url
+        }); 
+      },
+      fail (res) { 
+        wx.showToast({
+          title: '支付调用失败',
+          icon: 'none',
+          duration: 2000
+        })
+      }
+    })
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload() {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh() {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom() {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage() {
+
+  }
+})

+ 4 - 0
pages/pay/index.json

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

+ 28 - 0
pages/pay/index.wxml

@@ -0,0 +1,28 @@
+<view>
+  <view wx:if="{{!info}}" class="sn">
+    <!-- 获取支付参数失败,请重试 -->
+  </view>
+  <view wx:if="{{info}}">
+    <view class="title">大正云陪护商户平台</view>
+    <view class="money">
+      ¥{{info.money}}
+    </view>
+
+    <view class="sn">
+      收款方: <text class="sn-desc">大正陪护平台</text>  
+    </view>
+    <view class="sn">
+      订单号: <text class="sn-desc">{{info.sn}}</text>  
+    </view>
+   
+
+    <view class="btn" bindtap="pay">
+      确认支付
+    </view>
+
+    <!-- <view class="btn" bindtap="paymsg">
+      消息
+    </view> -->
+  </view>
+  
+</view>

+ 36 - 0
pages/pay/index.wxss

@@ -0,0 +1,36 @@
+/* pages/pay/index.wxss */
+.title{
+  font-size: 34rpx;
+  font-weight: 500;
+  text-align: center;
+  margin-top: 100rpx;
+}
+.sn{
+  padding: 10rpx 60rpx;
+  text-align: left;
+  color: #777777;
+}
+.sn-desc{
+  float: right;
+}
+
+.money{
+  text-align: center;
+  margin-top: 40rpx;
+  font-size: 78rpx;
+  font-weight: bold;
+  margin-bottom: 150rpx;
+}
+
+.btn{
+  width: 80%;
+  height: 80rpx;
+  line-height: 80rpx;
+  color: #ffffff;
+  background-color: #089875;
+  border-radius: 10rpx;
+  text-align: center;
+  margin: 0 auto;
+  margin-top: 60rpx;
+  margin-bottom: 50rpx;
+}

+ 88 - 0
pages/user/index.js

@@ -0,0 +1,88 @@
+// pages/user/index.js
+var app = getApp();
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    name: "",
+    canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad(options) {
+    var userId = wx.getStorageSync("userId");
+    this.setData({
+      name: "ID:"+userId
+    });
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload() {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh() {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom() {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage() {
+
+  },
+
+  goOrder(){
+    let url = encodeURIComponent(app.globalData.h5Url + "/#/pages/order/index?"+app.getCommonParam());
+    wx.navigateTo({
+        url: '/pages/webview/index?url='+url
+    });
+  },
+  goIndex(){
+    wx.switchTab({
+      url: '/pages/index/index'
+    });
+  },
+  goPay(){
+    wx.navigateTo({
+      url: '/pages/pay/index?id=106'
+  });
+  }
+})

+ 4 - 0
pages/user/index.json

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

+ 40 - 0
pages/user/index.wxml

@@ -0,0 +1,40 @@
+<view>
+		<view class="user-bg" style="background-color: rgb(8,152,117)">
+
+		</view>
+		
+		<view class="user-top">
+			<!-- <view wx:if="{{canIUseOpenData}}" class="user-info">
+        <view class="userinfo-avatar">
+          <open-data type="userAvatarUrl"></open-data>
+        </view>
+				<view class="user-info-nick">
+          <open-data type="userNickName"></open-data>
+        </view>
+			</view> -->
+
+      <view class="user-info">
+				<view class="user-info-avatar">
+					<image src="/images/avatar.png"></image>
+				</view>
+				<view class="user-info-nick">{{name}}</view>
+			</view>
+			
+			<view class="menu-box">
+
+				<view class="menu-box-list" bindtap="goOrder">
+					<text class="menu-box-list-text">我的订单</text>
+					<image class="menu-box-list-right" src="/images/jiantouyou.png"></image>
+				</view>
+				<view class="menu-box-list" bindtap="goIndex">
+					<text class="menu-box-list-text">去下单</text>
+					<image class="menu-box-list-right" src="/images/jiantouyou.png"></image>
+				</view>
+        <!-- <view class="menu-box-list" bindtap="goPay">
+					<text class="menu-box-list-text">支付</text>
+					<image class="menu-box-list-right" src="/images/jiantouyou.png"></image>
+				</view> -->
+			</view>
+		</view>
+		
+	</view>

+ 75 - 0
pages/user/index.wxss

@@ -0,0 +1,75 @@
+page{
+  background-color: #F3F3F3;
+}
+.user-bg{
+  position: absolute;
+  width: 750rpx;
+  height: 475rpx;
+  top: 0;
+  left: 0;
+  z-index: 1;
+}
+.user-bg image{
+  width: 100%;
+  height: 100%;
+}
+.user-top{
+  position: absolute;
+  width: 100%;
+  height: 100%;
+  top: 0;
+  left: 0;
+  z-index: 2;
+}
+.user-info{
+  overflow: hidden;
+  padding-top: 100rpx;
+  padding-bottom: 40rpx;
+  text-align: center;
+  color: #FFFFFF;
+}
+.user-info-avatar{
+  overflow: hidden;
+}
+.user-info-avatar image{
+  width: 128rpx;
+  height: 128rpx;
+  border-radius: 66rpx;
+}
+.menu-box{
+  width: 687rpx;
+  height: auto;
+  border-radius: 10rpx;
+  background-color: #FFFFFF;
+  margin: 0 auto;
+  padding: 0 15rpx;
+  margin-top: 50rpx;
+}
+.menu-box .menu-box-list{
+  height: 108rpx;
+  line-height: 108rpx;
+  border-bottom: 1px solid #CCCCCC;
+}
+.menu-box .menu-box-list .menu-box-list-text{
+  display: inline-block;
+  width: 660rpx;
+  vertical-align: middle;
+}
+.menu-box .menu-box-list .menu-box-list-right{
+  width: 12rpx;
+  height: 22rpx;
+  vertical-align: middle;
+}
+.menu-box .menu-box-list:last-child{
+  border: 0;
+}
+
+.userinfo-avatar {
+  overflow: hidden;
+  width: 128rpx;
+  height: 128rpx;
+  margin: 20rpx;
+  border-radius: 50%;
+  margin: 0 auto;
+  margin-bottom: 30rpx;
+}

+ 81 - 0
pages/webview/index.js

@@ -0,0 +1,81 @@
+// pages/webview/index.js
+var app = getApp();
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+    url: ''
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function (options) {
+    let nurl = decodeURIComponent(options.url);
+    console.log(nurl);
+    this.setData({
+      url: nurl
+    });
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function () {
+    console.log('onShow webview');
+    let url = this.data.url;
+    this.setData({
+      url: '',
+    });
+
+    setTimeout(() => {
+      this.setData({
+        url: url,
+      })
+    }, 100);
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function () {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function () {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function () {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function () {
+
+  },
+
+  /**
+   * 用户点击右上角分享
+   */
+  onShareAppMessage: function () {
+
+  }
+})

+ 3 - 0
pages/webview/index.json

@@ -0,0 +1,3 @@
+{
+  "usingComponents": {}
+}

+ 1 - 0
pages/webview/index.wxml

@@ -0,0 +1 @@
+<web-view wx:if="{{ url }}" src="{{url}}"></web-view>

+ 1 - 0
pages/webview/index.wxss

@@ -0,0 +1 @@
+/* pages/webview/index.wxss */

+ 3 - 2
project.private.config.json

@@ -1,5 +1,5 @@
 {
-  "projectname": "%E5%A4%A7%E6%AD%A3%E9%99%AA%E6%8A%A4",
+  "projectname": "dazheng-ph-mini",
   "setting": {
     "compileHotReLoad": true,
     "urlCheck": false
@@ -17,5 +17,6 @@
         }
       ]
     }
-  }
+  },
+  "libVersion": "2.30.2"
 }