index.js 6.7 KB

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