confirm_order.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. var initNum = 7; //倒计时数
  2. var spaceNum = 1000; //文字倒计时间隔
  3. var space = 1000; //环倒计时间隔
  4. var begin = -(1 / 2 * Math.PI);
  5. var pai2 = 2 * Math.PI;
  6. var app = getApp();
  7. import {
  8. BluetoothManager,
  9. BtErrorCode,
  10. CMD
  11. } from '../../service/BluWkm'
  12. const bluM = new BluetoothManager;
  13. const util = require('../../utils/utils.js')
  14. Page({
  15. data: {
  16. progress_txt: 60,
  17. count:0, // 设置 计数器 初始为0
  18. countTimer: null, // 设置 定时器 初始为null
  19. money:[],
  20. request_data:[],
  21. notice:false,
  22. order:'',
  23. screenHeight:''
  24. },
  25. closeLock: function (data) {
  26. var that = this;
  27. bluM.connectDeivece(that.data.box_no,CMD.lock)
  28. app.request('/bike/close-lock', data, 'POST').then(res => {
  29. console.log(res)
  30. if (res.statusCode == 200) {
  31. wx.reLaunch({
  32. url: '../payment/payment?order=' + res.data.no
  33. })
  34. } else if (res.statusCode == 450) {
  35. // that.coundDown()
  36. }
  37. }).catch(err => {
  38. console.log(err)
  39. })
  40. },
  41. rent_closeLock: function(data) {
  42. var that = this;
  43. bluM.connectDeivece(that.data.box_no,CMD.lock)
  44. app.request('/rent/close-order', data, 'POST').then(res => {
  45. console.log(res)
  46. if (res.statusCode == 200) {
  47. wx.reLaunch({
  48. url: '../payment/payment?order=' + res.data.no + '&rent=rent'
  49. })
  50. } else if (res.statusCode == 450) {
  51. that.coundDown()
  52. }
  53. }).catch(err => {
  54. console.log(err)
  55. })
  56. },
  57. onLoad: function (options) {
  58. console.log(options)
  59. wx.setNavigationBarTitle({
  60. title: app.globalData.title
  61. })
  62. this.setData({
  63. screenHeight: app.globalData.screenHeight
  64. })
  65. wx.showLoading({
  66. title: '加载中...'
  67. })
  68. var data = {
  69. bike_no: options.bike_no,
  70. order_no: options.order_no,
  71. lat: options.lat,
  72. lng: options.lng
  73. }
  74. this.setData({request_data:data,order:options.order})
  75. if(options.order=='order'){
  76. app.request('/order/expect-order-money', data, 'POST').then(res => {
  77. console.log(res)
  78. if (res.statusCode == 200) {
  79. wx.hideLoading()
  80. this.setData({money:res.data})
  81. }
  82. })
  83. }else{
  84. app.request('/rent/expect-rent-order-money', data, 'POST').then(res => {
  85. console.log(res)
  86. if (res.statusCode == 200) {
  87. wx.hideLoading()
  88. this.setData({money:res.data})
  89. }
  90. })
  91. }
  92. },
  93. notice:function(){
  94. this.setData({notice:true})
  95. },
  96. notice_false:function(){
  97. this.setData({notice:false})
  98. },
  99. kefu:function(){
  100. wx.makePhoneCall({
  101. phoneNumber: wx.getStorageSync('home').customer_service_phone,
  102. })
  103. },
  104. close_bike:function(){
  105. if(this.data.order=='rent'){
  106. console.log('rent')
  107. this.rent_closeLock(this.data.request_data)
  108. }else{
  109. this.closeLock(this.data.request_data)
  110. }
  111. },
  112. onReady: function () {
  113. this.drawCircle(60 / (60/2))
  114. this.drawProgressbg();
  115. this.countInterval()
  116. },
  117. drawProgressbg: function(){
  118. // 使用 wx.createContext 获取绘图上下文 context
  119. var ctx = wx.createCanvasContext('canvasProgressbg')
  120. ctx.setLineWidth(6);// 设置圆环的宽度
  121. ctx.setStrokeStyle('#cccccc'); // 设置圆环的颜色
  122. ctx.setLineCap('round') // 设置圆环端点的形状
  123. ctx.beginPath();//开始一个新的路径
  124. ctx.arc(55, 55, 50, -Math.PI / 2, 60, false);
  125. //设置一个原点(100,100),半径为90的圆的路径到当前路径
  126. ctx.stroke();//对当前路径进行描边
  127. ctx.draw();
  128. },
  129. drawCircle: function (step){
  130. var context = wx.createCanvasContext('canvasProgress');
  131. // 设置渐变
  132. var gradient = context.createLinearGradient(100, 50, 50, 100);
  133. context.setStrokeStyle("#F95A29");
  134. context.setLineWidth(6);
  135. // context.setStrokeStyle(gradient);
  136. context.setLineCap('round')
  137. context.beginPath();
  138. // 参数step 为绘制的圆环周长,从0到2为一周 。 -Math.PI / 2 将起始角设在12点钟位置 ,结束角 通过改变 step 的值确定
  139. context.arc(55, 55, 50, -Math.PI / 2, step * Math.PI - Math.PI / 2, false);
  140. context.stroke();
  141. context.draw()
  142. // this.drawCircle(60 / (60/2))
  143. },
  144. countInterval: function () {
  145. // 设置倒计时 定时器 每100毫秒执行一次,计数器count+1 ,耗时6秒绘一圈
  146. this.countTimer = setInterval(() => {
  147. if (this.data.count <= 60) {
  148. /* 绘制彩色圆环进度条
  149. 注意此处 传参 step 取值范围是0到2,
  150. 所以 计数器 最大值 60 对应 2 做处理,计数器count=60的时候step=2
  151. */
  152. var time = this.data.progress_txt-1
  153. this.drawCircle(time / (60/2))
  154. this.data.count++;
  155. if(time<=0){
  156. clearInterval(this.countTimer);
  157. time = 0;
  158. wx.navigateBack()
  159. }
  160. this.setData({
  161. progress_txt: time
  162. });
  163. } else {
  164. clearInterval(this.countTimer);
  165. }
  166. }, 1000)
  167. },
  168. parkTip: function () {
  169. wx.navigateTo({
  170. url: '/pages/navigation/navigation',
  171. })
  172. },
  173. continue:function(){
  174. clearInterval(this.countTimer);
  175. wx.navigateBack()
  176. },
  177. onShow: function () {
  178. },
  179. onHide: function () {
  180. // clearInterval(this.countTimer);
  181. },
  182. onUnload: function () {
  183. clearInterval(this.countTimer);
  184. },
  185. onPullDownRefresh: function () {
  186. },
  187. onReachBottom: function () {
  188. },
  189. onShareAppMessage: function () {
  190. }
  191. })