<!-- 供应商 -->
<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>
					<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-easyinput v-model="form.material_cate" placeholder="请输入物料分类" v-if="mode!='show'"/>
					<span v-else>{{form.material_cate}}</span>
				</uni-forms-item>
				<uni-forms-item label="物料名称" required>
					<uni-easyinput v-model="form.material_name" placeholder="请输入物料名称" v-if="mode!='show'"/>
					<span v-else>{{form.material_name}}</span>
				</uni-forms-item>
				<uni-forms-item label="调查表">
					<xtUpload v-model="form.survery_form" v-model:obj="form.survery_form_" xtype="id" v-if="mode!='show'"></xtUpload>
					<view v-else>
						<filePreview v-if="form.survery_form_" :url="form.survery_form_.file" :name="form.survery_form_.name" style="width: 100%;height: 30upx;"></filePreview>
						<text v-else>无</text>
					</view>
					
				</uni-forms-item>
				<uni-forms-item label="营业执照">
					<xtUpload v-model="form.business_license" v-model:obj="form.business_license_" xtype="id" v-if="mode!='show'"></xtUpload>
					<filePreview v-if="mode=='show'&&form.business_license_" :url="form.business_license_.file" :name="form.business_license_.name" style="width: 100%;height: 30upx;"></filePreview>
				</uni-forms-item>
				<uni-forms-item label="质量证书">
					<xtUpload v-model="form.quality_certificate" v-model:obj="form.quality_certificate_" xtype="id" v-if="mode!='show'"></xtUpload>
					<filePreview v-if="mode=='show'&&form.quality_certificate_" :url="form.quality_certificate_.file" :name="form.quality_certificate_.name" style="width: 100%;height: 30upx;"></filePreview>
				</uni-forms-item>
			</uni-forms>
		</scroll-view>
		<view class="footer_fixed">
			<ticketd_b :workflow_key="'wf_supplieraudit'" :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"
import xtUpload from "@/components/xtUpload.vue"
import filePreview from "@/components/filePreview.vue"
	export default {
		components: { ticketd_b, ticketd, xtUpload,filePreview },
		data(){
			return{
				saveLoading: false,
				mode:"add",
				t_id: null,
				form:{
					name:"",
					material_cate:"",
					material_name:"",
					survery_form:"",
					business_license:"",
					quality_certificate:"",
				},
				userInfo:{},
				survery_form:{},
				business_license:{},
				quality_certificate:{},
				type:0,
				header:"",
				customRules: {
					filename: {
						rules: [{
							required: true,
							errorMessage: '姓名不能为空'
						}]
					},
					age: {
						rules: [{
							required: true,
							errorMessage: '年龄不能为空'
						}]
					},
				},
			}
		},
		async onLoad(options) {
			let that = this;
			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.supplierauditItem(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";
					}
				}
			}
		},
		methods:{
			async submit_b_func(id){
				let that = this;
				if (that.mode != 'show') {
					if(that.form.id) {
						await that.$api.supplierauditUpdate(that.form.id, that.form);
					}else{
						let res = await that.$api.supplierauditCreate(that.form);
						that.form.id = res.id;
					}
				}
			},
			submitSuccess(){
				uni.navigateTo({
					url: "/pages/index/index"
				})
			},
		}
	}
</script>

<style scoped>
	.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>