<template>
	<div>
		<el-dialog custom-class="bbsl-location-dialog" top="10vh" :close-on-click-modal="false" :title="title+'（水位库容）'"
			:visible.sync="showFormDia" width="80%" :before-close="handleClose">
			<el-form ref="formInfo" :model="params" label-width="150px">
				<el-row>
				<el-col :span="8">
						<el-form-item label="水库名称：" prop="waterName">
							<el-select style="width: 100%" size="mini" disabled v-model="params.rscd" clearable
								placeholder="请选择水库名称">
								<el-option v-for="item in waterList" :key="item.id" :label="item.rsnm"
									:value="item.rscd"></el-option>
							</el-select>
						</el-form-item>
					</el-col>	
					
                 <el-col :span="8">
                <el-form-item label="水库水位(m)：" prop="rslv">
                  <el-input
                    @input="deadLevs('2')"
                    style="width: 100%"
                    size="mini"
                    clearable
                    placeholder="请输入水库水位"
                    v-model="params.rslv"
                  ></el-input>
                </el-form-item>
              </el-col>   
				<el-col :span="8">
                <el-form-item label="水库库容(万m3)：" prop="rstpc">
                  <el-input
                    @input="deadLevs('1')"
                    style="width: 100%"
                    size="mini"
                    clearable
                    placeholder="请输入水库库容"
                    v-model="params.rstpc"
                  ></el-input>
                </el-form-item>
              </el-col>
				</el-row>
			
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="goInfo">保 存</el-button>
				<el-button @click="handleClose">取 消</el-button>
			</span>
		</el-dialog>
	</div>

</template>

<script>
    import req from '@/request.js'
    import latitude from '@/mixins/latitude'
	import capacity from '@/api/reservoirManagement/resFrom.js'
	import {
		mapState
	} from 'vuex'
	export default {
		props: {
			showFormDia: {
				type: Boolean,
				default: false,
			},
			title: {
				type: String,
				default: '',
			},
			wId: {
				type: String,
				default: '',
			},
			plId: {
				type: String,
				default: '',
			},
		},
		data() {
			return {
				params: {
                    rstpc: null,
                    rslv:null,
					rsnm:null
                },
				waterList: [],
                
			}
		},
		created() {
            this.getDetailInfo()
            this.getWaters()
		},
		methods: {
            getWaters() {
				capacity.getWater({}, (res) => {
					this.waterList = res.value
					this.waterList.forEach((ee) => {
						if (this.wId == ee.id) {
							this.params.rscd = ee.rscd
							this.params.rsnm = ee.rsnm
						}
					})
				})
			},
        deadLevs(val) {
        switch (val) {
        case '1':
          this.params.rstpc = latitude.SixTree(this.params.rstpc)
          break
           case '2':
          this.params.rslv = latitude.SixTree(this.params.rslv)
          break
      }
    },
			handleClose() {
				this.params = {}
				this.$emit('closeFormDiao')
			},

		
			//保存
			goInfo(e) {
				this.$refs.formInfo.validate((valid) => {
					if (valid) {
						if (this.title === '新增') {
							let arr = JSON.parse(JSON.stringify(this.params))
							capacity.addcapacity(this.params, (response) => {
								if (response.state) {
									this.$notify({
										type: 'success',
										message: '新增成功',
										duration: 2000,
									})
									this.$emit('closeFormDiao')
									this.$emit('refList')
								} else {}
							})
						}
						if (this.title === '修改') {
							capacity.upDataConcapacity(this.params, (response) => {
								if (response.state) {
									this.$notify({
										type: 'success',
										message: '修改成功',
										duration: 2000,
									})
									this.$emit('closeFormDiao')
									this.$emit('refList')
								} else {}
							})
						}
					} else {
						return false
					}
				})
			},
			//取消
			handleClose() {
				this.params = {}
				this.$emit('closeFormDiao')
			},
			//修改查询
			getDetailInfo() {
				if (this.title === '修改') {
					capacity.detailIdConcapacity(this.plId, (res) => {
						if (res.state) {
							this.params.rstpc = res.value.rstpc
							this.params.rslv = res.value.rslv
							this.params.rsnm = res.value.rsnm
							this.params.id = res.value.id
							this.params.pkVal = res.value.pkVal
						}
					})
				} else {

				}
			},
		
		}
	}
</script>

<style>

</style>
