<template>
	<view style="position: relative;">
		<!-- 胶囊 -->
		<mvBar :mysNavConfig="mysNavConfig"></mvBar>
		<view :style="{marginTop:navH}"></view>
		<view @click="toRecord()">
			<view style="display: flex;justify-content: center;">
				<image style="height: 60rpx;width: 60rpx;" src="../../static/img/icon-clock.png"></image>
			</view>
			<view style="display: flex;justify-content: center;">
				<p style="font-size: 30rpx;">查看修改/反馈记录</p>
			</view>
		</view>

		<view v-if="!loading && !onlyShow">
			<!-- 多行输入框 -->
			<view style="padding: 20rpx 30rpx 0;">
				<uni-easyinput type="text" :inputBorder="false" v-model="title" placeholder="在此填写让人眼前一亮的标题吧"
					:placeholderStyle="placeholderStyle">
				</uni-easyinput>
			</view>
			<view style="padding: 40rpx 30rpx 150rpx;font-size: 30rpx;">
				<textarea v-model="text" maxlength="5000" auto-height="true" placeholder="添加正文(任务未要求可不填写进行提交)" />
			</view>
			<view class="signup">
				<button type="default" class="but1" :loading="loading" @click="submit()">
					提交脚本</button>
			</view>
		</view>

		<view v-if="onlyShow" style="width: 100%;">
			<p style="font-size: 30rpx;padding: 20rpx 30rpx 0 ;">{{title}}</p>
			<view style="padding: 40rpx 30rpx 150rpx;font-size: 30rpx;">
				<text> {{text}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	import mvBar from "@/components/mys_navBar/mysNavBar";
	export default {
		components: {
			mvBar,
		},
		data() {
			return {
				onlyShow: false,
				loading: true,
				placeholderStyle: "font-size: 30rpx;",
				navH: getApp().globalData.navHeight,
				taskId: "",
				title: "",
				text: "",
				scriptStatus: "",
				mysNavConfig: {
					/* 开启单页显示首页图标 */
					isHome: true,
					/* 固定导航  */
					navFixed: true,
					/* 标题 （屏幕中心居中 两边图标中心居中使用slot center1） */
					navTitle: {
						text: "上传脚本",
						color: "",
						fontSize: "32rpx", // px upx rpx
						fontWeight: "normal", // 100 - 700
					},
					btnType: "type2",
					onLeftClick: '',
					/* type2 按钮 */
					type2Config: {
						// 左图标
						leftPath: "/static/img/png2.png",
						// 右图标
						rightPath: "/static/img/png4.png",
						// 圆角
						radius: "40rpx",
					},
				},
			}
		},
		onLoad(options) {
			let data = options.textObj.replace(/""/g, "");
			data = JSON.parse(decodeURIComponent(data))
			this.taskId = data.taskId
			this.scriptStatus = data.scriptStatus
			this.getScript()
		},
		methods: {
			async getScript() {
				this.loading = true
				uni.showLoading({
					title: '加载中'
				});
				await this.$https.get('/youngee/c/t/g/get-unsubmit-task-script' +
						"?" +
						"task_id" +
						"=" +
						this.taskId)
					.then(res => {
						console.log(res)
						if (res.data.data != null) {
							this.onlyShow = true
							this.text = res.data.data.content
							this.title = res.data.data.title
						}
					})
				uni.hideLoading();
				this.loading = false
			},
			toRecord() {
				var data = {
					taskId: this.taskId,
				};
				data = JSON.stringify(data)
				uni.navigateTo({
					url: '/page_workspace/task/record/scriptrecord?textObj=' + encodeURIComponent(data)
				});
			},

			async submit() {
				// 检验标题和内容是否为空
				// if (this.title == '') {
				// 	uni.showToast({
				// 		title: "请填写脚本标题",
				// 		icon: 'none'
				// 	})
				// 	return
				// }
				// if (this.text == '') {
				// 	uni.showToast({
				// 		title: "请填写脚本内容",
				// 		icon: 'none'
				// 	})
				// 	return
				// }
				let that = this
				uni.showModal({
					title: '提示',
					content: '提交后无法修改并进行审核，确认提交？',
					success: async function(res) {
						if (res.confirm) {
							await that.$https.post('/youngee/c/t/p/add-task-script', {
									task_id: that.taskId,
									title: that.title,
									content: that.text,
								})
								.then(res => {
									console.log(res)
								})

							await that.$https.get('/youngee/c/t/g/submit-task-script' +
									"?" +
									"task_id" +
									"=" +
									that.taskId)
								.then(res => {
									console.log(res)
								})
							uni.navigateBack()
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
		}
	}
</script>

<style>
	/deep/ .uni-easyinput__content-input {
		font-size: 30rpx !important;
		padding: 0 !important;
	}
</style>


<style lang="scss" scoped>
	.signup {
		box-shadow: 0rpx 5rpx 40rpx #ccc;
		width: 100%;
		position: fixed;
		bottom: 0rpx;
		display: flex;
		height: 90rpx;
		padding-top: 2%;
		background-color: #FFFFFF;
		z-index: 100;
	}

	.but1 {
		width: 60%;
		background-color: #f2d22d;
		border-radius: 20rpx;
		font-size: 36rpx;
		line-height: 200%;
		letter-spacing: 10rpx;
		font-weight: 500;
		height: 80%;

		&.on {
			background-color: #C0C0C0;

		}

	}
</style>
