<template>
    <div class="updateTerminalDialog">
        <el-dialog center width="636px" title="修改车载终端" :visible.sync="updataTerminalData.dialogVisible">
            <el-form label-width="110px" ref="ruleForm" :rules="rules" :model="updataTerminalData.data">
                <el-form-item label="车载终端编码" prop="terminalCode">
                    <el-input placeholder="请输入车载终端编码" v-model="updataTerminalData.data.terminalCode"></el-input>
                </el-form-item>
                <el-form-item label="车载终端名称" prop="terminalName">
                    <el-input placeholder="请输入车载终端名称" v-model="updataTerminalData.data.terminalName"></el-input>
                </el-form-item>
                <!-- <el-form-item label="状态" prop="status">
                    <el-radio v-model="updataTerminalData.data.status" label="1">在线</el-radio>
                    <el-radio v-model="updataTerminalData.data.status" label="2">离线</el-radio>
                </el-form-item> -->
                <!-- <el-form-item label="终端经度" prop="terminalLongitude">
                    <el-input type="number" max="90" placeholder="请输入终端经度" v-model="updataTerminalData.data.terminalLongitude"></el-input>
                </el-form-item>
                <el-form-item label="终端纬度" prop="terminalLatitude">
                    <el-input type="number" max="180" placeholder="请输入终端纬度" v-model="updataTerminalData.data.terminalLatitude"></el-input>
                </el-form-item> -->
                <el-form-item label="备注">
                    <el-input v-model="updataTerminalData.data.remark" type="textarea" autocomplete="off" placeholder="请输入备注" maxlength="200"
                        show-word-limit />
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <div class="search" @click="updateTerminal">保 存</div>
                <div class="reset" @click="reset">取 消</div>
            </span>
        </el-dialog>
    </div>
</template>
<script>
export default {
    props: {
        updataTerminalData: {
            type: Object,
            default: {}
        }
    },
    data() {
        return {            
            rules: {
                terminalCode: [{ required: true, message: '请输入车载终端编码', trigger: 'blur' },],
                terminalName: [{ required: true, message: '请输入车载终端名称', trigger: 'blur' }],
                status: [{ required: true, message: '请选择状态', trigger: 'blur' }],
                terminalLongitude: [{ required: true, message: '请输入终端经度', trigger: 'blur' }],
                terminalLatitude: [{ required: true, message: '请输入终端纬度', trigger: 'blur' }],
            }
        }
    },
    watch:{
        'updataTerminalData.data.terminalLongitude': function (newval, oldval) {
			   var reg = /^(\d{0,3})(\.(\d{0,13}))?$/g;
				if (!reg.test(newval)) {
					if (newval == undefined || newval == null ) {
						this.updataTerminalData.data.terminalLongitude = '';
						return;
					}
					this.updataTerminalData.data.terminalLongitude = oldval
				} else {
					this.updataTerminalData.data.terminalLongitude = newval.replace(/^\./g, "")
				}				
			},
            'updataTerminalData.data.terminalLatitude': function (newval, oldval) {
			   var reg = /^(\d{0,3})(\.(\d{0,13}))?$/g;
				if (!reg.test(newval)) {
					if (newval == undefined || newval == null ) {
						this.updataTerminalData.data.terminalLatitude = '';
						return;
					}
					this.updataTerminalData.data.terminalLatitude = oldval
				} else {
					this.updataTerminalData.data.terminalLatitude = newval.replace(/^\./g, "")
				}				
			}
    },
    methods: {
        updateTerminal() {
            this.$refs.ruleForm.validate(valid => {
                if (valid) {
                    this.$emit("updateTerminalBtn", this.updataTerminalData.data)
                }
            })
        },
        reset() {            
            this.updataTerminalData.dialogVisible = false
        }
    }
}
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
    padding: 20px 95px !important;
}
::v-deep .el-textarea .el-input__count {
  bottom: -40px;
}
</style>