<template>
	<view>
		<uni-collapse>
			<uni-forms ref="form" :modelValue="formData">
				<uni-forms-item label="设备编码" :labelWidth='90' name="equipmentCode">
					<uni-easyinput v-model="formData.equipmentCode" suffixIcon="scan" @iconClick="scanBarEquipmentCode"
						@confirm="confirmEquipmentCode" type="text" />
				</uni-forms-item>
				<uni-collapse-item title="查询结果" :open="true">
					<uni-card :is-shadow="false" v-for="(item,index) in useRecordList" :key="index" is-full>
						<view><strong>模具编码</strong> : {{item.mouldUuid}}</view>
						<view><strong>模具名称</strong> : {{item.mouldName}}</view>
						<view><strong>设备编码</strong> : {{item.equipmentCode}}</view>
						<view><strong>设备名称</strong> : {{item.equipmentTitle}}</view>
						<view><strong>上机时间</strong> : {{item.installTime}}</view>
						<view><strong>下机时间</strong> : {{item.removeTime}}</view>
						<view><strong>安装员编码</strong> : {{item.installBy}}</view>
						<view><strong>安装员</strong> : {{item.installByName}}</view>
						<view><strong>拆卸员编码</strong> : {{item.removeBy}}</view>
						<view><strong>拆卸员</strong> : {{item.removeByName}}</view>
						<view><strong>操作员编码</strong> : {{item.operator}}</view>
						<view><strong>操作员</strong> : {{item.operatorName}}</view>
						<view><strong>创建人</strong> : {{item.createBy}}</view>
						<view><strong>创建时间</strong> : {{item.createTime}}</view>
						<view><strong>修改人</strong> : {{item.updateBy}}</view>
						<view><strong>修改时间</strong> : {{item.updateTime}}</view>
						<view><strong>备注</strong> : {{item.remark}}</view>
					</uni-card>
				</uni-collapse-item>
			</uni-forms>
		</uni-collapse>
	</view>
</template>

<script>
	import {
		listUseRecord,
		getUseRecord,
		delUseRecord,
		addUseRecord,
		updateUseRecord,
		bindMould,
		unbindMould,
	} from "@/api/tpmMould/useRecord";
	export default {
		mounted() {},
		data() {
			return {
				formData: {
					equipmentCode: null
				},
				useRecordList: [],
			}
		},
		methods: {
			scanBarEquipmentCode(code) {
				const _this = this;
				uni.scanCode({
					scanType: ['barCode', 'qrCode'],
					success: function(res) {
						_this.formData.equipmentCode = res.result;
						_this.confirmEquipmentCode()
					}
				});
			},
			confirmEquipmentCode() {
				if (this.formData.equipmentCode) {
					listUseRecord({
						equipmentCode: this.formData.equipmentCode
					}).then(res => {
						if (res.rows.length > 0) {
							this.useRecordList = res.rows;
						} else {
							this.$modal.msg("未查询到该设备上模相关信息，请重新输入！")
							this.formData.equipmentCode = null;
						}
					})
				}
			}
		}
	}
</script>

<style>
	.text {
		text-align: center;
	}
</style>