123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- // pages/beerBoxPayment/beerBoxPayment.js
- const request = require("../../utils/request.js");
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- boxId: null,
- beerBoxDetail: {},
- type: 'BeerBlindBox',
- outId: null,
- priceList_index: 0,
- num: 1,
- deviceNo: 'wxMiniApp',
- userAddressId: null,
- adress_select: {}
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- if(options.boxId) {
- this.setData({
- boxId: options.boxId
- })
- }
- this.geBoxtDetail();
- this.getAddressDefault();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- },
- //查询订单支付状态
- orderGet(orderId) {
- let that = this;
- request.getData(
- 'app/order/get',{orderId: orderId},
- res => {
- console.log(res)
- },
- res => {
- console.log(res)
- }
- )
- },
- //测试环境支付
- orderPayGet(orderId) {
- let that = this;
- request.getData(
- 'app/order/notify_url',{orderId: orderId},
- res => {
- console.log(res)
- that.orderGet(orderId)
- },
- res => {
- console.log(res)
- }
- )
- },
- //微信小程序统一下单
- wxpayOrderPay(orderId) {
- let that = this;
- request.postData(
- 'app/pay/wxpay/program/unified',{orderId: orderId},
- res => {
- wx.requestPayment({
- timeStamp: res.data.data.timeStamp,
- nonceStr: res.data.data.nonceStr,
- package: res.data.data.packageVal,
- signType: 'RSA',
- paySign: res.data.data.paySign,
- success (res) { },
- fail (res) { }
- })
- },
- res => {
- console.log(res)
- }
- )
- },
- //创建订单
- createOrder() {
- let that = this;
- request.postData(
- 'app/order/create',
- {
- deviceNo: that.data.deviceNo,
- type: that.data.type,
- userAddressId: that.data.userAddressId,
- num: that.data.num,
- outId: that.data.outId
- },
- res => {
- console.log(res.data.data)
- let orderId = res.data.data;
- this.wxpayOrderPay(orderId);
- // this.orderPayGet(orderId);
- }
- )
- },
- geBoxtDetail() {
- let that = this;
- request.getData(
- 'app/box/detail',{boxId: that.data.boxId},
- res => {
- that.setData({
- beerBoxDetail: res.data.data,
- outId: res.data.data.priceList[0].priceId
- })
- },
- res => {
- console.log(res)
- }
- )
- },
- backFun() {
- wx.navigateBack({
- delta: 1
- })
- },
- reduce() {
- if(this.data.num>1 && this.data.num<4) {
- this.setData({
- num: this.data.num - 1
- })
- }
- },
- add() {
- if(this.data.num>=1 && this.data.num<3) {
- this.setData({
- num: this.data.num + 1
- })
- }
- },
- toMineAd() {
- let that = this;
- wx.navigateTo({
- url: '../mineAddress/mineAddress',
- events: {
- getSelectAd: function(data) {
- that.setData({
- adress_select: data,
- userAddressId: data.userAddressId
- })
- }
- },
- })
- },
- bindPickerCycle(e) {
- // console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- priceList_index: e.detail.value,
- outId: this.data.beerBoxDetail.priceList[e.detail.value].priceId
- })
- },
- //获取默认地址
- getAddressDefault() {
- let that = this;
- request.getData(
- 'app/user/address/list',{},
- res => {
- let ad_list = res.data.data;
- ad_list.filter(item=>{
- if(item.defaultAddress){
- that.setData({
- adress_select: item,
- userAddressId: item.userAddressId
- })
- }
- })
- }
- )
- },
- })
|