123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- const Parse = getApp().Parse;
- const dateF = require('../../../../../utils/date')
- const company = getApp().globalData.company
- const rechText = require('../../../../../utils/rech-text')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- show: false,
- id: "",
- foodOrder: null,
- orderTime: null,
- qrcode: null,
- latitude: null,
- longitude: null,
- tradeNo: null
- },
- async getQRCode(id) {
- let qrCodeUrl = `https://pwa.fmode.cn//gomini/rid=${id}`
- let that = this
- await wx.request({
- url: "https://server.fmode.cn/api/common/qrcode",
- data: {
- qrCode: qrCodeUrl,
- darkColor: "#000",
- lightColor: "#ffffff"
- },
- async success(res) {
- if (res.data.code == 1) {
- //把base64文件转图片
- let fileSystemManager = wx.getFileSystemManager()
- fileSystemManager.writeFile({
- filePath: wx.env.USER_DATA_PATH + '/qr_code.png',
- data: res.data.data.slice(22),
- encoding: 'base64',
- success: res => {
- that.setData({
- qrcode: wx.env.USER_DATA_PATH + '/qr_code.png'
- })
- console.log(that.data.qrcode)
- },
- fail(e) {
- console.log('文件保存失败', e)
- }
- })
- } else {
- wx.showToast({
- title: '请先删除小程序重新授权后重试',
- icon: 'none'
- })
- }
- },
- });
- },
- taxi() {
- let latitude = this.data.foodOrder.foods[0].store.location.latitude;
- let longitude = this.data.foodOrder.foods[0].store.location.longitude;
- console.log(latitude, longitude);
- wx.getLocation({
- type: 'gcj02', //返回可以用于wx.openLocation的经纬度
- success(res) {
- wx.openLocation({
- latitude,
- longitude,
- scale: 18
- })
- }
- })
- },
- phone() {
- let phone = this.data.foodOrder.foods[0].store.mobile
- console.log(phone);
- wx.makePhoneCall({
- phoneNumber: phone
- })
- },
- storepackage() {
- this.setData({
- show: true,
- })
- },
- async acceptResult(e) {
- let {
- order,
- } = this.data
- let that = this
- let {
- params,
- no
- } = e.detail;
- that.setData({
- show: false
- })
- try {
- if (params == "ok") {
- order.set("isPay", true)
- await order.save()
- this.setData({
- isPay: true
- })
- wx.showToast({
- title: '支付成功',
- icon: 'none',
- image: '',
- duration: 1500,
- mask: false,
- });
- } else {
- wx.showToast({
- title: '支付失败',
- icon: 'none',
- image: '',
- duration: 1500,
- mask: false,
- });
- }
- } catch (error) {
- console.log(error)
- wx.showToast({
- title: "支付失败",
- icon: "error",
- duration: 1500,
- });
- wx.hideLoading()
- }
- },
- async getFoodOrder() {
- let id = this.data.id
- console.log(id);
- let FoodOrder = new Parse.Query('FoodOrder')
- // ShopOrder.include('shopStore')
- FoodOrder.include('foods')
- FoodOrder.include('user')
- let foodOrder = await FoodOrder.get(id)
- let orderTime = dateF.formatTime("YYYY-mm-dd HH:MM:SS", foodOrder.createdAt)
- console.log(orderTime);
- foodOrder = foodOrder.toJSON()
- // foodOrder.foods.details = rechText.formatRichText(shopOrder.goods.details)
- this.setData({
- foodOrder: foodOrder,
- orderTime: orderTime,
- tradeNo: foodOrder.tradeNo
- })
- console.log(this.data.foodOrder, this.data.tradeNo);
- },
- async acceptResult(e) {
- let { activeOrder } = this.data
- let that = this
- let {
- params,
- no
- } = e.detail;
- that.setData({
- show: false
- })
- try {
- if (params == "ok") {
- activeOrder.set("status", 200)
- activeOrder.set("isPay", true)
- await activeOrder.save()
- wx.showToast({
- title: '购买成功',
- icon: 'none',
- image: '',
- duration: 1500,
- mask: false,
- });
- } else {
- wx.showToast({
- title: '支付失败,取消订单',
- icon: 'none',
- image: '',
- duration: 1500,
- mask: false,
- });
- }
- } catch (error) {
- console.log(error)
- wx.showToast({
- title: "支付失败",
- icon: "error",
- duration: 1500,
- });
- wx.hideLoading()
- }
- },
- shopadmin() {
- let id = this.data.id
- console.log(id);
- wx.navigateTo({
- url: '/nova-tourism/pages/shop-admin/index?id=' + id
- });
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function(options) {
- let id = options.id
- this.getQRCode(id)
- this.setData({
- id: id
- })
- this.getFoodOrder()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function() {
- }
- })
|