<template>
	<view class="zd_container">
		<!-- <nav-bar title="穿拔轴初始化"></nav-bar> -->
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item is-required">
					<view class="filter_label_wraper">
						<span class="filter_label">{{$t('filter.point')}}</span>
					</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index" :placeholder="$t('uni.dataSelect.placeholder')" :localdata="options" @change="selectChange"></uni-data-select>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label filter_label_1"></span>
					</view>
					<view class="filter_input_wraper filter_input_wraper_1">
						<view class="iconfont icon_unchecked" :class="{'icon_checked': isV === '1'}" @tap="isVirtual">&#xe66b;</view>
						<view class="filter_input_wraper_inn_text">{{$t('filter.ifreinstallshaft')}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submitbar">
			<button class="zd-col-22 btn-submit btn-success" :class="{'btn-info': !index}" :disabled="disabled" @tap="handleConfirm">{{$t('button.confirm')}}</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import { confirmAction } from '@/utils/utils.js'
	import {getShaftPoint, doInitShaftPoint} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				options: [],
				index: '',
				disabled: false,
				isV: '1'
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		created () {
			this._getShaftPoint()
		},
		methods: {
			isVirtual () {
				this.isV = this.isV === '0' ? '1' : '0'
			},
			async _getShaftPoint () {
				let res = await getShaftPoint()
				this.options = [...res]
			},
			selectChange (e) {
				this.index = e
			},
			async handleConfirm() {
				if (!this.index) {
					return
				}
				const isConfirmed = await confirmAction(this.$t('toast.prompt'), this.$t('toast.sure-perform-operation'))
				if (isConfirmed) {
					this._doInitShaftPoint()
				}
			},
			async _doInitShaftPoint () {
				this.disabled = true
				try {
					let res = await doInitShaftPoint(this.index, this.isV)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.index = ''
					this.disabled = false
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>