<template>
	<view class="content">
		<view class="card">
			<u-radio-group v-model="selete_corp" placement="column">
				<u-radio :customStyle="{marginBottom: '20upx'}" v-for="(item, index) in list" :key="item.CORPINFO_ID"
					:label="item.CORP_NAME" :name="item.CORPINFO_ID">
				</u-radio>
			</u-radio-group>
			<view class="button_placeholder"></view>
			<view class="button">
				<u-button type="primary" text="确定" @click="fnConfirm"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getCorpInfoList
	} from '../../api/index'

	export default {
		data() {
			return {
				type: '',
				list: [],
				selete_corp: ''
			}
		},
		onLoad(options) {
			this.type = options.type
			this.fnGetData()
		},
		methods: {
			async fnGetData() {
				const resData = await getCorpInfoList()
				this.list = resData.data
			},
			fnConfirm() {
				if (!this.selete_corp) {
					uni.$u.toast('请选择作业分公司')
					return;
				}
				const urlByTypeMap = {
					'confined_space': {
						'035958e685cf4850bc40151c5e0617a6': '',
						'default': '/pages/eight_assignments/confined_space/apply'
					}
				}
				const url = urlByTypeMap[this.type][this.selete_corp] ?? urlByTypeMap[this.type].default
				let params = {}
				for (let i = 0; i < this.list.length; i++) {
					if (this.list[i].CORPINFO_ID === this.selete_corp) {
						params = {
							CORPINFO_ID: this.list[i].CORPINFO_ID,
							CORP_NAME: this.list[i].CORP_NAME,
						}
						break
					}
				}
				uni.$u.route({
					url,
					type: 'redirect',
					params
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.button_placeholder {
		height: 100upx;
	}

	.button {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
	}
</style>