<!-- 平台审批 -->
<template>
	<view class="form-page">
		<scroll-view scroll-y class="form-scroll">
			<uni-forms v-model="form" label-width="150rpx"  ref="customForm" :rules="customRules">
				<view class="form-card" v-if="form.ticket_">
					<ticketd :ticket_="form.ticket_"></ticketd>
				</view>
				<view class="form-card">
					<view class="form-card-title">平台信息</view>
				<uni-forms-item label="名称" required>
					<uni-easyinput v-model="form.name" placeholder="请输入名称" v-if="mode!='show'"/>
					<span v-else>{{form.name}}</span>
				</uni-forms-item>
				<uni-forms-item label="日期" required>
					<uni-datetime-picker type="date" :clear-icon="false" v-model="form.p_date" v-if="mode!='show'"/>
					<span v-else>{{form.p_date}}</span>
				</uni-forms-item>
				<uni-forms-item label="归口部门" required>
					<uni-easyinput v-model="form.p_dept" placeholder="请输入归口部门" v-if="mode!='show'"/>
					<span v-else>{{form.p_dept}}</span>
				</uni-forms-item>
				<uni-forms-item label="建设期" required>
					<uni-easyinput v-model="form.const" placeholder="请输入建设期" v-if="mode!='show'"/>
					<span v-else>{{form.const}}</span>
				</uni-forms-item>
				<uni-forms-item label="省级平台">
					<uni-data-checkbox v-model="form.province_p" :localdata="hobby" :disabled="mode=='show'"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="市级平台">
					<uni-data-checkbox v-model="form.city_p" :localdata="hobby" :disabled="mode=='show'"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="负责人" required>
					<uni-easyinput v-model="form.charge" placeholder="请输入负责人" v-if="mode!='show'"/>
					<span v-else>{{form.charge}}</span>
				</uni-forms-item>
				<uni-forms-item label="平台基本情况与目标绩效" label-width="750" required>
				</uni-forms-item>
				<uni-forms-item label-width="100">
					<textarea v-model="form.condition"  v-if="mode!='show'" placeholder-style="color:#efefef" placeholder="平台基本情况与目标绩效" class="form-textarea"/>
					<span v-else>{{form.condition}}</span>
				</uni-forms-item>
				</view>
			</uni-forms>
		</scroll-view>
		<view class="footer_fixed">
			<ticketd_b :workflow_key="'wf_plat'" :title="form.name + '-平台申请'" :t_id="form.id" :ticket_="form.ticket_"
				@success="submitSuccess" :submit_b_func="submit_b_func" ref="ticketd_b_start"></ticketd_b>
		</view>
	</view>
</template>

<script>
import ticketd_b from "../wf/ticketd_b.vue"
import ticketd from "../wf/ticketd.vue"
import {actStateEnum} from "@/utils/enum.js"
	export default {
		components: { ticketd_b, ticketd },
		data(){
			return{
				mode:"add",
				t_id: null,
				form:{
					name:"",
					p_date:"",
					condition:"",
					p_dept:"",
					const:"",
					charge:"",
					city_p:false,
					province_p:false,
				},
				type:0,
				hobby: [
					{text: '是',value:true},
					{text: '否',value: false},
				],
				deptList:[],
				header:"",
				customRules: {
					filename: {
						rules: [{
							required: true,
							errorMessage: '姓名不能为空'
						}]
					},
					age: {
						rules: [{
							required: true,
							errorMessage: '年龄不能为空'
						}]
					},
				},
			}
		},
		async onLoad(options) {
			let that = this;
			that.form.id='';
			that.mode = options.mode?options.mode:'show';
			that.t_id = options.t_id?options.t_id:null;
			if(that.mode != "add"){
				if(that.t_id) {
					that.form = await that.$api.pfItem(that.t_id);
					if(that.form.ticket_.state_.type == 1 && that.form.create_by == uni.getStorageSync("userInfo").id ) {
						that.mode = "edit";
					}else{
						that.mode = "show";
					}
				}else{
					that.getDept();
				}
			}
		},
		methods:{
			getDept(){
				
			},
			sealChange(){
				console.log('seal1',this.seal1)
			},
			async submit_b_func(id){
				let that = this;
				that.$refs.customForm.validate().then(res => {
					
				}).catch(err => {
					console.log('err', err);
				})
				if (that.mode != 'show') {
					if(that.form.id) {
						await that.$api.pfUpdate(that.form.id, that.form)
					}else{
						let res = await that.$api.pfCreate(that.form)
						that.form.id = res.id;
					}
				}
			},
			submitSuccess(){
				uni.navigateTo({
					url: "/pages/index/index"
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
.form-page { min-height: 100vh; background: #F0F2F5; }
.form-scroll { padding: 0; padding-bottom: 180rpx; }
.form-card { background: #fff; border-radius: 0; padding: 24rpx; margin-bottom: 0; box-shadow: none; }
.form-card-title { font-size: 30rpx; font-weight: 600; color: #1F2937; margin-bottom: 16rpx; padding-left: 16rpx; border-left: 6rpx solid #2BA471; }
.form-textarea { width: 100%; min-height: 160rpx; border: 2rpx solid #E5E7EB; border-radius: 12rpx; padding: 16rpx; font-size: 28rpx; color: #374151; box-sizing: border-box; background: #F9FAFB; }
.form-btn { flex: 1; height: 80rpx; line-height: 80rpx; border-radius: 14rpx !important; font-size: 28rpx; font-weight: 500; border: none !important; }
.form-btn-primary { background: linear-gradient(135deg, #2BA471, #1F8C5E) !important; color: #fff !important; box-shadow: 0 4rpx 12rpx rgba(43,164,113,0.2); }
.form-btn-danger { background: linear-gradient(135deg, #EF4444, #DC2626) !important; color: #fff !important; box-shadow: 0 4rpx 12rpx rgba(239,68,68,0.3); }
.uni-data-checklist .checklist-group .checklist-box{
	margin: 10px 0!important;
}
.flex_file_picker>.uni-file-picker__files{
	flex-direction: row;
}
.flex_file_picker{
	width: 90px;
	flex: none;
}
</style>