作者 wangxuyu

修改购物车默认选中

@@ -6,9 +6,9 @@ Page({ @@ -6,9 +6,9 @@ Page({
6 * 页面的初始数据 6 * 页面的初始数据
7 */ 7 */
8 data: { 8 data: {
9 - choose: false, 9 + choose: true,
10 choose2: true, 10 choose2: true,
11 - chooseAll2: false, 11 + chooseAll2: true,
12 number: 1, 12 number: 1,
13 goodsList: [], 13 goodsList: [],
14 goodsId: 0, 14 goodsId: 0,
@@ -21,10 +21,10 @@ Page({ @@ -21,10 +21,10 @@ Page({
21 is_vip: 0, 21 is_vip: 0,
22 cartId: 1, 22 cartId: 1,
23 listlist: [], 23 listlist: [],
24 - all_both_choose: false, 24 + all_both_choose: true,
25 chuandi: 0, 25 chuandi: 0,
26 chuandis: 0, 26 chuandis: 0,
27 - xuanzhong: false, 27 + xuanzhong: true,
28 shengyu: 0 28 shengyu: 0
29 }, 29 },
30 //跳转至详情页 30 //跳转至详情页
@@ -119,6 +119,65 @@ Page({ @@ -119,6 +119,65 @@ Page({
119 }) 119 })
120 this.totalPrice(); 120 this.totalPrice();
121 }, 121 },
  122 + allBothChooses() {
  123 + let that = this
  124 + let goodsList = that.data.goodsList
  125 + let promotion = that.data.promotion
  126 + let all_both_choose = !that.data.all_both_choose
  127 + if (all_both_choose) {
  128 + all_both_choose = false
  129 + } else {
  130 + all_both_choose = true
  131 + }
  132 + goodsList.forEach(function (ele, index) {
  133 + if (all_both_choose) {
  134 + ele.chooseAll = true
  135 + for (let i = 0; i < ele.list.length; i++) {
  136 + ele.list[i].flag = true
  137 + }
  138 + that.setData({
  139 + goodsList: goodsList,
  140 + xuanzhong: true
  141 + })
  142 + } else {
  143 + ele.chooseAll = false
  144 + for (let i = 0; i < ele.list.length; i++) {
  145 + ele.list[i].flag = false
  146 + }
  147 + that.setData({
  148 + goodsList: goodsList,
  149 + xuanzhong: false,
  150 + })
  151 + }
  152 + })
  153 + promotion.forEach(function (ele, index) {
  154 + if (all_both_choose) {
  155 + ele.chooseAll = true
  156 + for (let i = 0; i < ele.list.length; i++) {
  157 + ele.list[i].flag = true
  158 + }
  159 + that.setData({
  160 + promotion: promotion,
  161 + xuanzhong: true
  162 + })
  163 + } else {
  164 + ele.chooseAll = false
  165 + for (let i = 0; i < ele.list.length; i++) {
  166 + ele.list[i].flag = false
  167 + }
  168 + that.setData({
  169 + promotion: promotion,
  170 + xuanzhong: false
  171 + })
  172 + }
  173 + })
  174 + that.setData({
  175 + all_both_choose: all_both_choose,
  176 + })
  177 + console.log(all_both_choose + "前")
  178 + this.totalPrice();
  179 + console.log(all_both_choose+"后")
  180 + },
122 //fetchUser 181 //fetchUser
123 fetchUser() { 182 fetchUser() {
124 let url = '/wxapp/user/index' 183 let url = '/wxapp/user/index'
@@ -140,12 +199,16 @@ Page({ @@ -140,12 +199,16 @@ Page({
140 var list = {}; 199 var list = {};
141 var number = 1; 200 var number = 1;
142 var g_price = 0; 201 var g_price = 0;
  202 + var totalPrice = 0
  203 + var chuandis = null
  204 + var chuandi = null
143 var vip = that.data.is_vip 205 var vip = that.data.is_vip
  206 + var shipprice = null
144 app.post(url).then(r => { 207 app.post(url).then(r => {
145 r.data.list.forEach(function(ele, index) { 208 r.data.list.forEach(function(ele, index) {
146 - ele.chooseAll = false 209 + ele.chooseAll = true
147 for (let v in ele.list) { 210 for (let v in ele.list) {
148 - ele.list[v].flag = false 211 + ele.list[v].flag = true
149 if (vip == 1) { 212 if (vip == 1) {
150 var price = ele.list[v].vip_price 213 var price = ele.list[v].vip_price
151 price = price.substring(0, price.length - 3) * 1 214 price = price.substring(0, price.length - 3) * 1
@@ -155,10 +218,12 @@ Page({ @@ -155,10 +218,12 @@ Page({
155 price = price.substring(0, price.length - 3) * 1 218 price = price.substring(0, price.length - 3) * 1
156 ele.list[v].goods_price = ele.list[v].number * price 219 ele.list[v].goods_price = ele.list[v].number * price
157 } 220 }
  221 +
  222 + totalPrice += ele.list[v].goods_price
158 } 223 }
159 }) 224 })
160 r.data.promotion.forEach(function(ele, index) { 225 r.data.promotion.forEach(function(ele, index) {
161 - ele.chooseAll=false 226 + ele.chooseAll=true
162 for (let v in ele.list) { 227 for (let v in ele.list) {
163 ele.list[v].t = false 228 ele.list[v].t = false
164 if (vip == 1) { 229 if (vip == 1) {
@@ -169,9 +234,21 @@ Page({ @@ -169,9 +234,21 @@ Page({
169 var price = ele.list[v].price 234 var price = ele.list[v].price
170 price = price.substring(0, price.length - 3) * 1 235 price = price.substring(0, price.length - 3) * 1
171 ele.list[v].goods_price = ele.list[v].number * price 236 ele.list[v].goods_price = ele.list[v].number * price
172 - } 237 + }
  238 + totalPrice += ele.list[v].goods_price
173 } 239 }
174 - }) 240 + })
  241 + chuandis = totalPrice
  242 + if (totalPrice > r.data.shipment.free) {
  243 + shipprice = 0
  244 + } else {
  245 + shipprice = r.data.shipment.price
  246 + }
  247 + var ship_balance = that.data.shipment.free * 1 - totalPrice
  248 + if (ship_balance <= 0) {
  249 + shipprice = 0
  250 + }
  251 + chuandi = totalPrice * 1 + shipprice * 1
175 that.setData({ 252 that.setData({
176 listlist: r.data, 253 listlist: r.data,
177 goodsList: r.data.list, 254 goodsList: r.data.list,
@@ -179,7 +256,10 @@ Page({ @@ -179,7 +256,10 @@ Page({
179 number: number, 256 number: number,
180 shipment: r.data.shipment, 257 shipment: r.data.shipment,
181 shipPrice: r.data.shipment.price, 258 shipPrice: r.data.shipment.price,
182 - shengyu: r.data.minimum_price 259 + shengyu: r.data.minimum_price,
  260 + totalPrice: totalPrice,
  261 + chuandi:chuandi,
  262 + chuandis:chuandis
183 }); 263 });
184 }); 264 });
185 }, 265 },
@@ -191,7 +271,6 @@ Page({ @@ -191,7 +271,6 @@ Page({
191 var vip = that.data.is_vip * 1 271 var vip = that.data.is_vip * 1
192 goodsList.forEach(function(ele, index) { 272 goodsList.forEach(function(ele, index) {
193 for (let v in ele.list) { 273 for (let v in ele.list) {
194 - console.log("进来了goodsList")  
195 if (vip == 1) { 274 if (vip == 1) {
196 var price = ele.list[v].vip_price 275 var price = ele.list[v].vip_price
197 price = price.substring(0, price.length - 3) * 1 276 price = price.substring(0, price.length - 3) * 1
@@ -341,6 +420,8 @@ Page({ @@ -341,6 +420,8 @@ Page({
341 */ 420 */
342 onLoad: function(options) { 421 onLoad: function(options) {
343 this.fetchUser(); 422 this.fetchUser();
  423 + this.allBothChooses()
  424 + console.log(this.data.all_both_choose + "zhong")
344 }, 425 },
345 // 再逛逛 426 // 再逛逛
346 get_return() { 427 get_return() {
@@ -829,13 +910,14 @@ Page({ @@ -829,13 +910,14 @@ Page({
829 let a=this.data.shipment.free 910 let a=this.data.shipment.free
830 this.fetchCartList(); 911 this.fetchCartList();
831 this.setData({ 912 this.setData({
832 - chooseAll: false,  
833 - chooseAll2: false, 913 + // chooseAll: false,
  914 + // chooseAll2: false,
834 totalPrice: 0, 915 totalPrice: 0,
835 - all_both_choose: false, 916 + // all_both_choose: false,
836 ship_balance:a 917 ship_balance:a
837 }) 918 })
838 this.fetchCartNum() 919 this.fetchCartNum()
  920 + this.allBothChooses()
839 }, 921 },
840 922
841 /** 923 /**
@@ -33,7 +33,7 @@ Page({ @@ -33,7 +33,7 @@ Page({
33 last_total_price: 0, 33 last_total_price: 0,
34 deliverTime: false, 34 deliverTime: false,
35 deliverList: [], 35 deliverList: [],
36 - deliverTimeId: 0, 36 + deliverTimeId: null,
37 deliverTimeStr: '请选择时间', 37 deliverTimeStr: '请选择时间',
38 order_sn: 0, 38 order_sn: 0,
39 39
@@ -106,7 +106,7 @@ Page({ @@ -106,7 +106,7 @@ Page({
106 let c = ele.labelArray.week 106 let c = ele.labelArray.week
107 if (e == c) { 107 if (e == c) {
108 ele.children.forEach(function (eles, indexs) { 108 ele.children.forEach(function (eles, indexs) {
109 - if (!eles.disabled) { 109 + if (eles.disabled) {
110 if (b == eles.label) { 110 if (b == eles.label) {
111 deliveryTimeId = eles.value 111 deliveryTimeId = eles.value
112 } 112 }
@@ -114,6 +114,7 @@ Page({ @@ -114,6 +114,7 @@ Page({
114 timeflag: false 114 timeflag: false
115 }) 115 })
116 } else { 116 } else {
  117 + console.log(909090)
117 wx.showToast({ 118 wx.showToast({
118 title: '亲,该时间段已排满咯~', 119 title: '亲,该时间段已排满咯~',
119 icon: 'none' 120 icon: 'none'
@@ -166,6 +167,8 @@ Page({ @@ -166,6 +167,8 @@ Page({
166 // weeks[1] = week_right 167 // weeks[1] = week_right
167 // weeks[1] = ["13.00-15.00","15.00-17.00"] 168 // weeks[1] = ["13.00-15.00","15.00-17.00"]
168 var weeks_two = week_right 169 var weeks_two = week_right
  170 + console.log('000')
  171 + console.log(week_arr)
169 this.setData({ 172 this.setData({
170 timeDataArray: canlda, 173 timeDataArray: canlda,
171 week_arr: week_arr, 174 week_arr: week_arr,
@@ -182,6 +185,8 @@ Page({ @@ -182,6 +185,8 @@ Page({
182 this.setData({ 185 this.setData({
183 multiArray: [week_arr, arr1[0]] 186 multiArray: [week_arr, arr1[0]]
184 }) 187 })
  188 + console.log(111)
  189 + console.log([week_arr, arr1[0]])
185 }, 190 },
186 //返回 191 //返回
187 get_my() { 192 get_my() {
@@ -234,14 +239,19 @@ Page({ @@ -234,14 +239,19 @@ Page({
234 let url = '/wxapp/cart/settlement'; 239 let url = '/wxapp/cart/settlement';
235 let params = { 240 let params = {
236 ids: this.data.ids 241 ids: this.data.ids
237 - } 242 + }
  243 + let addid = null
238 app.post(url, params).then(r => { 244 app.post(url, params).then(r => {
239 console.log(r) 245 console.log(r)
240 var list = r.data.list; 246 var list = r.data.list;
  247 + var addid = null
241 r.data.vips.forEach(function(ele, index) { 248 r.data.vips.forEach(function(ele, index) {
242 ele.t = false 249 ele.t = false
243 }); 250 });
244 r.data.timeDataArray.forEach(function(ele, index) { 251 r.data.timeDataArray.forEach(function(ele, index) {
  252 + if(index==0){
  253 + addid = ele.children[0].value
  254 + }
245 var new_arr = [] 255 var new_arr = []
246 for (let i = 0; i < ele.children.length; i++) { 256 for (let i = 0; i < ele.children.length; i++) {
247 new_arr.push(ele.children[i].label) 257 new_arr.push(ele.children[i].label)
@@ -258,8 +268,10 @@ Page({ @@ -258,8 +268,10 @@ Page({
258 timeDataArray: r.data.timeDataArray, 268 timeDataArray: r.data.timeDataArray,
259 deliverList: r.data.timeDataArray, 269 deliverList: r.data.timeDataArray,
260 addressList: r.data.address, 270 addressList: r.data.address,
261 - amount: that.data.amount 271 + amount: that.data.amount,
  272 + addressId:addid
262 }); 273 });
  274 + console.log(addid+'刚进来')
263 if (that.data.num == 0) { 275 if (that.data.num == 0) {
264 that.goodsTotalPrice(); 276 that.goodsTotalPrice();
265 } 277 }
@@ -274,11 +286,15 @@ Page({ @@ -274,11 +286,15 @@ Page({
274 let params = { 286 let params = {
275 ids: this.data.ids, 287 ids: this.data.ids,
276 num: this.data.num 288 num: this.data.num
277 - } 289 + }
  290 + let addid = null
278 app.post(url, params).then(r => { 291 app.post(url, params).then(r => {
279 if (r.code == 1) { 292 if (r.code == 1) {
280 var list = r.data.list; 293 var list = r.data.list;
281 - r.data.timeDataArray.forEach(function(ele, index) { 294 + r.data.timeDataArray.forEach(function (ele, index) {
  295 + if (index == 0) {
  296 + addid = ele.children[0].value
  297 + }
282 var new_arr = [] 298 var new_arr = []
283 for (let i = 0; i < ele.children.length; i++) { 299 for (let i = 0; i < ele.children.length; i++) {
284 new_arr.push(ele.children[i].label) 300 new_arr.push(ele.children[i].label)
@@ -292,7 +308,8 @@ Page({ @@ -292,7 +308,8 @@ Page({
292 vipList: r.data.vips, 308 vipList: r.data.vips,
293 timeDataArray: r.data.timeDataArray, 309 timeDataArray: r.data.timeDataArray,
294 deliverList: r.data.timeDataArray, 310 deliverList: r.data.timeDataArray,
295 - ship_ment_price: r.data.priceData.shipment_price 311 + ship_ment_price: r.data.priceData.shipment_price,
  312 + addressId:addid
296 }); 313 });
297 // that.fetchAmount(); 314 // that.fetchAmount();
298 that.amount() 315 that.amount()
@@ -344,11 +361,15 @@ Page({ @@ -344,11 +361,15 @@ Page({
344 let params = { 361 let params = {
345 ids: that.data.ids, 362 ids: that.data.ids,
346 id: that.data.proId 363 id: that.data.proId
347 - } 364 + }
  365 + let addid = null
348 var totalPrice = that.data.totalPrice 366 var totalPrice = that.data.totalPrice
349 app.post(url, params).then(r => { 367 app.post(url, params).then(r => {
350 if (r.code == 1) { 368 if (r.code == 1) {
351 - r.data.timeDataArray.forEach(function(ele, index) { 369 + r.data.timeDataArray.forEach(function (ele, index) {
  370 + if (index == 0) {
  371 + addid = ele.children[0].value
  372 + }
352 var new_arr = [] 373 var new_arr = []
353 for (let i = 0; i < ele.children.length; i++) { 374 for (let i = 0; i < ele.children.length; i++) {
354 new_arr.push(ele.children[i].label) 375 new_arr.push(ele.children[i].label)
@@ -362,7 +383,8 @@ Page({ @@ -362,7 +383,8 @@ Page({
362 vipList: r.data.vips, 383 vipList: r.data.vips,
363 timeDataArray: r.data.timeDataArray, 384 timeDataArray: r.data.timeDataArray,
364 deliverList: r.data.timeDataArray, 385 deliverList: r.data.timeDataArray,
365 - ship_ment_price: r.data.priceData.shipment_price 386 + ship_ment_price: r.data.priceData.shipment_price,
  387 + addressId:addid
366 }) 388 })
367 this.getWeek(); 389 this.getWeek();
368 } 390 }
@@ -408,10 +430,14 @@ Page({ @@ -408,10 +430,14 @@ Page({
408 id: that.data.packId, 430 id: that.data.packId,
409 ids: that.data.packIds 431 ids: that.data.packIds
410 } 432 }
  433 + let addid = null
411 app.post(url, params).then(r => { 434 app.post(url, params).then(r => {
412 if (r.code == 1) { 435 if (r.code == 1) {
413 console.log(r) 436 console.log(r)
414 - r.data.timeDataArray.forEach(function(ele, index) { 437 + r.data.timeDataArray.forEach(function (ele, index) {
  438 + if (index == 0) {
  439 + addid = ele.children[0].value
  440 + }
415 var new_arr = [] 441 var new_arr = []
416 for (let i = 0; i < ele.children.length; i++) { 442 for (let i = 0; i < ele.children.length; i++) {
417 new_arr.push(ele.children[i].label) 443 new_arr.push(ele.children[i].label)
@@ -434,7 +460,8 @@ Page({ @@ -434,7 +460,8 @@ Page({
434 ship_ment_price: r.data.priceData.shipment_price, 460 ship_ment_price: r.data.priceData.shipment_price,
435 amount: price, 461 amount: price,
436 goodsTotalPrice: price, 462 goodsTotalPrice: price,
437 - last_total_price: price 463 + last_total_price: price,
  464 + addressId: addid
438 }); 465 });
439 this.getWeek(); 466 this.getWeek();
440 } 467 }
@@ -134,6 +134,9 @@ position: relative; @@ -134,6 +134,9 @@ position: relative;
134 padding-right:16rpx; 134 padding-right:16rpx;
135 box-sizing: border-box; 135 box-sizing: border-box;
136 flex-grow: 1; 136 flex-grow: 1;
  137 + overflow: hidden;
  138 + text-overflow: ellipsis;
  139 + white-space: nowrap;
137 /* background: red */ 140 /* background: red */
138 } 141 }
139 142