Authored by htoooth

api

1 <template> 1 <template>
2 <div class="exchange-box"> 2 <div class="exchange-box">
3 - <CubuInput :value="code" placeholder="请输入优惠券码" :clearable="inputOption"></CubuInput> 3 + <input type="text" name="couponCodeInput" placeholder="请输入优惠券码" v-model="code">
4 <button :class="btnCls" @click="onClick">兑换</button> 4 <button :class="btnCls" @click="onClick">兑换</button>
5 </div> 5 </div>
6 </template> 6 </template>
7 7
8 -<script>  
9 -import {Input} from 'cube-ui';  
10 8
  9 +
  10 +<script>
11 export default { 11 export default {
12 name: 'ExchangeBox', 12 name: 'ExchangeBox',
13 data() { 13 data() {
14 return { 14 return {
15 - code: '',  
16 - inputOption: {  
17 - visible: true,  
18 - blurHidden: false  
19 - } 15 + code: ''
20 }; 16 };
21 }, 17 },
22 methods: { 18 methods: {
23 onClick() { 19 onClick() {
24 this.$emit('click'); 20 this.$emit('click');
25 }, 21 },
26 - onCodeInput(e) {  
27 - this.code += e.data;  
28 - this.$emit('input', this.code);  
29 - }  
30 }, 22 },
31 computed: { 23 computed: {
32 btnCls() { 24 btnCls() {
@@ -35,8 +27,10 @@ export default { @@ -35,8 +27,10 @@ export default {
35 }]; 27 }];
36 } 28 }
37 }, 29 },
38 - components: {  
39 - CubuInput: Input 30 + watch: {
  31 + code() {
  32 + this.$emit('input', this.code);
  33 + }
40 } 34 }
41 }; 35 };
42 </script> 36 </script>
@@ -51,7 +45,7 @@ export default { @@ -51,7 +45,7 @@ export default {
51 left: 0; 45 left: 0;
52 z-index: 2; 46 z-index: 2;
53 47
54 - .code { 48 + input {
55 width: 570px; 49 width: 570px;
56 height: 60px; 50 height: 60px;
57 margin-right: 12px; 51 margin-right: 12px;
@@ -51,7 +51,7 @@ @@ -51,7 +51,7 @@
51 <script> 51 <script>
52 import {createNamespacedHelpers} from 'vuex'; 52 import {createNamespacedHelpers} from 'vuex';
53 53
54 -const {mapState} = createNamespacedHelpers('coupon/yoho'); 54 +const {mapState, mapActions} = createNamespacedHelpers('coupon/yoho');
55 55
56 import Tabs from '../components/tabs'; 56 import Tabs from '../components/tabs';
57 import FilterBar from '../components/filter-bar'; 57 import FilterBar from '../components/filter-bar';
@@ -98,7 +98,7 @@ export default { @@ -98,7 +98,7 @@ export default {
98 } 98 }
99 ], 99 ],
100 scrollOptions: { 100 scrollOptions: {
101 - directionLockThreshold: 0 101 + directionLockThreshold: 0,
102 }, 102 },
103 slideOptions: { 103 slideOptions: {
104 listenScroll: true, 104 listenScroll: true,
@@ -123,6 +123,7 @@ export default { @@ -123,6 +123,7 @@ export default {
123 this.getNum(); 123 this.getNum();
124 }, 124 },
125 methods: { 125 methods: {
  126 + ...mapActions(['getCouponCode']),
126 changePage(current) { 127 changePage(current) {
127 const tab = this.tabLabels[current]; 128 const tab = this.tabLabels[current];
128 129
@@ -149,7 +150,19 @@ export default { @@ -149,7 +150,19 @@ export default {
149 this.$refs.tabs.showFilter = false; 150 this.$refs.tabs.showFilter = false;
150 }, 151 },
151 onSubmitCode() { 152 onSubmitCode() {
152 - 153 + this.getCouponCode({code: this.inputCouponCode}).then(result => {
  154 + if (result.code === 200) {
  155 + this.$createToast({
  156 + txt: result.message,
  157 + type: 'correct'
  158 + });
  159 + } else {
  160 + this.$createToast({
  161 + txt: result.message,
  162 + type: 'error'
  163 + });
  164 + }
  165 + });
153 } 166 }
154 }, 167 },
155 watch: { 168 watch: {
@@ -73,7 +73,7 @@ export default { @@ -73,7 +73,7 @@ export default {
73 async getCouponCode({commit}, {code}) { 73 async getCouponCode({commit}, {code}) {
74 commit(Types.FETCH_YOHO_COUPON_REQUEST); 74 commit(Types.FETCH_YOHO_COUPON_REQUEST);
75 75
76 - const result = await this.$api.post('/api/coupon/yoho/', { 76 + const result = await this.$api.post('/api/coupon/yoho/getcoupon', {
77 coupon_code: code 77 coupon_code: code
78 }); 78 });
79 79