<template>
	<view class="content-box">
		<form @submit="formSubmit" style="width: 100%"> 
		<view class="info-box" style="flex-direction: row;">
			<view class="info-title-box">
				<!-- <image src="/static/require-icon.png" mode="aspectFill"></image> -->
				<text>上传图片</text>
			</view>
			<view class="info-value-box">
				<view class="update_button display-flex">
				  <view class="upload-box" @click="getImage('album')">
				    <view class="img">
				      <image src="/static/upload-photo.png" class="photo"></image>
				    </view>
				  </view>
				  <view
				    class="display-flex upload-box-photo"
				    v-for="(item, index) in uploadList"
				    :key="index"
				  >
				    <image :src="item" mode="aspectFit"  style="width: 100%; height: 100%" @click="showLarge(item)"/>
				    <image src="/static/del.png" class="del-icon"mode="aspectFit" 
							  style="width: 30rpx; height: 30rpx" @click="delPhoto(index)"></image>
				  </view>
				</view>
			</view>		
		</view>
		<view class="info-box">
			<view class="info-title-box">
				<!-- <image src="/static/require-icon.png" mode="aspectFill"></image> -->
				<text>荣誉级别</text>
			</view>
			<view class="info-value-box">
				  <picker @change="bindPickerChange($event,'level')"  :range="honorLevel" class="select-box" name="education">
				        <view class="uni-input">{{levelValue}}</view>
						<image src="/static/arrow_down.svg" mode="aspectFill"></image>
				  </picker>
			</view>		
		</view>
		<view class="info-box">
			<view class="info-title-box">
				<!-- <image src="/static/require-icon.png" mode="aspectFill"></image> -->
				<text>荣誉来源</text>
			</view>
			<view class="info-value-box">
				  <picker @change="bindPickerChange($event,'education')"  :range="honorFrom" class="select-box" name="education">
				        <view class="uni-input">{{fromValue}}</view>
						<image src="/static/arrow_down.svg" mode="aspectFill"></image>
				  </picker>
			</view>		
		</view>
		<view class="info-box">
			<view class="info-title-box">
				<!-- <image src="/static/require-icon.png" mode="aspectFill"></image> -->
				<text>所属支部</text>
			</view>
			<view class="info-value-box">
				  <picker @change="bindPickerChange($event,'education')"  :range="honorBranch" class="select-box" name="education">
				        <view class="uni-input">{{branchValue}}</view>
						<image src="/static/arrow_down.svg" mode="aspectFill"></image>
				  </picker>
			</view>		
		</view>
		<view class="info-box">
			<view class="info-title-box">
				<!-- <image src="/static/require-icon.png" mode="aspectFill"></image> -->
				<text>荣誉类型</text>
			</view>
			<view class="info-value-box">
				  <picker @change="bindPickerChange($event,'education')"  :range="honorType" class="select-box" name="education">
				        <view class="uni-input">{{typeValue}}</view>
						<image src="/static/arrow_down.svg" mode="aspectFill"></image>
				  </picker>
			</view>	
			<view class="info-value-box">
				  <picker @change="bindPickerChange($event,'education')"  :range="honorType2" class="select-box" name="education">
				        <view class="uni-input">{{typeValue2}}</view>
						<image src="/static/arrow_down.svg" mode="aspectFill"></image>
				  </picker>
			</view>	
		</view>
		<view class="info-box">
			<view class="info-title-box">
				<!-- <image src="/static/require-icon.png" mode="aspectFill"></image> -->
				<text>选择成员</text>
			</view>
			<view class="info-value-box display-flex-start select-member">
				<input type="text" placeholder="请输入手机号" name="selfName">
				<button type="primary" class="submit-bth" style="background-color: #169bd5;" @click="addMember()">添加</button>
			</view>	
		   <view>
			   <checkbox-group @change="checkboxChange" class="display-wrap">
					  <label class="display-flex-start"  v-for="(item,index) in memberList" :key="item.value" style="margin-right:10rpx;transform:scale(.8);">
							<view>
								<checkbox :value="item.value" :checked="item.checked"/>
							</view>
							<view>{{item.name}}</view>
							<image src="/static/del.png" mode="aspectFit"
							style="width: 30rpx; height: 30rpx;margin-left: 10rpx;" @click="delMember(index)"></image>
						</label> 
				</checkbox-group>
			</view>	
		</view>
		<view style="display: flex;justify-content: space-evenly;">
			<button type="default" class="submit-bth" style="background-color: #aaaaaa;">清空</button>
			<button type="primary" class="submit-bth" style="background-color: #169bd5;" formType="submit">提交</button>
		</view>
	</form>	
	</view>
</template>

<script>
	import md5 from "@/common/md5.js";
	// import pickerAddress from '@/components/liudx-pickerAddress/index.vue'
	// var graceChecker = require("../../../common/graceChecker.js");
	export default {
		components: {
		},
		data() {
			return {
				dateYear:new Date().getFullYear(),
				dateMonth:new Date().getMonth() + 1,
				arrayMonth:["1", "2","3", "4","5", "6","7", "8","9", "10","11", "12"],
				title: 'Hello',
				detailObj:{},
				storeImg:'',
				isAuthPhone:getApp().globalData.user_phone,
				userSex:'1',
				txt: '请选择',
				levelValue:'请选择',
				honorLevel:['中央','省级','市级','区级','单位'],
				fromValue:'请选择',
				honorFrom:['党内荣誉','社会荣誉','单位荣誉','行业荣誉'],
				branchValue:'请选择',
				honorBranch:['浐灞一支部','浐灞二支部'],
				typeValue:'请选择',
				typeValue2:'请选择',
				honorType:['集体荣誉','个人荣誉','集体个人兼有'],
				honorType2:['多人','单人'],
				professionArray:[],
			    memberList: [
					{
						value: 'USA',
						name: '路小璐'
					},
					{
						value: 'CHN',
						name: '张三',
						checked: 'true'
					},
					{
						value: 'BRA',
						name: '李四'
					},
					{
						value: 'JPN',
						name: '王五'
					},
				],
				uploadList: [],
				imgIdList: [],
			}
		},
		onLoad() {
			//this.getTradeRequest();
		},
		onShow() {
		},
		// onShareAppMessage() {
		// 	  return {
		// 	      title: '分销小助手',
		// 	      path:'/pages/index/index?scene=' + getApp().globalData.user_id
		// 	    }
		// },
		methods: {
			bindDateChange(e){
						   this.dateYear = e.target.value
						   
			},
			bindDateMonthChange(e){
						   this.dateMonth = this.arrayMonth[e.target.value]
			},
			change(e) {
			  this.single = e;
			  console.log("-change事件:", e);
			 },
			checkboxChange: function (e) {
				var items = this.items,
					values = e.detail.value;
				for (var i = 0, lenI = items.length; i < lenI; ++i) {
					const item = items[i]
					if(values.includes(item.value)){
						this.$set(item,'checked',true)
					}else{
						this.$set(item,'checked',false)
					}
				}
			}, 
			addMember(){
				let items = {value: '6',name: '13630230648'}
				this.memberList.push(items)
			},
			delMember(idx){
				this.memberList.splice(idx, 1);
			},
			getImage(type) {
			  let that = this;
			  // if (that.uploadList.length >= 9) {
			  //   uni.showToast({
			  //     title: "最多上传9张图片",
			  //     icon: "none",
			  //     duration: 2500,
			  //   });
			  //   return;
			  // }
			  uni.chooseImage({
			    sourceType: [type],
			    count: 1,
			    sizeType: ["original", "compressed"], //可以指定是原图还是压缩图，默认二者都有
			    success: (res) => {
			      for (let i = 0; i < res.tempFilePaths.length; i++) {
					 console.log(res.tempFilePaths[i]) 
			        that.uploadList.push(res.tempFilePaths[i]);
			        that.uploadFileRequest(res.tempFilePaths[i]);
			      }
			    },
			  });
			},
			uploadFileRequest(fileVal) {
			  uni.showLoading({
			    title: "上传中",
			    mask: true,
			  });
			  let that = this;
			  let md5Sign = md5(
			    "method=" +
			      "upload" +
			      "&timestamp=" +
			      getApp().globalData.globalTimestamp +
			      "&secret=" +
			      getApp().globalData.secret
			  );
			  let url =
			    getApp().globalData.shareUrl +
			    "api/api.php" +
			    "?method=upload&source=activity&id=1&timestamp=" +
			    getApp().globalData.globalTimestamp +
			    "&sign=" +
			    md5Sign;
			  uni.uploadFile({
			    url: url, //需要设置为全局
			    filePath: fileVal,
			    name: "file",
			    formData: {
			      file: fileVal,
			    },
			    success: (res) => {
			      let tmpres = JSON.parse(res.data);
			      console.log(tmpres);
			      uni.hideLoading();
			      that.imgIdList.push(tmpres.data.id);
			    },
			    fail: (res) => {
			      console.log("上传请求失败");
			      console.log(res);
			    },
			  });
			},
			delPhoto(idx) {
			  this.uploadList.splice(idx, 1);
			  this.imgIdList.splice(idx, 1);
			},
			showLarge(src) {
			  uni.previewImage({
			    urls: [src],
			    longPressActions: {
			      itemList: ["发送给朋友", "保存图片"],
			      success: function (data) {},
			      fail: function (err) {
			        console.log(err.errMsg);
			      },
			    },
			  });
			},
			getProvinceRequest(){
				 let that = this;
			},
			 getTradeRequest(){
				 let that = this;
			 },
			 radioCheck(e){
			 	console.log(e.target.value)
			 	this.userSex = e.target.value;
			 	//this.gender = e.target.value == '0' ? '男' : '女';
			 },
			 changeCity(data) {
				 this.txt = data.data.join('')
				 console.log(data.data.join(''))
			  },
			 bindPickerChange(e,type) {
						 let that = this;
						  switch (type){
						  	case 'education':
							 that.educationValue =  that.educationArray[e.target.value]
							 console.log(that.educationValue)
						  		break;
						  	case 'profession':
						  	 that.professionValue =  that.professionArray[e.target.value]
						  		break;
							case 'ends':
							 that.endsValue =  that.endsArray[e.target.value]
								break;	
						  }
			             
			          },
				testLength(){
					 if(this.addressDetail.length > 25){
						 uni.showToast({
							title: '详细地址应为0-25个字符',
							icon: 'none'
						 });
					}
				}, 	  
			  formSubmit(e) {
				  //this.goCustomCardPage()
			  	//将下列代码加入到对应的检查位置
			  	//定义表单规则
			  	var rule = [
			  		{
			  			name: "selfName",
			  			checkType: "notnull",
			  			errorMsg: "姓名不能为空"
			  		},
			  		// {
			  		// 	name: "selfName",
			  		// 	checkType: "string",
			  		// 	checkRule: "2,15",
			  		// 	errorMsg: "姓名不能少于2个汉字"
			  		// },
			  		{
			  			name: "selfName",
			  			checkType: "reg",
			  			checkRule: "[\u4e00-\u9fa5]",
			  			errorMsg: "姓名需为中文"
			  		}
					// {
					// 	name: "trade",
					// 	checkType: "notnull",
					// 	errorMsg: "行业不能为空"
					// }
			  	];
			  	//进行表单检查
			  	var formData = e.detail.value;
				console.log(formData)
			  	var checkRes = graceChecker.check(formData, rule);
			  	if (checkRes) {
					this.txt === '请选择' ? 
					uni.showToast({
						title: '请选择地区',
						icon: "none"
					}):
					this.submitRequest(formData);
			  	} else {
			  		uni.showToast({
			  			title: graceChecker.error,
			  			icon: "none"
			  		});
			  	}
			  },
			submitRequest(params){
				   console.log(params)
				 	 let that = this;
			},  
			goCustomCardPage(){
				uni.redirectTo({
					url: '/pages/index/successPage/index?types='+'custom', //游客成功页面
					success: res => {},
					fail: () => {},
					complete: () => {}
				})
			}  
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		&_list{
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content:space-around;
			&_lable{
				
			}
			&_content{
				flex: 1;
				width: auto;
				text-align: right;
			}
		}
	}
	.content-box {
		width: 100%;
		/* height: 100%; */
		display: flex;
		flex-direction: column;
		align-items: center;
		/* justify-content: center; */
	}
	.header-box {
		width: 85%;
		height:80rpx;
		border: .5px dotted #00A1B4;
		border-radius: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 24rpx;
		color:#00A1B4 ;
		/* font-family: PingFangSC-Regular; */
		margin-top: 2%;
	}
	.header-box image {
		width: 36rpx;
		height: 36rpx;
		margin-right: 1%;
	}
	.self-title-box {
		width: 90%;
		display: flex;
		align-items: center;
		font-size: 32rpx;
		letter-spacing: 2rpx;
		color:#3C3C3C ;
		/* font-family: SimHei; */
		margin: 4% auto;
		font-weight: bold;
		height: 50rpx;
		line-height: 50rpx;

	}
	.self-title-box image {
		width: 6rpx;
		height: 32rpx;
		margin-right: 2%;
	}
	.info-box {
		width: 90%;
		margin: 3% auto;
		display: flex;
		flex-direction: column;
		// align-items: center;
		// height: 180rpx;
	}
	.info-title-box {
		width: 20%;
		display: flex;
		align-items: center;
		font-size: 26rpx;
	}
	.info-title-box image{
		width: 15rpx;
		height: 15rpx;
		margin-right: 2%;
	}
	.info-value-box {
		width: 100%;
	}
	.info-value-box input {
		height: 88rpx;
		background: #f7f7f7;
		font-size: 26rpx;
		padding-left: 4%;
		margin: 2% auto;
	}
	.info-value-box picker {
		position: relative;
	}
	.info-value-box picker image {
		position: absolute;
		width: 25rpx;
		height: 25rpx;
		right: 10px;
		top: 30rpx;
	}
	.select-box {
		height: 80rpx;
		background: #f7f7f7;
		font-size: 26rpx;
		padding-left: 4%;
		margin: 2% auto;
		color: #888;
		line-height: 88rpx;
	}
	.info-gender-box {
		width: 75%;
		font-size: 28rpx;
	}
	.form-radio {
			 transform: scale(0.6);
	}
	.padding-left-2 {
		// padding-left: 2%;
	}
	.margin-right-10 {
		margin-right: 10%;
	}
	.border-line-box {
		width: 100%;
		height: 20rpx;
		background: #f7f7f7;
	}
	.picker-box{
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 60rpx;
		line-height: 60rpx;
		background: #f7f7f7;
		height: 88rpx;
		line-height: 88rpx;
		background: #f7f7f7;
		font-size: 28rpx;
		padding-left: 4%;
	}
	.uni-input image {
		width: 40rpx;
		height: 40rpx;
		margin-right: 2%;
		float: right;
	}
	.textarea-box {
		background: #f7f7f7;
		min-height: 120rpx;
		font-size: 28rpx;
		margin: 5% auto;
		padding: 4%;
		margin-bottom: 8%;
	}
	.upload-box {
	  display: flex;
	  flex-flow: column;
	  width: 25%;
	  height: 100rpx;
	  border-radius: 10rpx;
	  padding-top: 15rpx;
	  image {
	    width: 100rpx;
	    height:100rpx;
	  }
	}
	.upload-box-photo {
		width: 25%;
		height: 100rpx;
		border-radius: 10rpx;
		padding-top: 15rpx;
		position: relative;
		margin-left: 10rpx;
	}
	.del-icon {
	  position: absolute;
	  right: 0;
	  width: 30rpx;
	  height: 30rpx;
	}
	
	.update_button {
	  text-align: center;
	  display: flex;
	  flex-wrap: wrap;
	}
	.picker-class {
		border-radius: 10rpx;
		padding: 10rpx;
		width: 73%;
		font-size: 28rpx;
		background: #f5f5f5;
	}
	.picker-class image {
		width: 26rpx;
		height: 26rpx;
	}
	.submit-bth {
		width: 25%;
		font-size: 26rpx;
		margin: 0 0 5% 0;
		color: #fff;
	}
	.select-member {
		input {
			    margin: 2% 2% 2% 0;
			    height: 80rpx;
			    line-height: 80rpx;
		}
		button {
			    background-color: #169bd5;
			    margin: 0;
			    height: 60rpx;
				line-height: 60rpx;
			    width: 20%;
		}
	}
</style>