<template>
	<view style="position: relative;">
		<!-- 胶囊 -->
		<mvBar :mysNavConfig="mysNavConfig"></mvBar>
		<view style="margin-top: 160rpx;"></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>

		<!-- 多行输入框 -->
		<uni-easyinput type="text" :inputBorder="false" v-model="title" placeholder="在此填写让人眼前一亮的标题吧">
		</uni-easyinput>
		<view style="padding: 40rpx 30rpx 150rpx;font-size: 32rpx">
			<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>
</template>

<script>
	import mvBar from "@/components/mys_navBar/mysNavBar";
	export default {
		components: {
			mvBar,
		},
		data() {
			return {
				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: {
			getScript() {
				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.text = res.data.data.content
							this.title = res.data.data.title
						}
					})
			},
			toRecord() {
				var data = {
					taskId: this.taskId,
				};
				data = JSON.stringify(data)
				uni.navigateTo({
					url: '/pages/workspace/scriptrecord?textObj=' + encodeURIComponent(data)
				});
			},

			submit() {
				// 检验标题和内容是否为空
				if (this.title == '') {
					uni.showToast({
						title: "请填写脚本标题",
						icon: 'none'
					})
					return 
				}
				if (this.text == '') {
					uni.showToast({
						title: "请填写脚本内容",
						icon: 'none'
					})
					return 
				}
				
				this.$https.post('/youngee/c/t/p/add-task-script', {
						task_id: this.taskId,
						title: this.title,
						content: this.text,
					})
					.then(res => {
						console.log(res)
						uni.navigateBack()
					})
			},
		}
	}
</script>

<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>
