<template>
	<view class="u-page">
		<!-- 使用状态组件 -->
		<view class="se-px-20 se-pt-40" v-if="obj && Object.keys(obj).length > 0">
			<order-status :order-data="obj" page-type="order"></order-status>
		</view>

		<!-- 先支付后试用 -->
		<view class="se-px-20" v-if="obj.payType == 0">
			<!-- 求职者 -->
			<view class="se-px-220 se-pb-30 se-fs-20 se-flex se-flex-h-c">
				<button
					open-type="contact"
					class="se-mx-10 se-w-200 se-br-40 se-flex-h-c se-h-50 se-lh-50 se-ta-c se-fs-24 se-c-white se-bgc-orange"
					style="background: #ff7a31; border: none; padding: 0; margin: 0; line-height: 50rpx;">
					<text>联系客服</text>
				</button>

				<template v-if="obj.status==0">
					<view @click="onCancel()"
						class="se-mx-10 se-w-200 se-b se-br-40 se-flex-h-c se-h-50 se-lh-50 se-ta-c se-fs-24 se-c-66 se-bgc-f5">
						<text>取消</text>
					</view>
				</template>
				
				<template v-if="obj.status==2">
					<view @click="confirmOrderTry()"
						class="se-mx-10 se-w-200 se-br-40 se-flex-h-c se-h-50 se-lh-50 se-ta-c se-fs-24 se-c-white se-bgc-orange">
						<text>确认试工完成</text>
					</view>
				</template>
			</view>
		</view>

		<!-- 先试用后支付 -->
		<view class="se-px-20" v-else>
			<view class="se-px-220 se-pb-30 se-fs-20 se-flex se-flex-h-c">
				<template v-if="obj.status==0">
					<view @click="onCancel()"
						class="se-mx-10 se-w-200 se-b se-br-40 se-flex-h-c se-h-50 se-lh-50 se-ta-c se-fs-24 se-c-66 se-bgc-f5">
						<text>取消</text>
					</view>
				</template>
				<template v-if="obj.status==1">
					<view @click="confirmOrderTry()"
						class="se-mx-10 se-w-200 se-br-40 se-flex-h-c se-h-50 se-lh-50 se-ta-c se-fs-24 se-c-white se-bgc-orange">
						<text>确认试工完成</text>
					</view>
					<view @click="onCancel()"
						class="se-mx-10 se-w-200 se-b se-br-40 se-flex-h-c se-h-50 se-lh-50 se-ta-c se-fs-24 se-c-66 se-bgc-f5">
						<text>取消</text>
					</view>
				</template>
				<template v-if="obj.status!=6">
					<button
						open-type="contact"
						class="se-mx-10 se-w-200 se-br-40 se-flex-h-c se-h-50 se-lh-50 se-ta-c se-fs-24 se-c-white se-bgc-orange"
						style="background: #ff7a31; border: none; padding: 0; margin: 0; line-height: 50rpx;">
						<text>联系客服</text>
					</button>
				</template>
				<template v-if="obj.status==4">
					<view @click="confirmOrderTryCompanyOk()"
						class="se-mx-10 se-w-200 se-br-40 se-flex-h-c se-h-50 se-lh-50 se-ta-c se-fs-24 se-c-white se-bgc-orange">
						<text>确认到账</text>
					</view>
				</template>
			</view>
		</view>

		<view class="se-px-40 se-py-20">
			<view class="se-flex se-flex-ai-c se-pb-10">
				<view class="line-orange"></view>
				<view class="se-ml-10 se-fs-32 se-c-black se-fw-6">
					招聘工作详情
				</view>
			</view>
			<view class="se-flex se-flex-v-sa se-flex-ai-fs se-py-20">
				<view class="se-flex">
					<view class="se-w-160 se-h-160">
						<image class="se-w-160 se-h-160 se-br-10" :src="obj.workHeadImg" mode=""></image>
					</view>
					<view class="se-ml-20 se-flex se-flex-v-sa se-flex-ai-fs">
						<view class="se-fw-6 se-c-black se-fs-30 se-display-ib">工作职位:{{obj.title || '暂未'}}</view>
						<view class="se-fs-24 se-c-text-third se-display-ib">所属行业:{{obj.categoryOne || '暂未'}}</view>
						<!-- <view class="se-fs-24 se-c-text-third se-display-ib">所属工种:{{obj.title}}</view> -->
						<view class="se-fs-24 se-c-text-third se-display-ib">所属工种:{{obj.categoryTwo || '暂未'}}</view>
					</view>
				</view>
				<view class="se-flex se-flex-h-sb se-w-p-100 se-pt-20">
					<view class="se-fs-24 se-display-ib">试工日薪</view>
					<view class="se-c-orange se-fs-32 se-fw-6 se-display-ib" v-if="obj.employJob && obj.employJob.salaryDay">{{obj.employJob.salaryDay}}元</view>
					<view class="se-fs-24 se-display-ib se-c-99" v-else>暂未</view>
				</view>
				<view class="se-flex se-flex-h-sb se-w-p-100 se-pt-20">
					<view class="se-fs-24 se-display-ib">月薪</view>
					<view class="se-c-orange se-fs-32 se-fw-6 se-display-ib" 
                    v-if="obj.employJob && (obj.employJob.salaryMax || obj.employJob.salaryMin)">

                        <text v-if="obj.employJob.salaryMin">{{obj.employJob.salaryMin}}</text>
                        
                        <text v-if="obj.employJob.salaryMax != obj.employJob.salaryMin 
                        && obj.employJob.salaryMax != 0 && obj.employJob.salaryMin != 0">-</text>

                        <text 
                        v-if="obj.employJob.salaryMax != obj.employJob.salaryMin && obj.employJob.salaryMax != 0">
                            {{obj.employJob.salaryMax || 0}}
                        </text>

                        元/月
                    </view>
					<view class="se-fs-24 se-display-ib se-c-99" v-else>暂未</view>
				</view>
			</view>
			<u-line dashed></u-line>
			<view class="se-py-10 se-pb-30">
				<view class="se-mt-30">
					<text class="se-fs-28 se-c-black se-fw5">招聘公司名称：{{obj.workName || '暂未'}}</text>
                    <br>
					<text class="se-fs-28 se-c-black se-fw5">招聘联系人：{{obj.employAuthenticationPerson && obj.employAuthenticationPerson.name || '暂未'}}</text>
                    <br>
					<text class="se-fs-24 se-c-text-third">联系方式：{{obj.employAuthenticationPerson && obj.employAuthenticationPerson.phone || '暂未'}}</text>
					<view class="se-bgc-orange se-c-white se-fs-20 se-display-ib se-px-10 se-py-5 se-br-10 se-ml-10"
						@click="copyText(obj.phone)">
						复制
					</view>
				</view>
				<view class="se-mt-10">
					<text class="se-fs-24 se-c-33">工作地址：{{obj.workAddress || '暂未'}}</text>
					<view class="se-bgc-orange se-c-white se-fs-20 se-display-ib se-px-10 se-py-5 se-br-10 se-ml-10"
						@click="copyText(obj.workAddress)">
						复制
					</view>
				</view>
			</view>
			<u-line dashed></u-line>
			<view class="se-mt-20 se-pt-20 se-pb-30">
				<view class="se-fw-6 se-fs-32 se-c-black">
					订单信息
				</view>
				<view class="se-flex se-pt-30 se-flex-h-sb">
					<view class="se-fs-24 se-display-ib">支付方式</view>
					<view class="se-fs-24 se-display-ib" v-if="obj.payType==0">先付后试用</view>
					<view class="se-fs-24 se-display-ib" v-else>先试用后支付</view>
					<view class="se-fs-24 se-display-ib se-c-99" v-if="obj.payType==null || obj.payType==undefined">暂未</view>
				</view>
				<view class="se-flex se-pt-30 se-flex-h-sb" v-if="obj.employJob">
					<view class="se-fs-24 se-display-ib">工作时间</view>
					<view class="se-fs-24 se-display-ib" v-if="obj.employJob.startTime && obj.employJob.endTime">
                        {{formatDate(obj.employJob.startTime)}} - {{formatDate(obj.employJob.endTime)}}
                    </view>
					<view class="se-fs-24 se-display-ib se-c-99" v-else>暂未</view>
				</view>
			</view>
			<u-line dashed></u-line>
			<view class="se-mt-20 se-pt-20 se-pb-30">
				<view class="se-fw-6 se-fs-32 se-c-black">
					工作内容
				</view>
				<view class="se-fs-24 se-pt-20 se-pb-20 se-lh-40">
					<u-parse :content="obj.details"></u-parse>
				</view>
			</view>
            <view class="se-px-220 se-pb-30 se-fs-20 se-flex se-flex-h-c">
				<view @click="onService()"
					class="se-mx-10 se-w-200 se-br-40 se-flex-h-c se-h-50 se-lh-50 se-ta-c se-fs-24 se-c-white se-bgc-orange">
					<text>联系客服</text>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		orderDetail,
		deleteOrder,
		confirmOrder,
		confirmOrderTry,
		confirmOrderTryCompanyOk,
	} from "@/common/api.js"
	import OrderStatus from "@/components/order-status/index.vue"
	export default {
		components: {
			OrderStatus
		},
		data() {
			return {
				detail: `<p>
						1、全日制大专以上学历，艺术设计类相关专业;<br/>
						2、两年以上平面、品牌、视觉设计等相关工作经验，能独立完成项目的设计工作，有 3C数码/个护健 康 类产品服务经验优先，有乙方工作经验佳;<br/>
						3、具备一定的设计提案能力，能完整的呈现设计思路与创意，能清晰的表达设计逻辑与思考;<br/>
						4、热爱设计，平面基本功扎实，拥有优良的审美与创意想法，对版式、色彩把控能力强;对工作富有责任心，具备团队沟通与协作能力;<br/>
						5、精通 PS、AI、CDR 等平面设计软件，能独立完成日常平面设计工作内容，熟练使用 PPT/Keynote，能完成提案内容的材料美化工作。<br/>
						</p>`,
				obj: {}
			}
		},
		onLoad(options) {
			this.orderId = options.orderId
		},
		onShow() {
			this.onOrderDetail()
		},
		methods: {
            checkStatus(){
				let that = this
                // 如果是求职者且orderStatusSeek没有值，跳转到保险页面
                if (that.obj && !that.obj.orderStatusSeek && that.obj.status > 0 && that.obj.status < 4) {
                    uni.navigateTo({
                        url: "/pages_subpack/payment/index?id=" + that.orderId
                    })
                }
            },
			onOrderDetail() {
				let that = this
				let params = {
					orderId: that.orderId
				}
				orderDetail(params).then(response => {
					that.obj = response.result
			        this.checkStatus()
				}).catch(error => {

				})
			},
			copyText(event) {
				uni.setClipboardData({
					data: event,
					success: () => {
						uni.showToast({
							title: "复制成功",
							icon: "none",
						});
					},
					fail: (err) => {
						console.error("复制失败", err);
					},
				})
			},
			// 确认企业已结款
			confirmOrderTryCompanyOk(){
				confirmOrderTryCompanyOk({
					orderId : this.orderId
				})
				.then(res => {
					this.onOrderDetail()
				})
			},
			onCancel() {
				deleteOrder(this.orderId).then(res => {
					if (res.code == 200) {
						uni.navigateBack(-1)
					}
				})
			},

			// 订单信息-企业确认订单
			confirmOrder() {
				confirmOrder(this.orderId)
				.then(res => {
					if(res.code == 200){
						uni.showToast({
							title: '确认成功',
							icon: 'none'
						})
						this.onOrderDetail()
					}
				})
			},
			// 订单信息-确认试工完成
			confirmOrderTry(){
				confirmOrderTry(this.orderId)
				.then(res => {
					if(res.code == 200){
						uni.showToast({
							title: '确认成功',
							icon: 'none'
						})
						this.onOrderDetail()
					}
				})
			},
			onPay() {
				uni.navigateTo({
					url: "/pages_subpack/pay/index"
				})
			},
			formatDate(dateString) {
				if (!dateString) return '';
				const date = new Date(dateString);
				const year = date.getFullYear();
				const month = String(date.getMonth() + 1).padStart(2, '0');
				const day = String(date.getDate()).padStart(2, '0');
				return `${year}-${month}-${day}`;
			},
		}
	}
</script>

<style lang="scss" scoped>
</style>