<template>
	<div class="mod-dict">
		<el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
			<el-form-item label="价格类型" prop="pricingType">
				<el-select v-model="dataForm.pricingType" placeholder="请选择" clearable>
					<el-option label="请选择"/>
					<el-option :key="1" :value="1" label="固定价格"/>
					<el-option :key="2" :value="2" label="动态价格"/>
				</el-select>
			</el-form-item>
			<el-form-item label="出行方式" prop="travelType">
				<el-select v-model="dataForm.travelType" placeholder="请选择" clearable>
					<el-option label="请选择"/>
					<el-option :key="1" :value="1" label="免费"/>
					<el-option :key="2" :value="2" label="出租"/>
					<el-option :key="3" :value="3" label="公共交通"/>
				</el-select>
			</el-form-item>
			<el-form-item label="时令" prop="seasonsType">
				<el-select v-model="dataForm.seasonsType" placeholder="请选择" clearable>
					<el-option label="请选择"/>
					<el-option :key="1" :value="1" label="夏令时"/>
					<el-option :key="2" :value="2" label="冬令时"/>
				</el-select>
			</el-form-item>
			<el-form-item label="时段" prop="timeIntervalType">
				<el-select v-model="dataForm.timeIntervalType" placeholder="请选择" clearable>
					<el-option label="请选择"/>
					<el-option :key="1" :value="1" label="白天"/>
					<el-option :key="2" :value="2" label="夜间"/>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button @click="getDataList()">查询</el-button>
				<!-- <el-button v-if="isAuth('travelConf:main:save')" type="primary" @click="addOrUpdateHandle(1)">新增</el-button> -->
<!--				 <el-button v-if="isAuth('travelConf:main:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
			</el-form-item>
		</el-form>
		<el-table :data="dataList" border v-loading="dataListLoading" @selection-change="selectionChangeHandle" style="width: 100%;">
			<el-table-column type="selection" header-align="center" align="center" width="50"/>

			<!-- <el-table-column prop="createTime" header-align="center" align="center" width="180" label="新增时间"/> -->
			<el-table-column prop="updateTime" header-align="center" align="center" width="180" label="修改时间"/>
			<el-table-column prop="pricingType" header-align="center" align="center" label="价格类型">
				<template slot-scope="scope">
					<span v-if="scope.row.pricingType == 1" class="people">固定价格</span>
					<span v-if="scope.row.pricingType == 2" class="people">动态价格</span>
				</template>
			</el-table-column>
			<el-table-column prop="travelType" header-align="center" align="center" label="出行方式">
				<template slot-scope="scope">
					<span v-if="scope.row.travelType == 1" class="people">公交</span>
					<span v-if="scope.row.travelType == 2" class="people">出租</span>
					<span v-if="scope.row.travelType == 3" class="people">免费</span>
				</template>
			</el-table-column>
			<el-table-column prop="seasonsType" header-align="center" align="center" label="时令">
				<template slot-scope="scope">
					<span v-if="scope.row.seasonsType == 1" class="people">夏令时</span>
					<span v-if="scope.row.seasonsType == 2" class="people">冬令时</span>
				</template>
			</el-table-column>
			<el-table-column prop="timeIntervalType" header-align="center" align="center" label="时段">
				<template slot-scope="scope">
					<span v-if="scope.row.timeIntervalType == 1" class="people">白天</span>
					<span v-if="scope.row.timeIntervalType == 2" class="people">夜间</span>
				</template>
			</el-table-column>
			<!-- <el-table-column prop="freeKilometers" header-align="center" align="center" width="180" label="起步价（元）"/> -->
			<el-table-column prop="nightTravelExpenses" header-align="center" align="center" width="140" label="夜间出行费（元）"/>
			<el-table-column prop="startingPrice" header-align="center" align="center" width="140" label="起步价格（元）"/>
			<el-table-column prop="freeKilometers" header-align="center" align="center" width="140" label="起步公里数"/>
			<el-table-column prop="pricePerKilometer" header-align="center" align="center" width="140" label="每公里价格（元）"/>
			<el-table-column prop="fixedType" header-align="center" align="center" label="固定价格往返">
				<template slot-scope="scope">
					<span v-if="scope.row.fixedType == 1" class="people">往返</span>
					<span v-if="scope.row.fixedType == 2" class="people">单程</span>
				</template>
			</el-table-column>
			<el-table-column prop="fixedPrice" header-align="center" align="center" width="140" label="固定价格（元）"/>
			<el-table-column fixed="right" header-align="center" align="center" width="120" label="操作">
				<template slot-scope="scope">
					<el-button v-if="isAuth('travelConf:main:update')" type="text" size="small" @click="addOrUpdateHandle(1,scope.row.id,scope.row.parentId)">修改</el-button>
					<!-- <el-button v-if="isAuth('travelConf:main:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button> -->
				</template>
			</el-table-column>
		</el-table>
		<el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex" :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage" layout="total, sizes, prev, pager, next, jumper"/>
		<!-- 弹窗, 新增 / 修改 -->
		<add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"/>

	</div>
</template>

<script>
	import AddOrUpdate from './add-or-update'
	export default {
		data() {
			return {
				dataForm: {
					name: ''
				},
				dataList: [],
				dataListEr:{},
				pageIndex: 1,
				pageSize: 10,
				totalPage: 0,
				dataListLoading: false,
				dataListLoadingEr:false,
				dataListSelections: [],
				addOrUpdateVisible: false,
				dialogFormVisible:false,
				parentId:0
			}
		},
		components: {
			AddOrUpdate
		},
		activated() {
			this.getDataList()
		},
		methods: {
			// 获取数据列表
			getDataList() {
				this.dataListLoading = true
				this.$http({
					url: this.$http.adornUrl('travelConf/list'),
					method: 'get',
					params: this.$http.adornParams({
						'page': this.pageIndex,
						'limit': this.pageSize,
						...this.dataForm,
					})
				}).then(({ data: rdata }) => {
					console.log(rdata);
					let { code, data } = rdata || {};
					let { records, total } = data || {};
					if(code === 0){
						this.dataList = records;
						this.totalPage = total;
					} else {
						this.dataList = []
						this.totalPage = 0
					}
					this.dataListLoading = false
				})
			},
			// 每页数
			sizeChangeHandle(val) {
				this.pageSize = val
				this.pageIndex = 1
				this.getDataList()
			},
			// 当前页
			currentChangeHandle(val) {
				this.pageIndex = val
				this.getDataList()
			},
			// 多选
			selectionChangeHandle(val) {
				this.dataListSelections = val
			},
			// 新增 / 修改
			addOrUpdateHandle(index,id) {
				this.addOrUpdateVisible = true
				this.$nextTick(() => {
					this.$refs.addOrUpdate.init(index,id)
				})
			},
			// 删除
			deleteHandle(id) {
				// let ids = (id ? [id] : this.dataListSelections.map(item => item.id)).join(',');
				// this.$confirm(`确定[${id ? '删除' : '批量删除'}]操作?`, '提示', {
				// 	confirmButtonText: '确定',
				// 	cancelButtonText: '取消',
				// 	type: 'warning'
				// }).then(() => {
				// 	this.$http({
				// 		url: this.$http.adornUrl('travelConf/deleteById' + (id?'':'s')),
				// 		method: 'delete',
				// 		params: this.$http.adornParams({ id: ids}, false)
				// 	}).then(({ data }) => {
				// 		if (data && data.code === 0) {
				// 			this.$message({
				// 				message: '操作成功',
				// 				type: 'success',
				// 				duration: 1500,
				// 				onClose: () => {
				// 					this.getDataList()
				// 				}
				// 			})
				// 		} else {
				// 			this.$message.error(data.msg)
				// 		}
				// 	})
				// }).catch(() => {})

				this.$http({
					url: this.$http.adornUrl('travelConf/getTaxiMoney'),
					method: 'get',
					params: this.$http.adornParams({ artificerId: 116,toLongitude:"125.423736",toLatitude:"43.878001"}, false)
				}).then(({ data }) => {
					if (data && data.code === 0) {
						console.log(data.data);
					} else {
						this.$message.error(data.msg)
					}
				})
			}
		}
	}
</script>
