<template>
	<view class="content">
		<view><jinEdit :placeholder="isCompanyIntroduction?'输入公司简介内容':'输入个人简介内容'" @editBlur="editBlur" @editOk="editOk" :html="brief" uploadFileUrl="/#"></jinEdit></view>
	</view>
</template>

<script>
const app = getApp();
const req = require('../../utils/request.js');
import jinEdit from '../components/jin-edit/jin-edit.vue';
export default {
	components: {
		jinEdit
	},
	data() {
		return {
			id: '',
			brief: '',
			isReadOnly: true,
			isCompanyIntroduction:false
		};
	},

	onLoad(opt) {
		this.id = opt.id;
		let pages = getCurrentPages();
		let prevPage = pages[pages.length - 2];
		if(opt.isCompanyIntroduction){
			this.isCompanyIntroduction = true
			this.brief = prevPage.$vm.companyIntroduction;
		}else{
			this.brief = prevPage.$vm.brief;
		}
	},
	onUnload: function() {
		// 页面销毁时执行保存
		this.saveContent(this.brief, false);
	},
	methods: {
		editBlur(res) {
			this.brief = res.detail.html;
		},
		saveContent(content, isBack) {
			let pages = getCurrentPages(); //获取所有页面栈实例列表
			let prevPage = pages[pages.length - 2]; //上一页页面实例
			if(this.isCompanyIntroduction){
				prevPage.$vm.companyIntroduction = content;
			}else{
				prevPage.$vm.brief = content;
			}
			if (isBack) {
				uni.navigateBack({
					delta: 1
				});
			}
		},
		// 点击发布
		editOk(res) {
			this.saveContent(res.html, true);
		}
	}
};
</script>

<style>
@import './editDesc.css';
.ql-editor.ql-blank:before {
	/* 此处设置 placeholder 样式 */
	color: rgba(204, 204, 204, 1);
	font-style: normal;
	min-height: 400px;
}
</style>
