This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nezha-nezha-fronted/nezha-fronted/src/components/common/rightBox/dcBox.vue

221 lines
7.8 KiB
Vue
Raw Normal View History

2020-02-21 17:57:19 +08:00
<template>
2021-01-18 18:58:57 +08:00
<div class="right-box right-box-dc" v-clickoutside="{obj:editDc,func:clickOutside}">
2020-02-21 17:57:19 +08:00
<!-- begin--顶部按钮-->
2020-10-15 14:27:46 +08:00
<div class="right-box-top-btns right-box-form-delete">
<button @click="del" class="nz-btn nz-btn-size-normal nz-btn-size-alien" id="dc-del" type="button" v-has="'dc_delete'" v-if="editDc.id">
2020-09-10 17:00:32 +08:00
<span class="right-box-top-btn-icon"><i class="nz-icon nz-icon-delete"></i></span>
2020-02-21 17:57:19 +08:00
<span class="right-box-top-btn-txt">{{$t('overall.delete')}}</span>
</button>
</div>
<!-- end--顶部按钮-->
<!-- begin--标题-->
<div class="right-box-title">{{editDc.id ? ($t("config.dc.editDc") + " ID" + editDc.id) : $t("config.dc.createDc")}}</div>
2020-02-21 17:57:19 +08:00
<!-- end--标题-->
<!-- begin--表单-->
2020-12-14 20:25:24 +08:00
<div class="right-box-form-box">
2021-03-25 19:33:48 +08:00
<el-form class="right-box-form right-box-form-left" label-width="120px" size="small" :model="editDc" label-position = "top" :rules="rules" ref="dcForm">
2020-02-21 17:57:19 +08:00
<el-form-item :label='$t("overall.name")' prop="name">
2021-02-04 11:21:00 +08:00
<el-input placeholder="" maxlength="64" show-word-limit v-model="editDc.name" size="small" id="dc-box-input-name"></el-input>
2020-02-21 17:57:19 +08:00
</el-form-item>
<el-form-item :label='$t("asset.location")' prop="location">
2021-02-04 11:21:00 +08:00
<el-input placeholder="" v-model="editDc.location" size="small" id="dc-box-input-location"></el-input>
2020-02-21 17:57:19 +08:00
</el-form-item>
<el-form-item :label='$t("asset.tel")' prop="tel">
2021-02-04 11:21:00 +08:00
<el-input placeholder="" v-model="editDc.tel" size="small" id="dc-box-input-tel"></el-input>
</el-form-item>
<el-form-item :label='$t("asset.principal")' prop="principal">
2021-02-04 11:21:00 +08:00
<el-select value-key="id" popper-class="config-dropdown" v-model="editDc.principal" placeholder="" size="small" id="dc-box-input-principal">
2021-03-19 18:52:19 +08:00
<el-option v-for="item in userData" :id="'dc-principal-op-'+item.userId" :key="item.userId" :label="item.username" :value="item.userId">
<span>{{item.username}}</span>
</el-option>
</el-select>
</el-form-item>
<!--<el-form-item :label='$t("config.dc.area")' prop="area">-->
<!--<select-area ref="selectArea" :areaData="areaData" :placement="'bottom-start'" @selectArea="selectArea" :currentArea="editDc.area.id">-->
<!--<template v-slot:trigger>-->
<!--<el-input placeholder="" v-model="editDc.area.name" size="small" readonly="readonly" @click.native="toSelectArea"></el-input>-->
<!--</template>-->
<!--</select-area>-->
<!--</el-form-item>-->
2021-03-25 19:33:48 +08:00
<el-form-item :label="$t('config.dc.lnglat')" prop="state">
<latlng-picker ref="latlngPicker" :append-to-body="false" :show-zoom="false"></latlng-picker>
</el-form-item>
<el-form-item :label='$t("config.dc.state")' prop="state">
2020-11-11 14:30:34 +08:00
<el-switch
2021-02-04 11:21:00 +08:00
id="dc-box-input-name"
2020-11-11 14:30:34 +08:00
v-model="editDc.state"
active-value="ON"
inactive-value="OFF"
active-color="#ee9d3f"
>
</el-switch>
</el-form-item>
2021-03-25 19:33:48 +08:00
2020-02-21 17:57:19 +08:00
</el-form>
2020-12-14 20:25:24 +08:00
</div>
2020-02-21 17:57:19 +08:00
<!--底部按钮-->
<div class="right-box-bottom-btns">
2021-01-18 18:58:57 +08:00
<button v-cancel="{obj:editDc,func:esc}" id="dc-box-esc" class="nz-btn nz-btn-size-normal-new nz-btn-style-light-new">
2020-02-21 17:57:19 +08:00
<span>{{$t('overall.cancel')}}</span>
</button>
2021-01-21 17:29:29 +08:00
<button :class="{'nz-btn-disabled':prevent_opt.save}" :disabled="prevent_opt.save" @click="save" class="nz-btn nz-btn-size-normal-new nz-btn-style-normal-new" id="dc-box-save">
2020-02-21 17:57:19 +08:00
<span>{{$t('overall.save')}}</span>
</button>
</div>
2020-02-24 20:27:14 +08:00
2020-02-21 17:57:19 +08:00
</div>
</template>
<script>
2021-03-25 19:33:48 +08:00
import latlngPicker from "../latlngPicker";
2021-03-19 18:52:19 +08:00
const regNum = /^[0-9]+.?[0-9]*/
export default {
name: 'dcBox',
2021-03-25 19:33:48 +08:00
components:{latlngPicker},
2021-03-19 18:52:19 +08:00
props: {
dc: Object,
userData: Array
},
data () {
return {
editDc: {},
rules: {
name: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
],
state: [
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
]
},
areaData: [],
coordinateFlag: false
}
},
methods: {
/* 关闭弹框 */
esc (refresh) {
this.prevent_opt.save = false
this.$emit('close', refresh)
2020-02-21 17:57:19 +08:00
},
2021-03-19 18:52:19 +08:00
clickOutside () {
this.esc(false)
2020-07-16 17:33:20 +08:00
},
2021-03-19 18:52:19 +08:00
/* 弹出选择area弹框 */
toSelectArea () {
this.$refs.selectArea.openBox(this.editDc.area)
2020-02-21 17:57:19 +08:00
},
2020-02-24 20:27:14 +08:00
2021-03-19 18:52:19 +08:00
/* 保存 */
2021-03-25 19:33:48 +08:00
save: function () {
if (this.prevent_opt.save) {
return
}
;
2021-03-19 18:52:19 +08:00
this.prevent_opt.save = true
this.$refs.dcForm.validate((valid) => {
if (valid) {
if (this.editDc.id) {
2021-03-25 19:33:48 +08:00
const param = {...this.editDc}
let attr = this.$refs.latlngPicker.getAttribute();
param.latitude = attr.latitude;
param.longitude = attr.longitude;
2021-03-19 18:52:19 +08:00
this.$put('idc', param).then(response => {
this.prevent_opt.save = false
if (response.code === 200) {
2021-03-25 19:33:48 +08:00
this.$message({duration: 1000, type: 'success', message: this.$t('tip.saveSuccess')})
2021-03-19 18:52:19 +08:00
this.esc(true)
} else {
this.$message.error(response.msg)
}
2021-03-19 18:52:19 +08:00
})
2020-02-21 17:57:19 +08:00
} else {
2021-03-25 19:33:48 +08:00
const param = {...this.editDc}
2021-03-19 18:52:19 +08:00
if (param.area) {
param.areaId = param.area.id
2020-02-21 17:57:19 +08:00
}
2021-03-19 18:52:19 +08:00
if (!regNum.test(param.longitude)) {
param.longitude = null
}
if (!regNum.test(param.latitude)) {
param.latitude = null
}
this.$post('idc', param).then(response => {
this.prevent_opt.save = false
if (response.code === 200) {
2021-03-25 19:33:48 +08:00
this.$message({duration: 1000, type: 'success', message: this.$t('tip.saveSuccess')})
2021-03-19 18:52:19 +08:00
this.esc(true)
} else {
this.$message.error(response.msg)
}
})
}
} else {
this.prevent_opt.save = false
return false
}
2021-03-19 18:52:19 +08:00
})
2020-02-21 17:57:19 +08:00
},
2021-03-19 18:52:19 +08:00
/* 删除 */
del () {
if (this.prevent_opt.save) { return } ;
this.prevent_opt.save = true
this.$confirm(this.$t('tip.confirmDelete'), {
confirmButtonText: this.$t('tip.yes'),
cancelButtonText: this.$t('tip.no'),
type: 'warning'
}).then(() => {
this.$delete('idc?ids=' + this.editDc.id).then(response => {
this.prevent_opt.save = false
if (response.code === 200) {
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.deleteSuccess') })
this.esc(true)
} else {
this.$message.error(response.msg)
}
})
}).catch(() => {
this.prevent_opt.save = false
})
2020-02-21 17:57:19 +08:00
},
2021-03-19 18:52:19 +08:00
// getAreaData() {
// this.$get('area', {pid: 0}).then(response => {
// if (response.code === 200) {
// this.areaData = response.data.list;
// }
// });
// },
selectArea (area) {
this.editDc.area.id = area.id
this.editDc.area.name = area.name
},
coordinateChange (val, str) { // 经纬度改变
if (regNum.test(this.editDc.longitude) || regNum.test(this.editDc.latitude)) {
this.coordinateFlag = true
} else {
this.coordinateFlag = false
this.$refs.dcForm.clearValidate(['longitude', 'latitude'])
}
}
},
mounted () {
// this.getAreaData();
},
watch: {
dc: {
immediate: true,
deep: true,
handler (n, o) {
this.editDc = JSON.parse(JSON.stringify(n))
2021-03-25 19:33:48 +08:00
this.$nextTick(()=>{
this.$refs.latlngPicker.setLnglat(this.editDc.latitude,this.editDc.longitude);
})
2021-03-19 18:52:19 +08:00
}
2020-02-21 17:57:19 +08:00
}
}
2021-03-19 18:52:19 +08:00
}
2020-02-21 17:57:19 +08:00
</script>