<template>
	<view>
		<form @submit="add">
			<view class="body">
				<input class="input" style="display:none;" name="coding" :value=coding />
				编码：<input class="input" v-model="coding" />
				<button type="primary" @click="saoma()" class="button1">
					<p class="p">扫码</p>
				</button>
				<button type="primary" @click="getMessage(coding)" class="button1">
					<p class="p">获取</p>
				</button>
			</view>
			<view class="body">
				名称：<input class="input" name="name" :value="name" />
			</view>
			<view class="body">
				版本号：<input class="input" name="versions" :value="versions" />
			</view>
			<view class="body">
				生产人员：<input class="input" name="producePersonnel" :value="producePersonnel" readonly="readonly" />
			</view>
			<timeSelector showType="date" @btnConfirm="btnConfirm0" @btnCancel="btnCancel0">
				<view class="body">
					<!-- 生产日期：<input type="text" class="input" name="produceDate" :value="produceDate"  /> -->
					生产日期：<view class="input">{{ produceDate }}</view>
				</view>
			</timeSelector>
			<view class="title">配件</view>
			<view class="lis" v-for="item in desList">
				{{item}}
			</view>

			<view class="">
				<button type="primary" formType="submit" class="button">
					<p class="p1">提交</p>
				</button>
			</view>
		</form>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from 'vuex';
	import timeSelector from '@/components/wing-time-selector/wing-time-selector.vue';
	export default {
		components: {
			timeSelector
		},
		data() {
			return {
				produceDate: '',
				coding: null,
				name: null,
				versions: null,
				producePersonnel: null,
				desList: {}
			}
		},
		methods: {
			btnConfirm0(e) {
				// console.log('确定时间为：', e);
				this.produceDate = e.key;
			},
			btnCancel0() {
				this.produceDate = '';
			},
			saoma() {
				var that = this;
				// 允许从相机和相册扫码
				uni.scanCode({
					success(res) {
						// console.log('条码类型：' + res.scanType);
						// console.log('条码内容：' + res.result);
						that.coding = res.result;
					}
				});
			},
			getMessage(coding) {
				console.log("a");
				var that = this;
				var serverUrl = that.serverurl;
				var token = uni.getStorageSync("token");
				uni.request({
					url: serverUrl + "/TModules/getMessage?coding=" + coding,
					method: "GET",
					header: {
						'token': token
					},
					success: (Result) => {
						var res = Result;
						if (res.data.code == true) {
							var codes = res.data.data;
							that.name = codes.name;
							that.versions = codes.versions
							that.produceDate = codes.createDate;
							that.producePersonnel = uni.getStorageSync("name");
							that.desList = codes.flagCode.split(",");
						} else {
							uni.showModal({
								content: res.data.message,
							});
						}
					}
				});
			},
			add(event) {
				var serverUrl = this.serverurl;
				const {
					value: modules
				} = event.detail;
				var token = uni.getStorageSync("token");
				uni.request({
					url: serverUrl + "/TModules/add",
					method: "POST",
					data: {
						"coding": modules.coding,
						"name": modules.name,
						"producePersonnel": modules.producePersonnel
					},
					header: {
						'token': token
					},
					success: (Result) => {
						var res = Result;
						if (res.data.code == true) {

						}

						uni.showModal({
							title: '提示',
							content: res.data.message,
						});
					}
				});


			},
		}
	}
</script>

<style>
	.body {
		background-color: #FFFFFF;
		padding: 20upx 20upx 20upx 20upx;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
	}

	.input {
		/* padding: 10upx 20upx 10upx 0upx; */
		padding: 0 10upx;
		/* padding-top: 10upx; */
		background-color: #FFFFFF;
		width: 350upx;
		height: 50upx;
		box-shadow: 0upx 0upx 20upx #D3D3D3;
		border-radius: 5upx;
	}

	.button {
		margin: auto;
		width: 60%;
		height: 100upx;
	}

	.button1 {
		margin: auto;
		width: 90upx;
		height: 50upx;
	}

	.p {
		/* #ifdef H5 */
		top: -13%;
		/* #endif */
		width: 50upx;
		height: 30upx;
		font-size: 25upx;
		padding-right: 9upx;
		padding-top: 6upx;
		/* #ifndef H5 */
		/* padding-top: 10upx; */
		/* #endif */

		position: absolute;
		/* 水平居中 */
		left: 50%;
		-webkit-transform: translateX(-50%);
		transform: translateX(-50%);
	}

	.p1 {
		/* #ifdef H5 */
		top: -13%;
		/* #endif */
		width: 80upx;
		height: 60upx;
		font-size: 40upx;
		padding-top: 6upx;
		/* #ifndef H5 */
		padding-top: 10upx;
		/* #endif */

		position: absolute;
		/* 水平居中 */
		left: 50%;
		-webkit-transform: translateX(-50%);
		transform: translateX(-50%);
	}

	.radio {
		padding-top: 20upx;
		padding-left: 30upx;
	}

	.lis {
		padding-left: 90upx;
		font-size: 30upx;
		padding-top: 5upx;
	}

	.title {
		padding-left: 20upx;
		font-size: 35upx;
	}
</style>