继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

【金秋打卡】第3天 全新升级,基于Vue3新标准,打造后台综合解决方案 第三讲

ToRAmen
关注TA
已关注
手记 77
粉丝 10
获赞 4

课程章节: 项目架构之搭建登录架构解决方案与实现

主讲老师: Sunday

课程内容:

今天学习的内容包括:

搭建登录架构的解决方案

课程收获:

3.1 心得:

import * as echarts from '../../components/ec-canvas/echarts';

var config = require("../../utils/config.js");
var app = getApp();
var trendPriceSeven = [];
var trendPriceFifteen = [];

Page({
  data: {
    chartIndex: '',
    tagIndex: 1,
    ec1: {
      onInit: function (canvas, width, height, dpr) {
        const chart = echarts.init(canvas, null, {
          width: width,
          height: height,
          devicePixelRatio: dpr, // new
        });
        canvas.setChart(chart);
        chart.setOption(getOption1());
        return chart;
      }
    },
    ec2: {
      onInit: function (canvas, width, height, dpr) {
        const chart = echarts.init(canvas, null, {
          width: width,
          height: height,
          devicePixelRatio: dpr // new
        });
        canvas.setChart(chart);
        chart.setOption(getOption2());
        return chart;
      }
    },
    num: 1,
    minusStatus: 'disabled',
    payMoney: '-',
    reportMoney: '',
    select: 1,
    amount: 1,
    date: '',
    startDate: '',
    IsUnAvailable:false,
    productId: '',
    totalMoney: 0,
    discountMoney: 0,
    salePrice: 0,
    telPhone: '',
    tripTime: '',
    orderUser: '',
    productName: '',
    time: '',
    typeName: '',
    showModalStatus: false,
    animationData: '',
    couponId: "",
    couponUseCount: 0,
    productList: [],
    couponitems: [],
    chooseCoupon: null, //存储选中的优惠卷Id和Price
    maxBuyCount: 0, //最大购买数(0为不限)
    minBuyCount: 0, //最小购买数(0为不限)
    addDays: 0, //提前购买天数
    isIdCard: true,
    idCard: "",
    timeChoose: [],
    isDays: false,
    isPrice: false,
    averageDealMoneyList: [],
    supplierProductOfferList: [],
    memberProductOfferList: [],
    salePrice1: 0,
    saleAmount1: 0,
    salePrice2: 0,
    saleAmount2: 0,
    salePrice3: 0,
    saleAmount3: 0,
    buyPrice1: 0,
    buyAmount1: 0,
    buyPrice2: 0,
    buyAmount2: 0,
    buyPrice3: 0,
    buyAmount3: 0,
    dealPrice1: 0,
    dealAmount1: 0,
    dealPrice2: 0,
    dealAmount2: 0,
    dealPrice3: 0,
    dealAmount3: 0,
    trendPrice: []
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  onLoad: function (options) {

    // this.setData({
    //   productName: options.productName,
    //   typeName: options.typeName
    // });

    this.data.productId = options.productId;

    var that = this;
    var openid = wx.getStorageSync('wxOpenId');
    if (!openid) {
      wx.navigateTo({
        url: '../login/login'
      })
    }

    var nowDate = new Date();
    var year = nowDate.getFullYear();
    var month = nowDate.getMonth() + 1;
    var day = nowDate.getDate();
    var dateStr = year + "-" + month + "-" + day;
    that.setData({
      date: dateStr
    });
    setTimeout(function () {
      that.setData({
        chartIndex: 1,
      });
    }, 500);

    that.getAuctionProductOffer();
    that.getAuctionOrderDealMoney();
    that.getAverageDealMoney();
  },

  getAverageDealMoney: function () {
    var that = this;
    var days = 7;
    var index = that.data.chartIndex;
    if (index == 2) {
      days = 15;
    }

    wx.request({
      url: app.getUrl(app.globalData.getAverageDealMoney),
      data: {
        productId: that.data.productId
      },
      success: function (res) {
        var result = res.data;
        if (result.result) {
          var listSeven = result.data.SevenDays;
          var listFifteen = result.data.FifteenDays;
          for (var i = 0; i < listSeven.length; i++) {
            trendPriceSeven.push(listSeven[i].Price);
          }

          for (var i = 0; i < listFifteen.length; i++) {
            trendPriceFifteen.push(listFifteen[i].Price);
          }

          // that.setData({
          //   ec1: {
          //     onInit: function (canvas, width, height, dpr) {
          //       const chart = echarts.init(canvas, null, {
          //         width: width,
          //         height: height,
          //         devicePixelRatio: dpr, // new
          //       });
          //       canvas.setChart(chart);
          //       chart.setOption(getOption1());
          //       return chart;
          //     }
          //   },
          //   ec2: {
          //     onInit: function (canvas, width, height, dpr) {
          //       const chart = echarts.init(canvas, null, {
          //         width: width,
          //         height: height,
          //         devicePixelRatio: dpr // new
          //       });
          //       canvas.setChart(chart);
          //       chart.setOption(getOption2());
          //       return chart;
          //     }}
          // });
        }
      },
      fail: function (err) {
        wx.hideLoading();
      }, //请求失败
      complete: function () {} //请求完成后执行的函数
    });

  },
  getAuctionProductOffer: function (e) {
    var that = this;
    var time = that.data.date;

    wx.request({
      url: app.getUrl(app.globalData.getAuctionProductOffer),
      data: {
        productId: that.data.productId,
        time: time,
        gearNum: 3
      },
      success: function (res) {
        var result = res.data;
        if (result.result) {
          var supplierProductOfferList = result.data.SupplierProductOfferList;
          var memberProductOfferList = result.data.MemberProductOfferList;
          var salePrice1 = 0;
          var saleAmount1 = 0;
          var salePrice2 = 0;
          var saleAmount2 = 0;
          var salePrice3 = 0;
          var saleAmount3 = 0;
          var buyPrice1 = 0;
          var buyAmount1 = 0;
          var buyPrice2 = 0;
          var buyAmount2 = 0;
          var buyPrice3 = 0;
          var buyAmount3 = 0;
          if (supplierProductOfferList[0] != undefined) {
            salePrice1 = supplierProductOfferList[0].Price;
            saleAmount1 = supplierProductOfferList[0].Amount;
          }

          if (supplierProductOfferList[1] != undefined) {
            salePrice2 = supplierProductOfferList[1].Price;
            saleAmount2 = supplierProductOfferList[1].Amount;
          }

          if (supplierProductOfferList[2] != undefined) {
            salePrice3 = supplierProductOfferList[2].Price;
            saleAmount3 = supplierProductOfferList[2].Amount;
          }

          if (memberProductOfferList[0] != undefined) {
            buyPrice1 = memberProductOfferList[0].Price;
            buyAmount1 = memberProductOfferList[0].Amount;
          }

          if (memberProductOfferList[1] != undefined) {
            buyPrice2 = memberProductOfferList[1].Price;
            buyAmount2 = memberProductOfferList[1].Amount;
          }

          if (memberProductOfferList[2] != undefined) {
            buyPrice3 = memberProductOfferList[2].Price;
            buyAmount3 = memberProductOfferList[2].Amount;
          }


          that.setData({
            salePrice: result.data.Price,
            supplierProductOfferList: supplierProductOfferList,
            memberProductOfferList: memberProductOfferList,
            salePrice1: salePrice1,
            saleAmount1: saleAmount1,
            salePrice2: salePrice2,
            saleAmount2: saleAmount2,
            salePrice3: salePrice3,
            saleAmount3: saleAmount3,
            buyPrice1: buyPrice1,
            buyAmount1: buyAmount1,
            buyPrice2: buyPrice2,
            buyAmount2: buyAmount2,
            buyPrice3: buyPrice3,
            buyAmount3: buyAmount3,
          });
        }
      },
      fail: function (err) {
        wx.hideLoading();
      }, //请求失败
      complete: function () {} //请求完成后执行的函数
    });
  },
  getAuctionOrderDealMoney: function (e) {
    var that = this;
    wx.request({
      url: app.getUrl(app.globalData.getAuctionOrderDealMoney),
      data: {
        productId: that.data.productId,
        gearNum: 3
      },
      success: function (res) {
        var result = res.data;
        if (result.result) {
          var list = result.data;
          var dealPrice1 = 0;
          var dealAmount1 = 0;
          var dealPrice2 = 0;
          var dealAmount2 = 0;
          var dealPrice3 = 0;
          var dealAmount3 = 0;

          if (list[0] != undefined) {
            dealPrice1 = list[0].Price;
            dealAmount1 = list[0].Amount;
          }

          if (list[1] != undefined) {
            dealPrice2 = list[1].Price;
            dealAmount2 = list[1].Amount;
          }

          if (list[2] != undefined) {
            dealPrice3 = list[2].Price;
            dealAmount3 = list[2].Amount;
          }

          that.setData({
            dealPrice1: dealPrice1,
            dealAmount1: dealAmount1,
            dealPrice2: dealPrice2,
            dealAmount2: dealAmount2,
            dealPrice3: dealPrice3,
            dealAmount3: dealAmount3
          });
        }
      },
      fail: function (err) {
        wx.hideLoading();
      }, //请求失败
      complete: function () {} //请求完成后执行的函数
    });
  },

  //出行日期选择
  bindDateChange: function (e) {
    if (this.data.date == '请选择您的出行日期') {
      wx.showToast({
        title: '请选择您的出行日期',
        duration: 2000,
        icon: 'none'
      });

      return;
    };

    this.setData({
      dateScore: '#2E2E2E',
      date: e.detail.value
    });

    this.getAuctionProductOffer();
  },
  /* 切换股票图*/
  change1: function (e) {
    this.setData({
      chartIndex: 1,
      tagIndex: e.target.dataset.index
    });
  },
  change2: function (e) {
    this.setData({
      chartIndex: 2,
      tagIndex: e.target.dataset.index
    });
  },

  /* 点击减号 */
  bindMinus: function () {
    var num = this.data.num;
    // 如果大于1时,才可以减
    if (num > 1) {
      num--;
    }
    // 只有大于一件的时候,才能normal状态,否则disable状态
    var minusStatus = num <= 1 ? 'disabled' : 'normal';
    if (this.data.reportMoney != '' && num > 0) {
      var payMoney = this.data.reportMoney * num;
    }
    // 将数值与状态写回
    this.setData({
      num: num,
      minusStatus: minusStatus,
      payMoney: payMoney,
    });
  },

  /* 点击加号 */
  bindPlus: function () {
    var num = this.data.num;
    // 不作过多考虑自增1
    num++;
    // 只有大于一件的时候,才能normal状态,否则disable状态
    var minusStatus = num < 1 ? 'disabled' : 'normal';
    if (this.data.reportMoney != '') {
      var payMoney = this.data.reportMoney * num;
    }
    // 将数值与状态写回
    this.setData({
      num: num,
      minusStatus: minusStatus,
      payMoney: payMoney,
    });
  },

  /* 输入框事件 */
  bindManual: function (e) {
    var num = e.detail.value;
    if (this.data.reportMoney != '' && num > 0) {
      var payMoney = this.data.reportMoney * num;
    } else if (this.data.reportMoney != '' && num == 0) {
      var payMoney = this.data.reportMoney * 1;
    }
    // 将数值与状态写回
    this.setData({
      num: num,
      payMoney: payMoney,
    });
    if (num == 0 || num == '')
      this.setData({
        num: 1
      });

  },

  formName: function (e) {
    var payMoney = e.detail.value * this.data.num;
    this.setData({
      reportMoney: e.detail.value,
      payMoney: payMoney
    })
    if (this.data.reportMoney == '') {
      this.setData({
        payMoney: '-'
      })
    }
    console.log('单价' + this.data.reportMoney + '数目' + this.data.num + '总价' + this.data.payMoney)
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  //判断输入的姓名
  onBlurOrderUser: function (e) {
    this.data.orderUser = e.detail.value;
    if (e.detail.value == null || e.detail.value.length == 0) {

      wx.showToast({
        title: '联系人姓名不能为空',
        duration: 2000,
        icon: 'none'
      });
    }
  },

  //判断输入的手机号
  onBlurTelPhone: function (e) {
    this.data.telPhone = e.detail.value;
    if (e.detail.value == null || e.detail.value.length == 0) {

      wx.showToast({
        title: '手机号码不能为空',
        duration: 2000,
        icon: 'none'
      });

      return;
    }

    if (!(/^1[3|4|5|6|7|8|9][0-9]{9}$/.test(e.detail.value))) {
      wx.showToast({
        title: '手机号码有误',
        duration: 2000,
        icon: 'none'

      });

      return;
    }
  },

  //判断输入的身份证号
  onBlurIdCard: function (e) {
    this.data.idCard = e.detail.value;

    if (e.detail.value == null || e.detail.value.length == 0) {
      wx.showToast({
        title: '身份证号不能为空',
        duration: 2000,
        icon: 'none'
      });
      return;
    }
    var judgeResult = config.IDCardJudge(this.data.idCard);
    if (!judgeResult) {
      wx.showToast({
        title: '身份证号有误',
        duration: 2000,
        icon: 'none'
      });
      return;
    }
  },

  //判断输入的申购价格
  onBlurIdReport: function (e) {
    this.data.reportMoney = e.detail.value;
    if (e.detail.value == null || e.detail.value.length == 0) {
      wx.showToast({
        title: '申购价格不能为空',
        duration: 2000,
        icon: 'none'
      });
      return;
    }
    if (e.detail.value <= 0) {
      wx.showToast({
        title: '申购价格不能为0',
        duration: 2000,
        icon: 'none'
      });
      return;
    }
  },

  //判断提交申购
  getOrderPayParameter() {
    var that = this;

    if (that.data.orderUser == null || that.data.orderUser.length == 0) {
      wx.showToast({
        title: '联系人姓名不能为空',
        icon: 'none',
        duration: 2000
      });
      return;
    }

    if (that.data.isIdCard) {
      if (that.data.idCard == null || that.data.idCard.length == 0) {
        wx.showToast({
          title: '身份证号不能为空',
          icon: 'none',
          duration: 2000
        });
        return;
      }

      var judgeResult = config.IDCardJudge(that.data.idCard);
      if (!judgeResult) {
        wx.showToast({
          title: '身份证号有误',
          duration: 2000,
          icon: 'none'
        });
        return;
      }
    }

    if (that.data.telPhone == null || that.data.telPhone.length == 0) {
      wx.showToast({
        title: '手机号码不能为空',
        icon: 'none',
        duration: 2000
      });
      return;
    }

    var myreg = /^1[3|4|5|6|7|8|9][0-9]{9}$/;
    if (!(myreg.test(that.data.telPhone))) {
      wx.showToast({
        title: '手机号码有误',
        duration: 2000,
        icon: 'none'
      });
      return;
    }

    if (that.data.reportMoney == null || that.data.reportMoney.length == 0) {
      wx.showToast({
        title: '申购价格不能为空',
        duration: 2000,
        icon: 'none'
      });
      return;
    }
    if (that.data.reportMoney <= 0) {
      wx.showToast({
        title: '申购价格不能为0',
        duration: 2000,
        icon: 'none'
      });
      return;
    }

    var openId = '';
    app.getOpenId(function (openid) {
      if (openid) {
        openId = openid
      }
    }, 'payment');
    if (openId.length > 0) {
      if (wx.showLoading) { // 基础库 1.1.0 微信6.5.6版本开始支持,低版本需做兼容处理
        wx.showLoading({
          title: '订单正在处理中',
          mask: true
        });
      } else { // 低版本采用Toast兼容处理并将时间设为20秒以免自动消失
        wx.showToast({
          title: '订单正在处理中',
          icon: 'loading',
          mask: true,
          duration: 10000
        });
      }
      wx.request({
        url: app.getUrl(app.globalData.submitOrderInfo),
        data: {
          productId: that.data.productItemId,
          openId: openId,
          oughtMoney: that.data.totalMoney,
          discountMoney: that.data.discountMoney,
          salePrice: that.data.salePrice,
          basePrice: that.data.basePrice,
          amount: that.data.amount,
          orderUser: that.data.orderUser,
          telPhone: that.data.telPhone,
          idCard: that.data.idCard,
          tripTime: that.data.tripTime,
          couponId: that.data.couponId,
          reductionAmount: that.data.totalDiscountMoney,
          memberAmount: that.data.memberDiscountMoney,
          enterAmount: that.data.enterDiscountMoney,
          days: that.data.selectTime,
          isSpecialPrice: that.data.isSpecialPrice
        },
        method: 'POST',
        success: function (res) {
          var result = res.data;
          if (result.result) {
            if (result.data.OrderId == null || result.data.OrderId.length == 0) {
              wx.showToast({
                title: result.data.Msg,
                icon: 'none',
                duration: 2000
              });
              return;
            }
            var orderId = result.data.OrderId;
            wx.request({
              url: app.getUrl(app.globalData.getOrderPayParameter),
              data: {
                openId: openId,
                orderId: result.data.OrderId
              },
              success: function (res) {
                if (wx.hideLoading) { // 基础库 1.1.0 微信6.5.6版本开始支持,低版本需做兼容处理
                  wx.hideLoading();
                } else {
                  wx.hideToast();
                }

                var result = res.data;
                if (result.result) {
                  if (result.data != null) {
                    wx.requestPayment({
                      'timeStamp': String(result.data.timeStamp),
                      'nonceStr': String(result.data.nonceStr),
                      'package': String(result.data.package),
                      'signType': String(result.data.signType),
                      'paySign': String(result.data.paySign),
                      'success': function (res) {
                        wx.switchTab({
                          url: '/pages/order/order'
                        })
                      },
                      'fail': function (res) {
                        wx.switchTab({
                          url: '/pages/order/order'
                        })
                      },
                      'complete': function (res) {}
                    })
                  }
                };
              },
              fail: function (err) {
                wx.hideLoading();
              }, //请求失败
              complete: function () {} //请求完成后执行的函数
            })
          }
        }
      });
    } else {
      wx.navigateTo({
        url: '../login/login'
      })
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */

  /**
   * 生命周期函数--监听页面隐藏
   */
})


// function getAverageDealMoney(index) {
//   wx.request({
//     url: app.getUrl(app.globalData.getAverageDealMoney),
//     data: {
//       productId: productId
//     },
//     success: function (res) {
//       var result = res.data;
//       if (result.result) {
//         var listSeven = result.data.SevenDays;
//         var listFifteen = result.data.FifteenDays;
//         for (var i = 0; i < listSeven.length; i++) {
//           trendPriceSeven.push(listSeven[i].Price);
//         }

//         for (var i = 0; i < listFifteen.length; i++) {
//           trendPriceFifteen.push(listFifteen[i].Price);
//         }
//       }
//     },
//     fail: function (err) {
//       wx.hideLoading();
//     }, //请求失败
//     complete: function () { } //请求完成后执行的函数
//   });

// }

//7日股票图
function getOption1() {
  return {
    title: {},
    legend: {
      textStyle: 8
    },
    color: ["#379FFF"],
    grid: {
      containLabel: false,
      x: 40,
      y: 10,
      x2: 20,
      y2: 20
    },
    tooltip: {
      show: true,
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['前七天', '前六天', '前五天', '前四天', '前三天', '前二天', '前一天'],
    },
    yAxis: {
      x: 'center',
      type: 'value',
      splitLine: {
        show: false
      }
    },
    series: [{
      type: 'line',
      smooth: false,
      data: trendPriceSeven
    }]
  };

}

//15日股票图
function getOption2() {
  return {
    title: {},
    legend: {
      textStyle: 8
    },
    color: ["#379FFF"],
    grid: {
      containLabel: false,
      x: 40,
      y: 10,
      x2: 20,
      y2: 20
    },
    tooltip: {
      show: true,
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      boundaryGap: false,
      data: ['前十五天', '前十四天', '前十三天', '前十二天', '前十一天', '前十天', '前九天', '前八天', '前七天', '前六天', '前五天', '前四天', '前三天', '前二天', '前一天'],
    },
    yAxis: {
      x: 'center',
      type: 'value',
      splitLine: {
        show: false
      }
    },
    series: [{
      type: 'line',
      smooth: false,
      data: trendPriceFifteen
    }]
  };
}

图片描述

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP