<template>
	<ciy-header title="意见建议"></ciy-header>
	<view v-if="init.code != 1" class="px4 py4">
		<view class="ciy-skeleton" style="height:80vw;width:100%;"></view>
		<view class="ciy-skeleton" style="height:6em;width:100%;"></view>
		<view class="ciy-skeleton" style="height:6em;width:100%;"></view>
	</view>
	<view v-else>
		<view class="ciy-card">
			<view class="content char4">
				<view class="ciy-form v">
					<label class="imp">意见建议</label>
					<view>
						<ciy-textarea v-model="editdata.content" type="text" bb ciystyle="min-height:5em"></ciy-textarea>
					</view>
				</view>
				<view class="ciy-form">
					<label>图片截图</label>
					<view>
						<ciy-upload left num="5" path="suggest" v-model="editdata.imgs" imgwidth="1600" sourcetype="camera,album,message"></ciy-upload>
					</view>
				</view>
				<view class="ciy-form">
					<label>联系方式</label>
					<view>
						<ciy-input v-model="editdata.contract" type="text" bb></ciy-input>
					</view>
				</view>
				<view class="ciy-form-bottom">
					<button class="btn lg cc" @tap="submit">提交</button>
				</view>
			</view>
		</view>
		<view class="ciy-list" v-for="(item,index) in init.list" :key="item.id">
			<view class="l2" v-html="tobr(item.content)"></view>
			<ciy-showimgs :src="item.imgs" label="图片截图"></ciy-showimgs>
			<view class="l2" v-if="item.contract">联系方式: {{item.contract}}</view>
			<template v-if="item.replytimes > 0">
				<view class="ciy-hr my4"></view>
				<view class="l2 ciy-tip" v-html="tobr(item.replymsg)"></view>
				<view class="rt" style="color:var(--succ5)">已答复</view>
			</template>
			<view class="rt" v-else>未答复</view>
			<view class="rb">{{todatetime(item.addtimes)}}</view>
		</view>
	</view>
</template>

<style>
</style>

<script>
	export default {
		data() {
			return {}
		},
		onLoad() {
			this.editdata.contract = this.me.mobile;
			this.getinit();
		},
		methods: {
			async getinit() {
				var retjson = await this.callfunc({
					func: 'me.suggest_get',
					data: {}
				});
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.init = retjson;
			},
			async submit(e) {
				if (this.editdata.content.length < 5)
					return this.toast('内容至少输入5个字');
				if (this._loading)
					return;
				this._loading = true;
				var retjson = await this.callfunc({
					func: 'me.suggest_submit',
					data: this.editdata
				});
				this._loading = false;
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.init.list.unshift(retjson.data);
				await this.toast('提交成功');
			}
		}
	}
</script>