<template>
	<view class="zd_container">
		<nav-bar title="点位管理"></nav-bar>
		<view class="zd_content">
			<view class="item-wrapper">
				<view class="item-wrap" v-for="(e, i) in dataList" :key="i" @tap="toCheck(e)">
					<view class="zd-row">
						<view class="zd-row jccenter unchecked" :class="{'checked-filled': e.group_id === pkId}">
							<uni-icons type="checkmarkempty" size="20" color="#fff"></uni-icons>
						</view>
						<view class="zd-col-21">
							<view class="zd-row">
								<view class="zd-col-24 item-font-1">{{e.point_code}}</view>
							</view>
							<view class="zd-row">
								<view class="zd-col-24 item-font-4">{{e.vehicle_name}}</view>
							</view>
							<view class="zd-row">
								<view class="zd-col-24 item-font-3">{{e.material_qty}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar_new">
			<button class="zd-col-11 submit-button_new" @tap="_getGhsPointList">查询</button>
			<button class="zd-col-11 submit-button_new" :class="{'btn-disabled': !pkId}" :disabled="disabled" @tap="_changePointQty">更改固化室库存</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {getGhsPointList, changePointQty} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				dataList: [],
				disabled: false,
				pkId: ''
			};
		},
		created () {
			this._getGhsPointList()
		},
		methods: {
			async _getGhsPointList () {
				let res = await getGhsPointList()
				this.dataList = [...res]
			},
			toCheck (e) {
				this.pkId = e.group_id === this.pkId ? '' : e.group_id
			},
			async _changePointQty () {
				this.disabled = true
				if (!this.pkId) {
					this.disabled = false
					return
				}
				try {
					let res = await changePointQty(this.pkId)
					this.disabled = false
					this.pkId = ''
					this._getGhsPointList()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style lang="stylus" scoped>
.item-font-1
	font-size 36rpx
	color #333
	font-weight 700
	padding 0
.item-font-4
	color #999
.item-font-3
	font-size 36rpx
	background-color transparent
	text-align left
</style>
