<template>
	<view class="supplier-container">
		<!-- <uni-swipe-action ref="slide">
				<view class="supplier-info" @click="gotoSupplierDetail(item)"  v-for="(item,index) in dataList" :key="item.id">
					<uni-swipe-action-item :right-options="options"
						@click="bindClick($event,item)" :show="isOpened" @change="change">
					<view class="supplier-title">
						<view class="supplier-title-text">
							{{item.name || '-'}}
						</view>
						<view class="supplier-title-contacts">
							{{item.contactName || '-'}}
						</view>
					</view>
					<view class="supplier-tel">
						{{item.contactPhone || '-'}}
					</view>
					</uni-swipe-action-item>
				</view>
		</uni-swipe-action> -->
		<view class="supplier-info" @click="gotoSupplierDetail(item)"  v-for="(item,index) in dataList" :key="item.id">
			<view class="supplier-title">
				<view class="supplier-title-text">
					{{item.name || '-'}}
				</view>
				<view class="supplier-title-contacts">
					{{item.contactName || '-'}}
				</view>
			</view>
			<view class="supplier-tel">
				{{item.contactPhone || '-'}}
			</view>
			
		</view>
		<u-button type="primary" class="commit-button" @click="jumpPage">增加合作者</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//列表数据
				dataList: [],
				//查询条件
				param: {
					stationCode: null,
					stationName:null,
				},
				options: [
					{
						text: "编辑",
						style: {
							backgroundColor: "blue",
							
						},
					}, 
					{
						text: "删除",
						style: {
							backgroundColor: "#ff3242",
							
						},
					},
				],
				isOpened: "none",
			}
		},
		//第一次加载
		onLoad(e) {
			this.param.stationCode = e.stationCode
			this.param.stationName=e.stationName
		},
		onReady() {

		},
		//页面显示
		onShow() {

		},
		mounted() {
			this.getSupplierListData();
		},
		methods: {
			//跳转合作者
			jumpPage(){
				uni.navigateTo({
					url:`/pages/index/supplierAdd?stationCode=${this.param.stationCode}&stationName=${this.param.stationName}`
				})
			},
			// bindClick(e,item) {
			// 	if(e.content.text==='删除'){
			// 		let _that = this
			// 		uni.showModal({
			// 			title: `确认删除吗?`,
			// 			content: '',
			// 			success: function(res) {
			// 				if (res.confirm) {
			// 					_that.$http.supplierDel({id:item.id,stationCode:_that.param.stationCode})
			// 						.then(res => {
			// 							if (res.code === 200) {
			// 								_that.getSupplierListData()
			// 							}else{
			// 								_that.$utils.msg(res.msg);
			// 							}
										
			// 						}).catch(err => {
			// 							console.error(err)
			// 						})
			// 				} else if (res.cancel) {
			// 					return false
			// 				}
			// 			}
			// 		})
			// 	}else{
			// 		uni.navigateTo({
			// 			url:'/pages/index/supplierAdd?item='+encodeURIComponent(JSON.stringify(item))
			// 		})
			// 	}
			// },
			// change(e) {
			// 	// console.log(e, '改变事件')
			// },
			//跳转详情页
			gotoSupplierDetail(item) {
				uni.navigateTo({
					url: '/pages/index/supplierDetail?dataInfo=' + encodeURIComponent(JSON.stringify(item)),
				})
			},
			//获取站点内供货商的列表
			getSupplierListData() {
				let _that = this;
				_that.dataList = [];
				uni.showLoading({
					title: '搜索中...',
				})
				_that.$http.getSupplierList(_that.param).then(res => {
					uni.hideLoading();
					if (res.code == 200) {
						_that.dataList = res.data.list || [];
					} else {
						_that.$utils.msg(res.msg);
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.supplier-container {
		height: 100vh;
		position: relative;
		box-sizing: border-box;
		background: $uni-bg-color;
		padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
		padding-top: 30rpx;
		.commit-button {
			position: fixed;
			width: calc(100% - 60rpx);
			bottom: calc(20rpx + env(safe-area-inset-bottom));
			z-index: 999;
			left: 30rpx;
		}
		.supplier-info {
			height: 160rpx;
			background: #FFFFFF;
			border-radius: 16rpx 16rpx 16rpx 16rpx;
			margin: 0 30rpx 30rpx;
			padding: 30rpx;

			.supplier-title {
				display: flex;
				padding-right: 30rpx;
				.supplier-title-text {
					flex: 1;
					font-size: 30rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #1D2129;
					line-height: 44rpx;
				}

				.supplier-title-contacts {
					font-size: 30rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #1D2129;
					line-height: 44rpx;
					text-align: right;
				}
			}

			.supplier-tel {
				text-align: right;
				font-size: 26rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				color: #86909C;
				line-height: 44rpx;
				margin-top: 20rpx;
				padding-right: 30rpx;
			}
		}
	}
</style>