Browse Source

优化request方法 新增信息不全强制登陆 优化图片上传功能 修复头像更改后个人中心需刷新才能看见

wangxin 6 years ago
parent
commit
6c7c04674e

BIN
.DS_Store


+ 2 - 1
app.json

@@ -11,7 +11,8 @@
     "pages/my-order/my-order",
     "pages/payment-records/payment-records",
     "pages/payment-records-detail/payment-records-detail",
-    "pages/tax-certificate/tax-certificate"
+    "pages/tax-certificate/tax-certificate",
+    "pages/web-view/web-view"
   ],
   "window": {
     "backgroundTextStyle": "light",

+ 47 - 22
pages/detail/detail.js

@@ -91,11 +91,18 @@ Page({
     // 获取线上合同  如果存在打开合同   不存在进行提示(暂无)
     const workContract = this.data.hwOrderAPI.workContract;
     if (workContract) {
+      wx.showLoading({
+        mask: true,
+        title: '正在打开文件...',
+      })
       wx.downloadFile({
         url: this.data.hwOrderAPI.workContract,
         success: (res) => {
           wx.openDocument({
             filePath: res.tempFilePath,
+            success: res => {
+              wx.hideLoading()
+            }
           })
         }
       })
@@ -112,28 +119,47 @@ Page({
    * 前台报名需求后  后台生成订单   需前台手动确定订单
    */
   buttonSubmit() {
-    wx.kx_request({
-      url: wx.kx_api.hwOrder.confirmOrder,
-      type: 'post',
-      data: {
-        orderId: this.data.hwOrderAPI.id
-      },
-      success: res => {
-        if (res.errcode === 0) {
-          wx.showToast({
-            title: '订单已确认',
-            success: res => {
-              // 确认成功后 更改按钮状态
-              const hwOrderAPI = this.data.hwOrderAPI;
-              hwOrderAPI.status = 2;
-              this.setData({
-                hwOrderAPI
-              })
-            }
-          })
+    const contractType = this.data.hwOrderAPI.contractType;
+    if (contractType === 2) {
+      wx.kx_request({
+        url: wx.kx_api.hwOrder.confirmECOrders,
+        type: 'post',
+        data: {
+          orderId: this.data.hwOrderAPI.id
+        },
+        success: res => {
+          if (res.errcode === 0) {
+            wx.navigateTo({
+              url: `/pages/web-view/web-view?url=${encodeURIComponent(res.data.url)}`,
+            })
+          }
         }
-      }
-    })
+      })
+    }
+    if (contractType === 1) {
+      wx.kx_request({
+        url: wx.kx_api.hwOrder.confirmOrder,
+        type: 'post',
+        data: {
+          orderId: this.data.hwOrderAPI.id
+        },
+        success: res => {
+          if (res.errcode === 0) {
+            wx.showToast({
+              title: '订单已确认',
+              success: res => {
+                // 确认成功后 更改按钮状态
+                const hwOrderAPI = this.data.hwOrderAPI;
+                hwOrderAPI.status = 2;
+                this.setData({
+                  hwOrderAPI
+                })
+              }
+            })
+          }
+        }
+      })
+    }
   },
   /**
    * 控制cover层的显示与隐藏
@@ -165,7 +191,6 @@ Page({
             },
             success: res => {
               if (res.errcode === 0) {
-                console.log(res.data.hwOrderAPI.serviceStage)
                 this.setData({
                   ...res.data.hwRequirementAPI,
                   hwOrderAPI: res.data.hwOrderAPI,

+ 5 - 10
pages/index/index.js

@@ -249,7 +249,7 @@ Page({
    * @country_code {number} 地区代码
    * @trade_type {number} 行业类型
    * @priceType {number} 价格代号(1-7)(不限的话不传此参数)
-   * @platform_company_id {number} 接单人用户所属企业id
+   * @platform_id {number} 接单人用户所属平台id
    */
   getList(pageNo = this.data.pageNo, province_code = this.data.province_id, city_code = this.data.city_id, country_code = this.data.area_id, trade_type = this.data.industry_id, priceType = this.data.price_id) {
     wx.kx_request({
@@ -262,7 +262,7 @@ Page({
         country_code,
         trade_type,
         priceType,
-        platform_company_id: wx.getStorageSync('userinfo').platformCompanyId
+        platform_id: wx.getStorageSync('userinfo').platformId
       },
       success: res => {
         // 如果没有网络  展示网络故障界面
@@ -287,7 +287,7 @@ Page({
           pageNo++;
           this.setData({
             pageNo,
-            list: [...this.data.list, ...res.data.requirements],
+            [`list[${pageNo - 2}]`]: res.data.requirements,
             isLast: res.data.isLast,
             offline: false,
             list_length: false,
@@ -302,13 +302,6 @@ Page({
           offline: false
         })
         this.doAnimation(false);
-      },
-      complete: () => {
-        wx.stopPullDownRefresh({
-          success: () => {
-            console.log('stopPullDownRefresh')
-          }
-        });
       }
     })
   },
@@ -381,6 +374,7 @@ Page({
       duration: 600,
       timingFunction: 'ease',
     })
+    // 获取系统信息算出像素比
     wx.getSystemInfo({
       success: res => {
         this.setData({
@@ -388,6 +382,7 @@ Page({
         })
       }
     })
+    // 获取绝对定位的高度
     wx.createSelectorQuery().select('.choose-area').boundingClientRect((rect) => {
       this.setData({
         fixTop: rect.top,

+ 23 - 21
pages/index/index.wxml

@@ -51,31 +51,33 @@
 
   <!-- 需求列表开始 -->
   <view class="list {{fixTop < scrollTop?'margin':''}} ">
-
-    <view class="list-item" wx:for='{{list}}' wx:key='{{index}}' data-id="{{item.id}}" bindtap="toDetail">
-      <view class="top">
-        <text class="name">{{item.name}}</text>
-        <text class="payment">
+    <block wx:for='{{list}}' wx:key='{{index}}'>
+      <view class="list-item" wx:for='{{item}}' wx:key='{{index}}' data-id="{{item.id}}" bindtap="toDetail">
+        <view class="top">
+          <text class="name">{{item.name}}</text>
+          <text class="payment">
           <text>{{item.price}}元*</text>
-        <text wx:if='{{item.settlementMethod===1 }}'>{{item.stage || 0}}期</text>
-        <text wx:if='{{item.settlementMethod===0 }}'>1次</text>
-        </text>
-      </view>
-      <view class="midden">
-        <text class="company">{{item.companyName}}</text>
-        <text class="time">{{tool.formatTime(item.createTime,'.','',true)}}</text>
-      </view>
-      <view class="bottom">
-        <view class="bottom-item">
-          <image src="/images/icon/address.png"></image>
-          <text>{{item.provinceCityCountry}}</text>
+          <text wx:if='{{item.settlementMethod===1 }}'>{{item.stage || 0}}期</text>
+          <text wx:if='{{item.settlementMethod===0 }}'>1次</text>
+          </text>
+        </view>
+        <view class="midden">
+          <text class="company">{{item.companyName}}</text>
+          <text class="time">{{tool.formatTime(item.createTime,'.','',true)}}</text>
         </view>
-        <view class="bottom-item">
-          <image src="/images/icon/job.png"></image>
-          <text>任务数:{{item.number || '若干'}}</text>
+        <view class="bottom">
+          <view class="bottom-item">
+            <image src="/images/icon/address.png"></image>
+            <text>{{item.provinceCityCountry}}</text>
+          </view>
+          <view class="bottom-item">
+            <image src="/images/icon/job.png"></image>
+            <text>任务数:{{item.number || '若干'}}</text>
+          </view>
         </view>
       </view>
-    </view>
+    </block>
+
     <view class="offline" wx:if='{{offline}}'>
       <view class="offline-content">
         <image src="/images/icon/offline.png"></image>

+ 2 - 2
pages/login/login.js

@@ -82,7 +82,7 @@ Page({
               }
             })
           }
-        }, false)
+        })
       } else {
         wx.showToast({
           icon: 'none',
@@ -178,7 +178,7 @@ Page({
             })
           }
         }
-      }, false)
+      })
     } else {
       wx.showModal({
         title: '登录失败',

+ 1 - 4
pages/my-apply/my-apply.js

@@ -41,15 +41,12 @@ Page({
           } else {
             pageNo++;
             this.setData({
-              list: [...this.data.list, ...res.data.enrollmentsList],
+              [`list[${pageNo - 2}]`]: res.data.enrollmentsList,
               isLast: res.data.isLast,
               pageNo
             })
           }
         }
-      },
-      complete: () => {
-        wx.stopPullDownRefresh();
       }
     })
   },

+ 25 - 21
pages/my-apply/my-apply.wxml

@@ -2,30 +2,34 @@
 <wxs src="my-apply.wxs" module="tool" />
 <wxs src="../../app.wxs" module="getPriceForm" />
 <view class="container">
-  <view class="cell" data-id="{{item.hwRequirement.id}}" bindtap="toDetail" wx:for='{{list}}' wx:key='{{index}}'>
-    <view class="info">
-      <view class="name">{{item.hwRequirement.name}}</view>
-      <view class="money">
-        <text>{{item.hwRequirement.price}}元</text>
-        <text class="month" wx:if='{{item.hwRequirement.settlementMethod===1 }}'>*{{item.hwRequirement.stage}}期</text>
-        <text class="month" wx:if='{{item.hwRequirement.settlementMethod===0 }}'>*1次</text>
+  <block wx:for='{{list}}' wx:key='{{index}}'>
+    <view class="cell" data-id="{{item.hwRequirement.id}}" bindtap="toDetail" wx:for='{{item}}' wx:key='{{index}}'>
+      <view class="info">
+        <view class="name">{{item.hwRequirement.name}}</view>
+        <view class="money">
+          <text>{{item.hwRequirement.price}}元</text>
+          <text class="month" wx:if='{{item.hwRequirement.settlementMethod===1 }}'>*{{item.hwRequirement.stage}}期</text>
+          <text class="month" wx:if='{{item.hwRequirement.settlementMethod===0 }}'>*1次</text>
+        </view>
       </view>
-    </view>
-    <view class="midden">
-      <view class="company">
-        <text>{{item.companyName}}</text>
-      </view>
-    </view>
-    <view class="bottom">
-      <view class="address">
-        <image src="/images/icon/address.png"></image>
-        <text>{{item.hwRequirement.provinceCityCountry || '暂无地址信息'}}</text>
+      <view class="midden">
+        <view class="company">
+          <text>{{item.companyName}}</text>
+        </view>
       </view>
-      <view class="status {{tool.status(item.orderNumber,item.hwRequirement.isOn).className}}">
-        <image src="{{tool.status(item.orderNumber,item.hwRequirement.isOn).src}}"></image>
-        <text>{{tool.status(item.orderNumber,item.hwRequirement.isOn).word}}</text>
+      <view class="bottom">
+        <view class="address">
+          <image src="/images/icon/address.png"></image>
+          <text>{{item.hwRequirement.provinceCityCountry || '暂无地址信息'}}</text>
+        </view>
+        <view class="status {{tool.status(item.orderNumber,item.hwRequirement.isOn).className}}">
+          <image src="{{tool.status(item.orderNumber,item.hwRequirement.isOn).src}}"></image>
+          <text>{{tool.status(item.orderNumber,item.hwRequirement.isOn).word}}</text>
+        </view>
       </view>
     </view>
-  </view>
+
+  </block>
+
   <empty message='您目前没有需要发布人确认的报名' wx:if='{{show}}' />
 </view>

+ 45 - 30
pages/my-order/my-order.js

@@ -48,30 +48,48 @@ Page({
   confirm(e) {
     const id = e.currentTarget.dataset.id;
     const index = e.currentTarget.dataset.index;
-    wx.kx_request({
-      url: wx.kx_api.hwOrder.confirmOrder,
-      type: 'post',
-      data: {
-        orderId: id
-      },
-      success: res => {
-        if (res.errcode === 0) {
-          wx.showToast({
-            title: '订单已确认',
-            success: res => {
-              // 确认成功  更改页面订单状态
-              // const list = this.data.list;
-              // list[index].status = 2;
-              // list[index].serviceStage = 1;
-              this.setData({
-                [`list[${index}].status`]: 2,
-                [`list[${index}].serviceStage`]: 2,
-              })
-            }
-          })
+    const contracttype = e.currentTarget.dataset.contracttype;
+    const parentindex = e.currentTarget.dataset.parentindex;
+    if (contracttype === 2) {
+      wx.kx_request({
+        url: wx.kx_api.hwOrder.confirmECOrders,
+        type: 'post',
+        data: {
+          orderId: id
+        },
+        success: res => {
+          if (res.errcode === 0) {
+            wx.navigateTo({
+              url: `/pages/web-view/web-view?url=${res.data.url}`,
+            })
+          }
         }
-      }
-    })
+      })
+    }
+
+    if (contracttype === 1) {
+      wx.kx_request({
+        url: wx.kx_api.hwOrder.confirmOrder,
+        type: 'post',
+        data: {
+          orderId: id
+        },
+        success: res => {
+          if (res.errcode === 0) {
+            wx.showToast({
+              title: '订单已确认',
+              success: res => {
+                // 确认成功  更改页面订单状态
+                this.setData({
+                  [`list[${parentindex}][${index}].status`]: 2,
+                  [`list[${parentindex}][${index}].serviceStage`]: 2,
+                })
+              }
+            })
+          }
+        }
+      })
+    }
   },
   /**
    * 获取订单列表
@@ -94,15 +112,12 @@ Page({
           } else {
             pageNo++;
             this.setData({
-              list: [...this.data.list, ...res.data.hwOrderList],
+              [`list[${pageNo - 2}]`]: res.data.hwOrderList,
               isLast: res.data.isLast,
               pageNo
             })
           }
         }
-      },
-      complete: () => {
-        wx.stopPullDownRefresh();
       }
     })
   },
@@ -110,8 +125,7 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad: function(options) {
-    // 获取订单列表
-    this.getList()
+
   },
 
   /**
@@ -125,7 +139,8 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function() {
-
+    // 获取订单列表
+    this.getList()
   },
 
   /**

+ 27 - 23
pages/my-order/my-order.wxml

@@ -3,32 +3,36 @@
 <wxs src="../../app.wxs" module="getPriceForm" />
 
 <view class="container">
-  <!-- close 根据状态添加 -->
-  <view class="cell" data-id="{{item.id}}" data-status="{{item.status}}" bindtap="toDetail" wx:for='{{list}}' wx:key='{{index}}'>
-    <view class="title">
-      <view class="order-num">{{item.orderNumber}} ></view>
-      <text class="status">{{tool.status(item.status,item.serviceStage)}}</text>
-    </view>
-    <view class="content">
-      <view class="info">
-        <view class="name {{(item.status === 1||item.status === 3)&&'close'}}">{{item.hwRequirement.name}}</view>
-        <view class="money {{(item.status === 1||item.status === 3)&&'close'}}">
-          <text>{{item.hwRequirement.price}}元</text>
-          <text class="month" wx:if='{{item.hwRequirement.settlementMethod===1 }}'>*{{item.hwRequirement.stage}}期</text>
-          <text class="month" wx:if='{{item.hwRequirement.settlementMethod===0 }}'>*1次</text>
-        </view>
+
+  <block wx:for='{{list}}' wx:for-index='key' wx:key='{{index}}'>
+
+    <view class="cell" data-id="{{item.id}}" data-status="{{item.status}}" bindtap="toDetail" wx:for='{{item}}' wx:key='{{index}}'>
+      <view class="title">
+        <view class="order-num">{{item.orderNumber}} ></view>
+        <text class="status">{{tool.status(item.status,item.serviceStage)}}</text>
       </view>
-      <view class="address">
-        <view class="address-content">
-          <image src="/images/icon/address.png"></image>
-          <text>{{item.hwRequirement.provinceCityCountry || '暂无地址信息'}}</text>
+      <view class="content">
+        <view class="info">
+          <view class="name {{(item.status === 1||item.status === 3)&&'close'}}">{{item.hwRequirement.name}}</view>
+          <view class="money {{(item.status === 1||item.status === 3)&&'close'}}">
+            <text>{{item.hwRequirement.price}}元</text>
+            <text class="month" wx:if='{{item.hwRequirement.settlementMethod===1 }}'>*{{item.hwRequirement.stage}}期</text>
+            <text class="month" wx:if='{{item.hwRequirement.settlementMethod===0 }}'>*1次</text>
+          </view>
+        </view>
+        <view class="address">
+          <view class="address-content">
+            <image src="/images/icon/address.png"></image>
+            <text>{{item.hwRequirement.provinceCityCountry || '暂无地址信息'}}</text>
+          </view>
         </view>
       </view>
+      <!-- wx:if='{{item.status === 0}}' -->
+      <view class="action" >
+        <view class="contract" wx:if='{{item.workContract}}' data-contract="{{item.workContract}}" catchtap="checkContract">查看合同</view>
+        <view class="order" data-id="{{item.id}}" data-parentIndex="{{key}}" data-index="{{index}}" data-contractType="{{item.contractType}}" catchtap="confirm">确认订单</view>
+      </view>
     </view>
-    <view class="action" wx:if='{{item.status === 0}}'>
-      <view class="contract" wx:if='{{item.workContract}}' data-contract="{{item.workContract}}" catchtap="checkContract">查看合同</view>
-      <view class="order" data-id="{{item.id}}" data-index="{{index}}" data-contractType="{{item.contractType}}" catchtap="confirm">确认订单</view>
-    </view>
-  </view>
+  </block>
   <empty message='您目前没有正在进行中的订单' wx:if='{{show}}' />
 </view>

+ 1 - 4
pages/payment-records/payment-records.js

@@ -31,15 +31,12 @@ Page({
           } else {
             pageNo++;
             this.setData({
-              list: [...this.data.list, ...res.data.hwPaymentDetailList],
+              [`list[${pageNo - 2}]`]: res.data.hwPaymentDetailList,
               isLast: res.data.isLast,
               pageNo
             })
           }
         }
-      },
-      complete: () => {
-        wx.stopPullDownRefresh();
       }
     })
   },

+ 12 - 10
pages/payment-records/payment-records.wxml

@@ -1,17 +1,19 @@
 <!--pages/payment-records/payment-records.wxml-->
 <wxs src="../../app.wxs" module='tool' />
 <view class="container">
+  <block wx:for='{{list}}' wx:key='index'>
+    <navigator url="/pages/payment-records-detail/payment-records-detail?id={{item.id}}" class="cell" hover-class="none" wx:for='{{item}}' wx:key='{{index}}'>
+      <view class="left">
+        <text class="order-nums">{{item.orderNumber}}</text>
+        <text class="time">{{item.createTime}}</text>
+      </view>
+      <view class="right">
+        <text>¥{{tool.formatMoney(item.netPayment)}}</text>
+        <text class="time">已扣税额:¥{{tool.formatMoney(item.taxFee)}}</text>
+      </view>
+    </navigator>
+  </block>
 
-  <navigator url="/pages/payment-records-detail/payment-records-detail?id={{item.id}}" class="cell" hover-class="none" wx:for='{{list}}' wx:key='{{index}}'>
-    <view class="left">
-      <text class="order-nums">{{item.orderNumber}}</text>
-      <text class="time">{{item.createTime}}</text>
-    </view>
-    <view class="right">
-      <text>¥{{tool.formatMoney(item.netPayment)}}</text>
-      <text class="time">已扣税额:¥{{tool.formatMoney(item.taxFee)}}</text>
-    </view>
-  </navigator>
 
   <view class="hint" hidden="{{!isLast}}">没有更多了</view>
 </view>

+ 3 - 1
pages/person/person.js

@@ -63,7 +63,9 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow: function() {
-
+    this.setData({
+      userinfo: wx.getStorageSync('userinfo')
+    })
   },
 
   /**

+ 5 - 1
pages/userinfo/userinfo.js

@@ -16,7 +16,11 @@ Page({
   changeAvatar() {
     wx.chooseImage({
       success: (res) => {
-        app.utils.upLoadImage(res.tempFilePaths, 'licenseFront').then((data) => {
+        app.utils.upLoadImage({
+          files: res.tempFilePaths,
+          name: 'licenseFront',
+          url: wx.kx_api.hwUser.changeAvatar
+        }).then((data) => {
           wx.setStorageSync('userinfo', data[0].hwUser);
           this.setData({
             userinfo: data[0].hwUser

+ 63 - 0
pages/web-view/web-view.js

@@ -0,0 +1,63 @@
+// pages/web-view/web-view.js
+Page({
+
+  /**
+   * 页面的初始数据
+   */
+  data: {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面加载
+   */
+  onLoad: function(options) {
+    if (options.url) {
+      this.setData({
+        url: decodeURIComponent(options.url)
+      })
+    }
+  },
+
+  /**
+   * 生命周期函数--监听页面初次渲染完成
+   */
+  onReady: function() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面显示
+   */
+  onShow: function() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面隐藏
+   */
+  onHide: function() {
+
+  },
+
+  /**
+   * 生命周期函数--监听页面卸载
+   */
+  onUnload: function() {
+
+  },
+
+  /**
+   * 页面相关事件处理函数--监听用户下拉动作
+   */
+  onPullDownRefresh: function() {
+
+  },
+
+  /**
+   * 页面上拉触底事件的处理函数
+   */
+  onReachBottom: function() {
+
+  }
+})

+ 3 - 0
pages/web-view/web-view.json

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

+ 2 - 0
pages/web-view/web-view.wxml

@@ -0,0 +1,2 @@
+<!--pages/web-view/web-view.wxml-->
+<web-view src='{{url}}'></web-view>

+ 1 - 0
pages/web-view/web-view.wxss

@@ -0,0 +1 @@
+/* pages/web-view/web-view.wxss */

+ 8 - 1
project.config.json

@@ -23,7 +23,7 @@
 		}
 	},
 	"compileType": "miniprogram",
-	"libVersion": "2.8.3",
+	"libVersion": "2.8.2",
 	"appid": "wx997164f2857c1a1d",
 	"projectname": "Mina_B",
 	"debugOptions": {
@@ -146,6 +146,13 @@
 					"pathName": "pages/service_agreement/service_agreement",
 					"query": "",
 					"scene": null
+				},
+				{
+					"id": 13,
+					"name": "pages/web-view/web-view",
+					"pathName": "pages/web-view/web-view",
+					"query": "",
+					"scene": null
 				}
 			]
 		}

+ 2 - 1
utils/api.js

@@ -8,13 +8,14 @@ module.exports = {
   },
   hwUser: {
     getHwUserInfo: '/api/hwUser/getHwUserInfo', //获取个人信息
-    changeAvatar: apiUrl + '/api/hwUser/changeAvatar', //更改头像
+    changeAvatar:  '/api/hwUser/changeAvatar', //更改头像
     banner: '/api/hwUser/banner', //获取首页banner
   },
   hwOrder: {
     getOrders: '/api/hwOrder/getOrders', //获取订单列表
     getOrderDetail: '/api/hwOrder/getOrderDetail', //获取订单详情
     confirmOrder: '/api/hwOrder/confirmOrder', //确认订单
+    confirmECOrders: "/api/hwOrder/confirmECOrders", //电子合同确认订单
   },
   hwRequirement: {
     getRequirements: '/api/hwRequirement/getRequirements', //需求列表

+ 9 - 0
utils/config_api.js

@@ -0,0 +1,9 @@
+module.exports = {
+  dont_login: [
+    '/api/hwuser/getAuthCode', //获取验证码
+    '/api/hwuser/phoneLogin', //手机号登陆
+  ],
+  no_openid: [
+    '/api/hwUser/banner'
+  ]
+}

+ 1 - 1
utils/proxy.js

@@ -125,7 +125,7 @@ class MyProxy {
     }
   }
   /**
-   * 
+   * 组件Behavior方法 需自行引入组件的behaviors
    */
   $_behavior() {
     return Behavior({

+ 177 - 88
utils/util.js

@@ -1,10 +1,14 @@
-const api = require('./api.js')
+const api = require('./api.js');
+const dont_login_api = require('./config_api.js').dont_login;
+const no_openid_api = require('./config_api.js').no_openid;
 class Utils {
   /**
    * @that  {OBject} 挂载对象
    */
   constructor(that) {
     this.api = api;
+    this._showModel = false;
+    this._loading = false;
     // this.message_hint = {
     //   100: '继续发送请求'
     // };
@@ -68,26 +72,34 @@ class Utils {
     @options {Object} request请求的参数
     @return 返回获取到的openID加入options并返回
   */
-  getOpenid(options) {
+  getOpenid() {
     return new Promise((resolve, reject) => {
-      wx.login({
-        success: (res) => {
-          let code = res.code;
-          this.request({
-            code,
-            success: res => {
-              wx.setStorage({
-                key: 'openid',
-                data: res.data.openid,
-                success: res => {
-                  options.openid = res.data.openid
-                  resolve(options);
-                }
-              })
-            }
-          })
-        }
-      })
+      const _openid = wx.getStorageSync('openid');
+      if (_openid) {
+        resolve(_openid);
+      } else {
+        wx.login({
+          success: (res) => {
+            const code = res.code;
+            this.request({
+              // url:'',
+              data: {
+                code,
+              },
+              success: res => {
+                wx.setStorage({
+                  key: 'openid',
+                  data: res.data.openid,
+                  success: res => {
+                    const openid = res.data.openid
+                    resolve(openid);
+                  }
+                })
+              }
+            })
+          }
+        })
+      }
     })
   }
 
@@ -98,36 +110,78 @@ class Utils {
    * 设置request参数中的userID和usertoken
    */
   getUserId(options) {
-    const userid = wx.getStorageSync('userid');
-    const usertoken = wx.getStorageSync('usertoken');
-    options.data.user_id = userid;
-    options.data.user_token = usertoken;
-    return options
+    return new Promise((reslove, reject) => {
+      const userid = wx.getStorageSync('userid');
+      const usertoken = wx.getStorageSync('usertoken');
+      options.data.user_id = userid;
+      options.data.user_token = usertoken;
+      reslove(options)
+    })
   }
+  /**
+   * 获取网络状态
+   */
+  getNetworkType() {
+    return new Promise((reslove, reject) => {
+      wx.getNetworkType({
+        success: function(res) {
+          if (res.networkType === 'none') {
+            reslove('offline')
+          } else {
+            reslove(res.networkType)
+          }
+        },
+        fail: function(res) {
+          reject('fail')
+        }
+      })
+    })
 
+  }
   /* 
     请求方法
     @options 请求参数
     @status 是否携带userID
   */
-  request(options, status = true) {
-
-    /* 判断是否传入参数 */
-    options.data = options.data ? options.data : {};
-
-    /* 设置请求方式 */
-    options.method = (options.type ? options.type : 'get').toUpperCase();
-
+  async request(options) {
     /* 拼接接口地址 */
     if (this.getDataType(options.url) !== 'String') {
       throw new Error('接口路径格式错误')
     }
+
+    /*判断是否需要登陆才能调用api */
+    options.dont_login = false; //默认全部需要登录
+    if (dont_login_api.length && dont_login_api.includes(options.url)) {
+      options.dont_login = true;
+    }
+
+    /**判断是否需要openid才能调用api */
+    options.no_openid = false; //默认全部需要
+    if (no_openid_api.length && no_openid_api.includes(options.url)) {
+      options.no_openid = true;
+    }
+
     /* 设置URL */
     options.url = this.getUrl(options.url);
 
+    /* 判断是否传入参数 */
+    options.data = options.data ? options.data : {};
+
+    /* 设置请求方式并转换为大写*/
+    options.method = (options.type ? options.type : 'get').toUpperCase();
+
+    /* 判断是否传入请求头 */
+    options.header = options.header || {};
+
+    /* 判断是否传入返回数据格式 */
+    options.dataType = options.dataType || 'json';
+
+    /* 判断是否传入响应数据格式 */
+    options.responseType = options.responseType || 'text';
+
     /* 消除空值字段 */
     // for (let key in options.data) {
-    //   if (options.data[key] === undefined || options.data[key] === '') {
+    //   if (!options.data[key] && options.data[key] !== 0) {
     //     delete options.data[key]
     //   }
     // }
@@ -136,41 +190,37 @@ class Utils {
      * 检测网络状况 并判断是否发起请求
      * 当无网络时传入 offline 并提示无网络
      */
-    wx.getNetworkType({
-      success: (res) => {
-        const networkType = res.networkType
-        if (networkType === 'none') {
-          wx.showToast({
-            icon: 'none',
-            title: '网络未连接',
-          })
-          wx.$emit('offline', true)
-          options.success && options.success('offline')
-          return
-        }
-        /* 根据需要判断是否传入openID */
-        if (status) {
-          /* 获取openID并将入参数 */
-          // const openid = wx.getStorageSync('openid');
-          // if (openid) {
-          //   _options.openid = openid;
-          //   this._request(_options);
-          // } else {
-          //   this.getOpenid(_options).then((data) => {
-          //     this._request(data);
-          //   });
-          // }
-          /* 设置userID和usertoken */
-          let _options = this.getUserId(options);
-          this._request(_options);
+    const networkType = await this.getNetworkType();
+    if (networkType === 'offline') {
+      wx.showToast({
+        icon: 'none',
+        title: '网络未连接',
+      })
+      wx.$emit('offline', true)
+      options.success && options.success(networkType)
+      return this.getNetworkType()
+    } else {
+      /**根据判断写入openid */
+      // if (!options.no_openid) {
+      //   options.data.openid = await this.getOpenid();
+      // }
+      /* 根据dont_login判断是否需要登录 */
+      if (options.dont_login) {
+        return this._request(options);
+      } else {
+        /* 设置userID和usertoken */
+        let _options = await this.getUserId(options);
+        /** 当user_id与user_token不全时 提示登陆重新获取 */
+        if (_options.data.user_id && _options.data.user_token) {
+          return this._request(_options);
         } else {
-          this._request(options);
+          this._doLogin();
         }
       }
-    })
+    }
   }
   /**
-   *  实际执行的请求方法体
+   * 实际执行的请求方法体
    * @opt  传入的参数对象
    * @return 返回promise对象
    * 执行完之后既能执行回调也能返回promise对象调用
@@ -178,22 +228,21 @@ class Utils {
   _request(opt) {
     let route = getCurrentPages();
     return new Promise((resolve, reject) => {
-      !wx.kx_loading && wx.showLoading({
+      !this._loading && wx.showLoading({
         mask: true,
+        title: '加载中...',
         success: () => {
-          wx.kx_loading = true
+          this._loading = true
         }
       })
       wx.request({
         url: opt.url,
-        data: opt.data || {},
-        header: opt.header || {},
+        data: opt.data,
+        header: opt.header,
         method: opt.method,
-        dataType: opt.dataType || 'json',
-        responseType: opt.responseType || 'text',
+        dataType: opt.dataType,
+        responseType: opt.responseType,
         success: function(res) {
-          console.log('请求参数=>', opt);
-          console.log('服务器响应结果=>', res.statusCode, res.data);
           // 设置网络状态
           wx.$emit('offline', false)
           // 判断是否含有成功方法并执行
@@ -240,14 +289,24 @@ class Utils {
             })
           }
         },
-        complete: function(res) {
+        complete: (res) => {
+          console.log('请求参数=>', opt);
+          console.log('请求结果=>', res.data.errmsg, res.data);
+          console.log('服务器响应状态=>', res.statusCode);
+          console.log('服务器响应结果=>', res);
+          console.log('当前页面=>', route[route.length - 1].route);
+          console.log(' ');
           wx.hideLoading({
             success: () => {
-              wx.kx_loading = false;
+              this._loading = false;
             }
           })
-          console.log('当前页面=>', route[route.length - 1].route);
-          console.log('请求结果=>', res.data.errmsg || res.data);
+          wx.stopPullDownRefresh({
+            success: () => {
+              console.log(route[route.length - 1].route, '=> stopPullDownRefresh')
+            }
+          });
+
           // 判断是否含有complete方法并执行
           if (opt.complete && typeof opt.complete === 'function') {
             opt.complete(res.data);
@@ -258,31 +317,61 @@ class Utils {
     })
   }
   /**
+   * 执行跳转登录页面操作
+   */
+  _doLogin() {
+    // wx.clearStorageSync();
+    if (!this._showModel) {
+      this._showModel = true;
+      wx.reLaunch({
+        url: '/pages/login/login',
+        success: () => {
+          setTimeout(() => {
+            wx.showModal({
+              title: '提示',
+              content: '登陆状态失效,请重新登录',
+              showCancel: false,
+              success: () => {
+                this._showModel = false;
+              }
+            })
+          }, 300)
+        }
+      })
+    }
+  }
+
+  /**
    * 上传图片
    * @pic_arr {Array} 图片数组 
    * @return {Array} 
    */
-  upLoadImage(pic_arr, name) {
-    let _type = this.getDataType(pic_arr);
+  upLoadImage(options) {
+    const _type = this.getDataType(options.files);
+    options.formData = options.formData || {};
+    const formData = {
+      user_id: wx.getStorageSync('userid'),
+      user_token: wx.getStorageSync('usertoken'),
+      ...options.formData
+    }
     return new Promise((reslove, reject) => {
       if (_type === "Array") {
-        let _arr = [];
-        let _len = pic_arr.length;
-        pic_arr.forEach((val, key) => {
+        const _arr = [];
+        const _files = options.files;
+        const _len = _files.length - 1;
+        const _url = this.getUrl(options.url);
+        _files.forEach((val, key) => {
           wx.uploadFile({
-            url: wx.kx_api.hwUser.changeAvatar,
+            url: _url,
             filePath: val,
-            name,
-            formData: {
-              user_id: wx.getStorageSync('userid'),
-              user_token: wx.getStorageSync('usertoken'),
-            },
+            name: options.name,
+            formData,
             success: res => {
               if (res.statusCode === 200) {
                 const data = JSON.parse(res.data);
                 if (data.errcode === 0) {
                   _arr.push(data.data);
-                  if (_len - 1 === key) {
+                  if (_len === key) {
                     reslove(_arr)
                   }
                 }