<template>
	<view class="content ">
		<view class="errorIf" v-if="dataInitError">
			初始化数据失败请重新填写数据
		</view>
		<!-- <view class="table flex" v-if="showModelType">
			<text class="table-text" @click="updata.modelType=0" :class="{action:updata.modelType==0}">
				图文模式
			</text>
			<text class="table-text" @click="updata.modelType=1" :class="{action:updata.modelType==1}">
				纯图模式
			</text>
		</view> -->
		<template v-if="updata.modelType==0">
			<view class="item-name">
				上传头像
			</view>
			<view class="con_box">
				<view class="con_image">
					<image class="img" v-if="modelid==7" @click="upImage('avatar',1)"
						:src="updata.avatar||`../../../static/image/upImg.png`">
					</image>
					<image class="img" v-else @click="navCroper(400,400,'one')"
						:src="updata.avatar||`../../../static/image/upImg.png`">
					</image>
				</view>
			</view>
			<view class="item-name">
				基本信息
			</view>
			<view class="listBox">
				<view class="list">
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="font-color-red font-size-sm">✲</text> <text class="title">真实姓名</text>
						</view>
						<view class="right flex">
							<input class="input" v-model="updata.name" type="text" placeholder="请填写真实姓名"
								placeholder-class="placeholder" />
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="font-color-red font-size-sm">✲</text><text class="title">手机号</text>
						</view>
						<view class="right flex">
							<input class="input" v-model="updata.phone" type="text" placeholder="请填写手机号"
								placeholder-class="placeholder" />
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="font-color-red font-size-sm">✲</text><text class="title">身份证号</text>
						</view>
						<view class="right flex">
							<input class="input" v-model="updata.cardId" type="text" placeholder="请填写身份证号"
								placeholder-class="placeholder" />
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="title">从业时长</text>
						</view>
						<view class="right flex">
							<input class="input" v-model="updata.work_year" type="number" placeholder="请填写从业时长"
								placeholder-class="placeholder" />
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="title">籍贯</text>
						</view>
						<!-- <view class="right flex">
							<pickerAddress @change="changeAncestralPlace">
								{{
									updata.ancestral_place||'请选择籍贯'
								}}
							</pickerAddress>
						</view> -->
						<view class="right flex">
							<picker class="input" :range='jgList' mode="selector" @change="changeAncestralPlace"
								range-key="name">
								<view>
									{{updata.ancestral_place||'选择籍贯'}}
								</view>
							</picker>
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="title">学历</text>
						</view>
						<view class="right flex">
							<picker class="input" :range='educationList' mode="selector" @change="changeEducation">
								<view>
									{{updata.education||'选择学历'}}
								</view>
							</picker>
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="title">民族</text>
						</view>
						<view class="right flex">
							<input class="input" v-model="updata.minority" type="text" placeholder="请填写民族"
								placeholder-class="placeholder" />
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="title">身高</text>
						</view>
						<view class="right flex">
							<input class="input" v-model="updata.height" type="number" placeholder="请填写身高"
								placeholder-class="placeholder" />
							<text class="margin-l-10 flex-shrink-false">厘米</text>
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="title">体重</text>
						</view>
						<view class="right flex">
							<input class="input" v-model="updata.weight" type="number" placeholder="请填写体重"
								placeholder-class="placeholder" />
							<text class="margin-l-10">kg</text>
						</view>
					</view>
					<!-- <view class="flex listItem">
						<view class="flex titleBox">
							<text class="title">出生日期</text>
						</view>
						<view class="right flex">
							<picker class="input" value='2000-01-01' mode="date" @change="changetime">
								<view>
									{{updata.time||'请选择日期'}}
								</view>
							</picker>
						</view>
					</view> -->
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="font-color-red font-size-sm">✲</text><text class="title">职业</text>
						</view>
						<view class="right flex">
							<picker class="input" :range='workTypeList' range-key='title' mode="selector"
								@change="changeWorkType">
								<view>
									{{updata.word.title||'选择职业'}}
								</view>
							</picker>
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="font-color-red font-size-sm">✲</text><text class="title">收费类型</text>
						</view>
						<view class="right flex">
							<picker class="input" :value="updata.timetype.ind" :range='timeTypeList' range-key='title'
								mode="selector" @change="changetimetype">
								<view>
									{{updata.timetype.title||'收费时间类型'}}
								</view>
							</picker>
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="font-color-red font-size-sm">✲</text><text class="title">最低价</text>
						</view>
						<view class="right flex">
							<input class="input" v-model="updata.minMoney" type="number" placeholder="请输入最低收费价"
								placeholder-class="placeholder" />
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="font-color-red font-size-sm">✲</text><text class="title">最高价</text>
						</view>
						<view class="right flex">
							<input class="input" v-model="updata.maxMoney" type="number" placeholder="请输入最高收费价"
								placeholder-class="placeholder" />
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="font-color-red font-size-sm">✲</text><text class="title">服务次数</text>
						</view>
						<view class="right flex">
							<input class="input" v-model="updata.service_count" type="number" placeholder="请输入已经服务的数量"
								placeholder-class="placeholder" />
						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="title">服务区域</text>
						</view>
						<view class="right flex">
							<picker class="input" range-key='title' :range='areaType' mode="selector"
								@change="changeAreaType">
								<view>
									{{areaType[actionAreaType].title}}
								</view>
							</picker>
						</view>
					</view>
					<view class="flex listItem" v-if="actionAreaType==1">
						<view class="flex titleBox">
							<text class="font-color-red font-size-sm">✲</text><text class="title">服务区域</text>
						</view>
						<view class="right">
							<view class="citylist">
								<view class="flex margin-b-20" v-for="(item,ind) in updata.onCity" :key="ind">
									<view></view>
									<view>
										{{item.province+item.city+item.district}}
										<text class="margin-l-10 del" @click="updata.onCity.splice(ind,1)">
											删除
										</text>
									</view>
								</view>
								<view class="flex">
									<view></view>
									<pickerAddress class="buttom" @change="onCityClick">添加地区</pickerAddress>
								</view>
							</view>

						</view>
					</view>
					<view class="flex listItem">
						<view class="flex titleBox">
							<text class="font-color-red font-size-sm">✲</text><text class="title">服务内容</text>
						</view>
						<view class="right">
							<checkbox-group @change="checkTypeChange">
								<label class="flex timetype margin-b-10" v-for="(item,ind) in typeList" :key="item.id">
									<view class="margin-r-10">{{item.title}}</view>
									<view>
										<checkbox :value="`${item.id}`" :checked="item.checked" />
									</view>
								</label>
							</checkbox-group>
						</view>
					</view>
				</view>
			</view>
			<view class="item-name">
				自我展示
			</view>
			<view class="listBox">
				<view class="list">
					<view class="listItem">
						<editor id='editor' class="textarea" auto-height :maxlength='-1' @input='changeMyask'
							type="text"
							placeholder="自我评价\n\n本人从业***年，已经服务***名客户\n成长经历：\n从事母婴工作之前是做***行业的，于***年经过专业培训后进入母婴行业；先后学习了***\n性格特征：\n本人性格直爽，具有很强的服务意识，做事认真负责，擅长……类工作\n服务格言：\n全心全意服务好每一位客户">
						</editor>
					</view>
				</view>
				<view class="con_box">
					<view class="con_image" v-for="(item,ind) in updata.imageList">
						<image class="img" v-if="modelid==7" @click="upImage('imageList',3,ind)" :src="item"></image>
						<image class="img" v-else @click="navCroper(400,400,'tab',ind)" :src="item"></image>
						
						<image @click="updata.imageList.splice(ind,1)" class="tip"
							src="../../../static/icon/goodsExit.png" mode="scaleToFill"></image>
					</view>
					<view class="con_image">
						<image class="img" v-if="modelid==7"  @click="upImage('imageList',2)"
							src="../../../static/image/upImg.png"></image>
						<image class="img" v-else @click="navCroper(400,400,'all')"
							src="../../../static/image/upImg.png"></image>

					</view>
				</view>
			</view>
			<view class="item-name" v-if="modelid!=7">
				我的证书
			</view>
			<view class="listBox" v-if="modelid!=7">
				<view class="con_box">
					<view class="con_image" v-for="(item,ind) in updata.service_audit_imgs">
						<image class="img" @click="navCroper(400,400,'audit',ind)" :src="item"></image>
						<image @click="updata.service_audit_imgs.splice(ind,1)" class="tip"
							src="../../../static/icon/goodsExit.png" mode="scaleToFill"></image>
					</view>
					<view class="con_image">
						<image class="img" @click="navCroper(400,400,'auditall')" src="../../../static/image/upImg.png">
						</image>
					</view>
				</view>
			</view>
			<view class="item-name" v-if="modelid!=7">
				服务展示
			</view>
			<view class="listBox" v-if="modelid!=7">
				<view class="con_box">
					<view class="con_image" v-for="(item,ind) in updata.service_imgs">
						<image class="img" @click="navCroper(400,400,'service',ind)" :src="item"></image>
						<image @click="updata.service_imgs.splice(ind,1)" class="tip"
							src="../../../static/icon/goodsExit.png" mode="scaleToFill"></image>
					</view>
					<view class="con_image">
						<image class="img" @click="navCroper(400,400,'serviceall')"
							src="../../../static/image/upImg.png">
						</image>
					</view>
				</view>
			</view>
		</template>
		<template v-else-if="updata.modelType==1">
			<view class="item-name">
				展示图片
			</view>
			<view class="listBox">
				<view class="con_box">
					<view class="con_image" v-for="(item,ind) in updata.model_imgs">
						<image class="img" @click="navCroper(300,400,'model',ind)" :src="item"></image>
						<image @click="updata.model_imgs.splice(ind,1)" class="tip"
							src="../../../static/icon/goodsExit.png" mode="scaleToFill"></image>
					</view>
					<view class="con_image">
						<image class="img" @click="navCroper(300,400,'modelall')" src="../../../static/image/upImg.png">
						</image>
					</view>
				</view>
			</view>
		</template>
		<view class="base-buttom flex">
			<view class="updata flex flex-center" :class="{ 'bg-gray': loding }" @click="loding ? '' : confirm()">
				提交
			</view>
			<view class="ylan flex flex-center" @click="look">
				预览
			</view>
		</view>
	</view>
</template>

<script>
	import AllAddress from '@/components/wangding-pickerAddress/data.js'
	import {
		getServiceTimeTypeList,
		getServiceTypeList,
		subInfoAudit,
		getUserWorkTypeList,
		getUserCardInfo
	} from '@/api/model.js';
	import {
		isCardNo
	} from '@/utils/rocessor.js';
	import {
		getAstro,
		getShengXiao,
		IdCard
	} from '@/utils/twelve.js';
	import {
		mapState
	} from "vuex"

	import pickerAddress from '@/components/wangding-pickerAddress/wangding-pickerAddress.vue';

	export default {
		components: {
			pickerAddress
		},
		data() {
			return {
				// showModelType:false,//默认类型
				// 初始化数据失败
				dataInitError: false,
				jgList: AllAddress,
				// 上传数据
				updata: {
					modelType: 0, //模板类型0为老类型，1为纯图片
					is_global: 0, //是否全国0是否1是是
					is_wm: '', //是否海外
					avatar: '', //用户头像
					name: '', //用户名称
					phone: '', //手机号
					cardId: '', //身份证号
					minMoney: '', //最低价
					maxMoney: '', //最高价
					height: '', //身高
					weight: '', //体重
					checkedType: [], //选中的服务类型
					time: '', //出生日期
					timetype: {
						title: '',
						code: '',
						ind: 0 //默认0
					}, //选中的时间类型
					onCity: [], //选中的城市
					mymask: '', //自评
					imageList: [], //自评上传图片列表
					ancestral_place: '', //籍贯
					education: '', //学历
					minority: '', //民族
					work_year: '', //从业时长
					word: {
						title: '',
						id: ''
					},
					service_audit_imgs: [], //我的证书
					service_imgs: [], //服务展示
					model_imgs: [], //服务展示
					no: '',
				},
				typeList: [], //服务类型
				timeTypeList: [], //时间类型
				workTypeList: [], //工作类型
				loding: false, //是否载入中
				type: 0, //0为新增，1为修改2为商品页进入注册
				userModelData: {}, //保存获取的用户模板
				modelid: '', //保存要预览的模板id
				educationList: ['小学', '初中', '高中', '大专', '本科', '研究生', '博士'], //学历列表
				areaList: ['是', '否'], //保存是否国内国外
				areaType: [{
						title: '国外',
						type: 2
					},
					{
						title: '国内',
						type: 1
					},
					{
						title: '全国',
						type: 3
					}
				],
				editorCtx: '', //保存详情页面数据
				actionAreaType: 1
			};
		},
		async onLoad(options) {
			const that = this;
			that.modelid = options.modelid
			// 判断是否为隐藏赠送模板
			if (that.modelid == 6) {
				that.updata.modelType = 1;
			}
			// console.log(that.modelid,'that.modelid')
			if (options.type == 1) {
				that.type = 1;
			} else if (options.type == 2) {
				that.type = 0
			}
		},
		onReady() {
			const that = this;
			// 保存对象
			if (that.modelid != 6) {
				this.$nextTick(() => {
					uni.createSelectorQuery().select('#editor').context(async (res) => {
						that.editorCtx = res.context
						// console.log(that.editorCtx,'that.editorCtx');
						if (that.type == 1) {
							await that.getUserCardInfo()
						}
						that.init()
					}).exec();
				})
			} else {
				if (that.type == 1) {
					that.getUserCardInfo()
				}
			}

		},
		computed: {
			// #ifdef H5
			...mapState(['urlFile']),
			// #endif
			...mapState(['baseURL']),
		},
		methods: {
			changeMyask({
				detail
			}) {
				this.updata.mymask = detail.html;
			},
			// 选择学历
			changeEducation(res) {
				this.updata.education = this.educationList[res.detail.value];
				// console.log(res);
			},
			//修改地区类型
			changeAreaType(re) {
				this.actionAreaType = re.detail.value * 1;
				if (re.detail.value == '1') {
					this.updata.is_wm = this.areaList[1];
					return
				} else {
					this.updata.is_wm = this.areaList[0];
				}

			},
			// 初始化
			init() {
				const that = this;
				getServiceTimeTypeList().then(
					(res) => {
						that.timeTypeList = res.data.list.map((arr) => {
							return arr
						})
						if (that.type == 0) {
							that.updata.timetype = that.timeTypeList[0];
						} else
						if (that.type == 1) {
							for (let i = 0; i < that.timeTypeList.length; i++) {
								if (that.timeTypeList[i].code == that.userModelData.service_type) {
									that.updata.timetype = that.timeTypeList[i]
									that.updata.timetype.ind = i;
									break
								}
							}
						}
					}
				).catch(
					(res) => {
						console.log(res);
					}
				)
				getServiceTypeList().then(
					(res) => {
						that.typeList = res.data.list
						if (that.type == 1) {
							try {
								if (that.userModelData.service_project_ar) {
									for (let i = 0; i < that.userModelData.service_project_ar.length; i++) {
										for (let a = 0; a < that.typeList.length; a++) {
											if (+that.typeList[a].id == +that.userModelData.service_project_ar[i].id) {
												that.typeList[a].checked = true;
												that.updata.checkedType.push('' + that.typeList[a].id)
											}
										}
									}
								}
							} catch (e) {
								//TODO handle the exception
							}

						}
					}
				).catch(
					(res) => {
						console.log(res);
					}
				)
				getUserWorkTypeList().then(
					(res) => {
						that.workTypeList = res.data.list
						if (that.type == 0) {
							that.updata.word = that.workTypeList[0];
						} else if (that.type == 1) {
							try {
								if (that.userModelData.user_work_type_id) {
									for (let i = 0; i < that.workTypeList.length; i++) {
										if (that.workTypeList[i].id == that.userModelData.user_work_type_id) {
											that.updata.word = that.workTypeList[i];
											break
										}
									}
								} else {
									that.updata.word = that.workTypeList[0];
								}
							} catch (e) {
								that.updata.word = that.workTypeList[0];
							}
						}
					}
				).catch(
					(res) => {
						console.log(res);
					}
				)
			},
			// 跳转查看预览页面
			look() {
				const that = this;
				if (!that.rendl()) {
					return
				}
				uni.showLoading({
					title: "生成预览中。。。",
					mask: true
				})
				setTimeout(function() {
					uni.hideLoading()
					// 获取生日
					const birthday = IdCard('' + that.updata.cardId, 1);
					// 复制选中的服务数组
					let arr = [...that.updata.checkedType]
					let pushar = [];
					that.typeList.forEach(
						(re) => {
							for (let i = 0; i < arr.length; i++) {
								if (+arr[i] == +re.id) {
									// 删除已选中的对象
									arr.splice(i, 1)
									pushar.push(re)
									break
								}
							}
						}
					)
					let data = {
						is_china: that.actionAreaType,
						name: that.updata.name,
						avatar: that.updata.avatar,
						age: IdCard(that.updata.cardId, 3),
						twelve: getShengXiao(birthday),
						work_year: that.updata.work_year,
						constellation: getAstro(...(birthday.split('-'))),
						ancestral_place: that.updata.ancestral_place,
						minority: that.updata.minority,
						education: that.updata.education,
						service_area_all: that.actionAreaType == 0 ? that.updata.onCity.map(
							(item) => {
								return item.province + item.city + item.district
							}
						) : (that.actionAreaType == 1 ? ['海外,海外,海外'] : ['全国,全国,全国']),
						service_min_price: that.updata.minMoney,
						service_max_price: that.updata.maxMoney,
						service_time_type_title: that.updata.timetype.title,
						service_intro_content: that.updata.mymask,
						service_intro_imgs: that.updata.imageList,
						service_audit_imgs: that.updata.service_audit_imgs,
						service_project_ar: pushar,
						service_imgs: that.updata.service_imgs,
						model_imgs: that.updata.model_imgs,
						no: that.updata.no,
						user_work_type_title: that.updata.word.title,
						service_count: that.updata.service_count,
						weight: that.updata.weight,
						height: that.updata.height
					}

					uni.setStorageSync('modeldata', data)
					uni.navigateTo({
						url: '/pages/user/model/model?mtype=' + that.modelid + '&type=1'
					})

				}, 1000);
			},
			// 获取用户提交数据
			getUserCardInfo() {
				const that = this;
				return new Promise((resolve, reject) => {
					getUserCardInfo().then(
						(data) => {
							try {
								const res = data.data;
								// 存储返回用户数据
								that.userModelData = res;
								that.actionAreaType = res.is_china;
								let onCity = [];
								if (res.is_china == 1) {
									for (let i = 0; i < res.service_area_all.length; i++) {
										let arr = res.service_area_all[i];
										if (arr.length > 0) {
											onCity.push({
												province: arr[0].name,
												city: arr[1].name,
												district: arr[2] ? arr[2].name : '市辖区'
											})
										}
									}
								};
								that.updata = Object.assign(that.updata, {
									modelType: that.modelid == 6 ? 1 : 0, //保存模板类型
									is_wm: res.is_china == 0 ? '是' : '否', //是否海外
									avatar: res.avatar, //用户头像
									name: res.name, //用户名称
									phone: res.mobile, //手机号
									cardId: res.idcard, //身份证号
									minMoney: res.service_min_price, //最低价
									maxMoney: res.service_max_price, //最高价
									time: res.birthday, //出生日期
									onCity: onCity, //选中的城市
									mymask: res.service_intro_content, //自评
									imageList: res.service_intro_imgs, //自评上传图片列表
									ancestral_place: res.ancestral_place, //籍贯
									education: res.education, //学历
									minority: res.minority, //民族
									work_year: res.work_year, //从业时长
									service_audit_imgs: res.service_audit_imgs, //我的证书
									service_imgs: res.service_imgs, //服务展示
									model_imgs: res.model_imgs, //服务展示
									no: res.no,
									service_count: res.service_count,
									weight: res.weight * 1,
									height: res.height
								})
								if (that.modelid != 6) {
									that.editorCtx.setContents({
										html: res.service_intro_content
									})
								}

								resolve('初始化数据成功')
							} catch (e) {
								console.log(e, 'eeee')
								that.dataInitError = true;
								//TODO handle the exception
							}
						}
					).catch(
						(res) => {
							that.dataInitError = true;
							reject(res)
						}
					)
				})

			},
			// 选中的服务类型
			checkTypeChange(type) {
				this.updata.checkedType = type.detail.value;
			},
			// 选中的工作类型
			changeWorkType(type) {
				this.updata.word = this.workTypeList[type.detail.value];
			},
			// 选择时间类型
			changetimetype(res) {
				this.updata.timetype = this.timeTypeList[res.detail.value];
			},
			// 时间选择
			changetime(time) {
				this.updata.time = time.detail.value;
			},
			// 选择籍贯
			changeAncestralPlace(val) {
				this.updata.ancestral_place = this.jgList[val.detail.value].name;
			},
			// 选择省市区
			onCityClick({
				data
			}) {
				let address = {};
				address.province = data[0];
				address.city = data[1];
				address.district = data[2];
				this.updata.onCity.push(address)
			},
			upLoad(path) {
				uni.showLoading({
					title: '图片上传中',
					mask: true
				});
				return new Promise((resolve, error) => {
					uni.uploadFile({
						url: this.baseURL + '/api/user/qiniuUpload', //仅为示例，非真实的接口地址
						filePath: path,
						name: 'file',
						header: {
							"token": uni.getStorageSync('token')
						},
						success: (uploadFileRes) => {
							if ("string" === typeof uploadFileRes.data) {
								resolve(JSON.parse(uploadFileRes.data).data)
							} else {
								resolve(uploadFileRes.data.data)
							}
						},
						complete() {
							uni.hideLoading()
						}
					});
				})
			},
			// 图片裁切
			/**
			 * @param {Number} w 裁切宽度比例
			 * @param {Number} h 裁切高度比例
			 * @param {Number} mw 图片最小宽度
			 * @param {Number} mh 图片最小高度
			 * @param {String} url url修改
			 */
			navCroper(w, h, type, ind) {
				let that = this;
				let tt = (type == 'upimg' ? 2 : 1)
				this.onImg(tt).then((url) => {
					uni.navigateTo({
						url: `../realName/cropper?width=${w}&height=${h}`,
						events: {
							uploadSuccess(res) {
								that.upLoad(res).then((urldata) => {
									if (type == 'one') {
										that.updata.avatar = urldata.img
									} else if (type == 'all') {
										that.updata.imageList.push(urldata.img)
									} else if (type == 'tab') {
										that.updata.imageList.splice(ind, 1, urldata.img)
									} else if (type == 'audit') {
										that.updata.service_audit_imgs.splice(ind, 1, urldata.img)
									} else if (type == 'auditall') {
										that.updata.service_audit_imgs.push(urldata.img)
									} else if (type == 'service') {
										that.updata.service_imgs.splice(ind, 1, urldata.img)
									} else if (type == 'serviceall') {
										that.updata.service_imgs.push(urldata.img)
									} else if (type == 'model') {
										that.updata.model_imgs.splice(ind, 1, urldata.img)
									} else if (type == 'modelall') {
										that.updata.model_imgs.push(urldata.img)
									}
								})
							}
						},
						success: function(res) {
							// 通过eventChannel向被打开页面传送数据
							res.eventChannel.emit('urlNext', {
								url
							})
						}
					})
				})
			},
			upImage(name, type, ind) {
				const that = this;
				that.onImg(1).then((res) => {
					console.log(res.tempFilePath,'res');
					that.upLoad(res.tempFilePath).then((urldata) => {
						console.log(urldata,'urldata');
						if (type == 1) {
							that.updata[name] = urldata.img
						} else if (type == 2) {
							that.updata[name].push(urldata.img)
						} else if (type == 3) {
							that.updata[name].splice(ind, 1, urldata.img)
						}
					})
				})
			},
			onImg(type) {
				const _this = this
				return new Promise((ok, erro) => {
					// 判断是否需要选择
					if (type == 1) {
						uni.showActionSheet({
							itemList: ['拍照', '选择一张照片'],
							success: function(res) {
								_this.chooseImage(res.tapIndex).then((url) => {
									ok(url)
								}).catch((res) => {
									erro(res)
								})
							},
							fail: function(res) {
								erro(res)
							}
						});
					}
					// 判断是否只需要拍照
					if (type == 2) {
						_this.chooseImage(0).then((url) => {
							ok(url)
						}).catch((res) => {
							erro(res)
						})
					}
				})

			},
			chooseImage: function(index) {
				const _this = this
				return new Promise((ok, error) => {
					// 从相册/相机选择
					// 如需直接开相机或直接选相册，请只使用一个选项
					const sourceType = index === 0 ? ['camera'] : ['album'];
					// #ifdef MP
					uni.chooseMedia({
						count: 1,
						mediaType: ['image'],
						sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
						sourceType: sourceType,
						success(res) {
							// 缓存文件路径
							ok(res.tempFiles[0])
						},
						fail(err) {
							uni.showModal({
								title: '文件打开错误',
								content: '请设置授权文件存储权限',
								showCancel: false,
							});
							error(e)
						}
					})
					// #endif
					// #ifndef MP
					uni.chooseImage({
						count: 1, //默认9
						sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
						sourceType: sourceType,
						success: function(res) {
							ok(res.tempFilePaths[0])
						},
						fail(e) {
							uni.showModal({
								title: '文件打开错误',
								content: '请设置授权文件存储权限',
								showCancel: false,
							});
							error(e)
						}
					});
					// #endif

				})
			},
			// 实名认证
			confirm(e) {
				const that = this;
				if (!that.rendl()) {
					return
				}
				that.loding = true;
				subInfoAudit({
						modelType: that.updata.modelType,
						is_china: that.actionAreaType,
						avatar: that.updata.avatar,
						name: that.updata.name,
						mobile: that.updata.phone,
						idcard: that.updata.cardId,
						service_type: that.updata.timetype.code,
						service_min_price: that.updata.minMoney,
						service_max_price: that.updata.maxMoney,
						service_area: that.updata.is_wm == '是' ? ["海外,海外1,海外2"] : that.updata.onCity.map((item) => {
							return item.province + ',' + item.city + ',' + item.district;
						}),
						service_project: that.updata.checkedType,
						service_intro_content: that.updata.mymask,
						service_intro_imgs: that.updata.imageList,
						work_year: that.updata.work_year,
						ancestral_place: that.updata.ancestral_place,
						education: that.updata.education,
						minority: that.updata.minority,
						service_audit_imgs: that.updata.service_audit_imgs,
						service_imgs: that.updata.service_imgs,
						model_imgs: that.updata.model_imgs,
						user_work_type_id: that.updata.word.id,
						service_count: that.updata.service_count,
						weight: that.updata.weight,
						height: that.updata.height
					})
					.then((e) => {
						if (e.msg == '提交成功,数据已通过审核') {
							this.$api.msg(e.msg);
							setTimeout(
								() => {
									uni.switchTab({
										url: "/pages/userhome/user",
										fail(re) {
											console.log(re)
										}
									})
								}, 1000
							)
						} else {
							this.$api.msg(e.msg);
						}
						that.loding = false;
					})
					.catch(err => {
						this.loding = false;
						console.log(err);
					});
			},
			// 认证
			rendl() {
				const that = this;
				if (that.updata.modelType == 0) {
					if (!that.updata.avatar) {
						uni.showModal({
							title: '错误',
							content: '请上传头像',
							showCancel: false,
						});
						return false
					}

					if (!that.updata.name) {
						uni.showModal({
							title: '错误',
							content: '请填写姓名',
							showCancel: false,
						});
						return false
					}
					if (!that.updata.cardId) {
						uni.showModal({
							title: '错误',
							content: '请填写身份证号',
							showCancel: false,
						});
						return
					} else if (!isCardNo(that.updata.cardId)) {
						uni.showModal({
							title: '错误',
							content: '请填写正确的身份证号',
							showCancel: false,
						});
						return false
					}
					if (!that.updata.phone) {
						uni.showModal({
							title: '错误',
							content: '请填写手机号',
							showCancel: false,
						});
						return false
					}
					if (!that.updata.timetype.code) {
						uni.showModal({
							title: '错误',
							content: '请选择收费时间类型',
							showCancel: false,
						});
						return false
					}
					if (!that.updata.minMoney) {
						uni.showModal({
							title: '错误',
							content: '请填写最低收费价',
							showCancel: false,
						});
						return false
					}
					if (!that.updata.maxMoney) {
						uni.showModal({
							title: '错误',
							content: '请填写最高收费价',
							showCancel: false,
						});
						return false
					}
					if (!that.updata.is_wm) {
						uni.showModal({
							title: '错误',
							content: '请选择服务区域是否海外',
							showCancel: false,
						});
						return
					}
					if (that.actionAreaType == 1 && that.updata.onCity.length == 0) {
						uni.showModal({
							title: '错误',
							content: '请选择服务区域',
							showCancel: false,
						});
						return false
					}
					if (that.updata.checkedType.length == 0) {
						uni.showModal({
							title: '错误',
							content: '请选择服务内容',
							showCancel: false,
						});
						return false
					}
				} else if (that.updata.modelType == 1) {
					if (that.updata.model_imgs.length == 0) {
						uni.showModal({
							title: '错误',
							content: '请上传展示图片',
							showCancel: false,
						});
						return false
					}
				}
				return true
			}
		}
	};
</script>

<style lang="scss">
	.content,
	page {
		min-height: 100%;
	}

	.content {
		padding-bottom: 150rpx;
	}

	.item-name {
		margin: $page-row-spacing;
		font-size: $font-lg;
		font-weight: bold;
		color: $font-color-dark;
	}

	.con_box {
		margin: $page-row-spacing;

		.con_image {
			width: 150rpx;
			height: 150rpx;
			display: inline-block;
			margin-right: 20rpx;
			position: relative;

			.img {
				width: 100%;
				height: 100%;
			}

			.tip {
				position: absolute;
				top: -10rpx;
				right: -10rpx;
				width: 30rpx;
				height: 30rpx;
				background-color: #FFF;
				border-radius: 99rpx;
			}
		}
	}

	.listBox {
		margin: $page-row-spacing;
		margin-top: 30rpx;
		border-radius: 20rpx;
		overflow: hidden;
		background-color: #FFFFFF;
	}

	.list {
		.input {
			text-align: right;
			font-size: $font-base;
			color: $color-gray;
			width: 100%;
		}

		.listItem {
			padding: 35rpx 40rpx;
			border-bottom: 1px solid $page-color-light;

			.ql-editor.ql-blank:before {
				font-style: normal;
			}

			.textarea {
				font-size: $font-base;
				width: 100%;
				word-wrap: break-word;
				white-space: pre-line;
				min-height: 9rem;
			}
		}

		.listIconImg {
			width: 36rpx;
		}

		.right {
			color: $font-color-light;
			font-size: $font-base;
			flex-grow: 1;
			justify-content: flex-end;

			.timetype {
				width: 100%;
				justify-content: flex-end;
			}

			.citylist {
				.del {
					color: $color-red;
					font-size: $font-sm;
					border: 1px solid $color-red;
					border-radius: 10rpx;
					line-height: 1;
					padding: 5rpx 15rpx;
				}
			}

			.img {
				width: 26rpx;
			}

			.buttom {
				color: $base-color;
				border: 1px solid $base-color;
				border-radius: 10rpx;
				line-height: 1;
				padding: 10rpx 20rpx;
			}
		}

		.titleBox {
			.title {
				color: $font-color-base;
				font-size: $font-base;
			}
		}
	}

	.bg-gray {
		background-color: $color-gray;
	}

	.base-buttom {
		position: fixed;
		bottom: 0rpx;
		right: 0rpx;
		left: 0rpx;
		margin: 0;
		padding: 0;
		height: 100rpx;
		border-radius: 0;

		.updata,
		.ylan {
			width: 50%;
			height: 100%;
			justify-content: center;
		}

		.ylan {
			background-color: #FFF;
			color: $font-color-dark;
		}
	}

	.errorIf {
		font-size: $font-lg;
		color: #F65486;
		padding: 30rpx;
	}

	.table {
		.table-text {
			color: #F65486;
			text-align: center;
			flex-grow: 1;
			padding: 30rpx;
			border: 1px solid #F65486;

			&.action {
				background-color: #F65486;
				color: #FFFFFF;
			}
		}
	}
</style>