<template>
	<ciy-header title="搜索/列表/删除页" ref="header"></ciy-header>
	<view v-if="init.code != 1">
		<view class="px4 py4">
			<view style="height:2em;width:60%;" class="ciy-skeleton"></view>
			<view style="height:1em;width:40%;margin-left:1em;" class="ciy-skeleton"></view>
			<view style="height:1em;width:50%;" class="ciy-skeleton"></view>
			<view style="height:6em;width:100%;" class="ciy-skeleton"></view>
		</view>
	</view>
	<view v-else>
		<view class="sti" :style="{top:(header_statusbar_height+header_title_height)+'px'}">
			<ciy-segment :lis="init.lis" all="全部" @change="segment_change"></ciy-segment>
			<ciy-query ref="query" :gdict="g" :qry="init.searchinput" @confirm="query_confirm">
				<template v-slot="{itm}">
					<ciy-input :name="itm.item.form" v-model="itm.data[itm.item.form]"></ciy-input>
				</template>
			</ciy-query>
		</view>
		<view class="ciy-list" :class="{del:item._del}" v-for="(item,index) in init.list" :key="item.id" @tap="showmenu(index)">
			<view class="l0">No: {{item.id}}</view>
			<view v-if="item.id%2 == 0" class="rt">
				<view class="code b" :class="ccode(g.auditstatus, item.auditstatus,'clas')">{{ccode(g.auditstatus, item.auditstatus)}}</view>
			</view>
			<view v-else class="rtz liner" :class="ccode(g.auditstatus, item.auditstatus,'clas')">
				{{ccode(g.auditstatus, item.auditstatus)}}
			</view>
			<view class="l1 c">
				<view>{{item.name}}</view>
			</view>

			<view class="ciy-hr"></view>
			<view class="l2">审核人　{{ccode('xa_user', item.audituser)}}</view>
			<view class="l2" v-if="item.auditmsg">审核理由　<text v-html="tobr(item.auditmsg)"></text></view>
			<view class="l2">审核时间　{{todatetime(item.audittimes)}}</view>
			<view class="ciy-hr"></view>

			<view class="l2">
				<label>所属菜单</label>
				<view>{{ccode(init.zc_menu, item.menuid)}}</view>
			</view>
			<view class="l2">
				<label>文件大小</label>
				<view>{{tofix(item.filesize/1024, -2)}}KB</view>
			</view>
			<view class="l2">
				<label>长度</label>
				<view>{{tofix(item.metre/1000, -2)}}米</view>
			</view>
			<view class="l2">
				<label>贷款金额</label>
				<view>{{tofix(item.bankmoney/1000000)}}万元</view>
			</view>

			<view class="l2">
				<label>设置日期</label>
				<view>{{todatetime(item.setdate, 'd')}}</view>
			</view>
			<view class="l2">
				<label>设置时间</label>
				<view>{{todatetime(item.settimes)}}</view>
			</view>
			<view class="l2">
				<label>营业时间</label>
				<view>{{totimepoint(item.dayclock, true)}}</view>
			</view>
			<ciy-showimgs label="文档" :src="item.downurl"></ciy-showimgs>
			<ciy-showimgs :src="item.avar" width="20em" mode="widthFix"></ciy-showimgs>

			<view class="l2">
				<label>是否使用</label>
				<view>{{item.isuse==1?'√':'×'}}</view>
			</view>
			<view class="l2">
				<label>是否开启</label>
				<view>{{item.isopen==1?'开启':'关闭'}}</view>
			</view>
			<view class="l2">
				<label>库存单位</label>
				<view>{{tounit(item.unit)}}</view>
			</view>
			<view class="l2">
				<label>单选状态</label>
				<view>{{ccode(g.auditstatus, item.sigstatus)}}</view>
			</view>
			<view class="l2">
				<label>多选状态</label>
				<view>
					<view class="kbd" v-for="(itm, index) in scode(g.auditstatus, item.mauditstatus)" :key="index">{{itm.name}}</view>
				</view>
			</view>
			<view class="l2">
				<label>组织结构</label>
				<view>{{mcode(g.zc_depart, item.prodcata, 'name').join(' . ')}}</view>
			</view>
			<view class="l2">
				<label>所在地区</label>
				<view>
					<text class="code" v-for="(itm, index) in mcode(g.ciy_arearpc, item.areacode)" :key="index">{{itm.name}}</text>
				</view>
			</view>
			<view class="l2">
				<label>认证情况</label>
				<view>
					<text class="kbd" v-for="(itm, index) in bcode(g.renzheng, item.renzheng)" :key="index">{{itm.name}}</text>
				</view>
			</view>
			<view class="l2">
				<label>临时字典</label>
				<view>{{ccode(g.ppint, item.ppint)}}</view>
			</view>

			<view class="l2">
				<label>执行周期</label>
				<view>{{tocyc(item.npcyc)}}</view>
			</view>
			<view class="l2">
				<label>执行用时</label>
				<view>{{totimesec(item.runsec)}}</view>
			</view>
			<view class="l2">
				<label>活动期数</label>
				<view>第{{item.acttm}}期</view>
			</view>
			<ciy-showimgs label="活动花絮" :src="item.imgs"></ciy-showimgs>
			<view class="l2">
				<label>吨位</label>
				<view>{{tofix(item.ton/1000000, 3)}}吨</view>
			</view>
			<view class="l2">
				<label>单价</label>
				<view>{{tofix(item.price/100, 2)}}元</view>
			</view>

			<view class="l2">
				<label>位置</label>
				<view><text style="text-decoration: underline;" @tap.stop="goloc(item.lat, item.lng)">查看位置</text>
				</view>
			</view>
			<view class="l2">
				<label>百分比</label>
				<view>{{tofix(item.pct/100, 2)}}%</view>
			</view>
			<view class="l2">
				<label>链接</label>
				<view><text style="text-decoration: underline;" @tap.stop="goweb(item.url)">转到链接</text>
				</view>
			</view>
			<view class="l2">
				<label>体重</label>
				<view>{{tofix(item.weightg/1000)}}公斤</view>
			</view>
			<view class="l2">
				<label>耳温</label>
				<view>{{tofix(item.eartmpr/1000, 1)}}℃</view>
			</view>
			<view class="l2">
				<label>身份证号</label>
				<view>{{tomsk(item.idcard,'******#*')}}</view>
			</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="edit()"></view>
	</view>
</template>

<style>
</style>

<script>
	export default {
		data() {
			return {}
		},
		onLoad() {
			this.load_ciydict(this.file_stor('/dict/ciy_arearpc.js')).then(json => {
				if (json.code != 1)
					return this.alert(json.errmsg);
				this.g.ciy_arearpc = json.arr;
			});
			this.getlist();
		},
		onReachBottom(b) {
			console.log('onReachBottom page', this.pageno);
			if (this.init.code != 1)
				return;
			this.getlist();
		},
		onPullDownRefresh(b) {
			console.log('onPullDownRefresh page');
			this.pageno = 0;
			this._stopPullDown = true;
			this.getlist();
		},
		watch: {},
		computed: {},
		methods: {
			async getlist() {
				if (this.pageno < 0)
					return;
				if (this._loading)
					return;
				this.pagepost.pageno = this.pageno + 1;
				this.pagepost.once = !this.init.once;
				this._loading = true;
				var retjson = await this.callfunc({
					func: 'demo/demo.list',
					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.once) {
					this.init.lis = [...this.g.auditstatus];
					this.g.zc_depart = retjson.zc_depart;
					this.g.ppint = retjson.ppint;
				}
				this.getrefs('query').then(ref => {
					ref.setdata(retjson.where);
				});
				if (retjson.list.length < retjson.pagecount)
					this.pageno = -1;
			},
			segment_change(e) {
				this.pagepost.liid = e.value.id;
				this.pageno = 0;
				this.getlist();
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 800
				});
			},
			query_confirm(dat) {
				this.pagepost.query = dat;
				this.pageno = 0;
				this.getlist();
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 800
				});
			},
			async edit(item) {
				item = item || {
					url: '',
					data: {
						id: 0,
						_idx: -1
					}
				};
				this.gourl('demo_edit?id=' + item.data.id, 'navigate', item.data, 'demo');
			},
			async del(item) {
				if (await this.askmsg('是否删除？', '删除') != 'ok')
					return;
				var retjson = await this.callfunc({
					func: 'demo/demo.del',
					data: {
						id: item.data.id
					}
				});
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.init.list[item.data._idx]._del = true;
				setTimeout(() => {
					this.init.list.splice(item.data._idx, 1);
				}, 500);
			},
			async audit(item) {
				var msg = await this.inputmsg({
					title: '请填写审核理由',
					ele: 'textarea'
				}, [{
					name: '审核通过',
					btn: 'ok'
				}, {
					name: '驳回',
					btn: 'ng',
					cls: 'dag liner'
				}, {
					name: '取消',
					btn: 'cancel',
					cls: 'def'
				}]);
				if (msg.btn == 'cancel')
					return;
				var retjson = await this.callfunc({
					func: 'demo/demo.audit',
					data: {
						id: item.data.id,
						msg: msg.text,
						status: msg.btn == 'ng' ? 90 : 100,
					}
				});
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				this.init.list[item.data._idx] = this.objdeepmerge(this.init.list[item.data._idx], retjson.data);
			},
			showmenu(idx) {
				var dat = this.init.list[idx];
				dat._idx = idx;
				var items = [];
				items.push({
					func: 'audit',
					name: '审核',
					data: dat
				});
				items.push({
					func: 'edit',
					name: '变更',
					data: dat
				});
				items.push({
					func: 'del',
					name: '删除',
					style: 'color:var(--dag5)',
					data: dat
				});
				this.popmenu({
					items
				});
			}
		}
	}
</script>