<template>
	<view class="enterpriseRecharge_body">
		<topBar height="343rpx" title="企业充值预处理">
			<view slot="coment">
				<view class="header_seach">
					<view class="header_seach_seach">
						<view class="seach_input">
							<view @click="inputFocusCompany" class="special-input">
								{{ parameter.params.companyName || '企业名称'}}
								<image v-if="parameter.params.companyName" class="close" src="../../static/close.png"
									@click.stop="inputClearCompany"></image>
							</view>
							<view @click="inputFocus" class="special-input">
								{{ parameter.params.name || '总公司名称'}}
								<image v-if="parameter.params.name" class="close" src="../../static/close.png"
									@click.stop="inputClear"></image>
							</view>
							<button @tap='search' class="header_seach_butten">
								<uni-icons type="search" size="20" color="#bbbbbb"></uni-icons>
							</button>
						</view>
					</view>
				</view>
			</view>
		</topBar>
		<view class="listContainer" style='flex: 1;overflow: hidden;'>
			<scroll-view :refresher-triggered='isShow.refresherTriggered' @refresherrefresh='refresherrefresh'
				:refresher-enabled='true' @scrolltolower='scrolltolower' style="height: 100%;" scroll-y="true">
				<view v-for="(item,index) in list" class="list_item_car">
					<view style="">
						<view class=" list_item_car_title flex jb">
							<view class="flex">
								<view class="flex acenter" style="width: 560rpx;">
									<view>企业名称：{{item.name}}</view>
								</view>
								<view class="tag-view">
									<uni-tag :text="item.parentMark===0?'总公司':'分公司'"
										:type="item.parentMark===0?'primary':''"></uni-tag>
								</view>

							</view>
						</view>
						<view class=" list_item_car_title flex ">
							<view class="flex">
								<view class="pricr_text">
									<view class="flex" style="padding: 15rpx 0;">
										加价策略
										<view style="margin: 0 10rpx; min-width: 150rpx;" class="blackcolor">
											{{item.oilsPriceStrategy == '1' ? '费率' : '增减'}}:{{item.oilsPriceScale?item.oilsPriceScale:''}}
										</view>
									</view>
									<view class="flex" style="padding: 15rpx 0;">
										折返策略
										<view style="margin: 0 10rpx;min-width: 150rpx;" class="blackcolor">
											<view
												v-if="item.consumRebateStrategy=='TYFL' || item.consumRebateStrategy == 'SITE_lEVEL'">
												{{item.consumRebateStrategy == 'TYFL' ? '统一费率' : '油站等级'}}:{{item.consumRebateScale ? item.consumRebateScale : '0'}}
											</view>
											<view v-else-if="item.consumRebateStrategy=='TYSSFL'">
												{{item.consumRebateStrategy == 'TYSSFL' ? '统一升数' : '未知'}}:{{item.consumRebateScale ? item.consumRebateScale + '元/L' : '0'}}
											</view>
											<view v-else>暂无</view>

										</view>
									</view>
									<view class="flex" style="padding: 15rpx 0;">
										企业类型
										<view style="margin: 0 10rpx;min-width: 150rpx;" class="blackcolor">
											{{ optionNature(item.companyNature).text }}
										</view>
									</view>
									<view class="flex" style="padding: 15rpx 0;">
										账户类型
										<view style="margin: 0 10rpx;min-width: 150rpx;" class="blackcolor">
											{{ optionType(item.companyType).text }}
										</view>
									</view>
									<view class="flex" style="padding: 15rpx 0;">
										共享总公司额度
										<view style="margin: 0 10rpx;min-width: 150rpx;" class="blackcolor">
											{{ item.shareParentAmt =='0'?'共享':'不共享' }}
										</view>
									</view>
								</view>
								<view class="flex" style="flex: 1;">
									<view class="pricr_text">
										<view class="flex" style="padding: 15rpx 0;">
											启用状态
											<switch class="my-switch" :checked="item.enableMark=='1'?true:false"
												style="transform:scale(0.7)" @change=" changeEnableMark(item)"></switch>
										</view>
										<view class="flex" style="padding: 15rpx 0;">
											联动分油
											<switch class="my-switch" :class="item.parentMark ==0?'disabledMark':''"
												:disabled="item.parentMark ==0?true:false"
												:checked="item.shareDistribute=='1'?true:false"
												style="transform:scale(0.7)" @change=" changeDistribute(item)"></switch>
										</view>
										<view class="flex" style="padding: 15rpx 0;">
											<view @tap="jump(item)"
												style="padding: 20rpx 30rpx;color: #FFBA00;background: #FFF8E6;border: 2rpx solid #FFBA00;">
												编辑银行信息
											</view>

										</view>
									</view>

								</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import scroll from '@/components/scroll'
	import companyManagement from '@/api/companyManagement'
	export default {
		components: {
			scroll
		},
		data() {
			return {
				list: [],
				isShow: {
					refresherTriggered: false
				},
				parameter: {
					pageSize: 15,
					currentPage: 1,
					params: {
						companyName: '',
						name: ''
					},
					sorted: {}
				},
			}
		},
		onShow() {
			this.search()
		},
		onLoad() {
			uni.$on('companyEnterprise', (item) => {
				if (!item.name) return
				this.parameter.currentPage = 1
				this.parameter.params.companyName = item.name
			})
			uni.$on('nameEnterprise', (item) => {
				if (!item.name) return
				this.parameter.currentPage = 1
				this.parameter.params.name = item.name
			})
			this.search()
		},
		methods: {
			jump(item) {
				uni.navigateTo({
					url: './detail?jsData=' + JSON.stringify(item)
				})
			},
			refresherrefresh(e) {
				this.isShow.refresherTriggered = true
				this.search()
			},
			changeEnableMark(item) {
				const data = [item]
				companyManagement.updateBatchEnable(data).then(res => {
					if (res.code === 20000) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
					this.search()
				})
			},
			changeDistribute(item) {
				const data = {
					id: item.id,
					shareDistribute: item.shareDistribute
				}
				companyManagement.openShareDistribute(data).then(res => {
					if (res.code === 20000) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
					this.search()
				})
			},
			inputFocusCompany(e) {
				uni.navigateTo({
					url: './companyEnterprise'
				})
			},
			inputFocus(e) {
				uni.navigateTo({
					url: './enterprise'
				})
			},
			inputClearCompany() {
				this.parameter.params.companyName = ''
			},
			inputClear() {
				this.parameter.params.name = ''
			},
			search() {

				companyManagement.getByPage(this.parameter).then(res => {
					this.isShow.refresherTriggered = false
					if (res.code !== 20000) return
					if (res.data.list.length == 0) {
						uni.showToast({
							title: '没有数据了哦',
							icon: 'none'
						})
					}
					if (this.parameter.currentPage !== 1) {
						this.list = this.list.concat(res.data.list)
						return
					}
					this.list = res.data.list
				})
			},
			scrolltolower() {
				this.parameter.currentPage += 1
				this.search()
			},
			optionNature(e) {
				switch (e) {
					case 0:
						return {
							text: '零售客户'
						}
						break;
					case 1:
						return {
							text: '外请客户'
						}
						break;
					case 2:
						return {
							text: '渠道客户'
						}
						break;
					case 3:
						return {
							text: '存量客户'
						}
						break;
					case 4:
						return {
							text: '批发客户'
						}
						break;
					case 5:
						return {
							text: 'LNG客户'
						}
						break;
					case 6:
						return {
							text: '推广业务'
						}
						break;
				}
			},
			optionType(e) {
				switch (e) {
					case '0':
						return {
							text: '柴油账户'
						}
						break;
					case '1':
						return {
							text: '汽油账户'
						}
						break;
					case '2':
						return {
							text: 'LNG账户'
						}
						break;
					case '3':
						return {
							text: '尿素账户'
						}
						break;
					case '4':
						return {
							text: '油批账户'
						}
						break;
					case '5':
						return {
							text: '电卡账户'
						}
						break;
				}
			}
		}
	}
</script>

<style>
	@import url("./index.css");
</style>
