saleReport.vue 7 KB
<template>
	<view class="pages">
		<view class="box" v-for="(item,index) in items" :key="index">
			<view class="contents">
				<!-- <u-form-item :required="true" label="活动类型" borderBottom>
			
				</u-form-item> -->
				<view class="item">
					<view class="title">
						<span style="color: red;">*</span>商铺
					</view>
					<view class="inputContent">
						<u-input  style="text-align: right;" v-model="item.name" type="select" @click="typeShow = true" placeholder="请选择"/>
						<u-select v-model="typeShow" :list="shopList" label-name="shopName" value-name="id" @confirm="typeChange($event,index)"></u-select>
					</view>
				</view>
				<view class="item">
					<view class="title">
						<span style="color: red;">*</span>商品名称
					</view>
					<view class="inputContent">
						<input type="text" v-model="item.productName" placeholder="请输入" />
					</view>
				</view>
				<view class="up_line"></view>
				<view class="item">
					<view class="title">
						<span style="color: red;">*</span>商品类型
					</view>
					<view class="inputContent">
						<input type="text" v-model="item.productType" placeholder="请输入" />
					</view>
				</view>
				
				<view class="up_line"></view>
				<view class="item">
					<view class="title">
						<span style="color: red;">*</span>品牌
					</view>
					<view class="inputContent">
						<input type="text" v-model="item.brand" placeholder="请输入" />
					</view>
				</view>
				<view class="up_line"></view>
				<view class="item">
					<view class="title">
						<span style="color: red;">*</span>单价
					</view>
					<view class="inputContent">
						<input type="digit" v-model="item.price" placeholder="请输入" />
					</view>
				</view>
				<view class="up_line"></view>
				<view class="item">
					<view class="title">
						<span style="color: red;">*</span>销售时间
					</view>
					<view class="inputContent">
						<u-input style="text-align: right;" v-model="item.saleTime" type="select" @click="busStartshow = true" placeholder="请选择"/>
						<u-picker mode="time" v-model="busStartshow" :params="params" @confirm="busStTimeChange($event,index)"></u-picker>	
					</view>
				</view>
				<view class="up_line"></view>
				<view class="item">
					<view class="title">
						<span style="color: red;">*</span>销售数量
					</view>
					<view class="inputContent">
						<input type="number"  v-model="item.salesQuantity" placeholder="请输入" />
					</view>
				</view>
				<view class="up_line"></view>
			</view>
		</view>
		<view class="addBox" @click="addItems">
			<uni-icons type="plusempty" color="#0FBB59"></uni-icons>
			<span class="addName" style="color: #0FBB59;font-size: 25rpx;">添加商品</span>
		</view>
		<view class="postBox">
			<button   @click ="go"
				style="background-color: #0FBB59;color: #fff;font-size: 28rpx;border-radius: 20rpx;padding: 10rpx 0;">提交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: [{
					productName: '',
					productType: '',
					brand: '',
					price: '',
					saleTime: '',
					salesQuantity: '',
					merchantId:'',
					name:''
				}],
				busStartshow:false,
				params: {
					year: true,
					month: true,
					day: true
				},
				typeShow:false,
				typeList:[],
				shopList:[],
				pageindex: {
					dataStatus: '1',
					pageNumber: 0,
					pageSize: 10,
					relatedMerchants:'',
					contractType:'商铺合同'
				},
			}
		},
		mounted() {
			this.getALL()
		},
		methods: {
			getALL(){
				this.$http.sendRequest('/cerePlatformMerchant/queryByPage', 'POST', {
					pageSize: 1,
					pageNumber: 0,
					phone: uni.getStorageSync('user').phone
				}, 1).then(res => {
					if (res.data.data.content.length > 0) {
						let c1 = res.data.data.content[0]
						if (c1.checkState == '2') {
							this.pageindex.relatedMerchants = c1.id
							this.gain()
						}
					}
				})
					
			},
			gain(){
				this.$http.sendRequest('/cereContractInformation/getPage', 'POST', this.pageindex, 1).then(res1 => {
					this.typeList = res1.data.data.content
					this.typeList.map((item,index)=>{
						this.shopList[index] =item.cereBasicInformationShop 
					})
					
				})
			},
			addItems() {
				this.items.push({
					productName: '',
					productType: '',
					brand: '',
					price: '',
					saleTime: '',
					salesQuantity: '',
					merchantId:'',
					name:''
				})
			},
			busStTimeChange(val,index){
				this.items[index].saleTime = this.timeChange(val)
			},
			timeChange(val) {
				const { year, month, day} = val;
				return `${year}-${month}-${day}`;
			},
			go(){
				
				let flag = true
				this.items.map((tem,index)=>{
					for (const key in tem) {
						if(tem[key] == ''){
							uni.showToast({
								title: '请输入信息',
								icon: 'none',
							})
							return false
							
						}
					}
					// return
					tem.createUser =  uni.getStorageSync('user').phone
					tem.createTime =  this.updateCurrentTime()
					this.$http.sendRequest('/cereSalesReporting/add', 'POST',tem,1).then(res => {
						uni.showToast({
							title: '上报成功',
							icon: 'none',
						})
						this.items=[{
					productName: '',
					productType: '',
					brand: '',
					price: '',
					saleTime: '',
					salesQuantity: '',
					merchantId:'',
					name:''
				}]	
				
					})
				})
				 
			
			},
			typeChange(val,index){
				// console.log(val[0].label,index,'indexindexindex')
				this.items[index].merchantId = val[0].value
				this.items[index].name = val[0].label
			},
			//获取当前时间
			updateCurrentTime() {
				const now = new Date();
				const year = now.getFullYear();
				const month = (now.getMonth() + 1).toString().padStart(2, '0');
				const day = now.getDate().toString().padStart(2, '0');
				const hours = now.getHours().toString().padStart(2, '0');
				const minutes = now.getMinutes().toString().padStart(2, '0');
				const seconds = now.getSeconds().toString().padStart(2, '0');
			
				return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
			},
		}
	}
</script>

<style lang="scss" scoped>
	.pages {
		width: 100vw;
		height: 100%;
		position: relative;
		overflow-y: auto;
		padding-bottom: 200rpx;

		.box {
			width: 96%;
			margin: 0 auto;
			background-color: #fff;
			border-radius: 20rpx;

			.contents {
				width: 92%;
				margin: 0 auto;
				// padding: 20rpx;
				margin-top: 20rpx;

				.item {
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
					padding: 20rpx 0;

					.title {
						font-size: 26rpx;
						font-weight: bold;
					}

					.inputContent {
						input {
							font-size: 26rpx;
							text-align: right;
						}
					}
				}

				.up_line {
					width: 100%;
					background-color: #e8e8e8;
					height: 1rpx;
					transform: scaleY(.5);
				}
			}
		}

		.addBox {
			width: 20%;
			display: flex;
			align-items: center;
			margin: 0 auto;
			margin-top: 30rpx;

			.addName {
				color: #0FBB59;
			}
		}

		.postBox {
			position: fixed;
			bottom: 40rpx;
			width: 90%;
			left: 50%;
			transform: translateX(-50%);
		}
	}
</style>