<template>
	<view>
		<view class="body">
			<input class="input" style="display:none;" name="code" :value=code />
			编码：<input class="input" v-model="code" />
			<button type="primary" @click="saoma()" class="button1">
				<p class="p">扫码</p>
			</button>
			<button type="primary" @click="getMessage(code)" class="button1">
				<p class="p">获取</p>
			</button>
		</view>

		<view class="">
			<t-table>
				<t-tr class="tr">
					机器编码：{{coding}}
				</t-tr>
				<t-tr class="tr">
					机器铭牌：{{nameplate}}
				</t-tr>
				<t-tr class="tr">
					设备编码：{{clientId}}
				</t-tr>
				<t-tr class="tr">
					机器名称：{{name}}
				</t-tr>
				<t-tr class="tr">
					总装开始时间：{{startDate}}
				</t-tr>
				<t-tr class="tr">
					总装结束时间：{{endDate}}
				</t-tr>
			</t-table>
		</view>
		<view class="">

			<view v-for="(item,index) in modulesList" :key="index">
				<t-table class="table">
					<t-tr class="tr table">
						名称：{{item.name}}
					</t-tr>
					<t-tr class="tr">
						<t-td>编码：{{item.coding}}</t-td>
						<t-td class="td">
							<button type="primary" @click="tran(item.coding)" class="button1">
								<p class="p">详情</p>
							</button>
						</t-td>
					</t-tr>
				</t-table>
			</view>


		</view>

	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				code: '',
				coding: '',
				nameplate: '',
				name: '',
				startDate: '',
				clientId: '',
				endDate: '',
				modulesList: []
			}
		},
		onShow() {
			
		},
		methods: {
			saoma() {
				var that = this;
				// 允许从相机和相册扫码
				uni.scanCode({
					success(res) {
						that.code = res.result;
					}
				});
			},

			getMessage(coding) {
				var that = this;
				var serverUrl = that.serverurl;
				var token = uni.getStorageSync("token");
				uni.request({
					url: serverUrl + "/TMachine/selectMachine?coding=" + coding,
					method: "GET",
					header: {
						'token': token
					},
					success: (Result) => {
						// console.log(Result);
						var res = Result;
						if (res.data.code == true) {
							//当机器已录入时，会先把所有录入模块给列出来
							if (res.data.message == 'all') {
								var tmachine = res.data.data.tmachine;
								that.name = tmachine.name;
								that.nameplate = tmachine.nameplate;
								that.clientId = tmachine.clientId;
								that.coding = tmachine.coding;
								that.startDate = tmachine.startDate;
								that.endDate = tmachine.endDate;
								that.modulesList = res.data.data.modulesList;
							} else {
								var codes = res.data.data;
								that.name = codes.name;
								that.nameplate = codes.nameplate;
								that.clientId = tmachine.clientId;
								that.producePersonnel = uni.getStorageSync("name");
							}

						} else {
							uni.showModal({
								title: '提示',
								content: res.data.message,
							});
						}
					}
				});
			},
			tran(coding) {
				uni.setStorageSync("selectCoding", coding);
				uni.navigateTo({
					url: 'selectModules',
				});
			}
		}
	}
</script>

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

	.table {
		padding-top: 30upx;

	}

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

	.td {
		padding-left: 280upx;

	}

	.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;
		text-align: right
	}

	.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>
