|
@@ -0,0 +1,115 @@
|
|
|
+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();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+})
|