<template>
	<view>		 
		<uni-list>
			<uni-list-item>
				<view slot="body" class="slot-box">
					<view class="row">
						<view class="column-left">当前检查项：</view>
						<view class="column-right section-title">{{listData.entity!=null?listData.entity.projectName:""}}</view>
					</view>
					</view>
			</uni-list-item>
		</uni-list>
		<uni-list>
			<uni-list-item v-for="(item, index) in listData.list" :key="index"  >
				<view slot="body" class="slot-box">
					<view class="row">
						<view class="column-left">编号：</view>
						<view class="column-right section-title">{{item.id}}</view>
					</view>
					<view class="row">
						<view class="column-left">材料名：</view>
						<view class="column-right">{{item.materialName}}</view>
					</view>
					<view class="row">
						<view class="column-left">单位：</view>
						<view class="column-right">{{item.unit}}</view>
					</view>
					 
					<view class="row">
						<view class="column-left">操作：</view>
						<view class="column-right"><a href="javascript:;" @click="deleteMaterial(item.id)"><i class="fa fa-times" aria-hidden="true"></i></a></view>
					</view>
				</view>
			</uni-list-item>
		</uni-list>
		<view style="bottom: 15px;right:10px;position: fixed;z-index: 50;">
			<router-link :to="'/pages/template/relationMaterialAdd/relationMaterialAdd?SafeQualityCheckCode=' + this.$util.getQuery('id')"   style="text-decoration: none;" title="材料添加">
				<uni-icons type="plus-filled" size="80" color="#F26C69"></uni-icons>
			</router-link>
		</view>
		<page-foot :isShow="true" :showIndex="2"></page-foot>
		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
		 
	</view>
</template>

<script>
	import {
		GetZRelationSafeQualityCheckMaterialDTOs,DeleteZRelationSafeQualityCheckMaterial
	} from "@/common/api/SafeQualityCheckApi.js";
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	

	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				listData: [],
				last_id: '',
				reload: false,
				status: 'more',
                
				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				}
			};
		},
		onLoad() {
			console.info("当前登录状态:" + this.$store.state.isLogin);
			//console.info(this);
			this.$util.persistLogin(this);
		},
		onPullDownRefresh() {
			this.reload = true;
			this.last_id = '';

			this.getList();
		},
		onReachBottom() {
			this.status = 'more';
			this.getList();
		},
		created: function() {
			this.getList();
		},
		methods: {

			getList() {
				let that = this;
				 
				let id = that.$util.getQuery("id");
				
				GetZRelationSafeQualityCheckMaterialDTOs(id).then((res) => {
					console.info('GetZRelationSafeQualityCheckMaterialDTOs',res);
					that.listData=res;
					console.info(that.listData);
				});
			},
			
			// 删除材料
           deleteMaterial:function(id){
			   let that = this;
			   uni.showModal({
			   	title:'提示',
				content:'确定要删除吗，删除后不能恢复！',
				success: function (res) {
				        if (res.confirm) {
				            console.log('用户点击确定');
							//删除操作
							DeleteZRelationSafeQualityCheckMaterial(id).then((res)=>{
								console.info('DeleteZRelationSafeQualityCheckMaterial',res);
								if(res>0){
									uni.showToast({
										title:'删除成功',
										duration:3000,
										icon:'none'
									});
									let thisid = that.$util.getQuery("id");
									//重新加载数据，以实现刷新
									GetZRelationSafeQualityCheckMaterialDTOs(thisid).then((res) => {
										console.info('GetZRelationSafeQualityCheckMaterialDTOs',res);
										that.listData=res;
										console.info(that.listData);
									});
								}
							   else{
								   uni.showToast({
								   	title:'删除失败',
								   	duration:3000,
								   	icon:'none'
								   });
							   }
							});
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
			   })
			  
		   }
		}
	};
</script>

<style scoped lang="scss">
	.uni-list-item{
		border-bottom: $BgColorBlue;
	} 
	
</style>
