<template>
	<view class="page">
		<view class="add-list">
			<!-- <view class="list">
				<view class="title">
					<text>方案编号</text>
					<text class="star">*</text>
				</view>
				<view class="content">
					<input type="text" placeholder="请输入" v-model="rulform.id">
				</view>
			</view> -->
			<view class="list" v-if="Fenshow">
				<view class="title">
					<text>方案分类</text>
					<text class="star">*</text>
				</view>
				<view class="juli" style="padding-top: 10px;" @click="chooseLocation(1)">
					<u-input v-model="lableXian" type="select" disabledColor="#ffffff"
						placeholder="请选择" :border="false" suffixIcon="arrow-right" style="pointer-events:none">
					</u-input>
					<!-- <u-icon name="arrow-right" @click="chooseLocation(1)"></u-icon> -->
				</view>
			</view>
			<view class="list">
				<view class="title">
					<text>方案名称</text>
					<text class="star">*</text>
				</view>
				<view class="content">
					<input type="text" placeholder="请输入" v-model="rulform.schemeTitle">
				</view>
			</view>
			<view class="list">
				<view class="title">
					<text>宣传内容</text>
					<text class="star">*</text>
				</view>
				<view class="content">
					<input type="text" placeholder="请输入" v-model="rulform.promotionContent">
				</view>
			</view>
			<!-- <view class="list" @click="setTime">
				<view class="title">
					<text>上线时间</text>
					<text class="star">*</text>
				</view>
				<view class="content">
					<u-picker mode="time" v-model="show" :params="params" default-time="2024-07-02 13:01"
						@confirm="timeConfirm"></u-picker>
					<input type="text" placeholder="请选择" v-model="rulform.createDate">
				</view>
			</view> -->

			<view class="feedback-data">
				<view>
					<view class="title">
						<text>渠道海报</text>
						<text class="star">*</text>
					</view>
				</view>
				<view class="voucher-img">
					<!-- <view class="voucher-list">
						<image src="../../static/voucher_bg.png"></image>
					</view> -->
					<u-upload :action="action" :file-list="fileList"  max-count="1"  :before-upload="beforeUpload"></u-upload>
				</view>
			</view>
		</view>
		<!-- <u-select v-model="popup1" :list="list" @confirm="pops"></u-select> -->
		<u-select v-model="popup1" mode="mutil-column-auto" :list="list" @confirm="pops" label-name="classificationName" child-name="childClassifications" value-name="id"></u-select>

		<!-- 保存按钮 -->
		<view class="page-footer" @click="go">
			<view class="footer-buy">
				<view class="cart-add">
					<text>提交</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				action: 'http://8.130.38.56:8027/admin-server/file/upload',
				fileList: [],
				lableXian:'',
				rulform: {
					schemeTitle: '',
					classificationCode: '',
					createDate: '',
					createUser: '',
					promotionContent: '',
					coverImage: ''
				},
				params: {
					year: true,
					month: true,
					day: true,
					hour: true,
					minute: true,
					second: true,
					province: true,
				},
				show: false,
				popup1: false,
				list: [{
						value: '1',
						label: '江'
					},
					{
						value: '2',
						label: '湖'
					}
				],
				pageindex: {
					classificationType: "3",
					pageNumber: 1,
					pageSize: 10
				},
				Fenshow:true,
			};
		},
		mounted() {
			this.getALL()
		},
		onLoad(optiong) {
			console.log(optiong.item)
			if(optiong.item){
				this.rulform = JSON.parse(optiong.item)
				this.Fenshow = false
			}
		},
		methods: {
			 padZero(num) {
			  return num < 10 ? '0' + num : num;
			},
		getCurrentTimeFormatted() {
			  const now = new Date();
			  return `${now.getFullYear()}-${this.padZero(now.getMonth() + 1)}-${this.padZero(now.getDate())} ${this.padZero(now.getHours())}:${this.padZero(now.getMinutes())}:${this.padZero(now.getSeconds())}`;
			},
			beforeUpload(index, list) {
							// 返回一个promise
						
						},
			
			getALL() {
				this.$http.sendRequest('/cereClassification/queryBySubquery', 'POST', this.pageindex, 1).then(res => {
					//成功回调	
					this.list = res.data.data.map(item => ({
					  ...item.cereClassification,
					  childClassifications: item.childClassifications
					}));
				})
			},
			go() {
				console.log(this.rulform)
				if(this.Fenshow){
					this.rulform.createDate = this.getCurrentTimeFormatted()
					  this.rulform.createUser =uni.getStorageSync('shopId')
					this.$http.sendRequest('/cerePromotion/addPromotionPlanning', 'POST', this.rulform,1).then(res => {
						//成功回调
						uni.redirectTo({
							url: '/pages/projectManagement/projectManagement'
						})
					})
				}else{
					this.rulform.updateDate = ''
					this.$http.sendRequest('/cerePromotion/editPromotionPlanning', 'POST', this.rulform,1).then(res => {
						//成功回调
						uni.redirectTo({
							url: '/pages/projectManagement/projectManagement'
						})
					})
				}
			
			},
			setTime() {
				this.show = true
			},
			// timeConfirm(e) {
			// 	this.rulform.createDate = e.year + '-' + e.month + '-' + e.day + ' ' + e.hour + ':' + e.minute + ':' + e.second
			// },
			pops(val) {
				this.lableXian =  val[0].label
				this.rulform.classificationCode = val[0].value
				
			},
			chooseLocation(val, item) {
				// this.popupShow = true
				this.popup1 = true
				// if (val == 1) {
				// 	this.$refs.popup1.open()
				// } else if (val == 2) {
				// 	this.$refs.popup2.open()
				// }

			},
		}
	}
</script>

<style scoped lang="scss">
	@import 'application.scss';

	.juli {
		padding: 10rpx;
		display: flex;
		flex-wrap: wrap;

		.u-transition {
			// width: 31%;
			margin: 1%;
			// width: 212rpx;
			// height: 80rpx;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			background-color: rgba(21, 98, 214, 0.1);
			// line-height: 80rpx;
			text-align: center;
			font-style: normal;
			color: #1562D6;
			font-size: 28rpx;
			border-radius: 2px;

		}

		::v-deep .u-tag--primary--plain {
			border: 0px;
			border-radius: 2px;
			background-color: #ebebeb;

			.u-tag__text--primary--plain {
				color: #000;

			}
		}

		::v-deep .u-tag--primary {
			background-color: rgba(245, 178, 160, 0.3);
			border: 0px;
			border-radius: 2px;

			.u-tag__text--primary {
				color: #ff3442;
			}
		}

		.jinbutiao {
			display: flex;
			width: 100%;
			align-items: center;

			.u-slider {
				width: 80%;
				margin-right: 20rpx;
			}
		}
	}

	.choose1 {
		width: 100%;
		display: flex;

		.choose1left {
			width: 26%;
			border-right: 2rpx solid #f6f6f6;

			.leftItem1 {
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
				padding: 20rpx 0;
			}
		}

		.choose1right {
			flex: 1;

			// width: 70%;
			.rightBox {
				width: 90%;
				margin: 0 auto;

				.weizhiName {
					display: flex;
					justify-content: space-between;
					align-items: center;

					// height: 80rpx;
					.weizhiLeft {
						display: flex;
						align-items: center;

						.weizhiInput {
							color: #959595;
						}
					}

					.weizhiSpan {
						color: #D32D25;
					}
				}

				.juli {
					display: flex;
					justify-content: space-between;
					align-items: center;
					flex-wrap: wrap;

					.u-transition {
						// width: 31%;
						margin: 1%;
						// width: 212rpx;
						// height: 80rpx;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						background-color: rgba(21, 98, 214, 0.1);
						// line-height: 80rpx;
						text-align: center;
						font-style: normal;
						color: #1562D6;
						font-size: 28rpx;

					}

					.u-tag-wrapper {
						width: 100%;
						height: 100%;
						border: none !important;
					}

					.u-tag {
						padding: 0;
						width: 212rpx !important;
						height: 60rpx !important;
					}

					.u-tag__text {
						width: 100%;
						font-size: 25rpx;
						text-align: center;
						margin: 0 auto;
					}

				}
			}

			.quyu {
				display: flex;
				padding-left: 20rpx;
				height: 300px;
				width: 100%;

				.sl_city {
					width: 48%;
					margin-right: 0px;
					overflow: auto;

				}
			}
		}
	}

	::v-deep .u-input__input {
		text-align: right;
	}
</style>