|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |  | <template>	<view>		<u--form labelPosition="left" :model="form" :rules="rules" ref="uForm" labelWidth="80">			<view class="se-p-20">				<view class="se-px-20 se-bgc-white se-br-10 se-fs-20">					<u-form-item labelWidth="0">						<view class="se-flex se-flex-ai-c">							<view class="line-orange"></view>							<view class="se-ml-10 se-fs-32 se-c-black se-fw-6">								标题							</view>						</view>					</u-form-item>					<u-form-item labelWidth="0" prop="title">						<u--input v-model="form.title" placeholder="请在此输入标题"></u--input>					</u-form-item>					<u-form-item label="工作地点" prop="area"  @click="handleAreaChange()">						<u--input readonly v-model="form.area" placeholder="请选择工作地点"							border="none"></u--input>						<u-icon  slot="right" name="arrow-right"></u-icon>					</u-form-item>					<!-- <u-form-item label="请选择地址" class="se-b-b" prop="area" @click="handleAreaChange()">						<u--input readonly v-model="form.area"  placeholder="请选择地址" border="none"></u--input>						<u-icon slot="right" name="arrow-right" ></u-icon>					</u-form-item> -->					<!-- <u-form-item label="详细地址" prop="address">						<u--textarea v-model="form.address" count							placeholder="请输入详细地址"></u--textarea>					</u-form-item> -->					<u-form-item label="所属行业" prop="industryId" @click="handleindustryChange">						<u--input @click="handleindustryChange" readonly v-model="form.industryName" placeholder="请选择行业"							border="none"></u--input>						<u-icon @click="handleindustryChange" slot="right" name="arrow-right"></u-icon>					</u-form-item>					<u-form-item label="所属工种" prop="typeId" @click="handleTypeChange">						<u--input @click="handleTypeChange" v-model="form.typeName" readonly placeholder="请选择工种"							border="none"></u--input>						<u-icon @click="handleTypeChange" slot="right" name="arrow-right"></u-icon>					</u-form-item>					<u-form-item label="期望月薪" prop="salary">						<view class="se-flex se-flex-h-c">							<u--input v-model="form.salaryMin" class="se-w-200" placeholder="最小值"></u--input>							<text class="se-mx-10">~</text>							<u--input v-model="form.salaryMax" class="se-w-200" placeholder="最大值"></u--input>						</view>					</u-form-item>					<u-form-item label="试工日薪" prop="dayMoney">						<u--input v-model="form.dayMoney" placeholder="试工日薪"></u--input>					</u-form-item>					<u-form-item label="结算方式" prop="settlement">						<u-radio-group  v-model="form.settlement" placement="row">							<u-radio activeColor="#FF7A31" name="0" label="提前支付"></u-radio>							<u-radio activeColor="#FF7A31" class="se-ml-20" name="1" label="试用以后支付"></u-radio>						</u-radio-group>					</u-form-item>					<u-form-item label="开始时间" prop="dateMin" @click="showMinDate=true">						<u--input v-model="form.dateMin" disabled placeholder="开始时间"></u--input>					</u-form-item>					<u-form-item label="结束时间" prop="dateMax" @click="showMaxDate=true">						<u--input v-model="form.dateMax" disabled placeholder="结束时间"></u--input>					</u-form-item>					<u-form-item label="联系电话" prop="mobile">						<u--input v-model="form.mobile"  placeholder="请输入联系方式"></u--input>					</u-form-item>					<u-form-item label="工作内容" prop="introduce">						<u--textarea v-model="form.introduce" count 							placeholder="请选择工作内容"></u--textarea>					</u-form-item>				</view>			</view>			<view class="se-p-20">				<view class="se-px-20 se-pb-20 se-bgc-white se-br-10 se-fs-20">					<u-form-item prop="fileList" labelWidth="2">						<view class="se-flex se-flex-v-sa">							<view class="se-py-20 se-w-p-100 se-flex">								<view class="line-orange"></view>								<view class="se-ml-10">									图片上传								</view>							</view>							<view class="se-py-20 se-w-p-100">								<u-upload :fileList="form.fileList" @afterRead="afterRead" @delete="deletePic" name="1"									multiple :maxCount="10"></u-upload>							</view>						</view>					</u-form-item>				</view>			</view>			<view class="se-px-20 se-pt-20">				<view class="se-px-20 se-pb-80 se-fs-20 se-flex">					<view @click="submit"						class="se-mx-10 se-flex-1 se-br-40 se-flex-h-c se-h-80 se-lh-80 se-ta-c se-fs-28 se-c-white se-bgc-orange">						<text>{{ editId ? '更新招聘信息' : '发布订单' }}</text>					</view>				</view>			</view>		</u--form>		<!-- 性别 -->		<u-action-sheet :show="showIndustry" :actions="indList" title="请选择行业" @close="showIndustry = false" @select="industrySelect">		</u-action-sheet>		<!-- 种类 -->		<u-action-sheet :show="showType" :actions="typeList" title="请选择种类" @close="showType = false"			@select="typeSelect">		</u-action-sheet>		<!-- 地址 -->		<citySelect v-model="showPicker" @city-change="handleCityChange"></citySelect>		<!-- 时间 Min-->		<u-datetime-picker			:show="showMinDate"			:value="form.dateMin"			:minDate="todayTimestamp"			mode="datetime"			closeOnClickOverlay			@confirm="dateMinConfirm"			@cancel="dateMinClose"			@close="dateMinClose"		></u-datetime-picker>		<u-datetime-picker			:show="showMaxDate"			:value="form.dateMax"			:minDate="todayTimestamp"			mode="datetime"			closeOnClickOverlay			@confirm="dateMaxConfirm"			@cancel="dateMaxClose"			@close="dateMaxClose"		></u-datetime-picker>	</view></template>
<script>	import QQMapWX from "@/util/qqmap-wx-jssdk.min.js"	import { addTask,industryList,industryById, updateJob, getTaskById } from "@/common/api.js"	import citySelect from '@/components/cityselect/index.vue'	export default {		props: {			editId: {				type: String,				default: null			}		},		components:{			citySelect		},		data() {			return {				showMinDate:false,				showMaxDate:false,				todayTimestamp: new Date().setHours(0, 0, 0, 0),								showPicker: false,				showIndustry: false,				indList:[],				industryList: [					{						name: '打铁',					},					{						name: '打牌',					}				],				showType: false,				typeList: [],				form: {					title:"",					area:'',					address:'',					industryId:"",					industryName:"",					settlement:'',					date:"",					dateMin:"",					dateMax:"",					mobile: '',					typeId: '',					typeName:"",					salary:'',					dayMoney:"",					salaryMin: '',					salaryMax: '',					introduce: '',					fileList: [],					latitude:'',					longitude:""				},				rules: {					title:[						{							type: 'string',							required: true,							message: '请在此输入标题',							trigger: ['blur', 'change']						}					],					area:[						{							type: 'string',							required: true,							message: '请选择地址',							trigger: ['blur', 'change']						}					],					address:[						{							type: 'string',							required: true,							message: '请填写详细地址',							trigger: ['blur', 'change']						}					],					industryName:[						{							type: 'string',							required: true,							message: '请选择行业',							trigger: ['blur', 'change']						}					],					typeId:[						{							type: 'string',							required: true,							message: '请选择工种',							trigger: ['blur', 'change']						}					],					dayMoney:[						{							required: true,							message: '请输入试工日薪',							trigger: ['blur', 'change']						}					],					settlement:[						{							type: 'string',							required: true,							message: '请选择结算方式',							trigger: ['blur', 'change']						}					],					mobile: [						{							required: true, 							message: '请输入手机号',							trigger: ['change','blur'],						},						{							validator: (rule, value, callback) => {								return uni.$u.test.mobile(value);							},							message: '手机号码不正确',							trigger: ['change','blur'],						},					],										date: [{						type: 'string',						max: 1,						required: true,						message: '请填写时间',						trigger: ['blur', 'change']					}],					salary: [{						type: 'string',						required: true,						message: '请输入试用日薪',						trigger: ['blur', 'change']					}],					introduce: [{						type: 'string',						required: true,						message: '请输入工作内容',						trigger: ['blur', 'change']					}],					fileList:[						{							validator: (rule, value, callback) => {							  if (value === null || value === undefined || value === '' || (Array.isArray(value) && value.length === 0)) {								callback(new Error('照片不能为空'));							  } else {								callback();							  }							}, 							trigger: 'blur' 						}					],									},			}		},		watch: {			'form.salaryMin': {			  handler(newVal, oldVal) {				if (!uni.$u.test.isEmpty(newVal) && !uni.$u.test.isEmpty(this.form.salaryMax)) {					this.form.salary = '有'				} else {					this.form.salary = ''				}			  },			  immediate: true			},			'form.salaryMax': {			  handler(newVal, oldVal) {				if (!uni.$u.test.isEmpty(newVal) && !uni.$u.test.isEmpty(this.form.salaryMin)) {					this.form.salary = '有'				} else {					this.form.salary = ''				}			  },			  immediate: true			},			'form.dateMin': {			  handler(newVal, oldVal) {				if (!uni.$u.test.isEmpty(newVal) && !uni.$u.test.isEmpty(this.form.dateMax)) {					this.form.date = '有'				} else {					this.form.date = ''				}			  },			  immediate: true			},			'form.dateMax': {			  handler(newVal, oldVal) {				if (!uni.$u.test.isEmpty(newVal) && !uni.$u.test.isEmpty(this.form.dateMin)) {					this.form.date = '有'				} else {					this.form.date = ''				}			  },			  immediate: true			},		},		methods: {			dateMinConfirm(event){				console.info(event)				this.showMinDate = false				this.form.dateMin = uni.$u.timeFormat(event.value, 'yyyy-mm-dd hh:MM:ss')			},			dateMinClose(){				this.showMinDate = false			},			dateMaxConfirm(event){				this.showMaxDate = false				this.form.dateMax = uni.$u.timeFormat(event.value, 'yyyy-mm-dd hh:MM:ss')			},			dateMaxClose(){				this.showMaxDate = false			},			handleAreaChange(){				const that = this;				wx.chooseLocation({                    type: 'gcj02',					// type: 'wgs84',
					success: function (res) {
                        that.form.latitude = res.latitude                        that.form.longitude = res.longitude
                        if (!res.address && res.name) { //用户直接选择城市的逻辑
                            return that.form.area = res.name                        }                        if (res.address || res.name) {                            return that.form.area = res.address + res.name                        }                        that.form.area = '' //用户啥都没选就点击勾选
						// const qqmapsdk = new QQMapWX({
						// 	key: 'TT7BZ-Z3LW4-KOAUB-KWHOA-SBJJ6-Y5B6R' // 必填
						// });
						// uni.showLoading({
						// 	title:"获取中...."
						// })
						// qqmapsdk.reverseGeocoder({
						// 	location: {
						// 		latitude: res.latitude,
						// 		longitude: res.longitude
						// 	},
						// 	success: function(response) {
						// 		console.log('逆地理编码结果:', response);
						// 		uni.hideLoading()
						// 		that.form.longitude = response.result.location.lng
						// 		that.form.latitude = response.result.location.lat
						// 		that.form.area = response.result.address
						// 	},
						// 	fail: function(error) {
						// 		uni.hideLoading()
						// 		console.error('逆地理编码失败:', error);
						// 	}
						// });
					}				})				// this.showPicker = true
			},			handleCityChange(e) {				console.info(e)				this.form.area = e.province.label + '-' + e.city.label + '-' + e.area.label;			},			handleindustryChange() {				this.showIndustry = true			},			industrySelect(e) {				this.form.industryId=e.id				this.form.industryName = e.name				this.$refs.uForm.validateField('industryName')				this.onIndustryById()			},						onIndustryById(){				let that = this				industryById({pid:that.form.industryId}).then(response=>{					console.info("response",response);					that.typeList = response.result										// 如果是编辑模式且已有工种ID,需要在工种列表加载后验证工种字段
					if (that.editId && that.form.typeId) {						that.$nextTick(() => {							if (that.$refs.uForm) {								that.$refs.uForm.validateField('typeId')							}						})					}				}).catch(error=>{									})			},			handleTypeChange() {				if(!this.form.industryId){					return uni.$u.toast('请选择行业')				}				this.showType = true			},			typeSelect(e) {				this.form.typeId = e.id				this.form.typeName = e.name				this.$refs.uForm.validateField('typeId')			},			submit() {				this.$refs.uForm.validate().then(res => {					this.onaddTask()				}).catch(errors => {				})			},						onaddTask(){				let that = this				let params ={				  "phone": that.form.mobile,//招聘方联系方式
				  "salaryDay": that.form.dayMoney,//期望日薪
				  "endTime": that.form.dateMax,				  "categoryOne": that.form.industryId,				  "categoryTwo": that.form.typeId,				  "latitude": that.form.latitude,				  "longitude": that.form.longitude,				  "salaryMax": that.form.salaryMax,//期望薪资最大值
				  "salaryMin": that.form.salaryMin,//期望薪资最小值
				  "payType": that.form.settlement,//结算方式 0提前支付 1 试用后支付
				  "startTime": that.form.dateMin,				  "title": that.form.title,//工作标题
				  "address": that.form.area,//工作地址
				  "details": that.form.introduce,				  "image": that.form.fileList.map(item => item.url).join(','),//照片
				}								// 如果是编辑模式,添加ID参数
				if (this.editId) {					params.id = this.editId				}								if(this.$dayjs(params.startTime).isAfter(this.$dayjs(params.endTime))){					return uni.$u.toast('开始时间不能大于结束时间')				} else if(this.$dayjs(params.endTime).isBefore(this.$dayjs())){					return uni.$u.toast('结束时间不能小于当前时间')				}else if(this.$dayjs(params.startTime).isBefore(this.$dayjs())){					return uni.$u.toast('开始时间不能小于当前时间')				}								// 根据是否为编辑模式选择不同的API
				const apiMethod = this.editId ? updateJob : addTask				const successMessage = this.editId ? '更新成功!' : '提交成功!'								apiMethod(params).then(response=>{					console.info("response",response)					uni.$u.toast(successMessage)					setTimeout(()=>{						uni.switchTab({							url: '/pages/home/index'						})					},800)				}).catch(error=>{									})			},			deletePic(event) {				this.form.fileList.splice(e.index, 1)			},			async afterRead(e) {				let self = this				e.file.forEach(file => {					self.$Oss.ossUpload(file.url).then(url => {						self.form.fileList.push({							url						})					})				})			},			onIndustryList(){				industryList({}).then(response=>{					console.info("industryList",response);					this.indList = response.result				}).catch(error=>{									})			},						// 获取招聘详情数据用于编辑
			getJobDetail() {				getTaskById({ 					id: this.editId,					edit : '1'				 }).then(response => {					const data = response.result					// 回填表单数据
					this.form.title = data.title || ''					this.form.area = data.address || ''					this.form.industryId = data.categoryOne || ''					this.form.industryName = data.categoryOneName || ''					this.form.typeId = data.categoryTwo || ''					this.form.typeName = data.categoryTwoName || ''					this.form.salaryMin = data.salaryMin || ''					this.form.salaryMax = data.salaryMax || ''					this.form.dayMoney = String(data.salaryDay || '')					this.form.settlement = data.payType || ''					this.form.dateMin = data.startTime || ''					this.form.dateMax = data.endTime || ''					this.form.mobile = data.phone || ''					this.form.introduce = data.details || ''					this.form.latitude = data.latitude || ''					this.form.longitude = data.longitude || ''										// 处理图片列表
					if (data.image) {						const imageUrls = data.image.split(',')						this.form.fileList = imageUrls.map(url => ({ url: url.trim() }))					}										// 如果有行业ID,获取对应的工种列表
					if (this.form.industryId) {						this.onIndustryById()					}										// 数据回填后,清除表单验证错误状态
					this.$nextTick(() => {						if (this.$refs.uForm) {							// 清除所有字段的验证错误
							this.$refs.uForm.clearValidate()							// 或者单独验证已填充的字段
							if (this.form.industryName) {								this.$refs.uForm.validateField('industryName')							}							if (this.form.typeId) {								this.$refs.uForm.validateField('typeId')							}							if (this.form.dayMoney) {								this.$refs.uForm.validateField('dayMoney')							}						}					})				}).catch(error => {					console.error('获取招聘详情失败:', error)					uni.showToast({						title: '获取数据失败',						icon: 'none'					})				})			},		},		onReady() {			this.$refs.uForm.setRules(this.rules)			this.onIndustryList()			// 如果是编辑模式,获取招聘详情数据
			if (this.editId) {				this.getJobDetail()			}		},	}</script>
<style></style>
 |