<template>
	<view class="huoyuan">
		<view style="width:100%;position: fixed;top:0;z-index:99">
			<view class="navBarContent">
				<u-navbar title="我要货源" :border-bottom="false" :background="background" title-color="#fff"></u-navbar>
			</view>

		</view>
		<image src="../../static/news1/walletBg.png" class="bgImg" mode="widthFix"></image>
		<view style="border:1px solid transparent;margin-top:-190px;position: relative;z-index: 9;">
			<view class="process">

				<view class="pItem" v-for="(item,index) in list" :key="index">
					<image :src="item.icon" mode="widthFix" class="icon"></image>
					<view class="title">{{item.title}}</view>
					<view class="subTitle">{{item.subTitle}}</view>
				</view>
			</view>
			<view class="formContent">
				<u-form :model="form" ref="uForm">
					<u-form-item label="商品名称" label-width="150"><u-input placeholder="请填写您求购的商品名称"
							v-model="form.name" /></u-form-item>
					<u-form-item label="产品描述" label-width="150"><u-input maxlength="200"
							placeholder="如品牌、型号、参数 、配置、规格等，可复制电商标题、链接。" v-model="form.intro"
							type="textarea" /></u-form-item>
					<u-form-item label="求购类型" label-width="150" @click="typeShow = true">
						<u-input v-model="form.type" type="select" @click="typeShow = true" />
						<u-action-sheet :list="type" :cancel-btn="false" v-model="typeShow"
							@click="actionSheetCallback"></u-action-sheet>
					</u-form-item>
					<u-form-item label="交货日期" label-width="150" @click="timeShow = true">
						<u-input v-model="form.date" type="select" @click="timeShow = true" />
						<u-picker mode="time" v-model="timeShow" :params="timeParams" @confirm="timeChage"></u-picker>
					</u-form-item>
					<u-form-item label="求购数量" label-width="150"><u-input placeholder="请输入数量及单位"
							v-model="form.num" /></u-form-item>
					<u-form-item label="预估单价" label-width="150">
						<view class="">
							<view class="qujian">
								<u-input placeholder="请输入价格区间" border v-model="form.startNum" />
								<text style="margin:0 10upx;">-</text>
								<u-input placeholder="请输入价格区间" border v-model="form.endNum" />
								<text style="margin-left:10upx">元</text>
							</view>
							<u-checkbox-group>
								<u-checkbox active-color="#FE483B" shape="circle" v-model="form.mianyi"
									v-for="(item, index) in radioList" :key="index" :name="item.name">
									{{ item.name }}
								</u-checkbox>
							</u-checkbox-group>

						</view>
					</u-form-item>
					<u-upload :fileList="finishImageList" :previewFullImage="true" @afterRead="afterRead" :maxCount="8"
						width="180" height="180" upload-text="上传照片" @delete="deletePic" name="1" multiple></u-upload>
					<u-form-item label="收货地址" label-width="150" @click="addrshow = true">
						<u-input v-model="form.addr" type="select" @click="addrshow = true" />
						<u-picker mode="region" v-model="addrshow"></u-picker>
					</u-form-item>
					<u-form-item label="备注" label-width="150" label-position="top">
						<u-input v-model="form.remark" class="remarkInput" placeholder="请填写您要补充的内容，如规格、包装和运输等要求"
							type="textarea" />
					</u-form-item>
				</u-form>
				<button class="submitBtn" @click="sureSubmit">确认发布</button>
			</view>
		</view>
	</view>
</template>

<script>
	import img from "@/static/news1/walletBg.png";
	import * as help from '@/api/help'
	export default {
		data() {
			return {
				background: {
					background: 'url(' + img + ') center top no-repeat',
					backgroundSize: '100%',
				},
				list: [{
						icon: '/static/news1/m1.png',
						title: '发采购询价单',
						subTitle: '填写所需信息一键发布询价'
					},
					{
						icon: '/static/news1/m2.png',
						title: '卖家实时报价',
						subTitle: '60分钟获取卖家报价'
					},
					{
						icon: '/static/news1/m3.png',
						title: '卖家上架商品',
						subTitle: '采购方案根据需要下单采购'
					},
				],
				form: {
					name: '',
					intro: '',
					type: '',
					date: '',
					num: '',
					startNum: '',
					endNum: '',
					mianyi: true,
					addr: '',
					remark: ''
				},
				typeShow: false,
				timeShow: false,
				addrshow: false,
				type: [{
					text: '一件代发'
				}],
				timeParams: {
					year: true,
					month: true,
					day: true,
					hour: false,
					minute: false,
					second: false
				},
				radioList: [{
						name: '面议'
					},

				],
				radio: '',
				//照片
				finishImageList: [],
				imgage_ids:[10001,10002]
			}
		},
		methods: {
			timeChage(e) {
				// 时间改变
				console.log(e, '时间值')
				this.form.date = e.year + '-' + e.month + '-' + e.day
			},
			sureSubmit() {
				// 确认发布 0000
				const that = this;
				let params = {
					goods_name: that.form.name,
					goods_desc: that.form.intro,
					type: that.form.type,
					deliver_at: that.form.date,
					num: that.form.num,
					min_price: that.form.startNum,
					max_price: that.form.endNum,
					is_face: that.form.mianyi,
					address_id: '10001',
					remark: that.form.remark,
					
				}
				help.addGoodsSource(params)
					.then(res => {
						console.log(res, '确认发布')
					})
					.finally()
			},
			actionSheetCallback(index) {

				this.form.type = this.type[index].text;
			},
			// 新增图片
			async afterRead(event) {

				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)

					if (JSON.parse(result).code == 1) {
						let item = this[`fileList${event.name}`][fileListLen]
						this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: result
						}))
						fileListLen++
					} else {
						this[`fileList${event.name}`].splice(fileListLen, 1)
					}

				}

			},
			//上传照片
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					// let a = uni.uploadFile({
					// 	url: this.baseUrl+'/api/common/upload', // 仅为示例，非真实的接口地址
					// 	filePath: url,
					// 	name: 'file',
					// 	formData: {
					// 		user: 'test',
					// 		token:getToken()
					// 	},
					// 	success: (res) => {
					// 		if(JSON.parse(res.data).code==1){
					// 			setTimeout(() => {
					// 				this.finishImageList.push({url:JSON.parse(res.data).data.fullurl,path:JSON.parse(res.data).data.url})
					// 				resolve(res.data)
					// 			}, 1000)
					// 		}else{
					// 			uni.$u.toast(JSON.parse(res.data).msg)

					// 			resolve(res.data)
					// 		}
					// 	},
					// 	fail: (res) => {
					// 		console.log(res,"rrr")
					// 	}
					// });
				})
			},
			//删除图片
			deletePic(event) {

				this.finishImageList.splice(event.index, 1)
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		min-height: 100%;
		padding-bottom: 100upx;
	}

	.huoyuan {
		.process {
			height: 266upx;
			background: #FFFFFF;
			border-radius: 14upx;
			opacity: 1;
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin: 0 30upx;
			// padding:0 28upx;
			position: relative;

			.pItem {
				flex: 1;
				height: 100%;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				image {
					width: 56upx;
					height: auto;
				}

				.title {
					font-size: 24upx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 600;
					color: #2D2D2D;
					margin: 16upx 0;
				}

				.subTitle {
					font-size: 24upx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					color: #8A8A8A;
					width: 75%;
					text-align: center;

				}
			}
		}

		.formContent {
			margin: 0 30upx;
			background-color: #fff;
			border-radius: 14upx;
			margin-top: 20upx;
			padding: 0 38upx;
			padding-bottom: 64upx;

			::v-deep .u-form-item--left {
				align-items: flex-start;
			}

			::v-deep .u-form-item--left__content__label {
				color: #2D2D2D;
				font-size: 28upx;
			}

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

	.remarkInput {
		width: 100%;
		height: 246upx;
		background: #F7F8FA;
		border-radius: 3px 3px 3px 3px;
		opacity: 1;
		padding: 20upx !important;
	}

	.submitBtn {
		height: 88upx;
		margin: 64upx 0;
		margin-bottom: 0;
		line-height: 88upx;
		// background: #FFAAA4;
		background: #FE483B;
		border-radius: 36px 36px 36px 36px;
		opacity: 1;
		font-size: 28upx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		text-align: center;
	}

	.navBarContent {
		height: 88upx;
		line-height: 88upx;
		text-align: center;
		position: relative;

		text {
			font-size: 32upx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			color: #FFFFFF;
		}

	}

	.bgImg {
		width: 100%;
	}
</style>