<template>
	<view>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" top="20" @down="downCallback" :up="upOption"
			@up="upCallback" @emptyclick="emptyClick">
			<!-- 数据列表 -->
			<view class="list" v-if="goods.length!=0">
				<view class="list-item" v-for="(item,index) in goods">
					<view class="row1 flex jcsb alc">
						<view class="left flex alc">
							<view class="bottom" style="margin-top: 6rpx;">
								<text class="color1" v-if="item.tranType=='采购'">采购</text>
								<text class="color2" v-if="item.tranType=='销售'">销售</text>
								<text class="color3">{{item.remark3}}</text>
							</view>
						</view>
						<view class="right" style="color: #FE6430;" v-if="item.status=='待审核'">审核中</view>
						<view class="right" style="color: #FB2323;" v-if="item.status=='已驳回'">已驳回</view>
						<view class="right" style="color: #22C572;" v-if="item.status=='审核通过'">已通过</view>
					</view>
					<view class="row2">
						<mote-lines-divide :dt="item.publishingContent" :line="3" expandText="展开" foldHint="收起" />
					</view>
					<view class="row3">
						<image :src="item1" mode="aspectFill" v-for="(item1,index) in item.imgList" class="img">
						</image>
					</view>
					<view class="row4">
						<u-icon name="map-fill" color="#AFB3BF" size="28" bold></u-icon>
						<text class="text">{{item.placeDelivery}}</text>
					</view>
					<view class="row5">
						<view class="del btn" @click="del(item)">
							删除
						</view>
						<view class="edit btn" @click="edit(item)">
							编辑
						</view>
						<view class="edit btn" @click="refresh(item)">
							刷新
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
		<view class="add" @click="release">
			<u-icon name="plus" color="#fff" size="34" bold></u-icon>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MoteLinesDivide from "@/components/text-over-flow"
	import selectAddress from "@/components/selectAddress.vue"
	import {
		apiGoods
	} from "@/api/mock.js"
	export default {
		components: {
			MoteLinesDivide,
			selectAddress
		},
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				canReset: false,
				keyword: '',
				inputStyle: {
					// "padding-left": '30rpx'
				},
				content: '上半年，普陀区开展“绿剑”系列执法行动二次，共计出动执法人员120余人次，检有关经营主体87余家次，发放宣传资料等200余份；加强农产品和农业…上半年，普陀区开展“绿剑”系列执法行动二次，共计出动执法人员120余人次，检有关经营主体87余家次，发放宣传资料等200余份；加强农产品和农业…',
				upOption: {
					// page: {
					// 	num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					// 	size: 10 // 每页数据的数量
					// },
					noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						icon: '/static/empty.png',
						tip: '暂无内容', // 提示
						// btnText: '去看看'
					}
				},
				goods: [], //列表数据
				tabs: [{
					name: '全部',
					type: 'xx'
				}, {
					name: '采购',
					type: 'xx'
				}, {
					name: '销售',
					type: 'xx'
				}, {
					name: '关注',
					type: 'xx'
				}],
				tabIndex: 0 // tab下标
			}
		},


		onShow() {
			uni.showTabBar()
			uni.hideKeyboard()
			var userInfo = uni.getStorageSync("userInfo")
			var that = this
			console.log("userInfo", userInfo)
			this.$nextTick(function() {
				this.canReset && this.mescroll.resetUpScroll() // 重置列表数据为第一页  
				this.canReset && this.mescroll.scrollTo(0, 0) // 重置列表数据为第一页时,建议把滚动条也重置到顶部,避免无法再次翻页的问题  
				this.canReset = true // 过滤第一次的onShow事件,避免初始化界面时重复触发upCallback, 无需配置auto:false
			});

		},
		onLoad(options) {},


		methods: {
			refresh(val) {
				let _obj = {
					id: val.id,
					flag: 0,
					remark3: new Date().getTime()
				}
				uni.showLoading({
					title: '数据加载中',
					mask: true
				})
				this.$api.doRequest('post', '/transactionExchangeInfo/editInfo', _obj).then(res => {
					console.log(res.data)
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '刷新成功成功',
							type: 'success',
						})
						this.mescroll.resetUpScroll()
					}
					uni.hideLoading()
				})
			},
			edit(val) {
				uni.navigateTo({
					url: '/pages/business/editRelease?id=' + val.id
				})
			},
			del(val) {
				let _obj = {
					id: val.id,
				}
				uni.showLoading({
					title: '数据加载中',
					mask: true
				})
				this.$api.doRequest('post', '/transactionExchangeInfo/deleteInfo', _obj).then(res => {
					console.log(res.data)
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '删除成功',
							type: 'success',
						})
						this.mescroll.resetUpScroll()
					}
					uni.hideLoading()
				})
			},
			selectAddress(val) {
				console.log(val)
			},
			release() {
				uni.navigateTo({
					url: 'release'
				})
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			async upCallback(page) {
				//联网加载数据
				let _obj = {
					pageSize: page.size,
					currentPage: page.num,
					userId: this.userInfo.id,
				}
				await this.$api.doRequest('get', '/transactionExchangeInfo/selectTransactionExchangeInfo', _obj).then(res => {
					console.log(res.data)
					if (res.data.code == 200) {
						let curPageData = res.data.data.records;
						let curPageLen = curPageData.length;
						let totalPage = res.data.data.total;
						if (page.num == 1) this.goods = [];
						this.goods = this.goods.concat(curPageData);
						console.log(curPageLen, totalPage)
						this.mescroll.endByPage(curPageLen, totalPage);
						// for (let i = 0; i < this.goods.length; i++) {
						// 	this.goods[i].imgList = this.goods[i].urlImg.split(',')
						// }
					}
					uni.hideLoading()
				})
				if (this.goods.length > 0) {
					for (let i = 0; i < this.goods.length; i++) {
						await this.$api.doRequest('get', 'appendix/query/getFileList', {
							appendixIds: this.goods[i].urlImg
						}).then(res1 => {
							if (i == this.goods.length - 1) {
								uni.hideLoading()
							}
							var arr = []
							for (let q = 0; q < res1.data.data.length; q++) {
								arr.push(res1.data.data[q].appendixPath)
							}
							this.goods[i].imgList = arr
							this.$forceUpdate()
						})
				
					}
				}
			},
			//点击空布局按钮的回调
			emptyClick() {
				uni.showToast({
					title: '点击了按钮,具体逻辑自行实现'
				})
			},

			// 切换菜单
			tabChange() {
				this.goods = [] // 先置空列表,显示加载进度
				this.mescroll.resetUpScroll() // 再刷新列表数据
			}

		}
	}
</script>

<style lang='scss'>
	page,
	.content {
		background: #F5F6FA;
	}

	.flex {
		display: flex;
	}

	.alc {
		align-items: center;
	}

	.jcse {
		justify-content: space-evenly;
	}

	.jcsb {
		justify-content: space-between;
	}

	.top-warp {
		z-index: 998;
		position: fixed;
		top: --window-top;
		/* css变量 */
		left: 0;
		width: 100%;
		/* height: 120upx; */
		background-color: white;
	}


	.top-warp .tip {
		font-size: 28upx;
		height: 60upx;
		line-height: 60upx;
		text-align: center;
	}

	.slot-wrap {
		margin-right: 45rpx;
		font-size: 32rpx;
	}

	.list {
		margin: 0 20rpx;

		.list-item {
			padding: 20rpx;
			background: #fff;
			margin-bottom: 20rpx;
			border-radius: 20rpx;

			.row1 {

				.head-img {
					width: 72rpx;
					background-color: red;
					border-radius: 8rpx;
					margin-right: 22rpx;
				}

				.left {
					.title {
						font-weight: 700;
						color: #333333;
					}

					.bottom {
						.color1 {
							font-size: 24rpx;
							padding: 4rpx 10rpx;
							color: #fff;
							display: inline-block;
							background: linear-gradient(180deg, #607AE0 0%, #516CDC 100%);
							border-radius: 4rpx;
						}

						.color2 {
							font-size: 24rpx;
							padding: 4rpx 10rpx;
							color: #fff;
							display: inline-block;
							background: linear-gradient(180deg, #FD714F 0%, #FD613C 100%);
							border-radius: 4rpx;
						}

						.color3 {
							font-size: 28rpx;
							/* color: #AFB3BF; */
							margin-left: 14rpx;

						}
					}
				}

				.right {
					/* padding: 10rpx 20rpx; */
				}
			}

			.row2 {
				margin-top: 20rpx;
				/* 		overflow: hidden;
				text-overflow: ellipsis;
				width: 100%;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 3;
				word-break: break-all; */
			}

			.row3 {
				/* padding: 30rpx 30rpx 0 30rpx; */
				margin-top: 18rpx;
				display: flex;
				align-items: center;
				/* justify-content: space-between; */
				flex-wrap: wrap;
				/* background: #bbb; */


				.img {
					display: flex;
					align-items: center;
					justify-content: center;
					width: 214rpx;
					height: 214rpx;
					margin-bottom: 20rpx;
					background: lightblue;
					list-style: none;
					border-radius: 10rpx;
					margin-right: 16rpx;
				}

				.img:nth-of-type(3),
				.img:nth-of-type(6),
				.img:nth-of-type(9) {
					margin-right: 0;
				}
			}

			.row4 {
				margin-top: 4rpx;

				.text {
					color: #878C9C;
					font-size: 24rpx;
				}
			}
		}

		.case {
			font-weight: 700;
			margin-left: 6rpx;
		}
	}

	.add {
		position: fixed;
		bottom: 250rpx;
		right: 32rpx;
		background: #22C572;
		z-index: 999;
		width: 84rpx;
		height: 84rpx;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.search {
		display: flex;
		align-items: center;
		position: relative;
		margin: 20rpx 28rpx 20rpx 28rpx;

		.text {
			width: 90rpx;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;

		}
	}

	/deep/.u-content {
		padding-left: 170rpx;
	}

	.place {
		display: flex;
		align-items: center;
		left: 28rpx;
		position: absolute;
		font-weight: 700;
	}

	.row5 {
		display: flex;
		justify-content: flex-end;
		margin-top: 20rpx;

		.btn {
			width: 120rpx;
			height: 66rpx;
			background: #FFFFFF;
			border-radius: 33px;
			border: 1px solid #CDCDCD;
			font-size: 28rpx;
			font-weight: 400;
			color: #333333;
			line-height: 66rpx;
			text-align: center;
			margin-left: 24rpx;
		}
	}
</style>
