<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 primaryColor='#00b666' btnText="取消" type="default" size="small" @clickBtn="goBack"></rh-button>
					</view>
					<view class="g_flex_c" style="width: 50%">
						<rh-button primaryColor='#00b666' 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 primaryColor='#00b666' btnText="取消" type="default" size="small" @clickBtn="goBack"></rh-button>
					<rh-button primaryColor='#00b666' 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: "%",
				},
				{
					id: 6,
					text: "共计",
					pre: "共计",
					suffix: "元",
				},

				{
					id: 7,
					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 = "";
		console.log("this.options", options);
		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 {
	.showdoc {
		// box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04), 0 0 6px rgba(0, 0, 0, 0.02);
		overflow-x: auto;

		.menu-obj {
			// min-width: 422px;

			.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 #00b666;
					color: #00b666;
				}
			}
		}
	}
}
</style>
