<template>
    <div>
        <div class="layout-cont-btn">
            <van-form ref="form" @submit="onSubmit">
                <van-field
                        v-model="formObj.name"
                        name="name"
                        required
                        label="地点"
                        placeholder="请输入地点"
                        :rules="[{ required: true, message: '' }]">
                </van-field>
                <van-field
                        v-model="formObj.address"
                        name="address"
                        label="地址"
                        placeholder="请输入地址">
                </van-field>
                <van-field
                        v-model="formObj.longitude"
                        name="longitude"
                        label="经度"
                        placeholder="请输入经度">
                </van-field>
                <van-field
                        v-model="formObj.latitude"
                        name="latitude"
                        label="纬度"
                        placeholder="请输入纬度">
                </van-field>
            </van-form>
        </div>
        <div class="bottom-btn">
            <van-button type="info" block @click="_save">保存</van-button>
        </div>
    </div>
</template>

<script>
    import {samplingPlace} from '../../../api'

    export default {
        name: "LocAdd",
        data() {
            return {
                formObj: {
                    name: '',
                    address: '',
                    longitude: '',
                    latitude: '',
                },
                planId: ''
            }
        },
        mounted() {
            this.planId = this.$route.query.planId
        },
        methods: {
           _save(){
               this.$refs.form.submit()
           },
            onSubmit(){
              this._saveOk()
            },
            _saveOk: async function () {
                let obj = {...this.formObj, ...{planId: this.planId}}
                let result = await samplingPlace.add(this.$serializeForm(obj))
                if (result) {
                    this.$toast('操作成功！')
                    this.$router.go(-1)
                }
            }
        }
    }
</script>

<style scoped>

</style>
