<!-- 专利申请 -->
<template>
	<view class="container">
		<scroll-view scroll-y style="padding-bottom: 180rpx;background-color: #fff;">
			<uni-forms v-model="form" label-width="150rpx"  ref="customForm" :rules="customRules">
				<ticketd :ticket_="form.ticket_"></ticketd>
				<uni-forms-item label="专利名称" required name="filename">
					<uni-easyinput v-model="form.filename" placeholder="请输入专利名称" :disabled="mode=='show'"/>
				</uni-forms-item>
				<uni-forms-item label="发明人" required>
					<uni-easyinput v-model="form.filename" placeholder="请输入发明人" :disabled="mode=='show'"/>
				</uni-forms-item>
				<uni-forms-item label="专利类型">
					<uni-data-checkbox multiple v-model="form.seal" :localdata="hobby" @change="sealTypeChange"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="提前公开">
					<uni-data-checkbox multiple v-model="form.seal" :localdata="hobby2" @change="sealTypeChange"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="申请地域">
					<uni-data-checkbox multiple v-model="form.seal" :localdata="hobby3" @change="sealTypeChange"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="" v-if="(form.seal || '').includes('PCT申请')">
					<uni-easyinput v-model="form.seal_other" placeholder="请输入拟申请的国家" :disabled="mode=='show'"/>
				</uni-forms-item>
				<uni-forms-item label="技术状态">
					<uni-data-checkbox multiple v-model="form.seal" :localdata="hobby4" @change="sealTypeChange"></uni-data-checkbox>
					<template style="display: flex;flex-direction: column;">
						<uni-file-picker v-for="(item,index) in hobby4" v-model="form.file" limit="1" return-type="object" file-mediatype="all" @select="fileSelect" @success="fileSuccess"></uni-file-picker>
					</template>
				</uni-forms-item>
				<uni-forms-item label="技术文件">
					<uni-data-checkbox multiple v-model="form.seal" :localdata="hobby5" @change="sealTypeChange"></uni-data-checkbox>
					<template style="display: flex;flex-direction: column;">
						<uni-number-box v-for="(item,index) in hobby5" v-model="form.file_count" :key="item" :disabled="mode=='show'"></uni-number-box>
					</template>
				</uni-forms-item>
			</uni-forms>
		</scroll-view>
		<view class="footer_fixed">
			<ticketd_b :workflow_key="'seal'" :title="form.filename + '-印章申请'" :t_id="form.id" :ticket_="form.ticket_"
				@success="()=>{uni.navigateBack()} " :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:{
					id:null,
					file:"",
					filename:"",
					file_count:"",
					is_lending:false,
					contacts:"",
					belong_dept:"",
					ticket_:null,
				},
				type:0,
				hobby: [
					{text: '发明专利',value:  '发明专利'},
					{text: '实用新型专利',value: '实用新型专利'}, 
					{text: '外观设计专利',value: '外观设计专利'},
				],
				hobby2:[
					{text: '是',value: true},
					{text: '否',value: false},
				],
				hobby3: [
					{text: '国内申请',value: '国内申请'},
					{text: '国外申请',value: '国外申请'}, 
					{text: 'PCT申请',value: 'PCT申请'},
				],
				hobby4: [
					{text: '是否进行过科技成果鉴定',value: '是否进行过科技成果鉴定'},
					{text: '是否发表过文章',value: '是否发表过文章'}, 
					{text: '是否参与过展会展出',value: '是否参与过展会展出'},
					{text: '是否参与应用于生产/销售',value: '是否参与应用于生产/销售'},
					{text: '是否参与过技术交流',value: '是否参与过技术交流'}, 
					//以上项目选中的，应附详细信息
				],
				hobby5: [
					// 发明专利、实用新型专利申请提供：
					{text: '技术背景材料',value: ' 技术背景材料'},
					{text: '技术交底材料',value: '技术交底材料'}, 
					{text: '查新检索报告',value: '查新检索报告'},
					//外观设计专利申请提供：
					{text: '图或者照片',value: '图或者照片'}, 
				],
				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.sealItem(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.form = uni.getStorageSync("currentBooking");
				}
			}
		},
		methods:{
			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.patentUpdate(that.form.id, that.form)
					}else{
						let res = await that.$api.patentCreate(that.form)
						that.form.id = res.id;
					}
				}
			},
		}
	}
</script>

<style scoped>
	.uni-data-checklist .checklist-group .checklist-box{
		margin: 10px 0!important;
	}
</style>