123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- const app = getApp();
- Page({
- authdialog: null,
- product_ids: '',
- cash_code: '',
- data: {
- isUseAddress: false,
- settlement: 0.00
- },
- onLoad: function (options) {
- var that = this;
- app.showLoading();
- //获取自定义授权组件
- this.authdialog = this.selectComponent("#authdialog");
- //获取兑换商品信息
- this.cash_code = options.code;
- app.request('product.api.checkCode',{
- code: that.cash_code
- },{
- success: function(data, res){
- app.setList(that, data.product);
- that.doSettlement();
- app.hideLoading();
- }
- })
- },
- /**
- * 结算金额
- */
- doSettlement: function(){
- var list = this.data.list;
- var count=0;
- this.product_ids = '';
- for(var i=0; i<list.length; i++){
- var product_id = list[i].id;
- var pay_price = list[i].pay_price;
- count += pay_price*1;
- if(i==0){
- this.product_ids += product_id;
- }else{
- this.product_ids += ',' + product_id;
- }
- }
- app.set(this, 'settlement', count.toFixed(2));
- },
- /**
- * 立即兑换
- */
- doCash: function(e){
- var that = this;
- var addrObj = this.data.addrObj;
- if (!addrObj) {
- app.toast('请选择收货地址');
- }
- app.request('product.api.code',{
- product_id: that.product_ids,
- code: that.cash_code,
- name: addrObj.userName,
- address: addrObj.provinceName + addrObj.cityName + addrObj.countyName + addrObj.detailInfo,
- mobile: addrObj.telNumber,
- invite_uid: app.getInviteUid()
- },{
- success:function(data, res){
- app.saveInviteUid('');
- var id = that.product_ids;
- let idx = id.indexOf(',');
- if (idx > -1) {
- id = id.substring(0, idx);
- }
- app.redirect('pay/index?id=' + id);
- },
- fail: function(res){
- app.toast('兑换失败!');
- }
- })
- },
- /**
- * 使用微信地址
- */
- chooseAddress: function(event){
- var that = this;
- var success = function(){
- wx.chooseAddress({
- success: function (res) {
- app.set(that,'addrObj', res);
- app.set(that,'isUseAddress', true);
- }
- })
- }
- wx.getSetting({
- success: function(res){
- if (res.authSetting['scope.address']){
- success();
- }else{
- wx.authorize({
- scope: 'scope.address',
- success: function () {
- success();
- },
- fail: function(res){
- that.authdialog.showDialog();
- }
- })
- }
- }
- })
- }
- })
|