<template>
	<view>
		<view>
			<uni-easyinput suffixIcon="scan" placeholder="请输入设备编码" @iconClick="scanBar"
				v-model="queryParams.equipmentCode" type="text" @confirm="scanBarCode" />
			<button type="primary" size="mini" @click="reset"
				style="margin-top: 5px;text-align: center;display: block;width: 30%;">重置</button>
			<view class="cu-card article ">
				<view class="cu-item shadow borderBottom" v-for="(item,index) in list" :key="index">
					<view class="title">
						<view class="text-cut">故障号 : {{item.breakdownCode}}</view>
						<view>
							<button type="primary" size="mini" @click="detail(item)" style="float: right;">查看明细</button>
						</view>
					</view>
					<view class="content">
						<view class="desc">
							<view class="text-content">
								<view>故障名 : {{item.breakdownName}}</view>
								<view>任务名 : {{item.taskName}}</view>
								<view>设备编码 : {{item.equipmentCode}}</view>
								<view>故障类型 : {{item.type}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		listBreakdown,
		getBreakdown
	} from "@/api/tpm/index.js";

	export default {
		mounted() {
			this.getList()
		},
		data() {
			return {
				list: {},
				queryParams: {
					equipmentCode: null,
				},
				formData: {},
				rightOptions: [{
					text: '删除',
					style: {
						backgroundColor: '#ff2a17'
					}
				}, ],
			}
		},
		methods: {
			getList() {
				listBreakdown(this.queryParams).then(response => {
					this.list = response.rows;
				});
			},
			reset() {
				this.queryParams.equipmentCode = null;
				this.getList();
			},
			scanBarCode() {
				if (this.queryParams.equipmentCode) {
					this.getList();
				}
			},
			scanBar() {
				const _this = this;
				uni.scanCode({
					scanType: ['qrCode', 'barCode'],
					success: function(res) {
						_this.queryParams.equipmentCode = res.result;
						_this.scanBarCode();
					}
				});
			},
			detail(item) {
				getBreakdown(item.id).then(async res => {
					this.$tab.navigateTo('/pages/tpm/repairTaskItem?formData=' + JSON.stringify(res.data));
				})
			},
		}
	}
</script>

<style>
</style>