<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="ciy-form-group">
			<input type="hidden" name="id" :value="init.data.id" style="display:none;" />
			<view class="ciy-form">
				<label class="imp">默认标题</label>
				<view>
					<ciy-input name="name" v-model="init.data.name"></ciy-input>
				</view>
			</view>
			<view class="ciy-form">
				<label>所属菜单</label>
				<view>
					<ciy-select :range="g.zc_menu" name="menuid" v-model="init.data.menuid"></ciy-select>
				</view>
			</view>
			<view class="ciy-form">
				<label>文件大小</label>
				<view>
					<ciy-inputbet bet="1024" unit="KB" name="filesize" v-model="init.data.filesize"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>长度</label>
				<view>
					<ciy-inputbet bet="1000" unit="米" :ciystyle="{width:'8em'}" name="metre" v-model="init.data.metre"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>贷款金额</label>
				<view>
					<ciy-inputbet bet="1000000" unit="万元" name="bankmoney" v-model="init.data.bankmoney"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>设置日期</label>
				<view>
					<ciy-inputdatetime name="setdate" v-model="init.data.setdate"></ciy-inputdatetime>
				</view>
			</view>
			<view class="ciy-form">
				<label>设置时间</label>
				<view>
					<ciy-inputdatetime btime name="settimes" v-model="init.data.settimes"></ciy-inputdatetime>
				</view>
			</view>
			<view class="ciy-form">
				<label>营业时间</label>
				<view>
					<ciy-inputtimepoint bsec name="dayclock" v-model="init.data.dayclock"></ciy-inputtimepoint>
				</view>
			</view>
			<view class="ciy-form">
				<label>文档</label>
				<view>
					<ciy-upload num="5" filetype="all" imgwidth="1000" sourcetype="album,message" path="demo" name="downurl" v-model="init.data.downurl"></ciy-upload>
				</view>
			</view>
			<view class="ciy-form">
				<label>头像</label>
				<view>
					<ciy-upload imgwidth="600" imgheight="600" path="demo" name="avar" v-model="init.data.avar"></ciy-upload>
				</view>
			</view>
			<view class="ciy-form">
				<label>是否使用</label>
				<view>
					<ciy-selbool name="isuse" v-model="init.data.isuse"></ciy-selbool>
				</view>
			</view>
			<view class="ciy-form">
				<label>是否开启</label>
				<view>
					<ciy-selbool y="开启" n="关闭" name="isopen" v-model="init.data.isopen"></ciy-selbool>
				</view>
			</view>
			<view class="ciy-form">
				<label>库存单位</label>
				<view>
					<ciy-inputunitedit name="unit" v-model="init.data.unit"></ciy-inputunitedit>
				</view>
			</view>
			<view class="ciy-form">
				<label>单选状态</label>
				<view>
					<ciy-radiobox left :range="g.auditstatus" name="sigstatus" v-model="init.data.sigstatus"></ciy-radiobox>
				</view>
			</view>
			<view class="ciy-form">
				<label>多选状态</label>
				<view>
					<ciy-checkbox itemright line :range="g.auditstatus" name="mauditstatus" v-model="init.data.mauditstatus"></ciy-checkbox>
				</view>
			</view>
			<view class="ciy-form">
				<label>组织结构</label>
				<view>
					<ciy-selcas :range="g.zc_depart" name="prodcata" v-model="init.data.prodcata"></ciy-selcas>
				</view>
			</view>
			<view class="ciy-form">
				<label>所在地区</label>
				<view>
					<ciy-selcas :range="g.ciy_arearpc" name="areacode" v-model="init.data.areacode"></ciy-selcas>
				</view>
			</view>
			<view class="ciy-form">
				<label>认证情况</label>
				<view>
					<ciy-checkbox bin left line :range="g.renzheng" name="renzheng" v-model="init.data.renzheng"></ciy-checkbox>
				</view>
			</view>
			<view class="ciy-form">
				<label>临时字典</label>
				<view>
					<ciy-select :range="g.ppint" name="ppint" v-model="init.data.ppint"></ciy-select>
				</view>
			</view>
			<view class="ciy-form">
				<label>执行周期</label>
				<view>
					<ciy-inputcyc name="npcyc" v-model="init.data.npcyc"></ciy-inputcyc>
				</view>
			</view>
			<view class="ciy-form">
				<label>执行用时</label>
				<view>
					<ciy-input name="runsec" v-model="init.data.runsec"></ciy-input>
				</view>
				<view style="flex:none;">秒</view>
			</view>
			<view class="ciy-form">
				<label>活动期数</label>
				<view class="flex flex-center" style="justify-content: flex-end;">
					第
					<ciy-input :ciystyle="{width:'3em',margin:'0 0.5em',textAlign:'center',display:'inline-block'}" name="acttm" v-model="init.data.acttm"></ciy-input>
					期
				</view>
			</view>
			<view class="ciy-form">
				<label>活动花絮</label>
				<view>
					<ciy-upload num="9" imgwidth="1920" zipjpg="0.8" path="demo" name="imgs" v-model="init.data.imgs"></ciy-upload>
				</view>
			</view>
			<view class="ciy-form">
				<label>吨位</label>
				<view>
					<ciy-inputbet bb bet="1000000" unit="吨" :ciystyle="{width:'8em'}" name="ton" v-model="init.data.ton"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>单价</label>
				<view>
					<ciy-inputbet bet="100" unit="元" name="price" v-model="init.data.price"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>位置</label>
				<view>
					<ciy-selmap name="loc" v-model:lng="init.data.lng" v-model:lat="init.data.lat"></ciy-selmap>
				</view>
			</view>
			<view class="ciy-form">
				<label>监管数量</label>
				<view>
					<ciy-input name="nums" v-model="init.data.nums"></ciy-input>
				</view>
			</view>
			<view class="ciy-form">
				<label>百分比</label>
				<view>
					<ciy-inputbet bet="100" unit="%" name="pct" v-model="init.data.pct"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>链接</label>
				<view>
					<ciy-input name="url" v-model="init.data.url"></ciy-input>
				</view>
			</view>
			<view class="ciy-form">
				<label>体重</label>
				<view>
					<ciy-inputbet bet="1000" unit="公斤" name="weightg" v-model="init.data.weightg"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>耳温</label>
				<view>
					<ciy-inputbet bet="1000" unit="℃" name="eartmpr" v-model="init.data.eartmpr"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>身份证号</label>
				<view>
					<ciy-input name="idcard" v-model="init.data.idcard"></ciy-input>
				</view>
			</view>
			<view class="ciy-form">
				<label>介绍</label>
				<view>
					<ciy-textarea name="content" v-model="init.data.content"></ciy-textarea>
				</view>
			</view>
			<!-- <view class="ciy-form v">
				<label>富文本</label>
				<view>
					<ciy-mdedit name="md" v-model="init.data.md"></ciy-mdedit>
				</view>
			</view> -->
		</view>

		<view class="tabbar ciy-bottom">
			<button class="btn lg cc long" @tap="edited">{{lang('page.btn_submit')}}</button>
		</view>
	</view>
</template>

<style>
</style>

<script>
	export default {
		props: ['id'],
		data() {
			return {}
		},
		onLoad() {
			var app = getApp();
			this.init.data = app.globalData.ciy_page_init;
			if (!this.init.data)
				return this.alert('不能直接访问，请重新进入');
			this.g = app.globalData.ciy_page_g;
			this.getdata();
		},
		watch: {},
		computed: {},
		methods: {
			async getdata() {
				var act = 'edit';
				var page = getApp().getpage(1);
				if (page && page.init._editonce)
					act = '';
				if (this._loading)
					return;
				this._loading = true;
				var retjson = await this.callajax({
					func: 'demo/demo.getdata',
					data: {
						...this.opn,
						act: act
					}
				});
				this._loading = false;
				if (retjson.code != 1)
					return this.init = retjson;
				if (act == 'edit') {
					page.init._editonce = true;
					page.g.zc_menu = retjson.zc_menu;
					this.g.zc_menu = retjson.zc_menu;
				}
				this.init = this.objdeepmerge(this.init, retjson);
			},
			async edited() {
				if (this._loading)
					return;
				this._loading = true;
				var retjson = await this.callajax({
					func: 'demo/demo.update',
					data: {
						...this.init.data
					}
				});
				this._loading = false;
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				var page = getApp().getpage(1);
				if (!page)
					return;
				if (this.init.data._idx == -1)
					page.init.list.unshift(retjson.data);
				else
					page.init.list[this.init.data._idx] = this.objdeepmerge(page.init.list[this.init.data._idx], retjson.data);
				// const eventChannel = this.getOpenerEventChannel();
				// eventChannel.emit('writedata', retjson.data);
				uni.navigateBack();
			}
		}
	}
</script>