<template>
	<div>
		<avue-crud
			:data="tableData"
			v-model:page="page"
			@current-change="currentChange"
			@size-change="sizeChange"
			:table-loading="loading"
			@on-load="onLoad"
			@search-change="searchChange"
			:option="option"
			>
			<template #id="{row}">
				<el-radio :label="row.id" v-model="radio" style="margin-right: -10px;">&nbsp;</el-radio>
			</template>
		</avue-crud>

		<footer class="el-dialog__footer">
			<el-button icon="el-icon-circle-plus" type="primary" @click="submitDispatchForm">确 定</el-button>
		  <el-button icon="el-icon-circle-close" @click="cancel">取 消</el-button>
		</footer>
	</div>
</template>

<script>
	import {getAllList as getServiceList} from "@/api/systemSet/service";
	import {bindingSite} from "@/api/nh/powerStation";
	import {mapGetters} from "vuex";
	export default {
		props:{
			selectionList: {
				type: Array,
				default: []
			}
		},
		data () {
			return {
				loading:false,
				query:{},
				tableData:[],
				page: {
				  pageSize: 10,
				  currentPage: 1,
					total:0,
					layout:'prev, pager, next, ->',
				},
				radio:'',
				option:{
					menu:false,
					border:true,
					searchSpan:19,
					searchMenuSpan:5,
					searchMenuPosition:'right',
					searchGutter:0,
					searchLabelWidth:88,
					emptyBtn:false,
					header:false,
					column:[
						{
							label: '服务商名称',
							prop: 'name',
							search:true
						},
						{
							label: '选择',
							prop: 'id',
							width: 65,
							slot:true,
							fixed:'right',
							align:'center'
						},
					],
				},
			}
		},
		computed:{
			...mapGetters(["userInfo"]),
		},
		methods:{
			cancel(){
				this.$emit('childSubmit','cancel');
			},
			onLoad() {
				this.loading = true;
				getServiceList(this.query).then(res=>{
					this.tableData = res.data.data
					// this.page.total = res.data.data.total;
					this.loading = false;
				});
			},
			searchChange(params, done) {
			  this.query = params;
			  this.page.currentPage = 1;
			  this.onLoad();
			  done();
			},
			currentChange(currentPage){
			  this.page.currentPage = currentPage;
			},
			sizeChange(pageSize){
			  this.page.pageSize = pageSize;
			},
			submitDispatchForm(){
				// return
				if(!this.radio){
					this.$message.warning("请选择至少一条数据");
					return
				}
				bindingSite({
					// id:this.selectionList[0].id,
					id:this.selectionList.map(item=>item.id).join(','),
					omProviderId:this.radio
				}).then(res => {
					this.$message({
						type: 'success',
						message: '操作成功!',
					});
					this.$emit('childSubmit');
				}, error => {
					window.console.log(error);
				});

			},
		}
	}
</script>

<style>
</style>
