goodtail.vue 14.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
<template>
	<view class="content">
		<view class="goodtailtop">
			<image :src="goodtail.image" mode=""></image>
		</view>
		<view v-if="type==1">
			<view class="tailbox boxsizing" v-if="goodtail.is_seckill==2">
				<view class="tailname">
					{{goodtail.name}}
				</view>
				<view class="tailhezi flextwo">
					<view class="tailhezileft flexone">
						<view class="saleprice">¥{{goodtail.goods_price}}</view>
						<view class="huiyuanprice">会员价:¥{{goodtail.vip_price}}</view>
					</view>
					<view class="heziright flexone">
						<!-- {{goodtail.flour_goods_spec.stock_num}} -->
						<view class="heziprice stock">库存:件</view>
						<view class="heziprice">已售{{goodtail.sales}}件</view>
					</view>
				</view>
			</view>

			<view class="tailbox boxsizing" v-else>
				<view class="tailname">
					<text class='miaobox'>限时秒杀</text>
					{{goodtail.name}}
				</view>
				<view class="tailhezi flextwo">
					<view class="tailhezileft flexone">
						<view class="saleprice">¥{{item.seckill_price}}</view>
						<view class="oldprice">¥{{item.goods_price}}</view>
					</view>
				</view>
				<view class='miaodu flextwo'>
					<view class="miaoduleft">
						<view class="miaotiao">
							已抢购60%
						</view>
					</view>
					<view class="miaoright flexone">
						<view class="distance">距离结束还剩</view>
						<view class="remaintime">23</view>
						<view class="dian">:</view>
						<view class="remaintime">53</view>
						<view class="dian">:</view>
						<view class="remaintime">42</view>
					</view>
				</view>
			</view>

		</view>


		<view class="tailbox boxsizing" v-else-if="type==2">
			<view class="tailname">
				{{goodtail.name}}
			</view>
			<view class="tailhezi flextwo">
				<view class="tailhezileft flexone">
					<view class="saleprice">¥{{goodtail.score_goods_spec.goods_price}}</view>
					<!-- <view class="huiyuanprice">会员价:¥{{goodtail.vip_price}}</view> -->
				</view>
				<view class="heziright flexone">
					<view class="heziprice stock">库存:{{goodtail.score_goods_spec.stock_num}}件</view>
					<view class="heziprice">已售{{goodtail.sales}}件</view>
				</view>
			</view>
		</view>

		<view class="tailbox boxsizing" v-else-if="type==3">
			<view class="tailname">
				{{goodtail.name}}
			</view>
			<view class="tailhezi flextwo">
				<view class="tailhezileft flexone">
					<view class="saleprice">¥{{goodtail.goods_price}}</view>
					<!-- <view class="huiyuanprice">会员价:¥{{goodtail.vip_price}}</view> -->
				</view>
				<view class="heziright flexone">
					<!-- <view class="heziprice stock">库存:{{goodtail.score_goods_spec.stock_num}}件</view> -->
					<view class="heziprice">已售{{goodtail.sales}}件</view>
				</view>
			</view>
		</view>

		<view class="send">
			{{goodtail.postage}}
			<!-- 包邮 店铺满100元包邮 -->
		</view>
		<view class="tapnav flextwo">
			<view class="tapnavitem " :class="selnav==1?'tapnavactive':''" @click="navtap" :data-id="1">详情</view>
			<view class="tapnavitem" :class="selnav==2?'tapnavactive':''" @click="navtap" :data-id="2">评论(200)</view>
		</view>

		<view class="goodetailbox" v-if="selnav==1">
			<rich-text :nodes="goodtail.content"></rich-text>
		</view>
		<view class="goodcomment" v-else>
			<view class="goodcommentop flexone">
				<view class="topitem" @click="commenttype" :data-id="0">全部(60万)</view>
				<view class="topitem"  @click="commenttype" :data-id="1">好评(16万)</view>
				<view class="topitem" @click="commenttype" :data-id="2">中评(10万)</view>
				<view class="topitem" @click="commenttype" :data-id="3">差评(600)</view>
			</view>
			<view class="commentlist">
				<view class="jianintro photobox" bindtap="comdetail">
					<view class="comtop flextwo">
						<view class="comleft">
							<image src="../../static/userpic.png"></image>
						</view>
						<view class="comright">

							<view class="comrtop">
								<view class="usertop flextwo">
									<view class="comrname">皖湘情</view>
									<view class="comdate">2019年10月12日</view>
								</view>
								<view class="star starone flexone">
									<view class="staritem">
										<image src="../../static/starredk.png"></image>
									</view>
									<view class="staritem">
										<image src="../../static/starredk.png"></image>
									</view>
									<view class="staritem">
										<image src="../../static/starredk.png"></image>
									</view>
									<view class="staritem">
										<image src="../../static/starredk.png"></image>
									</view>
									<view class="staritem">
										<image src="../../static/starredk.png"></image>
									</view>
									<view class="staritem">
										<image src="../../static/starred.png"></image>
									</view>
								</view>

							</view>
						</view>
					</view>
					<view class="commenttext">
						太给力了!!要加紧学习了啊太给力了!!要加紧学习了啊太给力了!!要加紧学习了啊
					</view>
					<view class="commentimg flexone">
						<view class="commentimgitem">
							<image src="../../static/shop.png" mode=""></image>
						</view>
						<view class="commentimgitem">
							<image src="../../static/shop.png" mode=""></image>
						</view>
						<view class="commentimgitem">
							<image src="../../static/shop.png" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 底部购物车 -->
		<view class='cartbot flextwo'>
			<view class='cartbotleft'>
				<view class='cartimg'>
					<image src="../../static/cartche.png" mode=""></image>
					<view class="cartnum">32</view>
				</view>

			</view>
			<view class='cartbotright flexone'>
				<view class="addcarbtn" @click="addcart">加入购物车</view>
				<view class="buynowbtn" @click="buynow">立即抢购</view>
			</view>
		</view>
		<!-- 属性弹出层 -->
		<view class='register' v-if="shuwrap">
			<view class="shuxingwrap">
				<view class="goodtailtopk flex">
					<view class="shuxingimg">
						<!-- 面坊商品 -->
						<view class="shusmallimg" v-if="type==1">
							<image :src="goodtail.flour_goods_spec.spec_image" mode=""></image>
						</view>
						<!-- 积分商品 -->
						<view class="shusmallimg" v-if="type==2">
							<image :src="goodtail.score_goods_spec.spec_image" mode=""></image>
						</view>
					</view>
					<view class='shuright'>
						<view class="shutop flex">
							<view class="shuname">{{goodtail.name}}
							</view>
							<view class="shucha" @click="hideshu">
								<image src="../../static/goodtaicha.png" mode=""></image>
							</view>
						</view>
						<!-- 面坊商品 -->
						<view class="saleprice" v-if="type==1">¥{{goodtail.price}}</view>
						<!-- 积分商品 -->
						<view class="saleprice" v-if="type==2">¥{{goodtail.score_goods_spec.goods_price}}</view>
					</view>
				</view>
				<view v-for="(item,parindex) in specarr" :key="parindex">
					<view class="weightbox">
						<view class="weight">{{item.spec_name}}</view>
						<view class="weightlsit flexone">
							<!-- witemactive -->
							<view class="weightlsititem" :class="item.selindex==childindex?'witemactive':''" v-for="(itemk,childindex) in item.spec_value"
							 :key="childindex" @click.stop="selspec(parindex,childindex)">{{itemk.spec_value}}</view>

						</view>
					</view>
				</view>
				<view class="weightbox flextwo">
					<view class="weight">数量</view>
					<view class="weightnumk flexone">
						<view class="weightnumkleft leftk" @click="reducenum">
							<image src="../../static/reduceimg.png" mode=""></image>
						</view>
						<view class="detailnum">{{cartnumber}}</view>
						<view class="weightnumkleft rightk" @click="addnum">
							<image src="../../static/addimg.png" mode=""></image>
						</view>
					</view>
				</view>
				<view class="addcarbtnk flexthree">
					<!-- <view class="addcarbtnkleft">加入购物车</view> -->
					<view class="addcarbtnkright" @click="sure">确定</view>
				</view>
			</view>

		</view>
	</view>
</template>
<script>
	import app from "../../App.vue";
	export default {
		data() {
			return {
				footersel: 1,
				sel: 2,
				shuwrap: false,
				goodid: '',
				type: "", //type  1 面访商城 2 积分商城
				goodtail: '',
				tapnavactive: '',
				selnav: 1,

				// 商品规格
				specarr: [],
				// 商品规格id 
				spec_sku_id: [],
				addtype: '', //1 加入购物车 2立即购买
				cartnumber: 1,
				arr: [],
				page:1,
				star_type:'',
				// 评论列表
				commentlist:[]

			}
		},
		onLoad(options) {
			console.log(options)
			this.goodid = options.id,
				this.type = options.type;
			if (this.type == 1) {
				this.getgoodtail();
			} else if (this.type == 2) {
				this.getjifengoodtail();
			} else {
				this.getshopgoodtail()
			}

		},
		methods: {
			hideshu() {
				this.shuwrap = false
			},
			// 评论切换
			commenttype(e){
				this.star_type=e.currentTarget.dataset.id;
			},
			// 顶部导航切换
			navtap(e) {
				this.selnav = e.currentTarget.dataset.id;
				if(this.selnav==1){
					if (this.type == 1) {
						this.getgoodtail();
					} else if (this.type == 2) {
						this.getjifengoodtail();
					} else {
						this.getshopgoodtail()
					}
				}else{
					this.page=1;
					this.commentlist=[];
					this.getcommentlist();
				}
			},
			// 数量加减
			reducenum() {
				this.cartnumber = this.cartnumber - 1;
				if (this.cartnumber == 0) {
					uni.showToast({
						title: '不能再减少了',
						icon: "none"
					})
					this.cartnumber = 1
				} else {
					this.cartnumber = this.cartnumber
				}

			},
			addnum() {
				this.cartnumber = this.cartnumber + 1;
				console.log(this.cartnumber)
				this.cartnumber = this.cartnumber
			},
			
			// 获取评论列表
			getcommentlist(){
				let that = this;
				var url = 'goods_comments/get_list';
				var params = {
					type:that.type,
					goods_id:that.goodid,
					star_type:that.star_type,
					page:that.page,
					pageNum:10
				}
				app.post(url, params).then((res) => {
					console.log(res);
					that.commentlist=that.commentlist.concat(res.data.data)
					
				
				}).catch((err) => {
				
				})
			},
			//获取面坊商品详情
			getgoodtail() {
				let that = this;
				var url = 'flour_goods/get_flour_goods_detail';
				var params = {
					flour_goods_id: that.goodid,
				}
				app.post(url, params).then((res) => {
					console.log(res);
					that.goodtail = res.data.data

				}).catch((err) => {

				})
			},
			// 获取积分商城商品详情
			getjifengoodtail() {
				let that = this;
				var url = 'score_goods/get_score_goods_detail';
				var params = {
					score_goods_id: that.goodid,
				}
				console.log(params)
				app.post(url, params).then((res) => {
					console.log(res);
					that.goodtail = res.data.data

				}).catch((err) => {
					console.log(err)

				})
			},
			// 获取店铺商品详情
			getshopgoodtail() {
				let that = this;
				var url = 'store_goods/get_store_goods_detail';
				var params = {
					store_goods_id: that.goodid,
				}
				console.log(params)
				app.post(url, params).then((res) => {
					console.log(res);
					that.goodtail = res.data.data

				}).catch((err) => {
					console.log(err)
				})
			},
			// 加入购物车
			addcart() {
				this.shuwrap = true;
				this.getspecs();
				this.addtype = 1
			},
			// 立即购买
			buynow() {
				this.shuwrap = true;
				this.getspecs();
				this.addtype = 2
			},
			//获取商品规格
			getspecs() {
				let that = this;
				var url = 'score_goods/get_spec_sku1';
				var params = {
					score_goods_id: that.goodid,
				}
				console.log(params)
				app.post(url, params).then((res) => {
					console.log(res);
					that.specarr = res.data.data;
					that.specarr.forEach(function(value, index, array) {
						value.selindex = 0;

						value.spec_value.forEach(function(valuek, indexk, arrayk) {
							if (indexk == 0) {
								value.selid = valuek.id;
							}
							valuek.sel = false
						})
					})

					that.specarr = that.specarr;

				}).catch((err) => {
					console.log(err)
				})
			},
			// 选择商品规格
			selspec(parindex, childindex) {
				let newspecarr = this.specarr;

				newspecarr[parindex].spec_value[childindex].sel = !newspecarr[parindex].spec_value[childindex].sel;
				newspecarr[parindex].selindex = childindex;
				newspecarr[parindex].selid = newspecarr[parindex].spec_value[childindex].id
				this.arr.push(newspecarr[parindex].spec_value[childindex].id);
				// console.log(this.spec_sku_id)
				this.specarr = newspecarr;

				// console.log(this.specarr[parindex].spec_value[childindex].sel)
				console.log(JSON.stringify(this.specarr))
				this.changspec()
			},
			// 更换商品的图片和价格
			changspec() {
				let that = this;
				let newspec_sku_id = []

				that.specarr.forEach(function(value, index, array) {
					newspec_sku_id.push(value.selid)
				})
				that.spec_sku_id = newspec_sku_id
				var url = 'score_goods/get_spec_sku2';
				var params = {
					score_goods_id: that.goodid,
					spec_sku_id: that.spec_sku_id.join("_")
				}
				console.log(params)
				app.post(url, params).then((res) => {
					console.log(res);
					if (that.type == 1) {
						that.goodtail.flour_goods_spec = res.data.data;
						that.goodtail.price = res.data.data.price;
					} else if (that.type == 2) {
						that.goodtail.score_goods_spec = res.data.data
					}
					that.goodtail = that.goodtail;
				}).catch((err) => {
					console.log(err)

				})
			},
			sure() {
				if (this.addtype == 1) {
					this.addcartk();
				} else {
					this.buynowk()
				}
			},
			// 加入购物车
			addcartk() {
				let that = this;
				let newspec_sku_id = []

				that.specarr.forEach(function(value, index, array) {
					newspec_sku_id.push(value.selid)
				})
				that.spec_sku_id = newspec_sku_id
				var url = 'car/join_car';
				var params = {
					type: this.type,
					goods_id: this.goodid,
					spec_sku_id: that.spec_sku_id.join("_"),
					number: that.cartnumber,
				}
				console.log(params)
				app.post(url, params).then((res) => {
					console.log(res);
					uni.showToast({
						title: "加入购物车成功",
						icon: 'none'
					})

					setTimeout(function() {
						uni.navigateTo({
							url: '/pages/nearshop/cartlist'
						})
					}, 1500)


				}).catch((err) => {
					console.log(err)

				})
			},
			// 立即购买
			buynowk() {
				let that = this;
				let newspec_sku_id = []

				that.specarr.forEach(function(value, index, array) {
					newspec_sku_id.push(value.selid)
				})
				that.spec_sku_id = newspec_sku_id

				var url = 'car/join_car';
				var params = {
					type: this.type,
					goods_id: this.goodid,
					spec_sku_id: that.spec_sku_id.join(","),
					number: that.cartnumber,
				}
				console.log(params)
				app.post(url, params).then((res) => {
					console.log(res);


				}).catch((err) => {
					console.log(err)

				})
			}
		}

	}
</script>

<style>
	@import url('../../base/nearshop');
	@import url('../../base/homepage');

	.huiyuanprice {
		margin-left: 28rpx
	}

	.tapnav {
		padding: 32rpx 126rpx;
		box-sizing: border-box;
	}
</style>