浏览代码

新增数据

lyy@qq.com 1 年之前
父节点
当前提交
c7d24de036
共有 9 个文件被更改,包括 214 次插入230 次删除
  1. 102 99
      components/specPopup.vue
  2. 3 3
      main.js
  3. 0 8
      pages.json
  4. 47 92
      pages/classify/classify.vue
  5. 25 15
      pages/diningCar/diningCar.vue
  6. 13 10
      pages/diningList/diningList.vue
  7. 3 0
      pages/goodDetail/goodDetail.vue
  8. 1 1
      pages/login/login.vue
  9. 20 2
      pages/user/user.vue

+ 102 - 99
components/specPopup.vue

@@ -2,31 +2,30 @@
 	<uni-popup ref="popup" background-color="#fff" mode="bottom" @change="change">
 		<view class="s-box padding-sm">
 			<view class="s-img">
-				<image mode="aspectFit" class="wh-full" :src="cardMsg.src"></image>
+				<image mode="aspectFit" class="wh-full"
+					:src="caMsg.img[0].url ? caMsg.img[0].url : cardMsg.imgList[0].url"></image>
 			</view>
 			<view class="g-info">
-				<view class="s-name">{{cardMsg.goods_name}}</view>
-				<view class="s-price">{{cardMsg.goods_price}}</view>
+				<view class="s-name">{{caMsg.skuName ? caMsg.skuName : cardMsg.spuName}}</view>
+				<view class="s-price">{{caMsg.retailPrice ? caMsg.retailPrice : cardMsg.minPrice}}</view>
 			</view>
 		</view>
-		<uni-section title="规格">
-			<view class="spec-box padding-lr-sm">
-				<view class="spec-item padding-lr-sm" :class="{'on-spec': spec.selected}" :key="spec.id"
-					@click="selectSpec1(spec)" v-for="spec in specs1">{{ spec.name }}</view>
+		<scroll-view style="height: 270px;" scroll-y>
+			<view v-for="(item, index)  in specs" :key="index">
+				<uni-section :title="item.name">
+					<view class="spec-box padding-lr-sm">
+						<view class="spec-item padding-lr-sm" v-for="(spe, cindex) in item.values"
+							:class="{'on-spec': spe.selected}" :key="cindex" @click="selectSpec1(item, spe)">
+							{{ spe.label }}
+						</view>
+					</view>
+				</uni-section>
 			</view>
-		</uni-section>
-		<uni-section title="口味">
-			<view class="spec-box padding-lr-sm">
-				<view class="spec-item padding-lr-sm" :class="{'on-spec': spec.selected}" :key="spec.id"
-					@click="selectSpec2(spec)" v-for="spec in specs2">{{ spec.name }}</view>
-			</view>
-		</uni-section>
-		<uni-section title="购买数量">
-			<view class="purchase-num padding-lr-sm">
-				<view class="num">剩余562件</view>
-				<uni-number-box v-model="vModelValue" @change="changeValue(value)" />
-			</view>
-		</uni-section>
+		</scroll-view>
+		<view class="purchase-num padding-lr-sm">
+			<uni-section title="购买数量"></uni-section>
+			<uni-number-box v-model="vModelValue" @change="changeValue(value)" />
+		</view>
 		<view class="btn-box">
 			<view class="btn reset" @click="toShop">加入购物车</view>
 			<view class="btn confirm" @click="toBuy">立即购买</view>
@@ -49,97 +48,105 @@
 				shopMsg: {
 					id: '',
 					spec: '',
-					specs: '',
 					num: ''
 				},
-				specs1: [{
-						id: 1,
-						name: '规格1',
-						selected: false
-					},
-					{
-						id: 2,
-						name: '规格2',
-						selected: false
-					},
-					{
-						id: 3,
-						name: '规格3',
-						selected: false
-					},
-					{
-						id: 4,
-						name: '规格4',
-						selected: false
-					},
-					{
-						id: 5,
-						name: '规格5',
-						selected: false
-					}
-				],
-				specs2: [{
-						id: 1,
-						name: '大份1',
-						selected: false
-					},
-					{
-						id: 2,
-						name: '大份2',
-						selected: false
-					},
-					{
-						id: 3,
-						name: '大份3',
-						selected: false
-					},
-					{
-						id: 4,
-						name: '大份4',
-						selected: false
-					},
-					{
-						id: 5,
-						name: '大份5',
-						selected: false
-					}
-				]
+				specs: [], // 总查询数据
+				speL: [],
+				intSkuId: [], // 选择唯一的id
+				caMsg: [], // 根据id查出来的数据
 			}
 		},
+		mounted() {
+			console.log('specPopup mounted:', this.cardMsg)
+		},
 		methods: {
 			changeValue(e) {
 				console.log('vModelValue', e)
-
 			},
 			change(e) {
 				if (!e.show) { // 当弹出层关闭时
 					// 重置规格选择
-					this.specs1.forEach(spec => {
-						spec.selected = false;
-					});
-					this.specs2.forEach(spec => {
-						spec.selected = false;
-					});
-
+					if (this.specs.length > 0) {
+						this.specs.forEach(e => {
+							e.values.forEach(s => {
+								s.selected = false
+							})
+						})
+					}
+					this.speL = []
 					// 重置购买数量
 					this.vModelValue = 1;
 				}
 			},
-			selectSpec1(item) {
-				console.log('点击了规格:', item);
-				item.selected = !item.selected;
-				this.shopMsg.spec = item.name
-				// 在这里添加您的点击处理逻辑
-			},
-			selectSpec2(item) {
-				console.log('点击了大份:', item);
-				item.selected = !item.selected;
-				this.shopMsg.specs = item.name
-				// 在这里添加您的点击处理逻辑
+			async selectSpec1(item, spec) {
+				// 首先,取消选择所有其他选项
+				item.values.forEach(value => {
+					value.selected = false;
+				})
+				// 然后,选择当前点击的选项
+				spec.selected = true;
+				if (spec.selected) {
+					this.speL.push(spec)
+				}
+				console.log('speL', this.speL)
+
+				const seleList = this.speL.filter(item => item.selected == true)
+				// 计算选中规格项的skuIds数组的交集
+				if (seleList.length > 0) {
+					let intersection = seleList[0].skuIds;
+
+					// 遍历数组中的每个对象
+					for (let i = 1; i < seleList.length; i++) {
+						// 使用filter和includes方法找到交集
+						intersection = intersection.filter(skuId => {
+							return seleList[i].skuIds.includes(skuId);
+						});
+					}
+
+					// 如果交集不为空,取第一个元素作为唯一字符串
+					const uniqueString = intersection.length > 0 ? intersection[0] : '';
+
+					// 更新组件中的intSkuId
+					this.intSkuId = uniqueString;
+				} else {
+					// 如果没有选中的规格项,返回空字符串
+					this.intSkuId = '';
+				}
+				console.log('intSkuId', this.intSkuId)
+				// 确定每一个都有选择后发起请求
+				const isSelected = this.specs.every(spec => spec.values.some(value => value.selected))
+				if (isSelected) {
+					// 如果所有规格都至少有一个选项被选中
+					console.log('所有规格都已选择');
+					const res = await this.$request('get', `/item/sku/${this.intSkuId}`)
+					console.log('res================', res.data)
+					this.caMsg = res.data
+				} else {
+					// 否则,打印一个错误信息
+					console.log('还有规格未选择');
+				}
 			},
-			open() {
-				console.log('cardMsg', this.cardMsg)
+			async open() {
 				this.$refs.popup.open('bottom')
+				console.log('cardMsg', this.cardMsg)
+				const spuId = this.cardMsg.spuId
+				const res = await this.$request('get', `/item/sku/queryPropMapping?spuId=${spuId}`)
+				console.log('res.data', res.data)
+				this.specs = res.data.filter(item => item.values && item.values.length > 0);
+				// this.specs.forEach(item => Object.assign(item, {
+				// 	selected: false
+				// }))
+				this.specs.forEach(item => {
+					Object.assign(item, {
+						values: item.values.map(value => ({
+							...value,
+							ids: item.id,
+							selected: false
+						}))
+					});
+				});
+
+				console.log('this.spec', this.specs)
 			},
 			toShop() {
 				this.shopMsg.id = this.cardMsg.id
@@ -248,10 +255,6 @@
 		justify-content: space-between;
 		align-items: center;
 		border-bottom: solid 1px #EEE;
-		padding-bottom: 30upx;
-
-		.num {
-			font-size: 12px;
-		}
+		padding-bottom: 20upx;
 	}
 </style>

+ 3 - 3
main.js

@@ -54,9 +54,9 @@ Vue.prototype.$request = function(method, url, data, isJSON, hideLoading, showEr
 
 		const token = uni.getStorageSync('token');
 		const tenantId = uni.getStorageSync('tenantId');
-		if (tenantId) {
-			data.tenantId = tenantId;
-		}
+		// if (tenantId) {
+		// 	data.tenantId = tenantId;
+		// }
 		url = url.indexOf('http') === 0 ? url : `${Vue.prototype.serverPath}${url}`;
 		uni.request({
 			url,

+ 0 - 8
pages.json

@@ -1,6 +1,5 @@
 {
 	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
-		
 		{
 			"path" : "pages/classify/classify",
 			"style" : 
@@ -9,13 +8,6 @@
 				"enablePullDownRefresh" : false
 			}
 		},
-		{
-			"path" : "pages/login/login",
-			"style" : 
-			{
-				"navigationBarTitleText" : "登录"
-			}
-		},
 		{
 			"path" : "pages/user/user",
 			"style" : 

+ 47 - 92
pages/classify/classify.vue

@@ -10,9 +10,10 @@
 					</view>
 				</u-col>
 				<view class="container">
-					<u-tag plain :text="tags ? '营业中' : '离线'" :type="tags ? 'success' : 'error'" size="mini"></u-tag>
+					<u-tag plain :text="cList.openState ? '营业中' : '离线'" :type="cList.openState ? 'success' : 'error'"
+						size="mini"></u-tag>
 					<view @click="btnIc">
-						<u-icon label="当前餐车名称" labelPos="left" size="16" name="arrow-down"></u-icon>
+						<u-icon :label="cList.name" labelPos="left" size="16" name="arrow-down"></u-icon>
 					</view>
 				</view>
 				<u-col span="3">
@@ -22,34 +23,17 @@
 				</u-col>
 			</u-row>
 		</view>
-		<!-- <top-search :isSearch="false" @searchClick="searchClick"></top-search>
-		 <view class="w-full padding-lr-sm box-sizing-b dflex-b">
-			<scroll-view class="goods-category" scroll-x>
-				<view class="category-box">
-					<view class="category-item padding-lr-lg" v-for="item in 8" :key="item" :class="{'on-category':onIndex === item}">分类{{item+1}}</view>
-				</view>
-			</scroll-view>
-			<view class="classify-icon">
-				<u-icon name="grid-fill" size="30" @click="show = true" />
-			</view>
-		</view>
-		<u-popup :show="show" mode="left" @close="show = false">
-			<view class="classify-popup padding-lr-lg padding-tb box-sizing-b">
-				<view class="padding-tb-sm">全部</view>
-				<view class="padding-tb-sm" v-for="index in 8">分类{{index+1}}</view>
-			</view>
-		</u-popup> -->
 		<view class="w-full dflex-b padding-xs box-sizing-b dflex-wrap-w">
 			<view class="goods-item margin-bottom-sm" v-for="(item, gindex)  in goods" :key="gindex">
-				<view class="img dflex-c" @click="toDetial">
-					<image mode="aspectFit" :src="'../../static/x'+ gindex%2 +'.jpg'"></image>
+				<view class="img dflex-c" @click="toDetial(item)">
+					<image mode="aspectFit" :src="item.imgList[0].url"></image>
 				</view>
-				<view class="title">{{item.goods_name}}</view>
+				<view class="title">{{item.spuName}}</view>
 				<view class="dflex padding-bottom-xs">
 					<u-tag plain text="销量: 199" borderColor="#FF6D20" color="#FF6D20" size="mini"></u-tag>
 				</view>
 				<view class="w-full dflex-b">
-					<view class="price">{{item.goods_price}}</view>
+					<view class="price">{{item.minPrice ? item.minPrice : '无'}}</view>
 					<view>
 						<u-button type="primary" shape="circle" size="small"
 							color="linear-gradient(to right, #F54319, #FF6D20)" @click="goCart(item)">
@@ -59,7 +43,7 @@
 				</view>
 			</view>
 		</view>
-		<my-gap :height="130" />
+		<my-gap :height="10" />
 		<specPopup class='spec-box' ref="specPopup" :cardMsg="cardMsg" @update-shopmsg="handleUpdateShopMsg">
 		</specPopup>
 		<view class="cart-bottom padding-sm dflex-b">
@@ -97,89 +81,39 @@
 				shoppingCart: shoppingCart,
 				tags: 1,
 				txts: 1,
-				goods: [ // 购物车数据列表
-					{
-						id: 1,
-						goods_name: "小乳酸菌牛奶酸奶",
-						goods_price: 5.20,
-						goods_type: '大份',
-						goods_num: 1,
-						src: '../../static/x0.jpg',
-
-					},
-					{
-						id: 2,
-						goods_name: "饮料整箱饮品",
-						goods_price: 5.20,
-						goods_type: '大份',
-						goods_num: 1,
-						src: '../../static/x1.jpg',
-
-					},
-					{
-						id: 3,
-						goods_name: "饮品早餐酸乳益生菌",
-						goods_price: 5.20,
-						goods_type: '小份',
-						goods_num: 1,
-						src: '../../static/x0.jpg',
-
-					},
-					{
-						id: 4,
-						goods_name: "酸奶饮料",
-						goods_price: 5.20,
-						goods_type: '小份',
-						goods_num: 1,
-						src: '../../static/x1.jpg',
-
-					},
-					{
-						id: 5,
-						goods_name: "小乳酸菌",
-						goods_price: 5.20,
-						goods_type: '小份',
-						goods_num: 1,
-						src: '../../static/x0.jpg',
-
-					},
-					{
-						id: 6,
-						goods_name: "酸乳益生菌",
-						goods_price: 5.20,
-						goods_type: '大份',
-						goods_num: 1,
-						src: '../../static/x1.jpg',
-
-					}
-				],
+				carList: {},
+				goods: [],
 				total: 0,
-				carList: [],
+				cList: {},
 				cardMsg: {},
 				selectedList: [],
 				buyCount: 0
 			}
 		},
-		created() {
-			this.fatchDate()
+		onLoad() {
+			const e = uni.getStorageSync('carl')
+			this.cList = e
+			this.fatchDate(e)
 		},
 		methods: {
 			// 加购
 			goCart(e) {
 				console.log('================', e)
 				this.cardMsg = e
-				this.$refs.specPopup.open();
-				//this.$refs.specPopup.change(true);
+				this.$nextTick(() => {
+					this.$refs.specPopup.open();
+				});
+				this.carList = e
 			},
 			handleSelectedChanged(selectedItems) {
 				console.log('选中的数据:', selectedItems)
 				this.carList = selectedItems
-				if(selectedItems.length > 0){
+				if (selectedItems.length > 0) {
 					this.buyCount = this.carList.length
 				} else {
 					this.buyCount = 0
 				}
-				
+
 				this.totalPrice();
 			},
 			handleUpdateShopMsg(shopMsg) {
@@ -207,7 +141,7 @@
 					this.buyCount = this.carList.length
 					// 您可以在这里执行其他逻辑,比如保存到本地存储或发送到服务器
 				}
-				
+
 				console.log('购物车列表更新:', this.carList);
 				this.totalPrice();
 			},
@@ -257,9 +191,9 @@
 					url: `/pages/diningList/diningList`
 				})
 			},
-			toDetial() {
+			toDetial(e) {
 				uni.navigateTo({
-					url: `/pages/goodDetail/goodDetail`
+					url: `/pages/goodDetail/goodDetail?id=${e}`
 				})
 			},
 			toBuy() {
@@ -273,14 +207,35 @@
 				})
 			},
 			onMyInfo() {
+
+				const info = {
+					customerPhone: this.cList.customerPhone
+				}
+				console.log('======================', info)
+				uni.setStorageSync("info", info)
 				uni.navigateTo({
 					url: `/pages/user/user`
 				})
 			},
 			// 获取餐车列表
-			fatchDate() {
-				
+			async fatchDate(e) {
+				var queryParmas = {
+					id: e.id
+				}
+				console.log('idididididid', queryParmas)
+				const result = await this.$request('post', '/sale/diningCarProduct/queryDiningCarProduct', queryParmas,
+					true)
+				if (result) {
+					const queIds = new Set(result.rows.map(item => item.spuId));
+					const spuIds = Array.from(queIds).join(',');
+					const res = await this.$request('get', `/item/spu/queryByIds?spuIds=${spuIds}`)
+					const data = res.data
+					this.goods = data.filter(item => item.status !== 1)
+					
+					console.log('res', res.data)
+				}
 			}
+
 		}
 	}
 </script>

+ 25 - 15
pages/diningCar/diningCar.vue

@@ -2,7 +2,13 @@
 	<view>
 		<view class="boxWarp mb20px">
 			<view class="box" style="height:100vh;">
-				<my-swiper :datas="swiperDatas" />
+				<my-swiper v-if="dinList.diningCarImg && dinList.diningCarImg.length"
+					:datas="dinList.diningCarImg" />
+				<div v-else>
+					<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png">
+					</u-empty>
+				</div>
+				<!-- <my-swiper :datas="dinList.diningCarImg" /> -->
 				<view class="boxContent2" style="margin-top:-10%;">
 					<view class="clearfix" style="margin-bottom: 10px;">
 						<text class="fz26px" style="font-weight: bold;">{{dinList.name ? dinList.name : '无'}}</text>
@@ -10,9 +16,10 @@
 					</view>
 					<view class="flex-container">
 						<text class="flex-item">营业状态</text>
-						<u-tag class="flex-item tag-item" plain :text="dinList.openState ? '营业中' : '离线'" :type="dinList.openState ? 'success' : 'error'" size="mini"></u-tag>
+						<u-tag class="flex-item tag-item" plain :text="dinList.openState ? '营业中' : '离线'"
+							:type="dinList.openState ? 'success' : 'error'" size="mini"></u-tag>
 					</view>
-					<text>客服电话:18011111111</text>
+					<text>客服电话:{{dinList.customerPhone ? dinList.customerPhone : '无'}}</text>
 				</view>
 				<view class="footer">
 					<u-button type="primary" shape="circle" icon="phone" text="拨打客服电话"
@@ -32,26 +39,23 @@
 				dinList: {
 					name: '23333',
 					openState: 1,
-					imageUrl:''
+					imageUrl: ''
 				},
 				swiperDatas: [{
-					img:'../../static/banner1.jpg'
-				},{
-					img:'../../static/banner2.png'
+					img: '../../static/banner1.jpg'
+				}, {
+					img: '../../static/banner2.png'
 				}],
 			}
 		},
 		onLoad(e) {
-		  this.fatchDate(e);
+			this.fatchDate(e);
 		},
-		// created() {
-		// 	this.fatchDate(e.id)
-		// },
 		methods: {
 			call() {
-				if (this.orderinfo.shopCall) {
+				if (this.dinList.customerPhone) {
 					uni.makePhoneCall({
-						phoneNumber: this.orderinfo.shopCall
+						phoneNumber: this.dinList.customerPhone
 					});
 				} else {
 					uni.showToast({
@@ -63,14 +67,20 @@
 			async fatchDate(e) {
 				console.log('e===========================e', e)
 				var queryParmas = {
-					id : e.id
+					id: e.id
 				}
 				console.log('idididididid', queryParmas)
 				const result = await this.$request('post', '/sale/diningCar/queryDiningCarById', queryParmas, true)
 				if (result) {
-					console.log("result",result)
+					console.log("result", result)
 					this.dinList = result.data
+					// this.dinList.diningCarImg = JSON.parse(result.data.diningCarImg)
+					this.dinList.diningCarImg = JSON.parse(result.data.diningCarImg).map(item => {
+					  return {...item, img: item.url, ...(item.url ? {url: undefined} : {})};
+					});
+
 					console.log('this.dinList', this.dinList)
+					console.log('this.dinList.diningCarImg', this.dinList.diningCarImg)
 				}
 			}
 

+ 13 - 10
pages/diningList/diningList.vue

@@ -9,7 +9,7 @@
 
 		<view class="contain" style="margin: 10px 0;" v-for="(item, index)  in tableData" :key="index">
 			<view class="box" :class="{ 'boxed-border': item.defaultState == 2 }">
-				<view class="container" @click="carList">
+				<view class="container" @click="carList(item)">
 					<view class="text-container">
 						<view class="flex-item">{{item.name ? item.name : '无' }}</view>
 						<u-tag plain :text="item.openState ? '营业中' : '离线'" :type="item.openState ? 'success' : 'error'"
@@ -69,15 +69,10 @@
 				this.fatchDate()
 				console.log('==============================', e)
 			},
-			async call() {
-				const query = {
-					id: this.tableData.customerId
-				}
-				const response = await this.$request('post', '/sale/customer/queryCustomerById', query);
-
-				if (this.orderinfo.shopCall) {
+			call() {
+				if (this.tableData.customerPhone) {
 					uni.makePhoneCall({
-						phoneNumber: this.orderinfo.shopCall
+						phoneNumber: this.tableData.customerPhone
 					});
 				} else {
 					uni.showToast({
@@ -92,7 +87,15 @@
 					url: `/pages/diningCar/diningCar?id=${e.id}`
 				})
 			},
-			carList() {
+			carList(e) {
+				const carl = {
+					id: e.id,
+					customerPhone: e.customerPhone,
+					name: e.name,
+					openState: e.openState
+				}
+				uni.setStorageSync("carl", carl)
+				console.log('---------------------', carl)
 				uni.navigateTo({
 					url: `/pages/classify/classify`
 				})

+ 3 - 0
pages/goodDetail/goodDetail.vue

@@ -112,6 +112,9 @@
 				scrollTop: 0
 			}
 		},
+		onLoad(e) {
+			console.log('eeeeeeeeeeeee============', e)
+		},
 		methods: {
 			clickSpec(){
 				this.$refs.specPopup.open();

+ 1 - 1
pages/login/login.vue

@@ -158,7 +158,7 @@
 								// 发送code到开发者服务器换取用户信息
 								const result = await this.$request('post', '/auth/miniLogin', {
 									tenantId: '000000',
-									clientId: '8871d05eacc4406083d3bb0a085b6999',
+									// clientId: '8871d05eacc4406083d3bb0a085b6999',
 									code: loginRes.code
 								})
 								console.log('登录成功:', result);

+ 20 - 2
pages/user/user.vue

@@ -67,7 +67,7 @@
 							<u-icon name="car" labelColor="#96989e" label="餐车信息" labelSize="14px" labelPos="bottom"
 								size="40"></u-icon>
 						</view>
-						<view class="flex-box-item">
+						<view class="flex-box-item" @click="call">
 							<u-icon name="kefu-ermai" label="客服电话" labelColor="#96989e" labelSize="14px" labelPos="bottom"
 								size="40"></u-icon>
 						</view>
@@ -86,15 +86,33 @@
 				userdata:{
 					avatarUrl:'',
 					phone:''
-				}
+				},
+				cPhone: ''
 			}
 		},
+		onLoad() {
+			const e = uni.getStorageSync('info')
+			this.cPhone = e
+		},
 		methods: {
 			openPage(path) {
 				this.$u.route({
 					url: path
 				})
 			},
+			call() {
+				console.log('eeeeeeeeeeeeeeee===============', this.cPhone)
+				if (this.cPhone.customerPhone) {
+					uni.makePhoneCall({
+						phoneNumber: this.cPhone.customerPhone
+					})
+				} else {
+					uni.showToast({
+						icon: 'none',
+						title: '暂无商家电话'
+					})
+				}
+			},
 			onInfo() {
 				uni.navigateTo({
 					url: `/pages/user/myInfo`