checkItem.vue 3.26 KB
<template>
	<view class="margin-top">
		<u-grid col="2">
			<u-grid-item v-for="(item,index) in checkList" :key="index" @click="clickItem(item,index)">
				<view class="cardItemCss">
					<view class="">
						{{item.title}}
					</view>
					<view class="flex">
						<u-icon color="#EE2F24" :name="calcSfhg(item)"></u-icon>
						<!-- close-circle-fill -->
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
			</u-grid-item>
		</u-grid>
	</view>
</template>

<script>
	import ajJson from '@/static/aj.json'
	export default {
		name: "checkItem",
		components: {},
		props: {
			rhaj: {
				type: Object,
				default: () => {}
			},
		},
		data() {
			return {
				checkList: ajJson,
				// rhaj:{
				// 	lq:{},
				// 	syhj:{},
				// 	syxw:{},
				// 	rsqsnaz:{},
				// 	pgzf:{},
				// 	rqpxlbjzz:{}
				// }
			}
		},
		watch: {},
		computed: {

		},
		mounted() {
			// console.log('打印ajJson',JSON.parse(JSON.stringify(ajJson)));
		},
		methods: {
			calcSfhg(item) {
				let  key = item.key;
				let sflq = key === 'lq'; //是否漏气
				let sfbjOrRsq = key === 'rsqsnaz' || key === 'rqpxlbjzz' //是否报警或热水器
				// 如果为漏气选择是为不合格
				if (sflq && this.rhaj[key][0].jcjg === '是') {
					return '/static/images/home/fengxiang.png'
				}
				// 如果非漏气第一个选择为否为不合格
				if (!sflq && this.rhaj[key][0].jcjg === '否') {
					// console.log("不合格2");
					return '/static/images/home/fengxiang.png';
				}
				// 如果是漏气选择是为合格,如果非漏气且(非报警和热水器)第一个选择为是为合格
				if ((sflq && this.rhaj[key][0].jcjg === '否') || (!sflq && !sfbjOrRsq && this.rhaj[key][0].jcjg === '是')) {
					// console.log("合格3");
					return '/static/images/home/hege.png';
				}
				// 如果是(非报警和热水器),第一个选择和第二个选择都为是为合格
				if (sfbjOrRsq && this.rhaj[key][0].jcjg === '是' && this.rhaj[key][1]?.jcjg === '是') {
					return '/static/images/home/hege.png';
				}
				// 否则返回不合格
				return '/static/images/home/fengxiang.png';
			},
			clickItem(item, index) {
				// console.log("当前item",item);
				for (let i in this.rhaj) {
					if (item.key === i) {
						// console.log("1、安检项目", this.rhaj[i]);
						if (i === "rqpxlbjzz" || i === 'rsqsnaz') {
							this.rhaj[i].map((aj, aix) => {
								if (aix === 0) {
									item.radioOne = this.rhaj[i][aix].jcjg;
								} else if (aix === 1) {
									item.radioTwo = this.rhaj[i][aix].jcjg;
								} else {
									item.checkboxValue.push(this.rhaj[i][aix].bt);
								}
							})
						} else {
							this.rhaj[i].map((aj, aix) => {
								if (aix === 0) {
									item.radioOne = this.rhaj[i][aix].jcjg;
								} else {
									item.checkboxValue.push(this.rhaj[i][aix].bt)
								}
							})
						}
					}
				}
				item.ifhx = true;
				console.log('item', JSON.parse(JSON.stringify(item)));
				uni.$emit('chekItemData', item);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cardItemCss {
		display: flex;
		padding: 0 6px 0 6px;
		justify-content: space-between;
		align-items: center;
		background: #fff;
		border-radius: 10px;
		margin: 5px 0;
		width: calc(100% - 5px);
		height: 44px;
		border: 1px solid #f6f6f6 !important;
	}
</style>