按钮
<div class="xe-addbtn-panel">
<el-button type="primary" @click="addCapacity">新增运力池</el-button>
</div>
<el-button @click.native.prevent="edit(scope.row)" type="text" size="small">编辑</el-button>
点击按钮显示窗口
addCapacity() {
this.formVisible = true;
this.dialogTitle = '新增运力池';
},
edit(scope) {
let id = scope.id;
this.dialogTitle = '编辑运力池';
let _this = this;
_this.$http({
method: 'POST',
url: getHomeProjectLink().rmcApiBaseUrl + `/page/rmc/transpool/main/xxxx/${id}`
}).then((res) => {
console.log(res);
_this.formVisible = true;
_this.capacityForm = {
'name': res.result.name,
'effectiveTime': res.result.effectiveTime,
'description': res.result.description,
'id': id
};
}).catch((err) => {
console.log(err);
});
},
submitCapacity(form) {
this.$refs[form].validate((valid) => {
if (valid) {
let _this = this;
if (_this.capacityForm.id === '') {
_this.$http({
method: 'POST',
url: getHomeProjectLink().rmcApiBaseUrl + '/page/rmc/transpool/add/xxx',
data: _this.capacityForm
}).then((res) => {
_this.formVisible = false;
_this.queryData();
}).catch((err) => {
console.log(err);
});
} else {
_this.$http({
method: 'POST',
url: getHomeProjectLink().rmcApiBaseUrl + '/page/rmc/transpool/modify/xxxx',
data: _this.capacityForm
}).then((res) => {
_this.formVisible = false;
_this.queryData();
}).catch((err) => {
console.log(err);
});
}
}
});
窗体 html
<el-dialog title="窗口名称" :visible.sync="formVisible" @close="resetCapacity('capacityForm')" class="capacity">
<el-form :model="capacityForm" :label-width="xeLabelWidth" ref="capacityForm" :rules="capacityRules">
<el-form-item label="运力池" prop="name">
<el-input v-model.trim="capacityForm.name" class="xe-input3-col3"></el-input>
</el-form-item>
<el-form-item label="锁定时间(分钟)" prop="effectiveTime">
<el-input v-model.trim="capacityForm.effectiveTime" class="xe-input3-col3"></el-input>
</el-form-item>
<el-form-item label="描述信息" prop="description">
<el-input type="textarea" v-model.trim="capacityForm.description" class="xe-input3-col3"></el-input>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="formVisible = false">取 消</el-button>
<el-button type="primary" @click="submitCapacity('capacityForm')">确 定</el-button>
</div>
</el-dialog>
备注
visible.sync 为true 就显示窗口 false关闭窗口
@close="resetCapacity('capacityForm')" 关闭的时候要重置表单