<template>
	<ciy-header title="我的工单" ref="header"></ciy-header>
	<view v-if="init.code != 1" class="px4 py4">
		<view style="height:2em;width:100%;" class="ciy-skeleton"></view>
		<view style="height:6em;width:100%;" class="ciy-skeleton"></view>
		<view style="height:6em;width:100%;" class="ciy-skeleton"></view>
	</view>
	<view v-else>
		<view class="sti" :style="{top:(header_statusbar_height+header_title_height)+'px'}">
			<ciy-segment :lis="init.lis" v-model="liid" @change="segment_change"></ciy-segment>
		</view>
		<view class="ciy-list" v-for="(item,index) in init.list" :key="item.id">
			<view class="l2" v-html="tobr(item.content)" @tap="gourl" :data-url="'me_problechat?id=' + item.id"></view>
			<ciy-showimgs :src="item.imgs" label="图片截图"></ciy-showimgs>
			<view class="rt" v-if="item.closetimes>0">已关闭</view>
			<view class="rt" style="color:var(--succ5)" v-else-if="item.replytimes>0">有回复</view>
			<view class="rt" style="color:var(--warn5)" v-else>等待中</view>
			<view class="lb" v-if="item.contract">{{item.contract}}</view>
			<view class="rb">{{todatetime(item.addtimes)}}</view>
		</view>
		<ciy-listend :page="pageno" :listlen="init.list.length" :nodataimg="file_stor('/img/mbnone.png')"></ciy-listend>
		<view class="ciy-add" @tap="openadd()"></view>
		<ciy-dialog ref="dialog">
			<form @submit="editsubmit">
				<view class="ciy-form v">
					<label class="imp">问题描述</label>
					<view>
						<ciy-textarea name="content" type="text" bb ciystyle="min-height:4em"></ciy-textarea>
					</view>
				</view>
				<view class="ciy-form">
					<label>图片截图</label>
					<view>
						<ciy-upload left num="8" path="problem" name="imgs" imgwidth="1600" sourcetype="camera,album,message"></ciy-upload>
					</view>
				</view>
				<view class="ciy-form">
					<label>联系方式</label>
					<view>
						<ciy-input :value="me.mobile" name="contract" type="text" bb></ciy-input>
					</view>
				</view>
				<view class="ciy-form-bottom">
					<button class="btn lg cc" form-type="submit">建立工单</button>
				</view>
			</form>
		</ciy-dialog>
	</view>
</template>

<style>
</style>

<script>
	export default {
		data() {
			return {
				liid: 0,
				pageno: 0,
			}
		},
		onLoad() {
			this.init.lis = [];
			this.init.lis.push({
				id: '',
				name: '等待中'
			});
			this.init.lis.push({
				id: 3,
				name: '有回复'
			});
			this.init.lis.push({
				id: 9,
				name: '已关闭'
			});
			this.getlist();
		},
		onReachBottom(b) {
			if (this.init.code != 1)
				return;
			this.getlist();
		},
		onPullDownRefresh(b) {
			this.pageno = 0;
			this._stopPullDown = true;
			this.getlist();
		},
		watch: {},
		computed: {},
		methods: {
			async getlist() {
				if (this.pageno < 0)
					return;
				this.pagepost.pageno = this.pageno + 1;
				this.pagepost.query.liid = this.liid;
				if (this._loading)
					return;
				this._loading = true;
				var retjson = await this.callajax({
					func: 'me.problem_get',
					data: this.pagepost
				});
				this._loading = false;
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.pageno++;
				if (this.pageno == 1)
					this.init.list = [];
				this.init = this.objdeepmerge(this.init, retjson);
				if (retjson.list.length < retjson.pagecount)
					this.pageno = -1;
			},
			openadd() {
				this.getrefsSync('dialog').Open({
					title: '新建工单'
				});
			},
			async editsubmit(e) {
				if (!e.detail.value.content)
					return this.toast('请输入问题描述');
				if (this._loading)
					return;
				this._loading = true;
				var retjson = await this.callajax({
					func: 'me.problem_add',
					data: e.detail.value
				});
				this._loading = false;
				this.getrefsSync('dialog').Close();
				this.init.list.unshift(retjson.data);
			},
			segment_change() {
				this.pageno = 0;
				this.getlist();
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 800
				});
			}
		}
	}
</script>