<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">
			<view class="ciy-form">
				<label class="imp">默认标题</label>
				<view>
					<ciy-input name="name" v-model="editdata.name"></ciy-input>
				</view>
			</view>
			<view class="ciy-form">
				<label>所属菜单</label>
				<view>
					<ciy-select :range="g.zc_menu" name="menuid" v-model="editdata.menuid"></ciy-select>
				</view>
			</view>
			<view class="ciy-form">
				<label>文件大小</label>
				<view>
					<ciy-inputbet bet="1024" unit="KB" name="filesize" v-model="editdata.filesize"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>长度</label>
				<view>
					<ciy-inputbet bet="1000" unit="米" :ciystyle="{width:'8em'}" name="metre" v-model="editdata.metre"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>贷款金额</label>
				<view>
					<ciy-inputbet bet="1000000" unit="万元" name="bankmoney" v-model="editdata.bankmoney"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>设置日期</label>
				<view>
					<ciy-inputdatetime name="setdate" v-model="editdata.setdate"></ciy-inputdatetime>
				</view>
			</view>
			<view class="ciy-form">
				<label>设置时间</label>
				<view>
					<ciy-inputdatetime btime name="settimes" v-model="editdata.settimes"></ciy-inputdatetime>
				</view>
			</view>
			<view class="ciy-form">
				<label>营业时间</label>
				<view>
					<ciy-inputtimepoint bsec name="dayclock" v-model="editdata.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="editdata.downurl"></ciy-upload>
				</view>
			</view>
			<view class="ciy-form">
				<label>头像</label>
				<view>
					<ciy-upload imgwidth="600" imgheight="600" path="demo" name="avar" v-model="editdata.avar"></ciy-upload>
				</view>
			</view>
			<view class="ciy-form">
				<label>是否使用</label>
				<view>
					<ciy-selbool name="isuse" v-model="editdata.isuse"></ciy-selbool>
				</view>
			</view>
			<view class="ciy-form">
				<label>是否开启</label>
				<view>
					<ciy-selbool y="开启" n="关闭" name="isopen" v-model="editdata.isopen"></ciy-selbool>
				</view>
			</view>
			<view class="ciy-form">
				<label>库存单位</label>
				<view>
					<ciy-inputunitedit name="unit" v-model="editdata.unit"></ciy-inputunitedit>
				</view>
			</view>
			<view class="ciy-form">
				<label>单选状态</label>
				<view>
					<ciy-radio left :range="g.auditstatus" name="sigstatus" v-model="editdata.sigstatus"></ciy-radio>
				</view>
			</view>
			<view class="ciy-form">
				<label>多选状态</label>
				<view>
					<ciy-checkbox itemright line :range="g.auditstatus" name="mauditstatus" v-model="editdata.mauditstatus"></ciy-checkbox>
				</view>
			</view>
			<view class="ciy-form">
				<label>组织结构</label>
				<view>
					<ciy-selcas :range="g.zc_depart" name="prodcata" v-model="editdata.prodcata"></ciy-selcas>
				</view>
			</view>
			<view class="ciy-form">
				<label>所在地区</label>
				<view>
					<ciy-selcas :range="g.ciy_arearpc" name="areacode" v-model="editdata.areacode"></ciy-selcas>
				</view>
			</view>
			<view class="ciy-form">
				<label>认证情况</label>
				<view>
					<ciy-checkbox bin left line :range="g.renzheng" name="renzheng" v-model="editdata.renzheng"></ciy-checkbox>
				</view>
			</view>
			<view class="ciy-form">
				<label>临时字典</label>
				<view>
					<ciy-select :range="g.ppint" name="ppint" v-model="editdata.ppint"></ciy-select>
				</view>
			</view>
			<view class="ciy-form">
				<label>执行周期</label>
				<view>
					<ciy-inputcyc name="npcyc" v-model="editdata.npcyc"></ciy-inputcyc>
				</view>
			</view>
			<view class="ciy-form">
				<label>执行用时</label>
				<view>
					<ciy-input name="runsec" v-model="editdata.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="editdata.acttm"></ciy-input>
					期
				</view>
			</view>
			<view class="ciy-form">
				<label>活动花絮</label>
				<view>
					<ciy-upload num="9" imgwidth="1920" zipjpg="80" path="demo" name="imgs" v-model="editdata.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="editdata.ton"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>单价</label>
				<view>
					<ciy-inputbet bet="100" unit="元" name="price" v-model="editdata.price"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>位置</label>
				<view>
					<ciy-selmap name="loc" v-model:lng="editdata.lng" v-model:lat="editdata.lat"></ciy-selmap>
				</view>
			</view>
			<view class="ciy-form">
				<label>百分比</label>
				<view>
					<ciy-inputbet bet="100" unit="%" name="pct" v-model="editdata.pct"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>链接</label>
				<view>
					<ciy-input name="url" v-model="editdata.url"></ciy-input>
				</view>
			</view>
			<view class="ciy-form">
				<label>体重</label>
				<view>
					<ciy-inputbet bet="1000" unit="公斤" name="weightg" v-model="editdata.weightg"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>耳温</label>
				<view>
					<ciy-inputbet bet="1000" unit="℃" name="eartmpr" v-model="editdata.eartmpr"></ciy-inputbet>
				</view>
			</view>
			<view class="ciy-form">
				<label>身份证号</label>
				<view>
					<ciy-input name="idcard" v-model="editdata.idcard"></ciy-input>
				</view>
			</view>
			<view class="ciy-form">
				<label>介绍</label>
				<view>
					<ciy-textarea name="content" v-model="editdata.content"></ciy-textarea>
				</view>
			</view>
			<!-- <view class="ciy-form v">
				<label>富文本</label>
				<view>
					<ciy-mdedit name="md" v-model="editdata.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() {
			if (!this.pagedata.demo)
				return this.alert('不能直接访问，请重新进入'); //独立进入写后端函数获取数据
			this.editdata = {...this.pagedata.demo};
			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.callfunc({
					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.callfunc({
					func: 'demo/demo.update',
					data: {
						...this.editdata
					}
				});
				this._loading = false;
				if (retjson.code != 1)
					return this.alert(retjson.errmsg);
				var page = getApp().getpage(1);
				if (page?.init?.list)
					this.objtolist(page.init.list, retjson.data);
				// const eventChannel = this.getOpenerEventChannel();
				// eventChannel.emit('writedata', retjson.data);
				uni.navigateBack();
			}
		}
	}
</script>