tripDetailController.js
5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
angular.module('myApp')
.controller('tripDetailController', ['$scope', '$rootScope', '$state', 'dingdaService', '$stateParams', 'wechatPayment',
function ($scope, $rootScope, $state, dingdaService, $stateParams, wechatPayment) {
console.log('tripDetailController');
/**
* 2. 选择dom元素
* */
var tripDetail = $('.tripDetail');
var winHeight = $(window).height();
var tripHeight = tripDetail.height() + 40;
var bottomPosition = $('.bottomPosition');
if (winHeight >= tripHeight) {
bottomPosition.css({'position': 'absolute', 'bottom': '0'})
}
/**
* 3. 定义当前业务需要的数据
* */
$scope.tripDetail = {};
$scope.needPay = false;
$scope.backHome = function () {
$state.go('main');
}
/**
* 4. 支付逻辑
* ispay 有无支付
* isActive
* choosePay 选择支付
* */
var ispay = false;
$scope.isActive = true; // 这个是个关键 TODO 要更改的
$scope.payType = 100;
$scope.choosePay = function (index) {
// if ($($('.checkboxS')[index]).hasClass('checkboxTrue')) {
// // 如果要选择的项已经选中,不处理
// return
// } else {
// $scope.isActive = !$scope.isActive;
// }
$scope.payType = index;
}
$scope.goPay = function () {
if (ispay) return;
if ($scope.payType == 100 || $scope.payType == 101) { //手机支付
ispay = true;
wechatPayment.callRentTypePay($scope.tripDetail.id, $scope.tripDetail.total_fee, $scope.payType)
.then(function (result) {
ispay = false;
//支付成功
init();
// $state.go('bondSuccess');
}, function (errMsg) {
ispay = false;
//支付失败
// layer.open({
// content: '支付失败,请重试',
// time:2
// });
})
} else {
if ($scope.tripDetail.total_fee > $scope.balance) { //钱包支付判断余额是否足够支付
layer.open({
content: '您的余额不够是否去充值?', //小米下面按钮对齐
btn: ['去充值', '取消'],
shadeClose: false,
yes: function (index) {
$state.go('prepay', {}, {reload: false});
layer.close(index);
}, no: function (index) {
layer.close(index);
}
});
} else {
// 余额支付
ispay = true;
var data = {
amount: $scope.tripDetail.total_fee,
body: '余额支付',
type: 102
}
dingdaService.payWX($scope.tripDetail.id, data)
.success(function (data, status) {
ispay = false;
layer.open({
content: '支付成功',
time: 2
});
init();
})
.error(function (data) {
ispay = false;
layer.open({
content: '支付失败',
time: 2
});
})
}
}
}
var orderid = $stateParams.orderId;
/**
* 1. init 获取初始化的数据 tripDetail 订单详情 needPay 是否需要发起支付
* */
var init = function () {
dingdaService.getOrderFinishInfo(orderid).success(function (data, status) {
$scope.tripDetail = data.data.order;
// alert(JSON.stringify(data));
if (data.data.order.status == 300 || $scope.tripDetail.total_fee == 0) {
$scope.needPay = false;
} else if (data.data.order.status == 200) {
$scope.needPay = true;
}
})
dingdaService.getWallet(orderid).success(function (data, status) {
$scope.balance = data.data.balance;
})
}
init();
}])