Authored by TaoHuang

add pay

@@ -56,6 +56,12 @@ export default { @@ -56,6 +56,12 @@ export default {
56 desc: { 56 desc: {
57 type: String, 57 type: String,
58 default: '' 58 default: ''
  59 + },
  60 + extra: {
  61 + type: Object,
  62 + default() {
  63 + return {};
  64 + }
59 } 65 }
60 }, 66 },
61 components: { 67 components: {
@@ -76,7 +82,7 @@ export default { @@ -76,7 +82,7 @@ export default {
76 async mounted() { 82 async mounted() {
77 }, 83 },
78 methods: { 84 methods: {
79 - ...mapOrderAction(['fetchPayList']), 85 + ...mapOrderAction(['payAction']),
80 show() { 86 show() {
81 this.$refs.actionSheet.show(); 87 this.$refs.actionSheet.show();
82 }, 88 },
@@ -90,6 +96,32 @@ export default { @@ -90,6 +96,32 @@ export default {
90 pay() { 96 pay() {
91 this.$emit('confirmAction'); 97 this.$emit('confirmAction');
92 98
  99 + const toast = this.$createToast({
  100 + txt: '正在调起支付宝'
  101 + }).show();
  102 +
  103 + this.payAction({
  104 + orderCode: this.orderCode
  105 + }).then((result) => {
  106 + toast.hide();
  107 + this.onSuccess(result);
  108 + }).catch((result) => {
  109 + toast.hide();
  110 + this.onError(result);
  111 + })
  112 + },
  113 + onError(result) {
  114 + this.$emit('on-pay-error');
  115 + this.$createToast({
  116 + txt: result.message,
  117 + time: 1500,
  118 + type: 'txt'
  119 + }).show();
  120 + },
  121 + onSuccess() {
  122 + this.hide();
  123 + this.$emit('on-pay-success');
  124 +
93 this.$router.push({ 125 this.$router.push({
94 name: 'OrderPay', 126 name: 'OrderPay',
95 query: { 127 query: {
@@ -154,37 +154,31 @@ export default { @@ -154,37 +154,31 @@ export default {
154 154
155 await this.compute(); 155 await this.compute();
156 156
157 - const { data: { orderCode, message } } = await this.buyPayAction({ 157 + const result = await this.buyPayAction({
158 skup: this.productDetail.skup, 158 skup: this.productDetail.skup,
159 addressId: this.address.address_id, 159 addressId: this.address.address_id,
160 couponCode: get(this.orderDetail, 'recommendedCouponInfo.coupon_code', ''), 160 couponCode: get(this.orderDetail, 'recommendedCouponInfo.coupon_code', ''),
161 promotionId: get(this.orderDetail, 'promotionTips.promotionIds', '') 161 promotionId: get(this.orderDetail, 'promotionTips.promotionIds', '')
162 }); 162 });
163 163
164 - if (!orderCode) { 164 + if (!result?.data?.orderCode) {
165 this.$createToast({ 165 this.$createToast({
166 time: 1500, 166 time: 1500,
167 - txt: message, 167 + txt: result?.message,
168 type: 'txt' 168 type: 'txt'
169 }).show(); 169 }).show();
170 return; 170 return;
171 } 171 }
172 172
173 this.$createOrderPayType({ 173 this.$createOrderPayType({
174 - orderCode, 174 + orderCode: result.data.orderCode,
175 price: this.orderDetail.amount, 175 price: this.orderDetail.amount,
176 desc: '金额', 176 desc: '金额',
177 onCloseAction() { 177 onCloseAction() {
178 - vm.onClose(orderCode); 178 + vm.onClose(result.data.orderCode);
179 }, 179 },
180 - onPayAction() {  
181 - vm.onPay();  
182 - }  
183 }).show(); 180 }).show();
184 }, 181 },
185 - onPay() {  
186 - console.log('ok');  
187 - },  
188 onClose(orderCode) { 182 onClose(orderCode) {
189 this.$router.push({ 183 this.$router.push({
190 name: 'orderDetail', 184 name: 'orderDetail',
@@ -199,8 +193,6 @@ export default { @@ -199,8 +193,6 @@ export default {
199 </script> 193 </script>
200 194
201 <style lang="scss" scoped> 195 <style lang="scss" scoped>
202 -@import '~statics/scss/variable.scss';  
203 -  
204 .footer { 196 .footer {
205 position: absolute; 197 position: absolute;
206 bottom: 0; 198 bottom: 0;
@@ -128,33 +128,24 @@ export default { @@ -128,33 +128,24 @@ export default {
128 return; 128 return;
129 } 129 }
130 130
131 - const { orderCode } = orderResult.data;  
132 -  
133 this.orderPay = this.$createOrderPayType({ 131 this.orderPay = this.$createOrderPayType({
134 price: this.fee.earnestMoneyStr, 132 price: this.fee.earnestMoneyStr,
135 desc: '保证金', 133 desc: '保证金',
136 - orderCode, 134 + orderCode: orderResult.data.orderCode,
137 onCloseAction() { 135 onCloseAction() {
138 - vm.onClose();  
139 - vm.$router.push({  
140 - name: 'orderDetail',  
141 - params: {  
142 - owner: UserType.sell,  
143 - code: orderCode  
144 - }  
145 - });  
146 - },  
147 - onPayAction() {  
148 - vm.onPay(); 136 + vm.onClose(orderResult.data.orderCode);
149 } 137 }
150 }).show(); 138 }).show();
151 }, 139 },
152 - onClose() {  
153 - console.log('close'); 140 + onClose(orderCode) {
  141 + this.$router.push({
  142 + name: 'orderDetail',
  143 + params: {
  144 + owner: UserType.sell,
  145 + code: orderCode
  146 + }
  147 + });
154 }, 148 },
155 - onPay() {  
156 - console.log('pay');  
157 - }  
158 } 149 }
159 }; 150 };
160 </script> 151 </script>
@@ -193,6 +193,19 @@ export default function() { @@ -193,6 +193,19 @@ export default function() {
193 }); 193 });
194 194
195 return order; 195 return order;
  196 + },
  197 +
  198 + async payAction(ctx, { orderCode }) {
  199 + const payResult = await this.$api.post('/api/order/pay', {
  200 + orderCode,
  201 + payment: 2
  202 + });
  203 +
  204 + if (payResult.code !== 200) {
  205 + return Promise.reject(payResult);
  206 + }
  207 +
  208 + return payResult;
196 } 209 }
197 }, 210 },
198 getters: {}, 211 getters: {},
@@ -322,6 +322,14 @@ module.exports = { @@ -322,6 +322,14 @@ module.exports = {
322 params: {} 322 params: {}
323 }, 323 },
324 324
  325 + // 支付下单
  326 + '/api/order/pay': {
  327 + ufo: true,
  328 + auth: true,
  329 + api: 'ufo.order.pay',
  330 + params: {}
  331 + },
  332 +
325 // 订单物流信息 333 // 订单物流信息
326 '/api/order/express': { 334 '/api/order/express': {
327 ufo: true, 335 ufo: true,