index.js 6.7 KB

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