<template>
	<view class="p-root-detail-job-desq g_w_all g_h_all g_bg_f_5 g_kuaishou">
		<view
			class="g_flex_column_between"
			v-if="type == 'view'"
			:style="{
				height: pheight + 'px',
				overflow: 'auto',
			}"
		>
			<view class="g_h_10 g_flex_none g_bg_f_5"></view>
			<view class="g_flex_1 g_bg_f g_pl_16 g_pr_16 g_pt_8 g_pb_8" style="overflow-y: auto">
				<view class="g_fs_16 g_c_6 g_mb_16">{{ time }}</view>
				<text class="g_fs_16 g_c_6 g_pb_100" :user-select="true"  style="word-break: break-all; white-space: pre-line">{{info}}</text>
			</view>
		</view>
		<view class="g_bg_f g_h_all g_flex_column_between" v-if="type == 'edit'">
			<view class="g_h_10 g_flex_none g_bg_f_5"></view>
			<view
				class="g_flex_1 g_bg_f g_pt_8 g_pb_8 g_pl_16 g_pr_16"
				:style="{
					'max-height': height + 'rpx',
					overflow: 'auto',
				}"
			>
				<u-input v-model="applyInfo.globalText" type="textarea" :border="false" :auto-height="true" :maxlength="1000" :height="height" :clearable="false" />
			</view>
			<view class="g_h_100 g_flex_none g_bg_f_5"></view>
			<g-panel-fixed>
				<view class="g_flex_row_between">
					<view class="g_flex_c" style="width: 50%">
						<rh-button  btnText="取消" type="default" size="small" @clickBtn="goBack"></rh-button>
					</view>
					<view class="g_flex_c" style="width: 50%">
						<rh-button  btnText="保存" type="primary" size="small" @clickBtn="goReturn"></rh-button>
					</view>
				</view>
			</g-panel-fixed>
		</view>
		<view class="g_bg_f g_h_all g_flex_column_between g_bg_f_5" v-if="type == 'form'">
			<view class="g_h_10 g_flex_none g_bg_f_5"></view>
			<view class="g_flex_1 g_pt_8 g_pb_8 g_bg_f_5" style="width: 100vw">
				<view class="g_flex_row_start g_mb_8 g_pl_10">
					代理费
					<view class="xing g_c_fa2b"> * </view>
				</view>
				<view class="showdoc g_flex_row_start g_clear_scroll g_pb_12">
					<view class="g_flex_row_start_none menu-obj">
						<view v-for="item in disList" :key="item.id" class="menu-btn g_flex_column_center" :class="applyInfo.agencyReturnFeeType == item.id ? 'menu-active' : ''" @click="changeDis(item)">
							<view class="btn g_radius_4 g_pl_8 g_pr_8 g_pt_4 g_pb_4 g_fs_12">{{ item.text }}</view>
						</view>
					</view>
				</view>
				<view class="g_flex_row_around flex_center g_bg_f g_h_44 g_pl_10 g_pr_10 g_radius_8" style="width: calc(100% - 20px); margin: 0 auto">
					<view class="g_mr_16">
						{{ disList[applyInfo.agencyReturnFeeType].pre }}
					</view>
					<u-input height="22" v-model="applyInfo.agencyReturnFee" type="digit" class="g_flex_1 weui-input" placeholder="仅数字" placeholder-style="color:#999" />
					<view class="">
						{{ disList[applyInfo.agencyReturnFeeType].suffix }}
					</view>
				</view>
			</view>
			<view class="g_h_100 g_flex_none g_bg_f_5"></view>
			<g-panel-fixed>
				<view class="g_flex_row_center">
					<rh-button  btnText="取消" type="default" size="small" @clickBtn="goBack"></rh-button>
					<rh-button  btnText="保存" type="primary" size="small" @clickBtn="goReturn" class="g_ml_16"></rh-button>
				</view>
			</g-panel-fixed>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			info: "-",
			time: "",
			title: "",
			type: "",
			applyInfo: {},
			height: 1200, 
			pheight: 800,
			disActive: 0,
			result: "",
			disList: [
				{
					id: 0,
					text: "按小时",
					pre: "按时",
					suffix: "元/小时",
				},
				{
					id: 1,
					text: "按天数",
					pre: "按天",
					suffix: "元/天",
				},
				{
					id: 2,
					text: "按月数",
					pre: "按月",
					suffix: "元/月",
				},
				{
					id: 3,
					text: "按次数",
					pre: "按次",
					suffix: "元/次",
				},
				{
					id: 4,
					text: "按件数",
					pre: "按件",
					suffix: "元/件",
				},
				{
					id: 5,
					text: "共计",
					pre: "共计",
					suffix: "元",
				},
			],
		};
	},
	onReady() {
		console.log(uni.getSystemInfoSync().windowHeight - 145);
		this.pheight = uni.getSystemInfoSync().windowHeight;
		this.height = (uni.getSystemInfoSync().windowHeight - 145) * 2;
	},
	onLoad(options) {
		let str = "";
		if (options.info) {
			if (options.info == "undefined" || options.info == "null" || options.info == "NaN") {
				this.info = "-";
			} else {
				this.info = options.info;
			}
		} else {
			this.info = "-";
		}
		this.time = options.time;
		this.title = options.title;
		this.type = options.type;
		console.log("this.info", this.info);
		this.disActive = options.dis ? options.dis : 0;
	},
	onShow() {
		let that = this;
		uni.setNavigationBarTitle({
			title: that.title,
		});
		if (uni.getStorageSync("APPLY_OBJ")) {
			let applyInfo = uni.getStorageSync("APPLY_OBJ");
			this.applyInfo = {
				orderId: applyInfo.id,
				relationId: applyInfo.relationId,
				applyUserId: applyInfo.applyUserId,
				agencyReturnFee: applyInfo.agencyReturnFee / 100,
				agencyReturnFeeType: applyInfo.agencyReturnFeeType === "" ? 0 : applyInfo.agencyReturnFeeType,
				agencyReturnFeeDesp: applyInfo.agencyReturnFeeDesp,
				policyIdx: applyInfo.policyIdx,
				interviewDesp: applyInfo.interviewDesp,
				employeeSalary: applyInfo.employeeSalary,
				version: applyInfo.version,
				globalText: "",
			};
			if (this.title == "其他说明") {
				that.applyInfo.globalText = that.applyInfo.interviewDesp;
			} else if (this.title == "职位说明") {
				that.applyInfo.globalText = that.applyInfo.employeeSalary;
			} else if (this.title == "代理费详情") {
				that.applyInfo.globalText = that.applyInfo.agencyReturnFeeDesp;
			}
			console.log("this.applyInfo", this.applyInfo);
		}
	},
	onUnload() {
		console.log("onUnload");
		uni.removeStorageSync("APPLY_OBJ");
	},
	methods: {
		goReturn() {
			let that = this;
			if (this.title == "其他说明") {
				that.applyInfo.interviewDesp = that.applyInfo.globalText;
			} else if (this.title == "职位说明") {
				that.applyInfo.employeeSalary = that.applyInfo.globalText;
			} else if (this.title == "代理费详情") {
				that.applyInfo.agencyReturnFeeDesp = that.applyInfo.globalText;
			}
			delete that.applyInfo.globalText;
			that.G.Post(
				that.api.order_update_detail,
				{
					...that.applyInfo,
					agencyReturnFee: that.applyInfo.agencyReturnFee * 100,
				},
				(res) => {
					console.log("res", res);
					uni.navigateBack();
				}
			);
		},
		goBack() {
			uni.navigateBack();
		},
		changeDis(e) {
			let that = this;
			this.applyInfo.agencyReturnFeeType = e.id;
		},
	},
};
</script>

<style lang="less">
.p-root-detail-job-desq {
	.menu-btn {
		margin-right: 8px;

		.btn {
			background: rgba(204, 204, 204, 0.2);
			border: 1rpx solid transparent;
			color: #666666;
			white-space: nowrap;
		}

		&:first-child {
			margin-left: 12px;
		}
	}

	.menu-active {
		.btn {
			background: rgba(0, 182, 102, 0.1);
			border: 1rpx solid #6a81ff;
			color: #6a81ff;
		}
	}
}
</style>
