123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283 |
- import orderApi from '../../api/order'
- import api from '../../utils/api';
- import drawQrcode from '../../utils/weapp.qrcode.js'
- // pages/order/order.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- orderId: 0,
- order: {},
- //1显示订单详情,2显示确认支付,取消订单,3显示删除订单
- orderStatus: 1,
- timer: {},
- codeUrl: '',
- percent:'1',
- color:'#10AEFF'
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: async function (options) {
- var orderId = options.id;
- this.setData({
- orderId: orderId
- })
- // let order = await orderApi.getOrderById(orderId);
-
- },
- //生成二维码
- createQrcode: function () {
- const self = this
- drawById.call(wx, "qrCode", {
- text: self.data.order.writeOffCode, // 二维码内容
- })
- },
- createTimeForCode: async function (){
- const self = this
- const order = this.data.order
- console.log(order.writeOffOverTime)
- let endTime = new Date(order.writeOffOverTime);
- console.log(endTime.getTime())
- var timerID = setInterval(async () => {
- let nowTime = new Date();
- let timer = endTime.getTime() - nowTime.getTime();
- self.setData({
- percent: 100 - (timer/1200),
- })
- if (timer < 60000 && timer > 1 && self.data.color !== '#f52e46') {
- self.setData({
- color:"#f52e46"
- })
- }
- if (timer < 1) {
- clearInterval(timerID);
- await orderApi.refreshCode({orderId:order.id})
- await self.orderInfo()
- self.setData({
- color:'#10AEFF'
- })
- }
- },1000)
- },
- createTimeClock: function () {
- var self = this;
- let order = this.data.order;
- let orderId = this.data.orderId;
- console.log(order.createTime)
- let orderCreateTime = new Date(order.createTime);
- let endTime = orderCreateTime.getTime() + 15 * 60 * 1000;
- // let endTime = orderCreateTime.getTime() + 30 * 1000;
- var timerID = setInterval(() => {
- let nowTime = new Date();
- let timer = endTime - nowTime;
- if (timer < 1) {
- clearInterval(timerID);
- orderApi.closeOrder(orderId);
- order.status = 3;
- self.setData({
- order
- })
- }
- let minute = Math.floor(timer / (60 * 1000));
- minute = minute < 0 ? 0 : minute;
- let second = Math.round((timer % (60 * 1000)) / 1000);
- this.setData({
- timer: {
- minute: minute,
- second: second
- }
- })
- }, 500);
- },
- cancelOrder: function () {
- let orderId = this.data.orderId;
- let order = this.data.order;
- var self = this;
- wx.showModal({
- title: '是否确认取消订单?',
- success(res) {
- if (res.confirm) {
- orderApi.closeOrder(orderId);
- order.status = 3;
- self.setData({
- order
- })
- } else if (res.cancel) {}
- },
- })
- },
- deleteOrder: async function () {
- let id = this.data.order.id;
- await orderApi.deleteOrder(id);
- wx.showToast({
- title: '删除成功',
- success: function () {
- setTimeout(() => {
- wx.switchTab({
- url: '../personorder/personorder',
- })
- }, 1000);
- }
- })
- },
- drawCode: function (writeOffCode) {
- let width = this.rpxToPx(280);
- drawQrcode({
- width: width,
- height: width,
- canvasId: 'qrCode',
- text: writeOffCode,
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: async function () {
- await this.orderInfo()
- },
- orderInfo: async function(){
- var orderId = this.data.orderId;
- let order = await orderApi.getOrderById(orderId);
- this.setData({
- order: order.info,
- orderStatus: order.info.status,
- })
- if (order.info.status == 1) {
- this.createTimeClock()
- }
- if (order.info.status == 2 && order.info.writeOffStatus == 1) {
- this.drawCode(order.info.writeOffCode)
- await this.createTimeForCode()
- }
- },
- rpxToPx(data) {
- return data / 750 * wx.getSystemInfoSync().windowWidth
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- payOrder: async function(){
- const self = this
- let orderId = this.data.orderId
- const data = {
- orderId
- }
- const rs = await orderApi.payOrderAgain(data)
- wx.requestPayment({
- timeStamp: rs.timeStamp,
- nonceStr: rs.nonceStr,
- package: rs.package,
- signType: rs.signType,
- paySign: rs.paySign,
- success: async function (res) {
- console.log(res)
- await self.orderInfo()
- },
- fail: async function (res) {
- await self.orderInfo()
- }
- })
- },
- guide: function(e){
- const self = this;
- var lat = parseFloat(self.data.order.latitude);
- var lon = parseFloat(self.data.order.longitude);
- wx.getSetting({
- success: async (res) => {
- let authSetting = res.authSetting
- if (authSetting['scope.userLocation']) {
- console.log('已授权地理位置')
- wx.openLocation({
- latitude:lat,
- longitude: lon,
- })
- // 已授权
- } else {
- // 未授权
- console.log('未授权地理位置');
- wx.getLocation({
- type: 'wgs84',
- async success(res) {
- console.log(res)
- const latitude = res.latitude
- const longitude = res.longitude
- wx.setStorageSync('lon', longitude)
- wx.setStorageSync('lat', latitude)
- wx.openLocation({
- latitude:lat,
- longitude: lon,
- })
- }
- })
- }
- }
- })
- },
- call: function(e){
- let phone = this.data.order.mobile
- wx.makePhoneCall({
- phoneNumber: phone,
- })
- }
- })
|