confirm_order.js 6.1 KB

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