123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- Page({
- dever: getApp().dever,
- authdialog: null,
- product_ids: '',
- cash_code: '',
- data: {
- isUseAddress: false,
- settlement: 0.00
- },
- onLoad: function (options) {
- var that = this;
- that.dever.showLoading();
- //获取自定义授权组件
- that.authdialog = this.selectComponent("#authdialog");
- //获取兑换商品信息
- that.cash_code = options.code;
- that.dever.request('product.api.checkCode',{
- signature: that.dever.getSignature(),
- code: that.cash_code
- },{
- success: function(data, res){
- that.dever.setList(that, data.product);
- that.doSettlement();
- that.dever.hideLoading();
- },
- fail: function(res){
- that.dever.log('product.api.checkCode', res);
- }
- });
- },
- /**
- * 结算金额
- */
- doSettlement: function(){
- var list = this.data.list;
- var count=0;
- 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;
- }
- }
- this.dever.set(this, 'settlement', count.toFixed(2));
- },
- /**
- * 去支付
- */
- doCash: function(e){
- var that = this;
- var addrObj = that.data.addrObj;
- if (!addrObj) {
- that.dever.alert('请选择收货地址');
- }
- that.dever.request('product.api.code',{
- json: 1,
- signature: that.dever.getSignature(),
- product_id: that.product_ids,
- code: that.cash_code,
- name: addrObj.userName,
- address: addrObj.provinceName + addrObj.cityName + addrObj.countyName + addrObj.detailInfo,
- mobile: addrObj.telNumber
- },{
- success:function(data, res){
- that.dever.redirect('pay/index');
- that.dever.log('doCash success', res);
- },
- fail: function(res){
- that.dever.alert('兑换失败!');
- that.dever.log('doCash fail', res);
- }
- });
- },
- /**
- * 使用微信地址
- */
- chooseAddress: function(event){
- var that = this;
- var success = function(){
- wx.chooseAddress({
- success: function (res) {
- that.dever.log('wx.chooseAddress', res);
- that.dever.set(that,'addrObj', res);
- that.dever.set(that,'isUseAddress', true);
- },
- fail: function (res) {
- that.dever.log('wx.chooseAddress', 'fail');
- }
- })
- }
- 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();
- }
- })
- }
- }
- })
- }
- })
|