Commit 24d24f17 by 张杰

新增v1.15.0版本需求

1 parent db75cdf8
......@@ -44,4 +44,34 @@ function dictInfo (params) {
function resetPassword(params) {
return request(params, '/usercenter/user/resetPassword')
}
// 获取车辆树列表
export const GET_VEHICLE_TREE = params => {
return request(params,'/trialdrive/vehicle/tree')
}
// 获取车辆树列表-查询用户下面的车辆
export const GET_USER_VEHICLE_LIST = params => {
return request(params,'/trialdrive/vehicle/uvlist')
}
// 获取车辆树列表-查询组织下面的车辆
export const GET_ORGANIZATION_VEHICLE_LIST = params => {
return request(params,'/trialdrive/vehicle/ovlist')
}
// 用户管理-指定数据-保存数据
export const SAVE_USER_ASSIGN_INFO = params => {
return request(params,'/trialdrive/vehicle/permit/assign','post')
}
// 用户管理-指定数据-获取用户指定数据
export const GET_USER_ASSIGN_INFO = params => {
return request(params,'/trialdrive/vehicle/permit/assigndetails')
}
// 用户管理-指定数据-文件导入接口
export const IMPORT_VEHICLE_TEMPLATE = '/trialdrive/vehicle/permit/import'
export { getUserList, getSuperUser, addUser, editUser, detailUser, deleteUser, roleList, dictInfo, resetPassword}
......@@ -23,4 +23,9 @@ export default {
updateOrganizationTree(state, list) {
state.organizationTree = list;
},
// 更新用户组织树数据
updateUserOrganizationTree(state, list) {
state.userVehicleTree = list;
},
};
......@@ -16,6 +16,7 @@ const state = {
vehicleCustomTree:[], // 新增工单-新增车辆-车型数据
deviceAssembly:[], // 新增工单-新增车辆-设备组合
organizationTree:[], // 组织树
userVehicleTree:[], // 用户管理-指定数据-组织树
}
try {
......
<template>
<div class="">
<el-tabs v-model="activeTabs">
<el-tab-pane label="选择数据" name="1">
<select-info ref="selectInfo" :id="id"></select-info>
</el-tab-pane>
<el-tab-pane label="导入数据" name="2">
<import-vehicle :id="id"></import-vehicle>
</el-tab-pane>
</el-tabs>
</div>
</template>
<script>
import SelectInfo from "./select.vue";
import ImportVehicle from "./import.vue";
export default {
name: "AssignInfo",
components: {
SelectInfo,
ImportVehicle,
},
props: {
id: {
type: [String, Number],
default: "",
},
},
data() {
return {
activeTabs: "2",
userId: "",
};
},
mounted() {
this.userId = this.id;
},
methods: {
// 保存数据
saveInfo() {
let id = this.id;
this.$refs.selectInfo.saveInfo(id);
},
},
};
</script>
<style lang="scss" scoped>
</style>
\ No newline at end of file
<template>
<div class="imort_page">
<div class="choose_box">
<div class="upload_wrap">
<el-input placeholder="请选择需要导入的车辆表格" v-model="uploadFile.name" readonly>
<el-button slot="append" @click="chooseFiles">选择文件</el-button>
</el-input>
<!-- 隐藏上传文件按钮 开始 -->
<el-upload ref="uploadBox" class="upload_box" :auto-upload="false" :headers="uploadHead" :data="uploadParams" :action="uploadPath" multiple :limit="1" :show-file-list="false" :on-change="onChange">
<el-button type="primary">点击上传</el-button>
</el-upload>
<!-- 隐藏上传文件按钮 end -->
</div>
<el-link type="primary" class="el_link">下载模版</el-link>
</div>
<div class="btn_group">
<el-button type="default" size="small">取消</el-button>
<el-button type="primary" size="small">确定</el-button>
</div>
<!-- 导入结果 开始 -->
<div class="upload_result">
<h2 class="title">导入结果</h2>
<div class="result_box">
<div class="cell">
<div class="name">
<span>成功记录</span>
</div>
<span class="txt">11071</span>
</div>
<div class="cell">
<div class="name">
<span>失败记录</span>
<span class="btn">导出记录</span>
</div>
<span class="txt">29</span>
</div>
</div>
</div>
<!-- 导入结果 end -->
</div>
</template>
<script>
import { IMPORT_VEHICLE_TEMPLATE } from "@/services/user";
export default {
name: "ImportVehicle",
props: {
id: {
type: [String, Number],
default: "",
},
},
data() {
return {
fileInfo: "",
uploadPath: "",
uploadHead: {},
uploadFile:{}
};
},
mounted() {
let id = this.id;
let token = localStorage.getItem("token");
this.uploadPath =
this.$root.parentVuex.getters.baseURL + IMPORT_VEHICLE_TEMPLATE;
this.uploadHead = { Authorization: token };
this.uploadParams = { receiverId: id };
},
methods: {
// 选择文件
chooseFiles() {
console.log(this.$refs.uploadBox.$el);
this.$refs.uploadBox.$el.click();
},
// 监听文件选择
onChange(file) {
console.log(file);
this.uploadFile = file;
},
},
};
</script>
<style lang="scss" scoped>
.choose_box {
display: flex;
align-items: center;
padding: 10px 72px;
.el_link {
flex-shrink: 0;
text-align: left;
margin: 0 10px;
}
.upload_wrap {
flex: 1;
position: relative;
.upload_box {
position: absolute;
right: 0;
bottom: 0;
top: 0;
opacity: 0;
}
}
}
.btn_group {
padding: 20px 0 10px 0;
text-align: center;
}
.upload_result {
border-top: 1px solid #eee;
margin-top: 30px;
.title {
font-family: PingFangSC-Medium;
font-size: 20px;
color: #333333;
font-weight: 500;
}
.result_box {
display: flex;
align-items: center;
justify-content: center;
padding-bottom: 30px;
.cell {
width: 248px;
height: 108px;
background: #fbfbfb;
border: 1px solid rgba(215, 215, 215, 1);
border-radius: 4px;
margin: 0 20px;
display: flex;
flex-direction: column;
justify-content: center;
padding: 20px;
box-sizing: border-box;
.name {
font-family: PingFangSC-Medium;
font-size: 14px;
color: #666666;
font-weight: 500;
display: flex;
align-items: center;
.btn {
width: 76px;
height: 30px;
border: 1px solid rgba(33, 150, 243, 1);
border-radius: 4px;
text-align: center;
line-height: 28px;
font-family: PingFangSC-Regular;
font-size: 14px;
color: #409eff;
font-weight: 400;
cursor: pointer;
margin-left: 10px;
}
.btn:hover {
opacity: 0.8;
}
}
.txt {
font-family: PingFangSC-Medium;
font-size: 30px;
color: #333333;
font-weight: 500;
line-height: 1.5;
}
}
}
}
</style>
\ No newline at end of file
......@@ -4,73 +4,30 @@
<div class="user-tree-top">
<span>组织架构</span>
</div>
<el-input
size="mini"
placeholder="输入内容搜索"
v-model="orgName"
@input="treeInput"
></el-input>
<el-tree
:data="treedata"
accordion
node-key="id"
highlight-current
@node-click="handleNodeClick"
:render-content="renderContent"
>
<el-input size="mini" placeholder="输入内容搜索" v-model="orgName" @input="treeInput"></el-input>
<el-tree :data="treedata" accordion node-key="id" highlight-current @node-click="handleNodeClick" :render-content="renderContent">
</el-tree>
</div>
<div class="user-container">
<search-form
class="searchTop border-shadow"
:formModel="searchForm"
:formList="userFormList"
>
<search-form class="searchTop border-shadow" :formModel="searchForm" :formList="userFormList">
<span class="inline-b" slot="form-slot">
<el-button
type="primary"
:size="btn_size"
icon="el-icon-search"
:id="tableParams.btnId"
>搜索</el-button
>
<el-button
type="primary"
:size="btn_size"
icon="el-icon-refresh"
@click="refresh"
>重置</el-button
>
<el-button type="primary" :size="btn_size" icon="el-icon-search" :id="tableParams.btnId">搜索</el-button>
<el-button type="primary" :size="btn_size" icon="el-icon-refresh" @click="refresh">重置</el-button>
</span>
</search-form>
<h3>
用户管理
<div class="pull-right">
<el-button
type="primary"
:size="btn_size"
icon="el-icon-plus"
@click="btnClick('create')"
>新增</el-button
>
<el-button type="primary" :size="btn_size" icon="el-icon-plus" @click="btnClick('create')">新增</el-button>
</div>
</h3>
<basic-table
ref="userTable"
:tableParams="tableParams"
:searchForm="searchForm"
:getListApi="getListApi"
:hasNum="false"
>
<basic-table ref="userTable" :tableParams="tableParams" :searchForm="searchForm" :getListApi="getListApi" :hasNum="false">
<span slot="status" slot-scope="scope">
<span
class="dot"
:class="
<span class="dot" :class="
scope.scope.enableStatus
? USERSTATUS[scope.scope.enableStatus].split(',')[1]
: ''
"
></span>
"></span>
<span class="statusText">{{
scope.scope.enableStatus
? USERSTATUS[scope.scope.enableStatus].split(",")[0]
......@@ -78,59 +35,39 @@
}}</span>
</span>
<span slot="table-button" slot-scope="scope">
<el-button
v-for="(j, idx) in tableParams.tableOption.btnList"
:key="idx"
:type="j.type || 'text'"
:size="btn_size"
@click="btnClick(j.pType, scope.scope)"
>{{ j.name }}</el-button
>
<el-button v-for="(j, idx) in tableParams.tableOption.btnList" :key="idx" :type="j.type || 'text'" :size="btn_size" @click="btnClick(j.pType, scope.scope)">{{ j.name }}</el-button>
<!-- <el-link @click="openDialog(scope.scope)">指定数据</el-link> -->
<auth-link type="primary" size="mini" class="auth_link" name="指定数据" @click.native="openDialog(scope.scope)">指定数据</auth-link>
</span>
</basic-table>
<basic-dialog
:title="userDialogTitle"
:isVisible="userVisible"
@confirmDialog="handleConfirm"
@closeDialog="handleClose"
:btnLoading="btnLoading"
>
<basic-dialog :title="userDialogTitle" :isVisible="userVisible" @confirmDialog="handleConfirm" @closeDialog="handleClose" :btnLoading="btnLoading">
<slot>
<rule-form
:ruleForm="userForm"
:rules="userRules"
:ruleData="userData"
ref="userForm"
></rule-form>
<rule-form :ruleForm="userForm" :rules="userRules" :ruleData="userData" ref="userForm"></rule-form>
</slot>
</basic-dialog>
<basic-dialog
:title="filterDialogTitle"
:isVisible="filterVisible"
@confirmDialog="filterConfirm"
@closeDialog="closeFilter"
>
<basic-dialog :title="filterDialogTitle" :isVisible="filterVisible" @confirmDialog="filterConfirm" @closeDialog="closeFilter">
<slot>
<el-input
placeholder="输入关键字进行过滤"
v-model="filterText"
size="small"
>
<el-input placeholder="输入关键字进行过滤" v-model="filterText" size="small">
</el-input>
<el-tree
class="filter-tree"
:data="filterTextData"
:filter-node-method="filterNode"
highlight-current
ref="tree"
node-key="id"
check-on-click-node
>
<el-tree class="filter-tree" :data="filterTextData" :filter-node-method="filterNode" highlight-current ref="tree" node-key="id" check-on-click-node>
</el-tree>
</slot>
</basic-dialog>
</div>
<!-- 指定数据弹框 开始 -->
<glsx-dialog :show="showDialog" title="指定数据">
<div>
<assign-info ref="assignInfo" :id="currentUserId"></assign-info>
</div>
<template slot="footer">
<el-button type="default" size="small" @click="closeDialog">取消</el-button>
<el-button type="primary" size="small" :loading="loading" @click="saveInfo">确定</el-button>
</template>
</glsx-dialog>
<!-- 指定数据弹框 end -->
</div>
</template>
......@@ -147,7 +84,15 @@ import {
resetPassword,
} from "services/user";
import { getSimpleList, getTreeOrg } from "services/orginizaManage";
import GlsxDialog from "@/components/dialog";
import AssignInfo from "./assign.vue";
import AuthLink from "@/components/auth-button/link";
export default {
components: {
GlsxDialog,
AssignInfo,
AuthLink,
},
data() {
return {
USERSTATUS: this.$Constants.USER_STATUS,
......@@ -159,7 +104,7 @@ export default {
type: "input",
inputType: "text",
prop: "searchField",
placeholder: "请输入登录名称、用户名称、手机号码、用户ID"
placeholder: "请输入登录名称、用户名称、手机号码、用户ID",
},
{
type: "select",
......@@ -168,14 +113,14 @@ export default {
options: [
{
value: "1",
label: "正常"
label: "正常",
},
{
value: "2",
label: "停用"
}
]
}
label: "停用",
},
],
},
],
tableParams: {
// mutiSelectName: 'user',
......@@ -185,51 +130,51 @@ export default {
tableColumns: [
{
label: "用户ID",
prop: "id"
prop: "id",
},
{
label: "登录名称",
prop: "account"
prop: "account",
},
{
label: "用户名称",
prop: "username"
prop: "username",
},
{
label: "部门",
prop: "departmentName"
prop: "departmentName",
},
{
label: "手机号",
prop: "phoneNumber"
prop: "phoneNumber",
},
{
label: "状态",
prop: "enableStatus",
addHtml: "status"
addHtml: "status",
},
{
label: "创建时间",
prop: "createdDate"
}
prop: "createdDate",
},
],
tableOption: {
width: 150,
btnList: [
{
name: "编辑",
pType: "edit"
pType: "edit",
},
{
name: "删除",
pType: "delete"
pType: "delete",
},
{
name: "重置密码",
pType: "reset"
}
]
}
pType: "reset",
},
],
},
},
getListApi: getUserList,
// 折叠菜单数据
......@@ -241,7 +186,7 @@ export default {
account: "",
departmentName: "",
superiorName: "",
enableStatus: true
enableStatus: true,
},
roleList: [],
userData: [
......@@ -250,14 +195,14 @@ export default {
prop: "account",
type: "input",
clearable: true,
maxlength: 50
maxlength: 50,
},
{
label: "部门名称:",
prop: "departmentName",
type: "input",
readonly: true,
clickFunc: this.selectDepart
clickFunc: this.selectDepart,
},
{
label: "直接上级:",
......@@ -265,21 +210,21 @@ export default {
type: "input",
readonly: true,
clickFunc: this.selectSuperior,
hidden: true
hidden: true,
},
{
label: "用户名称:",
prop: "username",
type: "input",
clearable: true,
maxlength: 50
maxlength: 50,
},
{
label: "密码:",
prop: "password",
type: "input",
inputText: "password",
showPassword: true
showPassword: true,
},
{
label: "角色:",
......@@ -288,7 +233,7 @@ export default {
options: [],
key: "roleName",
value: "roleId",
filterable: true
filterable: true,
},
{ label: "邮箱:", prop: "email", type: "input" },
{ label: "手机:", prop: "phoneNumber", type: "input", maxlength: 11 },
......@@ -299,7 +244,7 @@ export default {
options: [],
key: "dictLabel",
value: "dictValue",
visibleFunc: this.genderChange
visibleFunc: this.genderChange,
},
{ label: "状态:", prop: "enableStatus", type: "switch" },
{
......@@ -309,40 +254,50 @@ export default {
options: [],
key: "dictLabel",
value: "dictValue",
visibleFunc: this.positionChange
}
visibleFunc: this.positionChange,
},
],
userRules: {
account: [
{ required: true, message: "请输入登录名称", trigger: "blur" },
{ validator: this.$Common.checkName, trigger: "blur" },
{ min: 2, max: 50, message: "长度在 2 到 50 个字符", trigger: "blur" }
{
min: 2,
max: 50,
message: "长度在 2 到 50 个字符",
trigger: "blur",
},
],
departmentName: [
{ required: true, message: "请选择部门名称", trigger: "change" }
{ required: true, message: "请选择部门名称", trigger: "change" },
],
username: [
{ required: true, message: "请输入用户名称", trigger: "blur" },
{ validator: this.$Common.checkName, trigger: "blur" },
{ min: 2, max: 50, message: "长度在 2 到 50 个字符", trigger: "blur" }
{
min: 2,
max: 50,
message: "长度在 2 到 50 个字符",
trigger: "blur",
},
],
roleId: [{ required: true, message: "请选择角色", trigger: "change" }],
email: [
{
type: "email",
message: "请输入正确的邮箱地址",
trigger: ["blur", "change"]
}
trigger: ["blur", "change"],
},
],
phoneNumber: [
{ required: true, message: "请输入手机号", trigger: "blur" },
{ validator: this.$Common.checkRegExpPhoneTel, trigger: "blur" }
{ validator: this.$Common.checkRegExpPhoneTel, trigger: "blur" },
],
enableStatus: [{ required: true }]
enableStatus: [{ required: true }],
},
addRule: [
{ required: true, message: "请输入密码", trigger: "blur" },
{ min: 6, max: 50, message: "长度在 6 到 50 个字符", trigger: "blur" }
{ min: 6, max: 50, message: "长度在 6 到 50 个字符", trigger: "blur" },
],
sexList: [],
positionList: [],
......@@ -352,7 +307,11 @@ export default {
filterVisible: false,
filterText: "",
filterTextData: [],
isOpen: true
isOpen: true,
// 指定数据弹框
showDialog: false,
loading: false,
currentUserId: "",
};
},
watch: {
......@@ -363,9 +322,10 @@ export default {
if (val.path == "/user") {
this.init();
}
}
},
},
mounted() {
this.$on("assign-success", this.closeDialog);
this.init();
},
methods: {
......@@ -394,7 +354,7 @@ export default {
// 确定,新增用户、编辑用户
handleConfirm() {
console.log(this.userForm);
this.$refs.userForm.$children[0].validate(valid => {
this.$refs.userForm.$children[0].validate((valid) => {
if (valid) {
this.btnLoading = true;
let params = JSON.parse(JSON.stringify(this.userForm));
......@@ -407,7 +367,7 @@ export default {
this.emptyData(params);
let api = addUser;
if (params.id) api = editUser;
api(params).then(res => {
api(params).then((res) => {
this.btnLoading = false;
if (res.code == "200") {
this.getTreeOrg();
......@@ -415,12 +375,12 @@ export default {
this.handleClose();
this.$message({
type: "success",
message: "操作成功!"
message: "操作成功!",
});
} else {
this.$message({
type: "error",
message: res.message
message: res.message,
});
}
});
......@@ -457,7 +417,7 @@ export default {
this.userForm = {
departmentName: "",
superiorName: "",
enableStatus: true
enableStatus: true,
};
let gender = "";
if (this.sexList.length > 0) {
......@@ -466,7 +426,7 @@ export default {
this.getRoleList();
// this.userForm.gender = this.sexList.length > 0 ? this.sexList[0].dictValue + '' : ''
this.$set(this.userForm, "gender", gender);
this.userData.map(item => {
this.userData.map((item) => {
if (item.prop == "superiorName") {
item.hidden = true;
}
......@@ -492,20 +452,20 @@ export default {
tipTitle: "提示",
type: "warnning",
callBack: () => {
resetPassword({ id: scope.id }).then(res => {
resetPassword({ id: scope.id }).then((res) => {
if (res.code == "200") {
this.$message({
type: "success",
message: "重置密码成功!"
message: "重置密码成功!",
});
} else {
this.$message({
type: "error",
message: res.message
message: res.message,
});
}
});
}
},
};
this.$Common.confirmDialog(tipData);
break;
......@@ -513,22 +473,22 @@ export default {
},
// 编辑触发事件
editEvent(row) {
detailUser({ id: row.id }).then(res => {
detailUser({ id: row.id }).then((res) => {
this.userDialogTitle = "编辑用户";
this.userForm = JSON.parse(JSON.stringify(res.data));
this.userForm.enableStatus = res.data.enableStatus == 1 ? true : false;
this.userData.map(item => {
this.userData.map((item) => {
if (item.prop == "superiorName") {
item.hidden = this.userForm.deptDepth == 0;
} else if (item.prop == "gender") {
let flag = false;
item.options.map(i => {
item.options.map((i) => {
if (i.dictValue == this.userForm.gender) flag = true;
});
this.userForm.gender = flag ? this.userForm.gender + "" : "";
} else if (item.prop == "position") {
let isFlag = false;
item.options.map(j => {
item.options.map((j) => {
if (j.dictValue == this.userForm.position) isFlag = true;
});
this.userForm.position = isFlag ? this.userForm.position + "" : "";
......@@ -546,21 +506,21 @@ export default {
tipTitle: "提示",
type: "error",
callBack: () => {
deleteUser({ id: id }).then(res => {
deleteUser({ id: id }).then((res) => {
if (res.code == "200") {
this.$message({
type: "success",
message: "删除成功!"
message: "删除成功!",
});
this.$refs.userTable.refreshTable();
} else {
this.$message({
type: "error",
message: res.message
message: res.message,
});
}
});
}
},
};
this.$Common.confirmDialog(tipData);
},
......@@ -597,7 +557,7 @@ export default {
} else {
this.userForm.departmentId = this.$refs.tree.getCurrentNode().id;
this.userForm.departmentName = this.$refs.tree.getCurrentNode().label;
this.userData.map(item => {
this.userData.map((item) => {
if (item.prop == "superiorName") {
item.hidden = this.$refs.tree.getCurrentNode().depth == 0;
if (this.$refs.tree.getCurrentNode().depth == 0) {
......@@ -615,25 +575,25 @@ export default {
},
// 获取上级树
getSuperUser(params) {
getSuperUser(params).then(res => {
getSuperUser(params).then((res) => {
this.filterTextData = res.data;
});
},
// 获取组织树
getSimpleList() {
getTreeOrg().then(res => {
getTreeOrg().then((res) => {
this.filterTextData = res.data;
});
},
// 获取组织架构
getTreeOrg(params) {
getTreeOrg(params).then(res => {
getTreeOrg(params).then((res) => {
this.treedata = res.data;
});
},
// 角色下拉列表
getRoleList(params = {}) {
roleList(params).then(res => {
roleList(params).then((res) => {
this.roleList = res.data;
this.userData[5].options = res.data;
});
......@@ -641,14 +601,14 @@ export default {
// 组织架构搜索
treeInput(value) {
const params = {
orgName: value
orgName: value,
};
this.getTreeOrg(params);
this.isExpand = true;
},
// 岗位列表
getPosti(value) {
dictInfo("sys_position").then(res => {
dictInfo("sys_position").then((res) => {
if (res.data.length > 0) {
this.deleteDict(res.data, "position", this.positionList);
}
......@@ -656,7 +616,7 @@ export default {
},
// 获取性别列表
getSex() {
dictInfo("sys_user_sex").then(res => {
dictInfo("sys_user_sex").then((res) => {
if (res.data.length > 0) {
this.deleteDict(res.data, "gender", this.sexList);
}
......@@ -672,16 +632,16 @@ export default {
const arr = [];
if (!data[0].typeDeleted) {
// 过滤未删除列表
data.map(item => {
data.map((item) => {
if (!item.deleted) arr.push(item);
});
this.userData.map(item => {
this.userData.map((item) => {
if (item.prop == name) {
item.options = arr;
}
});
arr &&
arr.map(i => {
arr.map((i) => {
if (!i.disabled) list.push(i);
});
}
......@@ -692,17 +652,17 @@ export default {
* 2.label,字典名称,Strign
*/
disabledDict(name, label) {
this.userData.map(item => {
this.userData.map((item) => {
if (item.prop == name) {
if (item.options[0].typeDeleted) {
this.$message({
type: "error",
message: `${label}已删除,请联系管理员解决`
message: `${label}已删除,请联系管理员解决`,
});
} else if (item.options[0].typeDisabled) {
this.$message({
type: "error",
message: `${label}已停用,请联系管理员解决`
message: `${label}已停用,请联系管理员解决`,
});
}
}
......@@ -716,8 +676,26 @@ export default {
positionChange(e) {
if (e) this.disabledDict("position", "岗位");
},
selectChange(e) {}
}
selectChange(e) {},
// 指定数据
openDialog(row) {
console.log(row);
this.showDialog = true;
this.currentUserId = row.id;
},
// 关闭弹框
closeDialog() {
this.showDialog = false;
},
// 保存数据
saveInfo() {
//this.loading = true;
this.$refs.assignInfo.saveInfo();
},
},
};
</script>
<style rel="stylesheet/scss" lang="scss">
......@@ -725,3 +703,8 @@ export default {
overflow: initial !important;
}
</style>
<style lang="scss" scoped>
.auth_link {
font-size: 12px;
}
</style>
<template>
<div class="select_info_page">
<h2 class="title">注:仅选择已安装设备的车辆,账户所属组织细节数据不可选</h2>
<div class="device_box">
<!-- 左侧未选择 开始 -->
<div class="card_box">
<div class="head">全部列表(100条)</div>
<div class="info_box">
<div class="search_box">
<el-autocomplete placeholder="请输入搜索关键词" v-model="term" class="input_select" :size="inputSize">
<!-- <el-input placeholder="请输入搜索关键词" v-model="term" class="input_select" :size="inputSize"> -->
<el-select v-model="termType" slot="prepend" placeholder="请选择" :size="inputSize">
<el-option label="设备号" value="1"></el-option>
<el-option label="车架号" value="2"></el-option>
<el-option label="姓名" value="3"></el-option>
</el-select>
<!-- </el-input> -->
</el-autocomplete>
</div>
<div class="tree_box">
<el-scrollbar class="el_scroll" :vertical="false">
<el-tree :data="vehicleList" :props="treeProps" :default-checked-keys="checkKeys" :loading="ajaxloding" show-checkbox lazy node-key="id" :load="loadNode" :render-content="renderTreeContent" @check="onCheckChange">
</el-tree>
</el-scrollbar>
</div>
</div>
</div>
<!-- 左侧未选择 end -->
<!-- 中间按钮区域 开始 -->
<div class="middle_box">
<el-button type="primary" class="btn" icon="el-icon-arrow-right" size="small" :loading="ajaxloding" @click="moveToRight"></el-button>
<el-button type="primary" class="btn" icon="el-icon-arrow-left" size="small" :loading="ajaxloding" :disabled="!rightCheckList || rightCheckList.length<=0" @click="moveToLeft"></el-button>
</div>
<!-- 中间按钮区域 end -->
<!-- 右侧已选择 开始 -->
<div class="card_box">
<div class="head">已选列表({{checkList.length}}条)</div>
<div class="info_box">
<div class="search_box">
<el-input placeholder="请输入姓名|车牌号" prefix-icon="el-icon-search" :size="inputSize" v-model="checkSearchText">
</el-input>
</div>
<div class="tree_box">
<el-scrollbar ref="scrollbar" class="el_scroll">
<el-checkbox-group class="el_checkbox_group" v-model="rightCheckList">
<el-checkbox v-for="(item,index) in showCheckList" :key="index" :label="item.id">
<span class="checkbox_label" :title="`${item.label}/${item.label1}`">{{showLabels(item)}}</span>
</el-checkbox>
</el-checkbox-group>
</el-scrollbar>
</div>
</div>
</div>
<!-- 右侧已选择 end -->
</div>
</div>
</template>
<script>
import {
GET_VEHICLE_TREE,
GET_USER_VEHICLE_LIST,
GET_ORGANIZATION_VEHICLE_LIST,
SAVE_USER_ASSIGN_INFO,
GET_USER_ASSIGN_INFO,
} from "@/services/user";
import { deepClone, showToast } from "@/utils/util";
export default {
name: "SelectInfo",
props: {
id: {
type: [String, Number],
default: "",
},
},
data() {
return {
term: "",
termType: "1",
inputSize: "medium",
checkSearchText: "",
checkList: [], // 所有已选择的车辆
showCheckList: [], // 动态渲染的列表
pageNum: 1, // 渲染下标
vehicleList: this.$store.state.userVehicleTree,
treeProps: {
label: "label",
children: "children",
isLeaf: "leaf",
["node-key"]: "id",
},
temList: {}, // 临时存储车辆数据
checkKeys: [],
ajaxloding: false,
rightCheckList: [],
userId: "",
};
},
mounted() {
let list = this.$store.state.userVehicleTree;
if (!list || list.length <= 0) {
this.getList();
}
this.handleScroll();
this.getInfo();
},
methods: {
// 获取车辆树
getList() {
GET_VEHICLE_TREE().then((res) => {
this.vehicleList = res.data || [];
this.$store.commit("updateUserOrganizationTree", res.data || []);
});
},
// 异步加载树
loadNode(node, resolve) {
console.log(node);
let _cur = node.data;
let child = _cur.children || [];
let origin = _cur.origin;
if (child && child.length > 0) {
return resolve(child);
}
// 用户层级,查询该用户下面的车辆
if (origin && origin.type === "u") {
GET_USER_VEHICLE_LIST({ uIds: _cur.id }).then((res) => {
let list = res.data || [];
list.map((k) => {
k.leaf = true;
return k;
});
return resolve(list);
});
}
return resolve([]);
},
// 自定义展示数节点
renderTreeContent(h, { node, data, store }) {
if (data.leaf) {
return h("div", { class: "custom-tree-node" }, [
h("div", {
domProps: {
innerHTML: "姓名:" + node.data.label1 || "--",
},
}),
h("div", {
domProps: {
innerHTML: "设备号:" + node.data.label || "--",
},
}),
h("div", {
domProps: {
innerHTML: "车架号:" + node.data.label2 || "--",
},
}),
]);
}
return h("span", {
domProps: {
innerHTML: node.data.label,
},
});
},
// 监听组织树勾选
onCheckChange(data, e) {
console.log(data);
let _this = this;
let checkKeys = e.checkedKeys || [];
let idx = checkKeys.findIndex((k) => k == data.id);
let checked = idx >= 0 ? true : false;
// 如果是用户
if (data.origin.type == "u") {
GET_USER_VEHICLE_LIST({ uIds: data.id }).then((res) => {
let list = res.data || [];
_this.setList(data, list, checked);
});
return false;
}
_this.ajaxloding = true;
// 取消勾选,不查询接口
if (!checked) {
_this.setList(data, [], checked);
return false;
}
GET_ORGANIZATION_VEHICLE_LIST({ oIds: data.id })
.then((res) => {
_this.ajaxloding = false;
_this.setList(data, res.data, checked);
})
.catch((error) => {
_this.ajaxloding = false;
});
},
// 处理车辆数据
setList(data, list, checked) {
let _this = this;
let temList = deepClone(_this.temList);
console.log(temList);
// 勾选状态
if (checked) {
temList[data.id] = list;
_this.temList = temList;
return false;
}
// 取消勾选
delete temList[data.id];
_this.temList = temList;
console.log(_this.temList);
},
// 移动到已选择
moveToRight() {
let _this = this;
let list = deepClone(_this.checkList);
let temList = deepClone(_this.temList);
let arr = [];
for (var k in temList) {
arr = arr.concat(temList[k]);
}
// 去重
// 首先构造Object
const idSet = list.reduce((acc, v) => {
acc[v.id] = true;
return acc;
}, {});
// 遍历arr,去掉在idSet中存在的id
const result = arr.filter((v) => !idSet[v.id]);
if (result && result.length > 0) {
list = result.concat(list);
}
_this.checkList = list;
// 每次添加新数据,先清空,然后重新渲染
_this.pageNum = 1;
_this.showCheckList = [];
_this.loadList();
//_this.temList = {};
},
// 删除已选择
moveToLeft() {
let cList = this.rightCheckList;
let list = this.checkList;
let showList = this.showCheckList;
// 首先构造Object
const idSet = cList.reduce((acc, v) => {
acc[v] = true;
return acc;
}, {});
// 遍历arr,去掉在idSet中存在的id
let result = list.filter((v) => !idSet[v.id]);
let showResult = showList.filter((v) => !idSet[v.id]);
console.log(result);
this.showCheckList = showResult;
this.checkList = result;
this.rightCheckList = [];
},
// 加载列表
loadList() {
let list = this.checkList;
let arr = deepClone(this.showCheckList);
let size = 100;
let pageNum = Number(this.pageNum);
let start = (pageNum - 1) * size;
let end = pageNum * size;
let next = list.slice(start, end);
let newList = arr.concat(next);
this.showCheckList = newList;
this.pageNum += 1;
},
// 监听滚动
handleScroll() {
let _this = this;
let scrollbarEl = this.$refs.scrollbar.wrap;
let h = scrollbarEl.offsetHeight; // 可视区域高度
scrollbarEl.onscroll = () => {
let sTop = scrollbarEl.scrollTop; // 滚动条当前位置
let sHeight = scrollbarEl.scrollHeight; //整个滚动高度
if (sHeight - h - sTop <= 60) {
_this.loadList();
}
};
},
// 展示数据
showLabels(row) {
if (!row) {
return "";
}
let str = "";
let vin = row.label;
let _name = row.label1;
if (_name && _name.length >= 10) {
_name = _name.split(0, 10) + "...";
}
str = vin + "/" + _name;
return str;
},
// 保存数据
saveInfo() {
console.log(this.id);
let list = this.checkList;
let arr = [];
if (!list || list.length <= 0) {
showToast({
message: "请选择数据",
});
return false;
}
list.map((k) => {
arr.push(k.vid);
});
let oParams = {};
oParams.receiverId = this.id;
oParams.vehicleIds = arr;
SAVE_USER_ASSIGN_INFO(oParams).then((res) => {
if (res.code == 200) {
showToast({
message: "保存成功",
type: "success",
});
this.$emit("assign-success");
}
});
},
// 获取用户信息
getInfo() {
let oParams = {};
oParams.receiverId = this.id;
GET_USER_ASSIGN_INFO(oParams).then((res) => {
let list = res.data || [];
let arr = [];
list.map((k) => {
let idx = arr.findIndex((j) => j == k.pid);
if (idx < 0) {
arr.push(k.pid.replace("u", ""));
}
k.vid = k.vehicleId;
k.label = k.vin;
k.label1 = k.ownerName;
return k;
});
this.checkList = list;
this.checkKeys = arr;
console.log(arr);
this.loadList();
});
},
},
};
</script>
<style>
.el-tree-node__content {
height: auto;
padding: 2px;
}
.custom-tree-node {
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
font-size: 12px;
padding-right: 8px;
line-height: 26px;
}
</style>
<style lang="scss" scoped>
.select_info_page {
.title {
font-family: PingFangSC-Regular;
font-size: 14px;
color: #666666;
font-weight: 400;
}
.device_box {
display: flex;
justify-content: space-between;
.middle_box {
padding: 0 10px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
.btn {
margin: 10px 0;
}
}
.card_box {
//flex: 1;
width: 380px;
flex-shrink: 0;
box-sizing: border-box;
.head {
height: 54px;
line-height: 54px;
background: #f5f7fa;
padding: 0 16px;
font-family: PingFangSC-Regular;
font-size: 14px;
color: #333333;
font-weight: 400;
}
.info_box {
border: 1px solid #eee;
.search_box {
padding: 10px;
.input_select {
::v-deep .el-input-group__prepend {
background: #fff !important;
//padding: 0 10px;
padding-left: 10px;
.el-select {
width: 90px;
box-sizing: border-box;
}
}
}
}
.tree_box {
border-top: 1px solid #eee;
.el_scroll {
padding: 10px 0;
height: 340px;
box-sizing: border-box;
overflow-y: auto;
}
}
}
}
}
}
.el_checkbox_group {
padding: 0 10px;
display: flex;
flex-direction: column;
.el-checkbox {
margin: 4px 0;
}
}
</style>
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!