<template>
	<view style="padding: 20rpx;">
		<view style="padding: 30rpx;background-color: white;border-radius:50rpx">
			<u--form labelPosition="left" :model="formData" ref="uForm" labelWidth='120'>
				<u-form-item label="制衣生产车间:" prop="workshopInfo.zyProductWorkshop" borderBottom ref="uItem"
					:required="true">
					<u--input v-model="formData.workshopInfo.zyProductWorkshop" placeholder="请输入生产车间" border="none"></u--input>
				</u-form-item>
				<u-form-item label="启用:" prop="workshopInfo.status" borderBottom ref="uItem" v-show="adminType">
					<u-switch v-model="formData.workshopInfo.status"></u-switch>
				</u-form-item>
				<u-button type="primary" text="提交" customStyle="margin-top: 50px" @click="submit"></u-button>
				<u-button type="error" text="重置" customStyle="margin-top: 10px" @click="reset"></u-button>
			</u--form>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import {
		add
	} from '@/api/biz/workshop.js'
	import { getToken, setToken, removeToken,getAdminType,setAdminType,removeAdminType } from '@/utils/auth'
	export default {
		data() {
			return {
				formData: {
					workshopInfo: {
						zyProductWorkshop: '',
						// zyTeam: '',
						// orderNo: '',
						// deliveryDate: "",
						status: false
					}
				},
				deliveryDateShowFlag: false,
				rules: {
					'workshopInfo.zyProductWorkshop': {
						type: 'string',
						required: true,
						message: '请填写制衣生产车间',
						trigger: ['blur', 'change']
					}
					// 'workshopInfo.zyTeam': {
					// 	type: 'string',
					// 	required: true,
					// 	message: '请填写制衣班组',
					// 	trigger: ['blur', 'change']
					// },
					// 'workshopInfo.orderNo': {
					// 	type: 'string',
					// 	required: true,
					// 	message: '请填写订单号',
					// 	trigger: ['blur', 'change']
					// },
					// 'workshopInfo.deliveryDate': {
					// 	type: 'string',
					// 	required: true,
					// 	message: '请填写交期',
					// 	trigger: ['blur', 'change']
					// }
				},
				adminType:false
			}
		},
		onLoad() {
			
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules)
			this.adminType = this.$store.state.user.adminType
			console.log(getAdminType())
		},
		methods: {
			confirm(e) {
				console.log(e);
				this.deliveryDateShowFlag = false
				this.formData.workshopInfo.deliveryDate = e[0]
			},
			submit() {
				this.$refs.uForm.validate().then(val => {
					add(this.formData.workshopInfo).then(res => {
						if (res.success) {
							this.$refs.uToast.show({
								type: 'success',
								message: "新增成功",
								iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
							})
							this.reset()
						} else {
							this.$refs.uToast.show({
								type: 'error',
								message: res.message,
								iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
							})
						}
					})
				})
			},
			reset() {
				this.formData = {
					workshopInfo: {
						zyProductWorkshop: '',
						// zyTeam: '',
						// orderNo: '',
						// deliveryDate: "",
						// status: true
					}
				}
				this.$refs.uForm.clearValidate()
			}
		},
		onUnload() {
			uni.$emit('loadData');
		}
	}
</script>

<style>
</style>
