Browse Source

器件详情,需求调整

yangc 8 years ago
parent
commit
e496baa463
3 changed files with 98 additions and 31 deletions
  1. 10 8
      components/default/Header.vue
  2. 78 23
      components/store/CommodityInfo.vue
  3. 10 0
      layouts/main.vue

+ 10 - 8
components/default/Header.vue

@@ -38,7 +38,7 @@
           </template>
           <template v-else>
             <a class="item" @click="onLoginClick()">登录</a>
-            <a class="item" href="https://account.ubtob.com/sso/register">注册</a>
+            <a class="item" @click="onRegisterClick">注册</a>
             <nuxt-link class="item" :to="'/'">商城首页</nuxt-link>
           </template>
           <nuxt-link class="item" to="/help/home">帮助中心</nuxt-link>
@@ -79,17 +79,19 @@
         this.$http.get('/login/page').then(response => {
           if (response.data) {
             this.$router.push('/auth/login')
+     //       window.location.href = response.data.content
           }
         })
         // TODO 待Account Center改版
       },
-//      onRegisterClick () {
-//        this.$http.get('/register/page').then(response => {
-//          if (response.data) {
-//        //    this.$router.push('/auth/login')
-//          }
-//        })
-//      },
+      onRegisterClick () {
+        this.$http.get('/register/page').then(response => {
+          if (response.data) {
+        //    this.$router.push('/auth/login')
+            window.location.href = response.data.content
+          }
+        })
+      },
       toggleEnterprises () {
         this.showEnterprises = !this.showEnterprises
       },

+ 78 - 23
components/store/CommodityInfo.vue

@@ -60,16 +60,25 @@
             <div class="com-info form-inline">
               <span class="name">数&nbsp;量</span>:
               <div class="input-group" style="width: 120px">
-                <div class="input-group-addon operate" @click="subNum()" :disabled="!fragment.canAdd">-</div>
+                <div :class="fragment.canSub ? ' input-group-addon operate':'input-group-addon'" @click="fragment.canSub ?subNum():''" :style="!fragment.canSub ?'cursor: not-allowed;':''">-</div>
                 <input type="text" class="form-control" placeholder="数量" v-model="fragment.num" @change="inputNum()"style="padding: 0;min-width: 100px;text-align: center;"/>
-                <div class="input-group-addon operate" @click="addNum()" :disabled="!fragment.canSub">+</div>
+                <div :class="fragment.canAdd ?'input-group-addon operate':'input-group-addon'" @click="fragment.canAdd ?addNum():''" :style="!fragment.canAdd ?'cursor: not-allowed;':''">+</div>
+             <!--   <div class="input-group-addon operate" @click="subNum()">-</div>
+                <input type="text" class="form-control" placeholder="数量" v-model="fragment.num" @change="inputNum()"style="padding: 0;min-width: 100px;text-align: center;"/>
+                <div class="input-group-addon operate" @click="addNum()">+</div>-->
               </div>
               ×
-              <div class="select">
+              <!--<div class="select">
                 <select class="form-control"  :disabled="commodity.currencyName != 'RMB-USD'" v-model="fragment.currency" @change="changeCurrency()">
                   <option value="RMB">RMB</option>
                   <option value="USD">USD</option>
                 </select>
+              </div>-->
+              <div class="select">
+                <span v-if="fragment.currency == 'RMB'">¥</span>
+                <span v-if="fragment.currency == 'USD'">$</span>
+                <span>{{(fragment.prices.rMBPrice || 0)}}</span>
+                <span v-if="fragment.currency == 'RMB'" class="tax"> ( 含税 ) </span>
               </div>
               <span class="money">
@@ -134,6 +143,8 @@ function initFragment (commodity) {
   } else {
     fragment.price = prices.uSDPrice
   }
+  fragment.canAdd = true
+  fragment.canSub = false
   return fragment
 }
 function getFragment (commodity, fragment) {
@@ -155,7 +166,12 @@ export default {
   name: 'commodity-info',
   data () {
     return {
-      fragment: { currency: 'RMB', num: 0, price: 0, canAdd: true }
+      fragment: {
+        currency: 'RMB',
+        num: 0,
+        price: 0,
+        canAdd: true,
+        canSub: true}
     }
   },
   computed: {
@@ -196,32 +212,63 @@ export default {
         this.fragment.price = this.fragment.prices.uSDPrice
       }
     },
-    subNum () {
-      let newNum = this.fragment.num - this.commodity.minPackQty
-      if (newNum >= this.commodity.minBuyQty) {
-        this.fragment.num = newNum
-      } else {
+    changeNum: function (newNum) {
+      let pack = this.commodity.minPackQty
+      let buy = this.commodity.minBuyQty
+      let reserve = this.commodity.reserve
+      if (newNum < buy) {
+        this.$message.error('该商品最少购买' + buy + '件')
+        this.fragment.num = buy
         this.fragment.canSub = false
+        if (this.fragment.num > reserve) {
+          this.$message.error('库存不足')
+          this.fragment.num = reserve - (reserve % pack)
+          this.fragment.canAdd = false
+        } else {
+          if (reserve - this.fragment.num - pack < 0) {
+            this.fragment.canAdd = false
+          } else {
+            this.fragment.canAdd = true
+          }
+        }
+      } else {
+        if (newNum - buy - pack < 0) {
+          this.fragment.canSub = false
+        } else {
+          this.fragment.canSub = true
+        }
+    //    console.log(newNum) 2222
+        if (newNum % pack === 0) {
+          this.fragment.num = newNum
+        } else {
+          this.fragment.num = (Math.floor(newNum / pack) + 1) * pack
+        }
+        if (this.fragment.num > reserve) {
+          this.$message.error('库存不足')
+          this.fragment.num = reserve - (reserve % pack)
+          this.fragment.canAdd = false
+        } else {
+          if (reserve - this.fragment.num - pack < 0) {
+            this.fragment.canAdd = false
+          } else {
+            this.fragment.canAdd = true
+          }
+        }
       }
-      this.fragment.canAdd = true
+      console.log(this.fragment)
+    },
+    subNum () {
+      let newNum = this.fragment.num - this.commodity.minPackQty
+      this.changeNum(newNum)
       getFragment(this.commodity, this.fragment)
     },
     addNum () {
       let newNum = this.fragment.num + this.commodity.minPackQty
-      if (newNum <= this.commodity.reserve) {
-        this.fragment.num = newNum
-      } else {
-        this.fragment.canAdd = false
-      }
-      this.fragment.canSub = true
+      this.changeNum(newNum)
       getFragment(this.commodity, this.fragment)
     },
     inputNum () {
-      if (this.fragment.num < this.commodity.minBuyQty) {
-        this.fragment.num = this.commodity.minBuyQty
-      } else if (this.fragment.num > this.commodity.reserve) {
-        this.fragment.num = this.commodity.reserve
-      }
+      this.changeNum(this.fragment.num)
       getFragment(this.commodity, this.fragment)
     },
     buyNow: function (isBuy, item) {
@@ -457,8 +504,15 @@ export default {
 
 	.com-info div.select {
 		display: inline-block;
-	}
-
+    font-weight: 600;
+    color: red;
+    font-size: 14px;
+	}
+  .com-info div.select .tax {
+    font-weight: normal;
+    color: black;
+    font-size: 12px;
+  }
 	.com-info .operate {
 		cursor: pointer;
 	}
@@ -471,6 +525,7 @@ export default {
 	.com-info .money {
 		font-weight: 600;
 		color: red;
+    font-size: 14px;
 	}
 
 	.com-info select {

+ 10 - 0
layouts/main.vue

@@ -20,5 +20,15 @@
       MainHeader,
       MainNav
     }
+//    data () {
+//      return {
+//        url: window.location.href
+//      }
+//    },
+//    watch: {
+//      url: function (val, oldVal) {
+//        console.log(val)
+//      }
+//    }
   }
 </script>