index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. const Parse = getApp().Parse;
  2. const company = getApp().globalData.company
  3. const dateF = require('../../../../../utils/date')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. id: "",
  10. orderTime: null,
  11. Time: null,
  12. day: null,
  13. order: null,
  14. time: null,
  15. show: false,
  16. qrcode: null,
  17. latitude: null,
  18. longitude: null,
  19. activeColor:""
  20. },
  21. async getQRCode(id) {
  22. let qrCodeUrl = `https://pwa.fmode.cn//gomini/rid=${id}`
  23. let that = this
  24. await wx.request({
  25. url: "https://server.fmode.cn/api/common/qrcode",
  26. data: {
  27. qrCode: qrCodeUrl,
  28. darkColor: "#000",
  29. lightColor: "#ffffff"
  30. },
  31. success(res) {
  32. console.log(res);
  33. if (res.data.code == 1) {
  34. //把base64文件转图片
  35. let fileSystemManager = wx.getFileSystemManager()
  36. fileSystemManager.writeFile({
  37. filePath: wx.env.USER_DATA_PATH + '/qr_code.png',
  38. data: res.data.data.slice(22),
  39. encoding: 'base64',
  40. success: res => {
  41. that.setData({
  42. qrcode: wx.env.USER_DATA_PATH + '/qr_code.png'
  43. })
  44. console.log(that.data.qrcode)
  45. },
  46. fail(e) {
  47. console.log('文件保存失败', e)
  48. }
  49. })
  50. } else {
  51. wx.showToast({
  52. title: '请先删除小程序重新授权后重试',
  53. icon: 'none'
  54. })
  55. }
  56. },
  57. });
  58. },
  59. shopadmin() {
  60. let id = this.data.id
  61. console.log(id);
  62. wx.navigateTo({
  63. url: '/nova-tourism/pages/shop-admin/index?id=' + id
  64. });
  65. },
  66. storepackage() {
  67. this.setData({
  68. show: true,
  69. })
  70. },
  71. async acceptResult(e) {
  72. let {
  73. order,
  74. } = this.data
  75. let that = this
  76. let {
  77. params,
  78. no
  79. } = e.detail;
  80. that.setData({
  81. show: false
  82. })
  83. try {
  84. if (params == "ok") {
  85. order.set("isPay", true)
  86. await order.save()
  87. this.setData({
  88. isPay: true
  89. })
  90. wx.showToast({
  91. title: '支付成功',
  92. icon: 'none',
  93. image: '',
  94. duration: 1500,
  95. mask: false,
  96. });
  97. } else {
  98. wx.showToast({
  99. title: '支付失败,取消订单',
  100. icon: 'none',
  101. image: '',
  102. duration: 1500,
  103. mask: false,
  104. });
  105. }
  106. } catch (error) {
  107. console.log(error)
  108. wx.showToast({
  109. title: "支付失败",
  110. icon: "error",
  111. duration: 1500,
  112. });
  113. wx.hideLoading()
  114. }
  115. },
  116. taxi() {
  117. let latitude = this.data.shopOrder.shopStore.location.latitude;
  118. let longitude = this.data.shopOrder.shopStore.location.longitude;
  119. console.log(latitude, longitude);
  120. wx.getLocation({
  121. type: 'gcj02', //返回可以用于wx.openLocation的经纬度
  122. success() {
  123. wx.openLocation({
  124. latitude,
  125. longitude,
  126. scale: 18
  127. })
  128. }
  129. })
  130. },
  131. phone() {
  132. let phone = this.data.order.shopStore.mobile
  133. console.log(phone);
  134. wx.makePhoneCall({
  135. phoneNumber: phone
  136. })
  137. },
  138. async getShopOrder() {
  139. let id = this.data.id
  140. console.log(id);
  141. let ShopOrder = new Parse.Query('RoomOrder')
  142. ShopOrder.include('room')
  143. let shopOrder = await ShopOrder.get(id)
  144. let orderTime = dateF.formatTime("mm-dd", shopOrder.toJSON().startTime.iso)
  145. let time = dateF.formatTime("mm-dd", shopOrder.toJSON().createdAt)
  146. let Time = dateF.formatTime("mm-dd", shopOrder.toJSON().endTime.iso)
  147. let a = dateF.formatTime("YYYY-mm-dd HH:MM:SS", shopOrder.toJSON().startTime.iso)
  148. let e = dateF.formatTime("YYYY-mm-dd HH:MM:SS", shopOrder.toJSON().endTime.iso)
  149. //计算天数
  150. let day = parseInt((new Date(e.replace(/-/g, '/')).getTime() - new Date(a.replace(/-/g, '/')).getTime()) / (1000 * 60 * 60 * 24))
  151. console.log(day, Time, orderTime);
  152. this.setData({
  153. order: shopOrder.toJSON(),
  154. day: day,
  155. orderTime: orderTime,
  156. Time: Time,
  157. time: time
  158. })
  159. console.log(this.data.order);
  160. },
  161. /**
  162. * 生命周期函数--监听页面加载
  163. */
  164. onLoad: function(options) {
  165. this.setData({
  166. activeColor:getApp().globalData.activeColor || '#229293'
  167. })
  168. let id = options.id
  169. this.setData({ id: id })
  170. this.getShopOrder()
  171. this.getQRCode(id)
  172. },
  173. /**
  174. * 生命周期函数--监听页面初次渲染完成
  175. */
  176. onReady: function() {
  177. },
  178. /**
  179. * 生命周期函数--监听页面显示
  180. */
  181. onShow: function() {
  182. },
  183. /**
  184. * 生命周期函数--监听页面隐藏
  185. */
  186. onHide: function() {
  187. },
  188. /**
  189. * 生命周期函数--监听页面卸载
  190. */
  191. onUnload: function() {
  192. },
  193. /**
  194. * 页面相关事件处理函数--监听用户下拉动作
  195. */
  196. onPullDownRefresh: function() {
  197. },
  198. /**
  199. * 页面上拉触底事件的处理函数
  200. */
  201. onReachBottom: function() {
  202. },
  203. /**
  204. * 用户点击右上角分享
  205. */
  206. onShareAppMessage: function() {
  207. }
  208. })