<template>
	<view>
		<uni-forms ref="form" :modelValue="formData" :rules="rules">
			<uni-row>
				<uni-col :span="24">
					<uni-forms-item label="套装编码" :labelWidth='80' name="suitCode">
						<uni-easyinput suffixIcon="scan" @iconClick="scanBar" type="text" v-model="formData.suitCode" />
					</uni-forms-item>
				</uni-col>
				<uni-col :span="24">
					<uni-forms-item label="套装名称" :labelWidth='80' name="suitName">
						<uni-easyinput type="text" v-model="formData.suitName" />
					</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 {
		listMesProductSuit,
		getMesProductSuit,
		delMesProductSuit,
		addMesProductSuit,
		updateMesProductSuit
	} from "@/api/mes/productSuit";
	export default {

		data() {
			return {
				formData: {
					suitCode: null,
					suitName: null,
					remark: null,
					type: null,
					status: 0,
					createBy: null,
					createTime: null,
					updateBy: null,
					updateTime: null,
					delStatus: "0"
				},
				rules: {
					suitCode: {
						rules: [{
							required: true,
							errorMessage: '请输入套装编码!'
						}]
					},
					suitName: {
						rules: [{
							required: true,
							errorMessage: '请输入套装名称!'
						}]
					}
				},
			}
		},
		methods: {
			submit() {
				const _this = this;
				_this.$refs.form.validate().then(res => {
					uni.showModal({
						title: '提示',
						content: '您确定添加该套装吗？',
						success: function(res) {
							if (res.confirm) {
								// cons
								_this.$modal.loading('提交中')
								addMesProductSuit(_this.formData).then(res => {
									_this.$modal.closeLoading();
									_this.$modal.msgSuccess("添加套装成功！");
									setTimeout(() => {
										_this.$tab.switchTab("/pages/work/index");
									}, 500);
								})
							}
						}
					})
				});
			},
			scanBar() {
				const _this = this;
				uni.scanCode({
					scanType: ['barCode', 'qrCode'],
					success: function(res) {
						_this.formData.suitCode = res.result;
					}
				});
			}
		}
	}
</script>