Commit cc196c33cca49d2c88ced1f67f17c6a0179cf45f

Authored by 喻鹏
1 parent c4c4f1251c
Exists in master

购物车和用户推荐接口渲染

src/components/CommodityCard/CommodityCard.vue
1 1 <template>
2   - <view class="card" @tap="toGoods(goods.id,goods.goodType)">
3   - <image mode="widthFix" :src="goods.imgurl" ></image>
4   - <view class="name">{{goods.name}}</view>
  2 + <view class="card" @tap="toGoods(goods.id?goods.id:goods.pid,goods.goodType?goods.goodType:goods.p_root_index)">
  3 + <image mode="widthFix" :src="goods.imgurl?goods.imgurl:goods.pic" ></image>
  4 + <view class="name">{{goods.name?goods.name:goods.p_name}}</view>
5 5 <view class="info">
6 6 <view class="priceBox">
7   - <view class="price">{{goods.price}}</view>
  7 + <view class="price">{{goods.price?goods.price:goods.real_price}}</view>
8 8 <view class="originCost">
9   - {{goods.rsSon.Max_Price}}
  9 + {{goods.rsSon.Max_Price?goods.rsSon.Max_Price:goods.old_price}}
10 10 </view>
11 11 </view>
12 12 <view class="trade_num">{{goods.trade_num}}人购买</view>
... ...
src/pages/cart/cart.vue
1 1 <template>
2 2 <view class="content">
3   -
4   - <view class="card">
5   - <view class="cardHeader">
6   - <block v-if="pIsoPen">
7   - <view class="partentChecked" @click="pChange(pIsoPen)">
8   - <span class="status correct"></span>
9   - </view>
10   - </block>
11   - <block v-else>
12   - <view class="partentCheck" @click="pChange(pIsoPen)"></view>
13   - </block>
14   - <image src="../../static/store.png" mode="aspectFill"></image>
15   - <text>非常戴镜</text>
16   - </view>
  3 + <block v-if="cartList.length==0">
17 4  
18   - <view class="cardBody">
19   - <template v-if="childIsOpen.child1">
20   - <view class="partentChecked" @click="cChange(childIsOpen.child1,'child1')">
21   - <span class="status correct"></span>
  5 + </block>
  6 + <block v-else>
  7 + <view class="card">
  8 + <view class="cardHeader">
  9 + <view v-bind:class="pIsoPen? 'partentChecked' : 'partentCheck'"
  10 + @click="pChange(pIsoPen)">
  11 + <span class="correct"></span>
22 12 </view>
23   - </template>
24   - <template v-else>
25   - <view class="partentCheck" @click="cChange(childIsOpen.child1,'child1')"></view>
26   - </template>
27   - <view class="goodInfo">
28   - <view class="imageWrap">
29   - <image src="../../static/img/detail/d1.png" mode="aspectFill" style="width: 188rpx;height: 168rpx;"></image>
  13 + <image src="../../static/store.png" mode="aspectFill"></image>
  14 + <text>非常戴镜</text>
  15 + </view>
  16 +
  17 + <view class="cardBody" v-for="(item,index) in cartList" :key="item.cart_id"
  18 + @longpress="delCart(item.cart_id,index)">
  19 + <view v-bind:class="childIsOpen[index]? 'partentChecked':'partentCheck'"
  20 + @click="Change(childIsOpen[index],index)">
  21 + <span class="correct"></span>
30 22 </view>
31   - <view class="infoRight">
32   - <text class="goodName">眼镜名称眼镜名称眼镜名称眼镜名称</text>
33   - <view class="describ"><text>颜色 玫瑰金 /材质 钛合金 / 功能 防日光 / 配件 免费送 /折射 … </text>
34   - <view class="icon"></view>
  23 + <view class="goodInfo">
  24 + <view class="imageWrap">
  25 + <image :src="item.img_index_url" mode="aspectFit" style="width: 188rpx;height: 168rpx;"></image>
35 26 </view>
36   - <view class="priceBox">
37   - <view class="price">¥{{198}}</view>
38   - <text>(限购{{maxCount}}副)</text>
39   - <view class="counter">
40   - <view class="btn" disabled="this.addDisabled" type="default" @click="counter(false)">-</view>
41   - <text>{{count}}</text>
42   - <view class="btn" disabled="this.desDisabled" type="default" @click="counter(true)">+</view>
  27 + <view class="infoRight">
  28 + <view class="goodName" @tap="toGoods(item.pid,item.p_root_index)">{{item.p_name}}</view>
  29 + <view class="describ" @tap="toshop(item.pid,item.p_root_index)">
  30 + <text>
  31 + <block v-for="tag in item.tag.prod_tag_fun" :key="tag.value">
  32 + {{tag.label+`&nbsp;&nbsp;`}}
  33 + </block>
  34 + </text>
  35 + <view class="icon"></view>
  36 + </view>
  37 + <view class="priceBox">
  38 + <view class="price">¥{{item.nowPrice*item.num}}</view>
  39 + <text>(限购{{maxCount}}副)</text>
  40 + <view class="counter">
  41 + <view class="btn" disabled="this.addDisabled" type="default"
  42 + @click="counter(index,false,item.mp_id,item.sk_id,item.num,item.cart_id)">-</view>
  43 + <text>{{item.num}}</text>
  44 + <view class="btn" disabled="this.desDisabled" type="default"
  45 + @click="counter(index,true,item.mp_id,item.sk_id,item.num,item.cart_id)">+</view>
  46 + </view>
43 47 </view>
44 48 </view>
45 49 </view>
46 50 </view>
47 51 </view>
48   - <view class="cardBody">
49   - <!-- <MyCheckbox :isOpenProp="controlCheck.child1"></MyCheckbox> -->
50   - <template v-if="childIsOpen.child2">
51   - <view class="partentChecked" @click="cChange(childIsOpen.child2,'child2')">
52   - <span class="status correct"></span>
53   - </view>
54   - </template>
55   - <template v-else>
56   - <view class="partentCheck" @click="cChange(childIsOpen.child2,'child2')"></view>
57   - </template>
58   - <view class="goodInfo">
59   - <view class="imageWrap">
60   - <image src="../../static/img/detail/d1.png" mode="aspectFill" style="width: 188rpx;height: 168rpx;"></image>
61   - </view>
62   - <view class="infoRight">
63   - <text class="goodName">眼镜名称眼镜名称眼镜名称眼镜名称</text>
64   - <view class="describ"><text>颜色 玫瑰金 /材质 钛合金 / 功能 防日光 / 配件 免费送 /折射 … </text>
65   - <view class="icon"></view>
66   - </view>
67   - <view class="priceBox">
68   - <view class="price">¥198</view>
69   - <text>(限购{{maxCount}}副)</text>
70   - <view class="counter">
71   - <view class="btn" disabled="this.addDisabled" type="default" @click="counter(false)">-</view>
72   - <text>{{count}}</text>
73   - <view class="btn" disabled="this.desDisabled" type="default" @click="counter(true)">+</view>
74   - </view>
75   - </view>
76   - </view>
77   - </view>
78   - </view>
79   - </view>
80   -
  52 + </block>
81 53 <view class="footer">
82 54 <view class="footerLeft">实付金额:<text>¥{{totalPrice}}</text></view>
83 55 <view class="footerRight">
84   - <navigator url="/pages/myOrderPaying/myOrderPaying" hover-class="navigator-hover">
85   - <view class="paybtn">立即支付</view>
  56 + <navigator url="/pages/confirmOrder/confirmOrder" hover-class="navigator-hover">
  57 + <view class="paybtn" >立即结算</view>
86 58 </navigator>
87 59 </view>
88 60 </view>
... ... @@ -97,50 +69,273 @@
97 69  
98 70 data() {
99 71 return {
100   - totalPrice: 360,
101   - count:1,
  72 + totalPrice: 0,
  73 + pIsoPen:false,
  74 + // childIsOpen:[],
102 75 maxCount:20,
103   - pIsoPen: false,
104   - childIsOpen:{
105   - "child1":true,
106   - "child2":true
107   - },
108 76 }
109 77 },
110 78 computed:{
  79 +
111 80 cartList() {
112   - // 也可以从 getters 获取
113   - console.log('cart-list', this.$store.state.cart.cartList);
  81 + // console.log('cart-list', this.$store.state.cart.cartList);
114 82 return this.$store.state.cart.cartList;
  83 + },
  84 + childIsOpen(){
  85 + let temp=[];
  86 + temp.length=this.$store.state.cart.cartList.length;
  87 + for (let i = 0; i < temp.length; i++) {
  88 + temp[i]= false
  89 + }
  90 + console.log('this.childisOPne===>',temp)
  91 + return temp
115 92 }
116 93 },
117 94 onLoad: function() {
  95 + // 判断是否授权
  96 + // uni.getSetting({
  97 + // success(res) {
  98 + // console.log('authSetting',res.authSetting)
  99 + // if(res.authSetting['scope.userInfo'] !== true) {
  100 +
  101 + // uni.switchTab({
  102 + // url:'/pages/user/user'
  103 + // })
  104 + // }else {
  105 + // }
  106 + // }
  107 + // })
  108 +
  109 + // console.log('usr-my',this.$store.state.user.userInfo)
  110 + // store.dispatch('cart/addCart',{
  111 + // "num":1,
  112 + // "pid": 7,//产品id
  113 + // "uid":1,
  114 + // "sk_id": 72,
  115 + // "price": 120,
  116 + // "mp_id":1,
  117 + // "checkedSKU":{
  118 + // "discount": "45",
  119 + // "in_price": "6000",
  120 + // "kc": "0",
  121 + // "model_pic": null,
  122 + // "out_price": 191.8,
  123 + // "pic": "https://glass.xiuyetang.com//upload_jk/7/7_22AE0C.jpg",
  124 + // "pid": "7",
  125 + // "real_price": 99,
  126 + // "sk_id": "89",
  127 + // "sku_name": "1.56非球面防蓝光_黑",
  128 + // "sku_shop_value": "",
  129 + // "sku_value": "58_61",
  130 + // "status": "1",
  131 + // },
  132 + // });
118 133 store.dispatch('cart/getCartList',{
119 134 uid: 1, //用户id
120 135 });
121 136 },
  137 +
122 138 methods: {
123   - counter(isadd){
  139 + // 跳转到对应的选购页面
  140 + toshop(id,type){
  141 + console.log('===',id,type)
  142 + switch(type){
  143 + case 1:
  144 + uni.navigateTo({
  145 + url: `../detailsChoiceArgs/detailsChoiceArgs?oderId=`+id+`&goodType=`+type,
  146 + success: res => {},
  147 + fail: () => {},
  148 + complete: () => {}
  149 + });
  150 + break;
  151 + case 2:
  152 + uni.navigateTo({
  153 + url: `../detailStandard/detailStandard_k?oderId=`+id+`&goodType=`+type,
  154 + success: res => {},
  155 + fail: () => {},
  156 + complete: () => {}
  157 + });
  158 + break;
  159 + case 3||4:
  160 + uni.navigateTo({
  161 + url: `../detailStandard/detailStandard_sun?oderId=`+id+`&goodType=`+type,
  162 + success: res => {},
  163 + fail: () => {},
  164 + complete: () => {}
  165 + });
  166 + break;
  167 + // case 4:
  168 + // uni.navigateTo({
  169 + // url: `../detailStandard/detailStandard_sun?oderId=`+id+`&goodType=`+type,
  170 + // success: res => {},
  171 + // fail: () => {},
  172 + // complete: () => {}
  173 + // });
  174 + case 5:
  175 + uni.navigateTo({
  176 + url: `../purchaseLenses/purchaseLenses?oderId=`+id+`&goodType=`+type,
  177 + success: res => {},
  178 + fail: () => {},
  179 + complete: () => {}
  180 + });
  181 + break;
  182 + default :
  183 + break
  184 + }
  185 + },
  186 + toGoods(id,type){
  187 + uni.navigateTo({
  188 + url: `../frameDetail/frameDetail?oderId=`+id,
  189 + success: res => {},
  190 + fail: () => {},
  191 + complete: () => {}
  192 + });
  193 + console.log('toGoods =====> id:'+id +"======>type:"+type)
  194 + switch(type){
  195 + case 1:
  196 + uni.navigateTo({
  197 + url: `../frameDetail/frameDetail?oderId=`+id+`&goodType=`+type,
  198 + success: res => {},
  199 + fail: () => {},
  200 + complete: () => {}
  201 + });
  202 + break;
  203 + case 2:
  204 + uni.navigateTo({
  205 + url: `../frameDetail/frameDetail?oderId=`+id+`&goodType=`+type,
  206 + success: res => {},
  207 + fail: () => {},
  208 + complete: () => {}
  209 + });
  210 + break;
  211 + case 3:
  212 + uni.navigateTo({
  213 + url: `../frameDetail/frameDetail?oderId=`+id+`&goodType=`+type,
  214 + success: res => {},
  215 + fail: () => {},
  216 + complete: () => {}
  217 + });
  218 + break;
  219 + case 4:
  220 + uni.navigateTo({
  221 + url: `../frameDetail/frameDetail?oderId=`+id+`&goodType=`+type,
  222 + success: res => {},
  223 + fail: () => {},
  224 + complete: () => {}
  225 + });
  226 + break;
  227 + default :
  228 + break
  229 + }
  230 + },
  231 +
  232 + counter(index,isadd,mp_id,sk_id,num,cart_id){
  233 + // console.log('===>>counter ===>num',num)
  234 + // console.log('===>>counter ===>isadd',isadd)
  235 + num=parseInt(num);
124 236 if(isadd){
125   - this.count >= this.maxCount? this.addDisabled = true:this.count++;
  237 + if(num>=this.maxCount){
  238 + this.addDisabled = true
  239 + } else{
  240 + this.addDisabled= true
  241 + // 修改num
  242 + store.dispatch('cart/modiCart',{
  243 + uid: 1,
  244 + // openid: '',
  245 + mp_id: mp_id,
  246 + sk_id: sk_id,
  247 + cart_id:cart_id,
  248 + num:num+1,
  249 + args:{
  250 + index:index,
  251 + isadd:isadd,
  252 + }
  253 + })
  254 + this.addDisabled= false
  255 + }
  256 + }else{
  257 + if(num<=1){
  258 + this.desDisabled = true
  259 + } else{
  260 + this.desDisabled = false
  261 + // post 请求修改相关参数
  262 + store.dispatch('cart/modiCart',{
  263 + uid: 1,
  264 + // openid: '',
  265 + mp_id: mp_id,
  266 + sk_id: sk_id,
  267 + cart_id:cart_id,
  268 + num:num-1,
  269 + args:{
  270 + index:index,
  271 + isadd:isadd,
  272 + }
  273 + })
  274 + this.desDisabled = true
  275 + }
  276 + }
  277 + },
  278 +
  279 + Change(isopen,indexC){
  280 + // console.log('lalla===>',isopen)
  281 + this.childIsOpen[indexC]=!isopen
  282 + if(!isopen){
  283 + this.totalPrice=this.totalPrice+(this.$store.state.cart.cartList[indexC].num*this.$store.state.cart.cartList[indexC].nowPrice)
126 284 }else{
127   - this.count <= 1? this.desDisabled = true:this.count--;
  285 + this.totalPrice=this.totalPrice-(this.$store.state.cart.cartList[indexC].num*this.$store.state.cart.cartList[indexC].nowPrice)
  286 + }
  287 + let m=true;
  288 + for (let i = 0; i < this.childIsOpen.length; i++) {
  289 + m=m&this.childIsOpen[i]
  290 + }
  291 + if(m==1){
  292 + this.pIsoPen=true
  293 + } else{
  294 + this.pIsoPen=false
128 295 }
129 296 },
130 297 pChange(isopen){
131   - // console.log(isopen)
132 298 this.pIsoPen=!isopen
133   - this.childIsOpen.child1=!isopen
134   - this.childIsOpen.child2=!isopen
135   - },
136   - cChange(isopen,child){
137   - // console.log(child)
138   - if(child==='child1'){
139   - this.childIsOpen.child1=!isopen
  299 + for (let i = 0; i < this.childIsOpen.length; i++) {
  300 + this.childIsOpen[i]=!isopen
140 301 }
141   - if(child==='child2'){
142   - this.childIsOpen.child2=!isopen
  302 + if(this.pIsoPen){
  303 + // 计算总价逻辑
  304 + if(this.childIsOpen.length!=0){
  305 + for (let i = 0; i < this.childIsOpen.length; i++) {
  306 + if(this.childIsOpen[i]){
  307 + this.totalPrice= this.totalPrice+(this.$store.state.cart.cartList[i].num*this.$store.state.cart.cartList[i].nowPrice)
  308 + }
  309 + }
  310 + }
  311 + } else{
  312 + this.totalPrice=0
143 313 }
  314 +
  315 + },
  316 + delCart(cart_id,index){
  317 + // console.log('userInfo',this.$store.state.user.userInfo)
  318 + cart_id=parseInt(cart_id)
  319 + // console.log('delcart------>cart_id',cart_id)
  320 + // console.log('cartlist====>delcart',this.$store.state.cart.cartList)
  321 + // console.log('delcart======>index',index)
  322 + uni.showModal({
  323 + title: "是否删除该商品",
  324 + // content: '是否删除该商品',
  325 + success: function (res) {
  326 + if (res.confirm) {
  327 + // this.$store.state.cart.cartList.splice(index,1)
  328 + store.dispatch('cart/delCart',{
  329 + uid: 1, //用户id
  330 + openid: "",
  331 + cart_id: cart_id, // 要修改的购物车id
  332 + arg:index, // 由于action 传参是能接收两参数,因此将index放入对象
  333 + });
  334 + console.log('用户点击确定');
  335 + }
  336 + }
  337 + });
  338 +
144 339 }
145 340 }
146 341 }
... ... @@ -171,21 +366,22 @@
171 366 background-color: #FF6B4A;
172 367 .correct {
173 368 display: inline-block;
174   - width: 5px;
175   - height: 1px;
  369 + position: relative;
  370 + width: 10rpx;
  371 + height: 2rpx;
176 372 background: #FFFFFF;
177 373 line-height: 0;
178 374 font-size: 0;
179 375 position: relative;
180   - top: -6px;
  376 + top: -7px;
181 377 left: 4px;
182 378 -webkit-transform: rotate(45deg);
183 379 }
184 380 .correct:after {
185 381 content: '/';
186 382 display: block;
187   - width: 8px;
188   - height: 1px;
  383 + width: 16rpx;
  384 + height: 2rpx;
189 385 background: #FFFFFF;
190 386 -webkit-transform: rotate(-90deg) translateY(50%) translateX(50%);
191 387 }
... ... @@ -200,6 +396,7 @@
200 396 flex-direction: column;
201 397 align-items: center;
202 398 justify-content: space-between;
  399 + margin-bottom: 180rpx;
203 400 .cardHeader{
204 401 width: 100%;
205 402 height: 36rpx;
... ... @@ -248,6 +445,11 @@
248 445 justify-content: space-between;
249 446 height: 240rpx;
250 447 .goodName{
  448 + display: -webkit-box;
  449 + -webkit-box-orient: vertical;
  450 + -webkit-line-clamp: 2;
  451 + text-align: justify;
  452 + overflow: hidden;
251 453 font-size: 28rpx;
252 454 color: #333333;
253 455 }
... ... @@ -257,8 +459,10 @@
257 459 box-sizing: border-box;
258 460 padding: 10rpx;
259 461 font-size: 20rpx;
  462 + letter-spacing: -0.23px;
  463 + text-align: justify;
260 464 color: #999999;
261   - background: #F2F2F2;
  465 + background: #F9F9F9;
262 466 display: flex;
263 467 justify-content: center;
264 468 align-items: center;
... ...
src/pages/user/user.vue
... ... @@ -47,11 +47,13 @@
47 47 </view>
48 48 <!-- 商品列表 -->
49 49 <view class="goods-list">
50   - <view class="product-list">
51   - <view class="product" v-for="(goods) in goodsList" :key="goods.goods_id" >
52   - <Card :goods = "goods"></Card>
53   - </view>
54   - </view>
  50 + <scroll-view enable-flex @scrolltolower="handleScrolltolower" scroll-y class="product-list">
  51 + <block v-for="(goods) in userRecommandList " :key="goods.list.sk_id">
  52 + <view class="product" v-for="(item) in goods.list" :key="item.sk_id">
  53 + <Card :goods="item" ></Card>
  54 + </view>
  55 + </block>
  56 + </scroll-view>
55 57 <view class="loading-text">{{loadingText}}</view>
56 58 </view>
57 59 </view>
... ... @@ -93,7 +95,8 @@
93 95 { goods_id: 8, img: '/static/img/goods/p9.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' },
94 96 { goods_id: 9, img: '/static/img/goods/p10.jpg', name: '商品名称',originCost:'¥198',price: '¥168', slogan:'1235人浏览' }
95 97 ],
96   - isAuth: true, // 是否显示授权页面
  98 + isAuth: true, // 是否显示授权页面,
  99 + pagesnum:1 // 分页请求初始值
97 100 }
98 101 },
99 102 onLoad() {
... ... @@ -108,6 +111,7 @@
108 111 }
109 112 }
110 113 })
  114 +
111 115 },
112 116 computed: {
113 117 nickName() {
... ... @@ -122,11 +126,18 @@
122 126 return this.$store.state.userRecommand.recommandList;
123 127 }
124 128 },
125   - onLoad: function() {
  129 + onLoad:function(){
  130 + console.log('usr-my',this.$store.state.user.userInfo)
  131 +
126 132 store.dispatch('userRecommand/getRecommandList', {
127   - uid: 2,
  133 + // uid:468,
  134 + uid: this.$store.state.user.userInfo.uid,
  135 + // openid:"oc8cg0d-0mFIInO4LyrCFtInPWr4",
  136 + openid:this.$store.state.user.userInfo.openid,
  137 + page: this.pagesnum
128 138 });
129 139 },
  140 +
130 141 methods: {
131 142 // 授权
132 143 onGotUserInfo(e) {
... ... @@ -172,6 +183,15 @@
172 183 uni.navigateTo({
173 184 url:'../refundProgress/refundProgress'
174 185 })
  186 + },
  187 + handleScrolltolower(){
  188 + // console.log('usr-my',this.$store.state.user.userInfo)
  189 + this.pagesnum++;
  190 + store.dispatch('userRecommand/getRecommandList', {
  191 + uid: this.$store.state.user.userInfo.uid,
  192 + openid:this.$store.state.user.userInfo.openid,
  193 + page: this.pagesnum
  194 + });
175 195 }
176 196 }
177 197 }
... ... @@ -334,6 +354,7 @@
334 354 width: 92%;
335 355 padding: 0 4% 3vw 4%;
336 356 display: flex;
  357 + height: 200px;
337 358 justify-content: space-between;
338 359 flex-wrap: wrap;
339 360 .product{
... ...
src/store/modules/cart.js
1 1 import urlAlias from '../url';
2 2 import request from '../request';
3 3  
4   -const { cartList } = urlAlias;
  4 +const { cartList , cartModi, cartDel, cartAdd } = urlAlias;
5 5  
6 6 const state = {
7 7 cartList: [],
8 8 };
9 9  
  10 +
  11 +const data = {
  12 + data:{
  13 + // list 购物车列表
  14 + list:[
  15 + {
  16 + goods_name: "1.56非球面防蓝光_黑01-8701志平防蓝光-防辐射电脑网课眼镜,TR90弹性漆,近视镜,青春潮流", //商品名称
  17 + pid: "6",//产品id
  18 + real_price: 99,
  19 + checked: true,//是否选中
  20 + name: "颜色 玫瑰金 /材质 钛合金 / 功能 防日光 / 配件 免费送 /折射防日光 / 配件 免费送 /折射",//属性名称 ,颜色 玫瑰金 /材质 钛合金 / 功能 防日光 / 配件 免费送 /折射 …
  21 + cart_id: "39", //购物车唯一序列号
  22 + num: "1", //此购物
  23 + pics: "/static/myorder-paying-pic.png", //商品图片
  24 + goodsType:2,// 商品种类
  25 + },
  26 + {
  27 + goods_name: "1.56非球面防蓝光_黑01-8701志平防蓝光-防辐射电脑网课眼镜,TR90弹性漆,近视镜,青春潮流", //商品名称
  28 + pid: "4",//产品id
  29 + real_price: 189,
  30 + checked: false,//是否选中
  31 + name: "颜色 玫瑰金 /材质 钛合金 / 功能 防日光 / 配件 免费送 /折射防日光 / 配件 免费送 /折射",//属性名称 ,颜色 玫瑰金 /材质 钛合金 / 功能 防日光 / 配件 免费送 /折射 …
  32 + cart_id: "38", //购物车唯一序列号
  33 + num: "2", //此购物
  34 + pics: "/static/myorder-paying-pic.png", //商品图片
  35 + goodsType:3,// 商品种类
  36 + },
  37 + ],
  38 + mp_id: "1",
  39 + mp_list://使用人,一个产品只有一个使用人
  40 + [
  41 + {
  42 + glassWidth: "54",//镜宽
  43 + img_url2: "http://localhost:8087/images/shop_1/1/",//使用人的头像,根据此头像,AI识别出数据。
  44 + in_time: "2020-02-22 03:19:38",//使用人加入的时间
  45 + leftAxi: "124",//左眼数据
  46 + leftCyl: "-2",//左眼数据
  47 + leftSph: "-1",//左眼数据
  48 + leftVis: "5",//左眼数据
  49 + legWidth: "158",//镜腿长
  50 + metal: null,//使用人的其它定义(材质过敏之类的)
  51 + mp_id: "1",//使用的id
  52 + name: "me",//使用人的名字
  53 + norseWidth: "18",//鼻宽
  54 + pd: "89.6",//瞳距
  55 + price: "0",//此人偏好的价格
  56 + rightAxi: "123",//右眼数据
  57 + rightCyl: "24",//右眼数据
  58 + rightSph: "-4",//右眼数据
  59 + rightVis: "5.1",//右眼数据
  60 + uid: "1",//购买人的uid
  61 + }
  62 + ],
  63 + sk_id: "80",//此产品下的sku的唯一id
  64 + skuList:[//sku清单
  65 + {
  66 + discount: "45",//折扣,数据库中以int型存储,所以要除100
  67 + in_price: "6000",//进货价格,数据库中以int型存储,单位是分,所以显示时要除以100
  68 + kc: "0",//库存
  69 + model_pic: null,//模型试戴图
  70 + out_price: 191.8,//销售价格,元
  71 + pic: "https://glass.xiuyetang.com//upload_jk/6/6_321EB1.jpg",//可供查看图
  72 + pid: "6",//索引产品id
  73 + real_price: 99,//真实可成交价格
  74 + sk_id: "74",//成交时的sku_id
  75 + sku_name: "1.56非球面防蓝光_黑色",//sku名称
  76 + sku_shop_value: "",//sku商家定义值
  77 + sku_value: "47_51",//sku系统生成值
  78 + status: "1",//此产品下的sku状态
  79 + }
  80 + ]
  81 + }, // 一个产品下,会有多个sku,都在这个skuList数组下
  82 + msg: "ok",
  83 + status: 1,
  84 +}
  85 +
10 86 const mutations = {
11 87 INIT: (state, cartList) => {
12 88 state.cartList = cartList;
13 89 },
  90 + DEL:(state,index)=>{
  91 + console.log('mutations====>',state.cartList)
  92 + state.cartList.splice(index,1)
  93 + console.log('mutations====>index',index)
  94 + // state.cartList=delList
  95 + },
  96 + MODI:(state,args) => {
  97 + console.log('the num',state.cartList[args.index].num)
  98 + console.log('mutations====>isadd',args)
  99 + if(args.isadd)
  100 + {
  101 + state.cartList[args.index].num=args.num
  102 + } else{
  103 + state.cartList[args.index].num=args.num
  104 + }
  105 + console.log('the num',state.cartList[args.index].num)
  106 + },
  107 +
14 108 };
15 109  
16   -
17   -
18 110 const actions = {
19 111  
20   - getCartList({ commit }, param) {
21   - request({
22   - url: cartList,
23   - success: (res) => {
24   -
25   - commit('INIT', res.data.data)
26   - },
27   - fail: (res) => {
28   - console.log("fail status === > ", res);
29   - },
30   - complete: (res) => {
31   - console.log("complete status === > ", res);
32   - },
33   - })
34   - }
35   -
  112 + getCartList({ commit }, param) {
  113 + request({
  114 + url: cartList,
  115 + data:param,
  116 + success: (res) => {
  117 + console.log('cart===>接口数据',res.data.data)
  118 + // const resData = {
  119 + // ...res,
  120 + // data,
  121 + // }
  122 + commit('INIT', res.data.data)
  123 + },
  124 + fail: (res) => {
  125 + console.log("fail status === > ", res);
  126 + },
  127 + complete: (res) => {
  128 + console.log("complete status === > ", res);
  129 + },
  130 + })
  131 + },
  132 +
  133 + modiCart({ commit }, param) {
  134 + const args=Object.assign({num:param.num},param.args)
  135 + delete param.args
  136 + request({
  137 + url: cartModi,
  138 + data: param,
  139 + success: (res) => {
  140 + console.log('modi-parm',param)
  141 + commit('MODI',args)
  142 + },
  143 + fail: (res) => {
  144 + console.log("fail status === > ", res);
  145 + },
  146 + complete: (res) => {
  147 + console.log("complete status === > ", res);
  148 + },
  149 + })
  150 + },
  151 +
  152 + delCart({ commit },param ) {
  153 + let arg = param.arg;
  154 + delete param.arg
  155 + request({
  156 + url: cartDel,
  157 + data: param,
  158 + success: (res) => {
  159 + console.log('del-parm',param)
  160 + console.log('del-myparms==>',arg)
  161 + // console.log('deacart====>cartList',this.$store.state.cart.cartList)
  162 +
  163 + commit('DEL',arg)
  164 + },
  165 + fail: (res) => {
  166 + console.log("fail status === > ", res);
  167 + },
  168 + complete: (res) => {
  169 + console.log("complete status === > ", res);
  170 + },
  171 + })
  172 + },
  173 +
  174 + addCart({ commit }, param) {
  175 + console.log('请求接口开始')
  176 + request({
  177 + url: cartAdd,
  178 + data:param,
  179 + success: (res) => {
  180 + console.log('add-parm',param)
  181 + console.log('addcart===>res.data===>',res.data)
  182 + // commit('INIT', res.data.data)
  183 + },
  184 + fail: (res) => {
  185 + console.log("fail status === > ", res);
  186 + },
  187 + complete: (res) => {
  188 + console.log("complete status === > ", res);
  189 + },
  190 + })
  191 + },
  192 +
36 193 }
37 194  
38 195 export default {
... ...
src/store/modules/userRecommand.js
... ... @@ -9,21 +9,65 @@ const state = {
9 9 recommandList: [],
10 10 };
11 11  
  12 +const data = {
  13 + "code": 1,
  14 + "msg": "请求成功",
  15 + "data": {
  16 + // list 表示商品数据列表
  17 + "list": [
  18 + {
  19 + model_pic: null,
  20 + p_name: "1.61防蓝光镜片 非球面_枪色款镜架商务男士防蓝光眼镜",
  21 + p_root_index: "1", //对应goodType
  22 + pic: "http://localhost/sys-glass/image/picture.png",
  23 + pid: "96",
  24 + real_price: "17800",
  25 + sk_id: "1448",
  26 + sku_name: "1.61防蓝光镜片 非球面_枪色款镜架",
  27 + trade_num: "0",
  28 + },
  29 + {
  30 + "sk_id": "39",
  31 + "pic": "/static/img/goods/p1.jpg",
  32 + "p_name": "1.56防蓝光镜片非球面_黑银色镜架防蓝光眼镜超轻不压鼻",
  33 + "old_price": "18000",
  34 + "real_price": "9900",
  35 + "trade_num": 123, // 对应购买人数
  36 + "p_root_index": 2, // 对应跳转的详情页
  37 + "pid":4, // 产品id
  38 + },
  39 + ],
  40 + pagesnum:1, // 懒加载要用到的页数
  41 + pagessize:10,// 每次请求返回的list长度
  42 + }
  43 +
  44 +}
  45 +
12 46 const mutations = {
13 47 INIT: (state, list) => {
14 48 state.recommandList = list;
15 49 },
16 50 };
17 51  
  52 +let goodsList=[];
  53 +
18 54 const actions = {
19 55 getRecommandList({ commit }, param) {
20 56 request({
21 57 url: recommandList,
22 58 success: (res) => {
23   - console.log(res.data)
24   - commit('INIT', res.data.data)
  59 + console.log('userRecommand-parm',param)
  60 + console.log(res.data.data)
  61 + // const Res={...res.data.data.list,...data.data.list}
  62 + goodsList=[...goodsList,...res.data.data]
  63 + // console.log(res.data)
  64 + commit('INIT', goodsList)
25 65 },
26 66 fail: (res) => {
  67 + uni.showToast({
  68 + title:"数据加载完了",
  69 + icon:"none"
  70 + })
27 71 console.log("fail status === > ", res);
28 72 },
29 73 complete: (res) => {
... ...
... ... @@ -20,6 +20,9 @@ const urlAlias = {
20 20  
21 21 // 购物车
22 22 cartList: '/app/cart/list', // 获取购物车列表
  23 + cartModi: '/app/cart/modi', // 修改购物车
  24 + cartDel: '/app/cart/del', // 删除购物车
  25 + cartAdd: '/app/cart/add',// 添加购物车
23 26  
24 27 // 我的
25 28 recommandList:'/app/prod/recommand', // 获取用户个性化推荐商品
... ...