bick_back/src/views/system/model/index.vue
2024-11-08 09:38:40 +08:00

500 lines
17 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="代理商" prop="deptId" v-if="userName == 'admin' && !deptId">
<el-select v-model="queryParams.operator" filterable placeholder="选择代理商" clearable>
<el-option
v-for="item in deptOptions"
:key="item.deptId"
:label="item.deptName"
:value="item.deptId"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="车型" prop="model">
<el-input
v-model="queryParams.model"
placeholder="请输入车型"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['system:model:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['system:model:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['system:model:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['system:model:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="modelList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="车型" align="center" prop="model" />
<!-- <el-table-column label="代理商" align="center" prop="operatorName" /> -->
<el-table-column label="代理商" align="center" :show-overflow-tooltip="true">
<template slot-scope="scope">
<router-link :to="'/system/deptDetail/index/' + scope.row.operator" class="link-type">
<span>{{scope.row.operatorName}}</span>
</router-link>
</template>
</el-table-column>
<el-table-column label="运营区" align="center" prop="areaName" />
<el-table-column label="满电电压(V)" align="center" prop="fullVoltage" />
<el-table-column label="亏电电压(V)" align="center" prop="lowVoltage" />
<el-table-column label="满电续航(km)" align="center" prop="fullEndurance" />
<el-table-column label="骑行低电量提醒(%)" align="center" prop="lowBatteryReminder" />
<!-- 新增低电量提醒开关 -->
<el-table-column label="低电量提醒开关" align="center">
<template slot-scope="scope">
<el-switch
v-model="scope.row.lowBatteryReminderSwitch"
:active-value="true"
:inactive-value="false"
@change="handleLowBatteryReminderSwitchChange(scope.row)"
></el-switch>
</template>
</el-table-column>
<el-table-column label="已投放车辆" align="center" prop="deviceNum" />
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
</template>
</el-table-column>
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['system:model:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['system:model:remove']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改车辆型号对话框 -->
<el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="车型" prop="model">
<el-input v-model="form.model" placeholder="请输入车型" />
</el-form-item>
<el-form-item v-if="userName == 'admin'" label="代理商" prop="operator">
<el-select v-model="form.operator" style="width: 100%" clearable placeholder="请选择代理商">
<el-option
v-for="item in deptOptions"
:key="item.deptId"
:label="item.deptName"
:value="item.deptId"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="运营区" prop="areaId">
<el-select v-model="form.areaId" style="width: 100%" clearable placeholder="请选择代理商">
<el-option
v-for="item in areaOptions"
:key="item.areaId"
:label="item.areaName"
:value="item.areaId"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="满电电压(V)" label-width="90" prop="fullVoltage">
<el-input style="width: 85%" v-model="form.fullVoltage" placeholder="请输入满电电压" />
</el-form-item>
<el-form-item label="亏电电压(V)" label-width="90" prop="lowVoltage">
<el-input style="width: 85%" v-model="form.lowVoltage" placeholder="请输入亏电电压" />
</el-form-item>
<el-form-item label="满电续航(KM)" label-width="90" prop="fullEndurance">
<el-input style="width: 80%" v-model="form.fullEndurance" placeholder="请输入满电续航" />
</el-form-item>
<el-form-item label="低电量提醒" label-width="90" prop="lowBatteryReminderSwitch">
<el-switch v-model="form.lowBatteryReminderSwitch" class="drawer-switch" />
</el-form-item>
<el-form-item v-if="form.lowBatteryReminderSwitch == true" label="骑行低电量提醒(%)" label-width="120" prop="lowBatteryReminder">
<el-input style="width: 78%" v-model="form.lowBatteryReminder" placeholder="请输入骑行低电量提醒" />
</el-form-item>
<el-form-item label="应用收费方式" label-width="120" prop="ruleIds">
<el-select
v-model="form.ruleIds"
multiple
style="width: 85%"
placeholder="请选择收费方式">
<el-option
v-for="item in ruleOptions"
:key="item.ruleId"
:label="item.name"
:value="item.ruleId"
></el-option>
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listModel, getModel, delModel, addModel, updateModel } from "@/api/system/model";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import { listDept2 } from '@/api/system/dept'
import { listFee } from '@/api/system/fee'
import { listArea, optionselect as getAreaOptionselect, selectAreaListByDeptId } from '@/api/system/area'
export default {
name: "Model",
components: { Treeselect },
props: {
// 用户id
deptId: {
type: Number,
default: null,
}
},
data() {
return {
// 遮罩层
loading: true,
isUpdating: false, // 标志位
// 选中数组
ids: [],
// 代理商树选项
deptOptions: [],
// 区域列表
areaOptions: [],
userName: undefined,
ruleOptions: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 车辆型号表格数据
modelList: [],
// 弹出层标题
title: "",
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 20,
model: null,
brand: null,
operator: this.deptId,
// operator:,
},
// 表单参数
form: {
lowBatteryReminderSwitch: false,
},
// 表单校验
rules: {
model: [
{ required: true, message: "车型不能为空", trigger: "blur" }
],
operator: [
{ required: true, message: "代理商不能为空", trigger: "blur" }
],
fullVoltage: [
{ required: true, message: "满电电压不能为空", trigger: "blur" },
{ pattern: /^\d+(\.\d{1,2})?$/, message: '请输入最多两位小数的浮点数', trigger: 'blur' }
],
lowVoltage: [
{ required: true, message: "亏电电压不能为空", trigger: "blur" },
{ pattern: /^\d+(\.\d{1,2})?$/, message: '请输入最多两位小数的浮点数', trigger: 'blur' }
],
fullEndurance: [
{ required: true, message: "满电续航不能为空", trigger: "blur" },
{ pattern: /^\d+$/, message: '满电续航必须为正整数', trigger: 'blur' }
],
lowBatteryReminder: [
{ required: true, message: "骑行低电量提醒不能为空", trigger: "blur" },
{ pattern: /^\d+$/, message: '骑行低电量提醒必须为正整数', trigger: 'blur' }
]
}
};
},
created() {
this.getList();
console.log("当前用户信息:",this.$store.state.user.name)
this.userName = this.$store.state.user.name;
if(this.userName == 'admin'){
this.getDeptTree();
}
this.getAreaList();
},
watch: {
'form.operator'(newVal,oldVal) {
if (!this.isUpdating) {
this.fetchData2(newVal,oldVal);
}
},
},
methods: {
handleLowBatteryReminderSwitchChange(row) {
// 获取低电量提醒开关的状态提示
let text = row.lowBatteryReminderSwitch ? "启用低电量提醒" : "关闭低电量提醒";
this.$modal.confirm(`确认要"${text}"吗?`).then(() => {
// 创建更新数据对象,将需要更新的模型信息传递给后端
const updateData = {
...row, // 将模型的所有字段都传递过去
lowBatteryReminderSwitch: row.lowBatteryReminderSwitch // 确保传递最新的开关状态
};
// 调用 updateModel 方法更新模型信息
return updateModel(updateData).then(response => {
this.$modal.msgSuccess(`${text}成功`);
this.getList(); // 刷新列表
}).catch(() => {
// 如果更新失败,恢复开关原始状态
row.lowBatteryReminderSwitch = !row.lowBatteryReminderSwitch;
});
});
},
/** 当选择代理商时 根据代理商id获取运营区和型号 */
fetchData2(deptId,oldVal) {
console.log("deptId1111",deptId)
console.log("oldVal1111",oldVal)
if (deptId) {
this.isUpdating = true; // 设置标志位
selectAreaListByDeptId(deptId).then((response) => {
this.areaOptions = response.data.areaList;
let areaOptions = response.data.areaList;
areaOptions.length > 0
? (this.form.areaId = areaOptions[0].areaId)
: (this.form.areaId = null);
this.ruleOptions = response.data.ruleList;
// this.form.ruleIds = null
// ruleOptions.length > 0
// ? (this.form.ruleIds = ruleOptions.map((rule) => rule.ruleId))
// : (this.form.ruleIds = null);
}).finally(() => {
this.isUpdating = false; // 清除标志位
});
} else {
this.reset2();
}
},
getAreaList() {
getAreaOptionselect().then((response) => {
this.areaOptions = response.data;
});
},
getRuleList() {
listFee({ deptId: this.form.modelId }).then(response => {
this.ruleOptions = response.rows;
});
},
/** 查询车辆型号列表 */
getList() {
this.loading = true;
listModel(this.queryParams).then(response => {
this.modelList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
modelId: null,
hardwareVersionId: null,
model: null,
brand: null,
operator: null,
fullVoltage: null,
parentId: undefined,
lowVoltage: null,
fullEndurance: null,
lowBatteryReminder: null,
createBy: null,
createTime: null,
updateBy: null,
updateTime: null,
remark: null
};
this.resetForm("form");
},
reset2() {
console.log(111111111111111111);
this.form.areaId = null;
this.form.deptId = null;
// this.form.ruleId = null;
this.form.ruleIds = null;
if (this.userName === "admin") {
listDept2({ status: "0", pageNum: 1, pageSize: 999 }).then(
(response) => {
this.deptOptions = response.rows;
}
);
}
listFee(this.queryParams).then(response => {
this.ruleOptions = response.rows;
});
listArea(this.queryParams).then((response) => {
this.areaOptions = response.rows;
});
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.modelId)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 查询代理商下拉树结构 */
getDeptTree() {
listDept2({status: '0',pageNum:1,pageSize:999 }).then(response => {
this.deptOptions = response.rows;
});
// deptTreeSelect().then(response => {
// this.deptOptions = response.data;
// });
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加车辆型号";
if(this.deptId){
this.form.operator=this.deptId
}
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const modelId = row.modelId || this.ids
getModel(modelId).then(response => {
this.form = response.data;
this.form.ruleIds = response.ruleIds
this.open = true;
this.title = "修改车辆型号";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.lowBatteryReminderSwitch === undefined || this.form.lowBatteryReminderSwitch === null) {
this.form.lowBatteryReminderSwitch = false;
}
if (this.form.modelId != null) {
updateModel(this.form).then(response => {
this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addModel(this.form).then(response => {
this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const modelIds = row.modelId || this.ids;
this.$modal.confirm('是否确认删除车辆型号编号为"' + modelIds + '"的数据项?').then(function() {
return delModel(modelIds);
}).then(() => {
this.getList();
this.$modal.msgSuccess("删除成功");
}).catch(() => {});
},
/** 导出按钮操作 */
handleExport() {
this.download('system/model/export', {
...this.queryParams
}, `model_${new Date().getTime()}.xlsx`)
}
}
};
</script>