<!-- 商家-已报名人员列表 -->

<template>
	<view>
		<view class="main_width">
			<view class="loading_text" v-if="loading">加载中...</view>
			<view v-else>
				<view class="plan_dotime_box" v-if="plan_dotime_arr.length>1">
					<view class="plan_dotime">
						<view :style="current_plan_dotime==''? 'font-weight: bold;':'font-weight: normal;'"
							@click="set_plan_dotime('')">全部报名日期</view>
						<view :style="current_plan_dotime==item? 'font-weight: bold;':'font-weight: normal;'"
							@click="set_plan_dotime(item)" v-for="item in plan_dotime_arr">{{item}}</view>
					</view>
					<view style="clear: both;"></view>
				</view>

				<view v-if="item.plan_dotime == current_plan_dotime||current_plan_dotime==''" class="item_box"
					:key="index" v-for="(item, index) in data">
					<view style="position: relative;" class="item">
						<view v-if="workteam_mode==0" style="position: absolute;right: 0;top: 0;"
							:class="item.wk_realname_handled=='1'? 'tags':'tags2' ">
							{{item.wk_realname_handled=='1'?'已实名':'未实名'}}
						</view>
						<!-- 状态名称-->
						<view style="display: flex;align-items: center;">
							<view @click="show_remark(item.remark)" class="status_title">
								{{item.statusName||''}}{{item.salary_status==1?'（部分结算）':''}}{{item.statusName == '已结算'&&item.final_status == 1?' 自动结算':''}}
							</view>
						</view>

						<!-- 基础信息显示 -->
						<view>
							<!-- 头像姓名 -->
							<view style="position: relative;" class="mem_item">
								<view class="auth" v-if="item.wk_idcard">身份已认证</view>
								<image :src="item.wkprofile_photo?item.wkprofile_photo: '../../static/user.png'">
								</image>
								<view style="font-size: 32upx;margin-left: 15upx;">
									{{item.wk_name}}
								</view>
								<view @click="contact(item)" style="color: #01bcc3; margin-left: 15upx;">联系会员</view>
							</view>
							<!-- 性别年龄 -->
							<view class="box" style="display: flex;align-items: center;margin-top:30upx;">
								<view style="width: 25%;text-align: left;">性别：{{item.gender}}</view>
								<view style="width: 25%;">年龄：{{item.wk_age}}</view>
								<view style="width: 25%;color: #01bcc3;">
									<navigator :url="'/pages/personal/resumeCheck?id='+item.wkid">查看简历</navigator>
								</view>
								<view style="border: none;width:25%;color: #01bcc3;">
									<navigator :url="'/pages/personal/appraisal?type=1&id='+item.wkid">查看评价</navigator>
								</view>
							</view>
						</view>

						<!-- 操作模块 双方评价 -->
						<view style="margin-top: 30upx;">
							<!-- 已结算显示 -->
							<view v-if="item.status==5">
								<!-- 会员对我的评价 -->
								<view v-if="item.wk_appraiseLevel!=-1">
									<view v-if="item.wk_appraiseLevel">
										<view style="display: flex;align-items: center;height: 50upx;">
											<view style="margin-right: 10upx;color: #ff5500;">会员评价</view>
											<trailerStars allowTap="0" :innerScore="item.wk_appraiseLevel">
											</trailerStars>
										</view>
										<view style="color: #8E97AE;">评价内容：{{item.wk_appraiseRemark}}
										</view>
									</view>
									<view style="color: #ff5500;" v-else>待会员评价</view>
								</view>

								<!-- 我对会员的评价 -->
								<view v-if="item.td_appraiseLevel!=-1" style="margin-top: 20upx;">
									<view v-if="item.td_appraiseLevel">
										<view style="display: flex;align-items: center;height: 50upx;">
											<view style="margin-right: 10upx;color: #ff5500;">我的评价</view>
											<trailerStars allowTap="0" :innerScore="item.td_appraiseLevel">
											</trailerStars>
										</view>
										<view style="color: #8E97AE;">评价内容：
											{{item.td_appraiseRemark}}
										</view>
									</view>
									<view style="display: flex;" v-else>
										<view @click="open_modal('appraise',item.id)" class="confirm">评价该会员</view>
									</view>
								</view>
							</view>
						</view>


						<view style="color: #8D8D8D;margin-top: 5upx;">
							报名时间：{{item.createtime}}</view>
						<view style="color: #8D8D8D;margin-top: 5upx;" v-if="item.plan_dotime&&item.urgent_level==1">
							<view>上班日期：{{item.plan_dotime}}  {{item.begin_hour}}~{{item.finish_hour}}</view>
						</view>
						<view style="color: #8D8D8D;margin-top: 5upx;" v-if="item.plan_dotime&&item.urgent_level==0">
							<view>上班日期：{{item.plan_dotime}}</view>
							<view>开始结束时间：{{item.btr_begindatetime1}}~{{item.btr_finishdatetime1}} {{item.begin_hour}}~{{item.finish_hour}}</view>
						</view>
						<view>
							<view style="color: #8D8D8D;margin-top: 5upx;" v-if="item.worked_begintime">
								开始工作时间：{{item.worked_begintime}}</view>
							<view style="color: #8D8D8D;margin-top: 5upx;" v-if="item.worked_finishtime">
								结束工作时间：{{item.worked_finishtime}}</view>
						</view>


						<!-- 操作模块 录用，结算 -->
						<view style="margin-left: 2%;" class="order_box">
							<!-- 待录用显示 -->
							<view class="order_btn_box" v-if="item.status==1">
								<view @click="open_modal('refuseSign',item.id, item)" class="cancel">拒绝
								</view>
								<view @click="open_modal('allowSign',item.id,item)" class="confirm">录用
								</view>
							</view>
							<!-- 待结算显示 -->
							<view class="order_btn_box" v-if="item.status==2||item.status==3||item.status==4">
								<view @click="open_modal('refusePay',item.id,item)" class="cancel">拒绝支付</view>
								<view @click="open_modal('allowPay',item.id,item)" class="confirm">确认支付</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="loading_text" v-if="data.length==0&&!loading">暂无数据</view>
			<view style="height: 200upx;"></view>
		</view>

		<!-- 遮罩内容 -->
		<uni-popup ref="popup" :mask-click="false">
			<view style="overflow: hidden;" class="modal_box">
				<!-- 评分 -->
				<view v-if="todo == 'appraise'" style="margin-top: 30upx;margin-left: 30upx;">
					<trailerStars allowTap="1" v-on:changeScore="changeScore" :innerScore="score">
					</trailerStars>
				</view>
				<view style=" margin-top: 30upx;">
					<textarea v-model="reason" @input="textarea_ipt" style="text-indent: 20upx;"
						:placeholder="todo_remarks"></textarea>
					<view class="modal_btn">
						<view @click="close_modal()" class="modal_btn_cancel">取消</view>
						<view @click="process()" class="modal_btn_confirm">
							确认{{todo_title}}{{todo=='allowPay'?(btr_feetotal+'元'):''}}</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import commonData from '../../commonData.js'
	import commonFun from '../../commonFun.js'
	import trailerStars from '../../components/starts/index.vue'

	export default {
		data() {
			return {
				checkUrlImg: 'url(' + this.serverUrl + 'check.png)',
				greenUrlImg: 'url(' + this.serverUrl + 'green_point.png)',
				downUrlImg: 'url(' + this.serverUrl + 'arrow_down_green.png)',
				id: '', //招聘id
				loading: false,
				check_box: [], //单选框单选状态
				data: [],
				workId: '',
				todo_title: '',
				todo_remarks: '',
				todo: '',
				reason: '',
				score: 5,
				btr_feetotal: '', //需要支付的金额
				status: 0, //get_data()中的status参数
				plan_dotime_arr: [], //可选日期
				current_plan_dotime: '',
			}
		},
		onPullDownRefresh() {
			this.get_data()
		},
		onLoad(e) {
			this.id = e.id //订单id
			// this.id = 503 //订单id
			this.status = e.status || 0
			this.get_data()
		},
		components: {
			trailerStars
		},
		methods: {
			set_plan_dotime(value) {
				this.current_plan_dotime = value
			},
			// 联系会员
			contact(item) {
				if (item.status > 1 || item.status == -3 || item.status == -5 || item.status == -8) {
					uni.showActionSheet({
						itemList: ['在线沟通', '拨打电话'],
						success: (res) => {
							if (res.tapIndex == 0) {
								uni.setStorageSync('targetUser', {
									name: item.wk_name,
									avatar: item.wkprofile_photo
								})
								// console.log(item)
								// console.log(uni.getStorageSync('targetUser'))
								uni.navigateTo({
									url: '/pages/message/chat?to=user_' + item.wkid
								})
							} else {
								uni.makePhoneCall({
									phoneNumber: item.bu_mobile,
									fail: res => {
										uni.showModal({
											title: '拨号失败',
											content: JSON.stringify(res),
											showCancel: false
										})
									}
								});
							}
						},
					});
				} else {
					uni.showModal({
						title: '录取后获得联系方式',
						showCancel: false
					})
				}

			},
			// 输入操作备注
			textarea_ipt(e) {
				this.reason = e.target.value
			},
			// 打开遮罩
			open_modal(todo, workId, item = {}) {
				if (item) {
					this.btr_feetotal = item.btr_feetotal
				}
				this.workId = workId
				this.todo_remarks = commonData.todo_title_obj[todo]['remarks'] + (commonData.todo_title_obj[todo][
						'is_require'
					] ?
					'（必填）' : '')
				this.todo_title = commonData.todo_title_obj[todo]['title']
				this.todo = todo
				this.$refs.popup.open('top')
			},
			// 关闭遮罩
			close_modal() {
				this.$refs.popup.close('top')
			},
			// 处理
			process() {
				let params = {
					bizCatalog: 'TodoWorkEntity',
					handleMode: commonData.todo_title_obj[this.todo]['handleMode'],
					todo: commonData.todo_title_obj[this.todo]['todo'],
					teamid: '',
					workid: this.workId,
					reason: this.reason,
					appraiseLevel: this.score,
					appraiseRemark: this.reason,
				}
				console.log(params)
				if (this.todo == "appraise" && !params.appraiseLevel) {
					uni.showModal({
						content: '请评价后提交！',
						showCancel: false
					})
					return
				}
				console.log('process请求参数', params)
				// return
				if (commonData.todo_title_obj[this.todo]['is_require'] && params.reason == '') {
					uni.showModal({
						content: commonData.todo_title_obj[this.todo]['title'] + '备注是必填的！',
						showCancel: false
					})
					return
				}

				if (this.todo == 'allowPay' || this.todo == 'allowSign') {
					commonFun.paySettleMer(this.workId, () => {
						this.reason = ''
						this.close_modal()
						this.get_data()
					}, this.todo == 'allowPay' ? 'paySettle' : 'auditEnroll')
					return
				}

				uni.showLoading({
					title: '加载中...',
					mask: true
				})
				commonFun.requestUrl('&WsAjaxBiz=Trader&WsAjaxAction=entityDataHandle', params, res => {
					if (res.status) {
						uni.showModal({
							content: this.todo_title + '成功！',
							showCancel: false,
							success: res => {
								this.reason = ''
								this.close_modal()
								this.get_data()
							}
						})
					}
					uni.hideLoading()
				})
			},
			// 获取数据
			get_data() {
				this.loading = true
				uni.showLoading({
					title: '加载中...',
					mask: true
				})
				let params = {
					bizCatalog: 'TodoWorkEntity',
					handleMode: 'fetchall',
					pageIndex: 1,
					pageSize: 1000,
					orderby: 0,
					query: {
						recuritId: this.id,
						status: this
							.status, //0空-全部；1-待提交；2-已报名待审核；3-已审核待开工；4-报名被驳回；5-已开始工作；6-已结束工作待结算；7-已结算；8-主动取消报名；9-被违约 10-被动取消报名；11-未结算； 91-进行中；92-异常工单；,
						teamstatus: "",
						recuritTitle: '', //招聘标题筛选  
						memberName: "", //成员姓名
					},
				}
				console.log('报名人员页面列表请求参数', params)
				commonFun.requestUrl('&WsAjaxBiz=Trader&WsAjaxAction=fetchPageData', params, res => {
					if (res.status) {
						this.data = res.data.Result.pageData.map(item => {
							item.gender = item.wk_gender == 0 ? '男' : item.wk_gender == 1 ? '女' : '--'
							return item
						})
						this.check_box = this.data.map(item => false)
						let plan_dotime_arr = []
						this.data.map(item => {
							if (plan_dotime_arr.indexOf(item.plan_dotime) == -1) {
								plan_dotime_arr.push(item.plan_dotime)
							}
						})
						this.plan_dotime_arr = plan_dotime_arr
						console.log('报名人员页面列表', this.data)
						console.log(this.plan_dotime_arr)
					}
					this.loading = false
					uni.hideLoading()
					uni.stopPullDownRefresh()
				})
			},
			// 评价星星回调
			changeScore(e) {
				this.score = e
			},
			// 展示备注信息
			show_remark(content) {
				uni.showModal({
					title: '操作备注',
					content,
					showCancel: false
				})
			}
		}
	}
</script>

<style>
	@import url("./memberList.css");
</style>
