lilei 4 лет назад
Родитель
Сommit
a36071415b
1 измененных файлов с 135 добавлено и 138 удалено
  1. 135 138
      pages/spotCheckConfigure/spotCheckList.vue

+ 135 - 138
pages/spotCheckConfigure/spotCheckList.vue

@@ -1,158 +1,155 @@
 <template>
 	<view class="pageInfo">
-		<!-- 自定义导航栏 -->
-		<u-navbar title-color="#fff" back-icon-size="30" back-icon-color="#fff" :border-bottom="false" :background="background">
-			<view class="slot-wrap">
-				<view class="left-icon">
-					点检任务配置
-				</view>
-				<!-- 新增 -->
-				<view class="right-icon" @click="openAddPage">
-					<u-icon name="plus-circle" size="30" color="#fff" label="新增" label-color="#fff"></u-icon>
-					<uni-font-icons type="icon-sousuo" size="16" color="#fff"></uni-font-icons> 
-				</view>
-			</view>
-		</u-navbar>
 		<!-- 任务列表 -->
-		<scroll-view scroll-y class="scroll-view" @scrolltolower="onreachBottom">
-			<view v-for="item in listData" :key="item.id" class="itemInfo">
-				<view class="itemName">
-					<span class="name">{{item.name}}</span>
-					<u-switch size="40" :value="item.status==1"></u-switch>
-				</view>
-				<view class="itemName">
-					<span>{{item.startDate}} 至 {{item.endDate}}</span>
-					<span>
-						<u-button v-if="item.status==1" type="warning" size="mini" style="margin-right: 15upx;" @click="handetail">查看</u-button>
-						<u-button type="primary" size="mini" style="margin-right: 15upx;" @click="handedit">编辑</u-button>
-						<u-button type="error" size="mini" @click="handelete(item)">删除</u-button>
-					</span>
-					
-				</view>
+		<view v-for="item in list" :key="item.id" class="itemInfo">
+			<view class="itemName">
+				<span class="name">{{ item.name }}</span>
+				<u-switch size="40" @change="changeItem(item)" v-model="item.status == 1"></u-switch>
+			</view>
+			<view class="itemName">
+				<span>{{ item.startDate }} 至 {{ item.endDate }}</span>
+				<span>
+					<u-button v-if="item.status == 1" type="success" size="mini" style="margin-right: 15upx;" @click="handetail">查看</u-button>
+					<u-button v-if="item.status == 0" type="primary" size="mini" style="margin-right: 15upx;" @click="handedit">编辑</u-button>
+					<u-button v-if="item.status == 0" type="error" size="mini" @click="handelete(item)">删除</u-button>
+				</span>
 			</view>
-		</scroll-view>
+		</view>
+		<u-empty :text="noDataText" v-if="list.length == 0 && status != 'loading'" mode="list"></u-empty>
+		<view style="padding: 20upx;"><u-loadmore v-if="total > pageSize || status == 'loading'" :status="status" /></view>
 	</view>
 </template>
 
 <script>
-	import {getCheckTaskConfigList,delCheckTaskConfig,enableCheckTaskConfig,saveBackLog} from '../../api/checkTaskConfig.js'
-	export default{
-		data(){
-			return{
-				background: {
-					// 渐变色
-					backgroundImage: 'linear-gradient(45deg, rgb(85, 170, 255), rgb(21, 102, 223))'
-				},
-				status: 'loadmore',
-				noDataText: '暂无数据',
-				listData:[]
-			}
+import {clzConfirm} from '@/libs/tools.js'
+import { getCheckTaskConfigList, delCheckTaskConfig, enableCheckTaskConfig } from '@/api/checkTaskConfig.js';
+export default {
+	data() {
+		return {
+			status: 'loadmore',
+			noDataText: '暂无数据',
+			list: [],
+			pageNo: 1,
+			pageSize: 10,
+			total: 0
+		};
+	},
+	onLoad() {
+		this.getList();
+	},
+	// 新增
+	onNavigationBarButtonTap() {
+		uni.navigateTo({
+			url: '/pages/spotCheckConfigure/addSpotCheck'
+		});
+	},
+	// 上拉分页
+	onReachBottom() {
+		console.log('onReachBottom');
+		if(this.list.length< this.total){
+		  this.pageNo++
+		  this.getList()
+		}else {
+		  uni.showToast({
+			title: '已经到底了',
+			icon: 'none'
+		  })
+		  this.status = "nomore"
+		}
+	},
+	methods: {
+		// 获取列表
+		getList() {
+			let _this = this;
+			let params = {
+				pageNo: this.pageNo,
+				pageSize: this.pageSize,
+			};
+			this.status = 'loading';
+			getCheckTaskConfigList(params).then(res => {
+				console.log(res)
+				if (res.status == 200) {
+					let list = res.data.list;
+					_this.list = _this.list.concat(list);
+					_this.total = res.data.count;
+				} else {
+					uni.showToast({
+						title: res.message,
+						icon: 'none'
+					});
+					_this.noDataText = res.message;
+				}
+				_this.status = 'loadmore';
+			});
 		},
-		watch: {
-			checked(val) {
-				// 等于false,意味着用户手动关闭了switch
-				if (val == false) {
-					if(this.listData.status == 0) {
-						this.listData.status = 1;
-						return ;
-					}
-					// 重新打开switch,并让它处于加载中的状态
-					this.checked = true;
-					this.loading = true;
-					// 模拟向后端发起请求
-					this.getRestultFromServer();
+		// 启用禁用
+		changeItem(item){
+			let _this = this
+			enableCheckTaskConfig({id:item.id,flag:item.status}).then(res=>{
+				if(res.status == 200){
+					let i = _this.list.findIndex(a=>a.id == item.id)
+					_this.list[i].status = item.status == 1 ? 0 : 1
+					_this.list.splice()
 				}
-			}
+				uni.showToast({
+					title: res.message,
+					icon: 'none'
+				})
+			})
 		},
-		onLoad() {
-			this.getListData()
+		// 查看详情
+		handetail(item) {
+			uni.navigateTo({
+				url: '/pages/spotCheckConfigure/spotCheckDetail/spotCheckDetail?id='+item.id
+			});
 		},
-		methods:{
-			// 列表数据
-			getListData(){
-				getCheckTaskConfigList({pageNo:1,pageSize:10}).then(res=>{
-					if(res.status==200){
-						this.listData=res.data.list
+		// 编辑
+		handedit(item) {
+			uni.navigateTo({
+				url: '/pages/spotCheckConfigure/addSpotCheck?id='+item.id
+			});
+		},
+		// 删除
+		handelete(item) {
+			const _this = this;
+			clzConfirm({
+				title: '提示',
+				content: '确认删除,删除后数据将无法恢复?',
+				success: function(res) {
+					if (res.confirm || res.index == 0) {
+						delCheckTaskConfig({id:item.id}).then(ret=>{
+							if(ret.status == 200){
+								let i = _this.list.findIndex(a=>a.id == item.id)
+								_this.list.splice(i,1)
+							}
+							uni.showToast({
+								title: ret.message,
+								icon: 'none'
+							})
+						})
 					}
-				})
-			},
-			openAddPage(){
-				console.log('-------------------')
-				uni.navigateTo({
-					url:'/pages/spotCheckConfigure/addSpotCheck'
-				})
-			},
-			// 查看详情
-			handetail(){
-				uni.navigateTo({
-					url:'/pages/spotCheckConfigure/spotCheckDetail/spotCheckDetail?id=${listData.id}'
-				})
-			},
-			// 编辑
-			handedit(){
-				uni.navigateTo({
-					url:'/pages/spotCheckConfigure/addSpotCheck'
-				})
-			},
-			// 删除
-			handelete(item){
-				const _this=this
-				clzConfirm({
-					title: '提示',
-					content: '确认删除,删除后数据将无法恢复?',
-					// success: function(res) {
-					// 	if (res.confirm || res.index == 0) {
-					// 		_this.isClose = true
-					// 		uni.navigateBack({
-					// 			delta: 1
-					// 		});
-					// 	}
-					// }
-				});
-			},
-			onreachBottom(){
-				
-			}
+				}
+			});
 		}
 	}
+};
 </script>
 
 <style lang="scss">
-	page{
-		height: 100%;
-		background-color: #eee;
+page {
+	background: #f8f8f8;
+}
+.itemInfo {
+	margin: 20upx;
+	background-color: #fff;
+	border-radius: 3px;
+	.itemName {
+		padding: 25upx 35upx;
+		display: flex;
+		justify-content: space-between;
 	}
-	.slot-wrap {
-			display: flex;
-			align-items: center;
-			/* 如果您想让slot内容占满整个导航栏的宽度 */
-			flex: 1;
-			/* 如果您想让slot内容与导航栏左右有空隙 */
-			padding: 0 30rpx 0 0;
-			color: #fff;
-			font-size: 28upx;
-			.left-icon{
-				flex-grow: 1;
-				font-size: 32upx;
-			}
-			.right-icon{
-				padding-left:50upx;
-			}
-			.uni-icons{
-				margin-right: 10upx;
-			}
-		}
-		.itemInfo{
-			margin: 20upx;
-			background-color: #fff;
-			border-radius: 3px;
-			.itemName{
-				padding: 25upx 35upx;
-				display: flex;
-				justify-content: space-between;
-			}
-			.itemName:first-child{
-				border-bottom: 1px solid #f8f8f8;
-			}
-		}
+	.itemName:first-child {
+		border-bottom: 1px solid #f8f8f8;
+	}
+}
 </style>