<template>
	<view class="">
		<!-- <view>
			<button size="default" v-if="type!='kaidan'" type="default" @tap="addAddress" hover-class="is-hover">新增线路</button>
		</view> -->
		<view class="list-1" style="display: flex;flex-direction: column;height: 150rpx;" v-for="(item, index) in standardList" :key="index">
			<view class="name-tel" style="width: 80%;overflow: hidden;">
				<text style="line-height: 75rpx;">{{item.province +'-'+ item.city+'-'+item.area}}</text>
			</view>
			<view class="name-tel" style="width: 60%;line-height: 35rpx;">
				<text style="font-size: 22rpx;">{{item.network == null ?'':item.network}}</text>
			</view>
			<!-- <view class="name-tel" style="width: 75%;overflow: hidden;">
				<text style="line-height: 75rpx;">{{item.chargingStandard}}</text>
			</view> -->
			<!-- <view class="name-edit" style="height: 50%;position: absolute;bottom: 0;right: 20%;">
				<text @tap.stop="priceDetail(item)" style='line-height: 75rpx;color: #088FEB;'>费用说明</text>
			</view> -->
			<!-- <view class="name-edit">
				<text @tap.stop="addAddress(item)" v-if="type!='kaidan'" style='line-height: 75rpx;color: #088FEB;'>编辑</text>
				<text @tap.stop="delAddress(item)" v-if="type!='kaidan'" style='color:red;line-height: 75rpx;'>删除</text>
			</view> -->
		</view>
		<u-loadmore :status="status" />
		<!-- 弹出输入框 -->
		<uni-popup ref="inputDialog" background-color="#fff">
			<cc-selectDity :show="show" @sureSelectArea="onsetCity" @hideShow="onhideShow"></cc-selectDity>
			<view class="popup-pay-content">
				<view class="popup-pay-title">
					填写信息
				</view>
				<uni-forms ref="form" :modelValue="formData" :rules="rules" labelWidth="85px">
					<uni-forms-item label="地址" name="address1">
						<view class="input selectcity" @tap="openPicker">
							<input placeholder="请选择省市区" disabled type="text" v-model="formData.address1"></input>
						</view>
					</uni-forms-item>
					<uni-forms-item label="费用说明" name="standard">
						<uni-easyinput type="textarea" v-model="formData.standard" />
					</uni-forms-item>
				</uni-forms>
				<view class="address-btn" @tap="setAddress">确认</view>
			</view>
		</uni-popup>
		<!-- 费用说明 -->
		<uni-popup ref="payDialog" background-color="#fff">
			<view class="popup-content">
				<view class="popup-title">
					<text>费用说明</text>
				</view>
				<view v-if="chargingStandard != undefined" style="margin-top: 20rpx;">
					{{chargingStandard}}
				</view>
				<view v-if="chargingStandard == null || chargingStandard == undefined || chargingStandard == ''" style="height:300rpx;line-height: 300rpx;">
					暂无此线路费用明细
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				formData: {
					address1: '',
					standard: '',
					province: '',
					city: '',
					area: '',
					id: ''
				},
				chargingStandard:'',
				show: false,
				standardList:[],
				status: 'loadmore',
				pages:1,
				total:1,
				rules: {
					address1: {
						rules: [{
							required: true,
							errorMessage: '请选择线路',
						}]
					},
					standard: {
						rules: [{
							required: true,
							errorMessage: '请输入费用说明',
						}]
					},
				},
				type:''
			}
		},
		onShow() {

		},
		created() {
			uni.hideHomeButton() //左上角HOME按钮
		},
		onLoad(options) {
			this.type = options.type
			this.getList()
		},
		onReachBottom() {
			if (this.total >= this.pages) return;
			this.status = 'loading';
			this.total += 1;
			this.getList();
		},
		methods: {
			priceDetail(item){
				this.chargingStandard = item.chargingStandard
				this.$refs.payDialog.open()
			},
			//获取列表
			getList(){
				let that = this;
				if(this.type == 'kaidan'){ //客户跳过来的
					this.tui.request("/app/operatingArea/getOperatingAreaList", "post", {
						pageNum:this.total,
						pageSize:10,
						shippingMethodId:uni.getStorageSync("transCompany")
					}, false, false).then((res) => {
						this.status = 'nomore';
						if (res.code == 200){
							this.pages = res.result.pages
							if (this.pages == 1) {
								this.standardList = res.result.records
							} else {
								this.standardList = [...this.standardList, ...res.result.records]
							}
						}
					})
				}else{  //物流公司登录的
					uni.request({
						url: this.tui.interfaceUrl() + '/app/operatingArea/getOperatingAreaList',
						data: {
							pageNum:this.total,
							pageSize:10,
							shippingMethodId:uni.getStorageSync("transCompany")
						},
						header: {
							'content-type': 'application/json',
							'appWLToken': this.tui.getToken()
						},
						method: 'POST', //'GET','POST'
						dataType: 'json',
						success: (res) => {
							this.status = 'nomore';
							if (res.data.code == 200){
								this.pages = res.data.result.pages
								if (this.pages == 1) {
									this.standardList = res.data.result.records
								} else {
									this.standardList = [...this.standardList, ...res.data.result.records]
								}
							}
						},
						fail: (res) => {
							this.tui.toast("网络不给力，请稍后再试~")
						}
					})
				}
			},
			//弹出弹窗
			addAddress(data) {
				let item = this.formData = {}
				if(data){
					item.id = data.id
					item.standard = data.chargingStandard
					item.province = data.province
					item.city = data.city
					item.area = data.area
					item.address1 = data.province + data.city + data.area;
				}
				this.$refs.inputDialog.open('bottom')
			},
			//新增修改
			setAddress(){
				let item = {}
				if(this.formData.id != ''){
					item = {
						shippingType:uni.getStorageSync("signCompany"),
						shippingMethod:uni.getStorageSync("companyName"),
						shippingMethodId:uni.getStorageSync("transCompany"),
						province:this.formData.province,
						city:this.formData.city,
						area:this.formData.area,
						chargingStandard:this.formData.standard,
						id:this.formData.id
					}
				}else{
					item= {
						shippingType:uni.getStorageSync("signCompany"),
						shippingMethod:uni.getStorageSync("companyName"),
						shippingMethodId:uni.getStorageSync("transCompany"),
						province:this.formData.province,
						city:this.formData.city,
						area:this.formData.area,
						chargingStandard:this.formData.standard
					}
				}
				uni.request({
					url: this.tui.interfaceUrl() + '/app/operatingArea/saveOrUpdateOperatingArea',
					data: item,
					header: {
						'content-type': 'application/json',
						'appWLToken': this.tui.getToken()
					},
					method: 'POST', //'GET','POST'
					dataType: 'json',
					success: (res) => {
						if (res.data.code == 200){
							this.tui.toast("操作成功")
							this.getList();
							this.$refs.inputDialog.close()
							this.formData = {}
						}
					},
					fail: (res) => {
						this.tui.toast("网络不给力，请稍后再试~")
					}
				})
			},
			delAddress(data){
				var that = this;
				uni.showModal({
					title: "提示",
					content: "确定删除此条线路吗？",
					success: function(res) {
						if (res.confirm) {
							uni.request({
								url: that.tui.interfaceUrl() + '/app/operatingArea/deleteOperatingArea',
								data: {
									id:data.id
								},
								header: {
									'content-type': 'application/x-www-form-urlencoded',
									'appWLToken': that.tui.getToken()
								},
								method: 'POST', //'GET','POST'
								dataType: 'json',
								success: (res) => {
									if (res.data.code == 200){
										that.tui.toast('删除成功')
										that.getList();
									}
								},
								fail: (res) => {
									that.tui.toast("网络不给力，请稍后再试~")
								}
							})
						}
						that.$forceUpdate()
					}
				})
			},
			openPicker() {
				this.show = true
			},
			onhideShow() {
				this.show = false
			},
			//选中省市区
			onsetCity(e) {
				let data = e.detail.target.dataset;
				let address = data.province + data.city + data.area;
				this.show = false
				this.formData.address1 = address;
				this.formData.province = data.province
				this.formData.city= data.city
				this.formData.area= data.area
			},
		}
	}
</script>

<style lang="scss" scoped>
	button {
		color: #ffffff;
		background: #5fd9ee;
		width: 90%;
		margin-top: 20rpx;
	}

	.list-1 {
		display: flex;
		height: 150rpx;
		border-bottom: 1px solid #eee;
		background: #fff;
		font-size: 32rpx;
		margin-top: 20rpx;
		position: relative;
	}

	.name-tel {
		width: 220rpx;
		height: 75rpx;
		line-height: 75rpx;
		padding-left: 40rpx;
	}

	.name-edit {
		width: 20%;
		height: 100%;
		position: absolute;
		right: 0;
		display: flex;
		flex-direction: column;
		text-align: center;
	}

	.standard-box {
		color: #088FEB;
		line-height: 75rpx;
		width: 50%;
		text-align: right;
		font-size: 26rpx;
	}


	.popup-content {
		align-items: center;
		justify-content: center;
		padding: 15px;
		width: 500rpx;
		height: auto;
		background-color: #fff;
		min-height: 500rpx;
		text-align: center;
	}

	.popup-title {
		font-size: 36rpx;
		font-weight: bold;
		text-align: center;
		position: relative;
	}

	.popup-container {
		margin-top: 20rpx;
	}

	.address-btn {
		width: 100%;
		height: 80rpx;
		background: #088FEB;
		color: #fff;
		font-size: 36rpx;
		text-align: center;
		line-height: 80rpx;
		border-radius: 10px;
	}

	.phone-btn {
		width: 150rpx;
		height: 75rpx;
		color: #088FEB;
		line-height: 75rpx;
		font-size: 26rpx;
	}

	.popup-pay-content {
		align-items: center;
		justify-content: center;
		padding: 0 15px 15px 15px;
		width: 95%;
		margin: 0 auto;
		height: auto;
		background-color: #fff;
	}

	.popup-pay-title {
		height: 100rpx;
		line-height: 100rpx;
		text-align: center;
		font-weight: bold;
		font-size: 32rpx;
	}
</style>