洪海涛 8 سال پیش
والد
کامیت
169c4df468

+ 11 - 0
www/vue/src/App.vue

@@ -7,6 +7,7 @@
 </template>
 
 <script>
+  import {mapState, mapActions} from 'vuex'
   export default {
     name: 'app',
     data () {
@@ -14,6 +15,16 @@
         routerStart: []
       }
     },
+    computed: {
+      ...mapState({
+        rechargeList: state => state.rechargeList
+      })
+    },
+    methods: {
+      ...mapActions([
+        'RECHARGELIST'
+      ])
+    },
     watch: {
       '$route' (to, from) {
 //        if (this.routerStart.to !== '') {

+ 1 - 10
www/vue/src/components/mine.vue

@@ -19,7 +19,6 @@
 	</div>
 </template>
 <script type="text/javascript">
-  import {mapState, mapActions} from 'vuex'
   import config from '../config/config'
   import {Cell, Group} from 'vux'
   export default({
@@ -63,17 +62,9 @@
       Cell
     },
     beforeCreate () {},
-    computed: mapState({
-      rechargeList: state => state.rechargeList
-    }),
     created () {
-      this.RECHARGELIST()
     },
-    methods: {
-      ...mapActions(['RECHARGELIST']),
-      btn: function (a) {
-      }
-    }
+    methods: {}
   })
 </script>
 <style type="text/css" lang="less" scoped>

+ 50 - 11
www/vue/src/components/recharge.vue

@@ -41,7 +41,8 @@
 	</div>
 </template>
 
-<script type="es6">
+<script>
+  import {mapState, mapActions} from 'vuex'
   import {Group, Cell} from 'vux'
   import axios from 'axios'
   import qs from 'qs'
@@ -59,7 +60,13 @@
     components: {
       Group, Cell
     },
-    beforeCreate () {},
+    computed: {
+      ...mapState({
+        rechargeList: state => state.rechargeList
+      })
+    },
+    beforeCreate () {
+    },
     created () {
 //      console.log(this.rechargeLists)
     },
@@ -82,6 +89,9 @@
       }
     },
     methods: {
+      ...mapActions([
+        'RECHARGELIST'
+      ]),
       btnRechargeList (item, index) {
         if (index !== 4) {
           this.otherAmount = ''
@@ -94,15 +104,44 @@
         this.rechargeItem = item
       },
       btnRecharge () {
-        console.log(this.isShow)
-//				console.log(this.rechargeItem.denomination)
-//        let addRechargeorder = {
-//          user_id: config.userId,
-//          value:
-//        }
-//        axios.post('o2o/recharge/addRechargeorder',qs.stringify()).then(res => {
-//          console.log(res)
-//        })
+        // 选择充值类型
+        if (this.rechargeItem.id === undefined) {
+          // 弹出提示框
+          this.otherAmount = ''
+          this.$vux.alert.show({
+            title: '金额错误',
+            content: '请您先选择充值金额'
+          })
+          return
+        }
+        if (this.rechargeItem.denomination === 1 && this.otherAmount === '') {
+          // 弹出提示框
+          this.otherAmount = ''
+          this.$vux.alert.show({
+            title: '重新输入',
+            content: '请输入您需要充值的金额'
+          })
+          return
+        }
+        let addRechargeOrder = {
+          user_id: config.userId,
+          value: this.otherAmount,
+          recharge_id: this.rechargeItem.id
+        }
+        let payRecharge = {}
+        axios.post('o2o/recharge/addRechargeorder', qs.stringify(addRechargeOrder)).then(res => {
+          console.log(res.data.success)
+          if (res.data.success) {
+            this.$router.push({path: '/pay'})
+          }
+          payRecharge = {
+            user_id: config.userId,
+            pay_channel: 'wx_pub',
+            order_id: res.data.data._id.$id
+          }
+          console.log(payRecharge)
+        })
+
         // axios     1.创建充值卡订单  user_id: user.id,        value:inputVal,
         // 第二步
       },

+ 2 - 1
www/vue/src/router/index.js

@@ -17,5 +17,6 @@ export default[
   {path: '/addressDetail', name: 'addressDetail', component: require('../components/address/addressDetail.vue')},
   {path: '/addressPoisiton', name: 'addressPoisiton', component: require('../components/address/addressPoisiton.vue')},
   {path: '/about', name: 'about', component: require('../components/about.vue')},
-  {path: '/activityText', name: 'activityText', component: require('../components/activityText.vue')}
+  {path: '/activityText', name: 'activityText', component: require('../components/activityText.vue')},
+  {path: '/pay', name: 'pay', component: require('../components/pay.vue')}
 ]

+ 1 - 3
www/vue/src/store/index.js

@@ -7,7 +7,6 @@ import user from './user'
 import PayCharge from './PayCharge'
 import order from './order'
 import product from './product'
-import recharge from './recharge'
 Vue.use(Vuex)
 const store = new Vuex.Store({
 
@@ -17,8 +16,7 @@ export default new Vuex.Store({
     user,
     PayCharge,
     order,
-    product,
-    recharge
+    product
   }
 })
 

+ 0 - 18
www/vue/src/store/recharge.js

@@ -1,18 +0,0 @@
-import api from '../config/api'
-export default {
-  state: {
-    rechargeList: []
-  },
-  mutations: {
-    RECHARGELIST (state, res) {
-      state.rechargeList = res.data
-    }
-  },
-  actions: {
-    RECHARGELIST ({commit}) {
-      api.getRechargeList(function (res) {
-        commit('RECHARGELIST', res)
-      })
-    }
-  }
-}