<template>
	<view style="padding: 20rpx;">
		<view style="padding: 30rpx;background-color: white;border-radius:50rpx">
			<u--form labelPosition="left" :model="teamInfo" ref="uForm" labelWidth='120'>
				<u-form-item label="制衣生产车间:" prop="workshop.zyProductWorkshop" borderBottom @click="showWorkshop = true;" :required="true" ref="uItem">
				<u--input v-model="teamInfo.workshop.zyProductWorkshop" disabled disabledColor="#ffffff" placeholder="请选择生产车间" border="none"></u--input>
					<u-icon slot="right" name="arrow-right"></u-icon>
				</u-form-item>
				<u-action-sheet :show="showWorkshop" :actions="options" title="请选择车间" @close="showWorkshop = false"
					@select="workshopSelect" />
				<u-form-item label="制衣班组:" prop="zyTeam" borderBottom ref="uItem" :required="true">
					<u--input v-model="teamInfo.zyTeam" border="none" placeholder="请输入班组"></u--input>
				</u-form-item>
				<u-form-item label="启用:" prop="status" borderBottom ref="uItem" v-show="adminType">
					<u-switch v-model="teamInfo.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 {
		edit,workshopData
	} from '@/api/biz/team.js'
	export default {
		data() {
			return {
				teamInfo: {
					workshop:{}
				},
				options: [],
				deliveryDateShowFlag: false,
				rules: {
					'workshop.zyProductWorkshop': {
						type: 'string',
						required: true,
						message: '请填写制衣生产车间',
						trigger: ['blur', 'change']
					},
					'zyTeam': {
						type: 'string',
						required: true,
						message: '请填写制衣班组',
						trigger: ['blur', 'change']
					}
				},
				showWorkshop:false,
				adminType: false
			}
		},
		onLoad(option) {
			const teamInfo = JSON.parse(decodeURIComponent(option.teamInfo))
			// this.teamInfo = teamInfo
			this.teamInfo = teamInfo
			this.getWorkshop()
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules)
		},
		methods: {
			getWorkshop() {
				workshopData().then(res => {
					if (res.success) {
						for (let i in res.data) {
							// console.log(res.data[i]['id'])
							// console.log(res.data[i]['zyProductWorkshop'])
						    let o = {
						        value: res.data[i]['id'], name: res.data[i]['zyProductWorkshop']
						    };
			
						    this.options.push(o)
						}
					} else {}
				})
			},
			confirm(e) {
				console.log(e);
				this.deliveryDateShowFlag = false
				this.orderInfo.deliveryDate = e[0]
			},
			workshopSelect(e) {
				console.log(e)
				this.teamInfo.workshop.zyProductWorkshop = e.name
				this.teamInfo.workshopId = e.value
				// this.teamInfo.workshopId = e.value
			},
			submit() {
				this.$refs.uForm.validate().then(val => {
					console.log(this.teamInfo)
					edit(this.teamInfo).then(res => {
						console.log(res)
						if (res.success) {
							this.$refs.uToast.show({
								type: 'success',
								message: "新增成功",
								iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
							})
							uni.$emit('loadData');
							uni.navigateBack(1);
						} else {
							this.$refs.uToast.show({
								type: 'error',
								message: res.message,
								iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
							})
						}
					})
				})
			},
			reset() {
			this.teamInfo = {
					zyProductWorkshop: '',
					zyTeam: '',
					status: false
			};
			}
		}
	}
</script>

<style>
</style>
