<template>
	<view>
		<uni-forms ref="form" :modelValue="formData" :rules="rules">
			<uni-row>
				<uni-col :span="24">
					<uni-forms-item label="共模作业组编码" :labelWidth='80' name="shareMouldJobGroupCode">
						<uni-easyinput suffixIcon="scan" @iconClick="scanBar1" type="text"
							v-model="formData.shareMouldJobGroupCode" />
					</uni-forms-item>
				</uni-col>
				<uni-col :span="24">
					<uni-forms-item label="共模组编码" :labelWidth='80' name="shareMouldGroupCode">
						<uni-easyinput type="text" suffixIcon="scan" @iconClick="scanBar2"
							v-model="formData.shareMouldGroupCode" />
					</uni-forms-item>
				</uni-col>
				<uni-col :span="24">
					<uni-forms-item label="模具编码" :labelWidth='80' name="mouldUuid">
						<uni-easyinput type="text" v-model="formData.mouldUuid" @focus="show=!show" />
						<u-picker :show="show" @cancel="showClose" @close="showClose" closeOnClickOverlay
							:columns="mouldUuidList" @confirm="showConfirm" keyName="label">
						</u-picker>
					</uni-forms-item>
				</uni-col>
				<uni-col :span="24">
					<uni-forms-item label="备注" :labelWidth='80' name="remark">
						<uni-easyinput type="textarea" v-model="formData.remark" />
					</uni-forms-item>
				</uni-col>
			</uni-row>
		</uni-forms>
		<u-button type="primary" @click="submit">提交</u-button>
	</view>
</template>

<script>
	import {
		listMesMouldShareGroup,
		getMesMouldShareGroup,
		delMesMouldShareGroup,
		addMesMouldShareGroup,
		updateMesMouldShareGroup,
		listMould
	} from "@/api/mes/mouldShareGroup";
	export default {

		data() {
			return {
				mouldUuidList: [],
				show: false,
				formData: {
					shareMouldJobGroupCode: null,
					shareMouldGroupCode: null,
					mouldUuid: null,
					mouldCode: null,
					remark: null,
					type: null,
					status: 0,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					delStatus: "0"
				},
				rules: {
					shareMouldJobGroupCode: {
						rules: [{
							required: true,
							errorMessage: '请输入共模作业组编码!'
						}]
					},
					// shareMouldGroupCode: {
					// 	rules: [{
					// 		required: true,
					// 		errorMessage: '请输入共模组编码!'
					// 	}]
					// }
				},
			}
		},
		mounted() {
			listMould().then(res => {
				this.mouldUuidList.push(res.rows.map(item => {
					item.label = item.mouldUuid + ':' + item.mouldName;
					return item
				}))
			})
		},
		methods: {
			showConfirm(e) {
				console.log(e)
				this.formData.mouldCode = e.value[0].mouldCode;
				this.formData.mouldUuid = e.value[0].mouldUuid;
				this.show = false
			},
			showClose() {
				this.show = false
			},
			submit() {
				const _this = this;
				_this.$refs.form.validate().then(res => {
					uni.showModal({
						title: '提示',
						content: '您确定添加该共模作业组吗？',
						success: function(res) {
							if (res.confirm) {
								_this.$modal.loading('提交中')
								addMesMouldShareGroup(_this.formData).then(res => {
									_this.$modal.closeLoading();
									_this.$modal.msgSuccess("添加共模作业组成功！");
									setTimeout(() => {
										_this.$tab.switchTab("/pages/work/index");
									}, 500);
								})
							}
						}
					})
				});
			},
			scanBar1() {
				const _this = this;
				uni.scanCode({
					scanType: ['barCode', 'qrCode'],
					success: function(res) {
						_this.formData.shareMouldJobGroupCode = res.result;
					}
				});
			},
			scanBar2() {
				const _this = this;
				uni.scanCode({
					scanType: ['barCode', 'qrCode'],
					success: function(res) {
						_this.formData.shareMouldGroupCode = res.result;
					}
				});
			}
		}
	}
</script>