<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="">
				<t-table>
					<t-tr class="tr">
						名称：{{name}}
					</t-tr>
					<t-tr class="tr">
						所属机器编码：{{machineCoding}}
					</t-tr>
					<t-tr class="tr">
						版本号：{{versions}}
					</t-tr>
					<t-tr class="tr">
						生产人员：{{producePersonnel}}
					</t-tr>
					<t-tr class="tr">
						生产日期：{{produceDate}}
					</t-tr>
					<view class="" v-if="installPersonnel!=''&&installPersonnel!=null">
						<t-tr class="tr">
							装配人员：{{installPersonnel}}
						</t-tr>
						<t-tr class="tr">
							装配日期：{{installDate}}
						</t-tr>
					</view>
					<view class="" v-if="replacePersonnel!=''&&replacePersonnel!=null">
						<t-tr class="tr">
							更换人员：{{replacePersonnel}}
						</t-tr>
						<t-tr class="tr">
							更换原因：{{replaceReason}}
						</t-tr>
						<t-tr class="tr">
							原模板编号：{{oldCoding}}
						</t-tr>
						<t-tr class="tr">
							更换日期：{{replateDate}}
						</t-tr>

					</view>
					<t-tr class="tr">
						状态：{{status}}
					</t-tr>
				</t-table>
			</view>
			<view class="title">配件</view>
<!-- 			<view class="lis" v-for="item in desList">
				{{item}}
			</view> -->
			<view class="lis" v-for="(item,index) in desList" :key="index">
				{{item}}
			</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 {
				oldCoding: '',
				replateDate: '',
				replaceReason: '',
				replacePersonnel: '',
				installDate: '',
				installPersonnel: '',
				produceDate: '',
				coding: '',
				name: '',
				versions: '',
				producePersonnel: '',
				machineCoding: '',
				status: '',
				desList: {}
			}
		},
		onShow() {
			var token = uni.getStorageSync("token");
			if (token.length > 2) {
				var coding = uni.getStorageSync("selectCoding");
				if (coding.length > 2) {
					this.coding = coding;
					this.getMessage(coding);
				}
			}

		},
		methods: {
			saoma() {
				var that = this;
				// 允许从相机和相册扫码
				uni.scanCode({
					success(res) {
						that.coding = res.result;
					}
				});
			},
			getMessage(coding) {
				var that = this;
				var serverUrl = that.serverurl;
				var token = uni.getStorageSync("token");
				uni.request({
					url: serverUrl + "/TModules/getModules?coding=" + coding,
					method: "GET",
					header: {
						'token': token
					},
					success: (Result) => {
						console.log("1");
						var res = Result;
						if (res.data.code == true) {
							var codes = res.data.data;
							that.name = codes.name;
							var co = codes.coding;
							if (co.substring(0, 4) != '1000') {
								that.versions = co.substring(8, 10);
								that.producePersonnel = codes.producePersonnel;
								that.produceDate = codes.createDate;
								var sta = codes.status;
								if (sta == '0') {
									that.status = "未安装";
								}
								if (sta == '1') {
									that.status = "已安装";
								}
								if (sta == '2') {
									that.status = "已替换";
								}
								that.machineCoding = codes.machineCoding;
							} else {
								that.versions = co.substring(co.length - 3, co.length);
								that.producePersonnel = "";
								that.produceDate = "";
								that.status = "";
								that.machineCoding = "";
							}
							
							if(codes.flagCode.length>1){
								that.desList = codes.flagCode.split(",");
							}
							that.installDate = codes.installDate;
							that.installPersonnel = codes.installPersonnel;
							that.replateDate = codes.replateDate;
							that.replaceReason = codes.replaceReason;
							that.replacePersonnel = codes.replacePersonnel;
							if (co.substring(0, 4) != '1000') {
								that.oldCoding = "";
							}else{
								that.oldCoding = "";
							}
							
						} else {
							uni.showModal({
								content: res.data.message,
							});
						}
					}
				});
			}
		}
	}
</script>

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

	.tr {
		padding-left: 30upx;
		padding-top: 13upx;
		font-size: 30upx;
		padding-bottom: 13upx;
	}

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

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

	.button1 {
		margin: auto;
		width: 75upx;
		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>
