wang-hao-jie
2022-01-05 3a9879dfcf271846605c7f896d0397472cf5e839
src/views/your/car-manage/carManage.vue
@@ -7,17 +7,16 @@
  <div class="search">
    <Card>
      <Row class="operation">
        <Button @click="addRole" type="primary" icon="md-add">添加角色</Button>
        <Button @click="delAll" icon="md-trash">批量删除</Button>
        <Button @click="addCar" type="primary" icon="md-add">添加车辆</Button>
        <Button @click="init" icon="md-refresh">刷新</Button>
        <Button type="dashed" @click="openTip = !openTip">{{
          openTip ? "关闭提示" : "开启提示"
        }}</Button>
        <Input
          v-model="searchForm.key"
          v-model="searchForm.carNo"
          suffix="ios-search"
          @on-change="getDataList"
          placeholder="输入关键词搜索"
          placeholder="输入车牌号搜索"
          clearable
          style="width: 250px"
        />
@@ -60,26 +59,90 @@
      :mask-closable="false"
      :width="500"
    >
      <Form
        ref="roleForm"
        :model="roleForm"
        :label-width="80"
        :rules="roleFormValidate"
      >
        <FormItem label="角色名称" prop="name">
          <Input
            v-model="roleForm.name"
            placeholder="按照Spring Security约定建议以‘ROLE_’开头"
          />
      <Form ref="carForm" :model="carForm" :label-width="80" :rules="carFormValidate">
        <FormItem label="品牌" prop="brand">
          <Input v-model="carForm.brand"/>
        </FormItem>
        <FormItem label="备注" prop="description">
          <Input v-model="roleForm.description" />
        <FormItem label="型号" prop="model">
          <Input v-model="carForm.model" />
        </FormItem>
        <FormItem label="排量" prop="displacement">
          <Input v-model="carForm.displacement" />
        </FormItem>
        <Form-item label="购置年份">
          <Row>
            <Col span="11">
              <Date-picker @on-change="change1" type="date"
                           value="yyyy-MM-dd" placeholder="选择日期" v-model="carForm.buyYear"></Date-picker>
            </Col>
          </Row>
        </Form-item>
        <FormItem label="牌照" prop="carNo">
          <Input v-model="carForm.carNo" />
        </FormItem>
        <FormItem label="加油卡号" prop="addOilCode">
          <Input v-model="carForm.addOilCode" />
        </FormItem>
        <FormItem label="司机" prop="userId">
          <Select v-model="carForm.userId" filterable>
            <Option v-for="item in userList" :value="item.id" :key="item.id">{{ item.nickname }}</Option>
          </Select>
        </FormItem>
        <FormItem label="配送员" prop="followUserId">
          <Select v-model="carForm.followUserId" filterable>
            <Option v-for="item in driverList" :value="item.id" :key="item.id">{{ item.nickname }}</Option>
          </Select>
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="cancelRole">取消</Button>
        <Button type="primary" :loading="submitLoading" @click="submitRole"
        <Button type="text" @click="carRole">取消</Button>
        <Button type="primary" :loading="submitLoading" @click="submitCar"
          >提交</Button
        >
      </div>
    </Modal>
    <Modal :title="modalTitle" v-model="equipmentVisible" :mask-closable="false" :width="1044">
      <Row class="operation" style="padding-bottom: 20px">
        <Button @click="addEquipment" type="primary" icon="md-add">添加设备</Button>
        <Button @click="init" icon="md-refresh">刷新</Button>
      </Row>
      <Table :loading="loading" border :columns="columns2" :data="data2" ref="table"
             sortable="custom" @on-sort-change="changeSort" @on-selection-change="changeSelect">
      </Table>
    </Modal>
    <Modal :title="modalTitle" v-model="addEquipmentVisible" :mask-closable="false" :width="500">
      <Form ref="equipmentForm" :model="equipmentForm" :label-width="80" :rules="equipmentFormValidate">
        <FormItem label="设备" prop="type">
          <Select v-model="equipmentForm.type">
            <Option :value="0">车机</Option>
            <Option :value="1">摄像机</Option>
            <Option :value="2">抓拍机</Option>
            <Option :value="3">pad</Option>
          </Select>
        </FormItem>
        <FormItem label="设备" prop="status">
          <Select v-model="equipmentForm.status">
            <Option :value="0">正常</Option>
            <Option :value="1">停用</Option>
          </Select>
        </FormItem>
        <FormItem label="编号" prop="code">
          <Input v-model="equipmentForm.code" />
        </FormItem>
        <FormItem label="ip地址" prop="ip">
          <Input v-model="equipmentForm.ip" />
        </FormItem>
        <FormItem label="端口号" prop="port">
          <Input v-model="equipmentForm.port" />
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="carRole">取消</Button>
        <Button type="primary" :loading="submitLoading" @click="submitEquipment"
        >提交</Button
        >
      </div>
    </Modal>
@@ -128,22 +191,14 @@
    <!-- 数据权限 -->
    <Modal
      :title="modalTitle"
      v-model="depModalVisible"
      v-model="carModalVisible"
      :mask-closable="false"
      :width="500"
      class="depModal"
    >
      <Alert show-icon
        >默认可查看全部数据,自定义数据范围时请勾选下方数据</Alert
      >
      <Form :label-width="85">
        <FormItem label="数据范围">
          <Select v-model="dataType" transfer>
            <Option :value="0">全部数据权限</Option>
            <Option :value="1">自定义数据权限</Option>
            <Option :value="2">本部门及以下数据权限</Option>
            <Option :value="3">本部门数据权限</Option>
          </Select>
      <Form :label-width="85" ref="removeForm" :model="removeForm">
        <FormItem label="移除原因" prop="removeReason">
          <Input v-model="removeForm.removeReason"/>
        </FormItem>
      </Form>
      <div v-show="dataType == 1" style="margin-top: 15px">
@@ -164,7 +219,7 @@
        <Button
          type="primary"
          :loading="submitDepLoading"
          @click="submitDepEdit"
          @click="submitRemove"
          >提交</Button
        >
      </div>
@@ -174,11 +229,7 @@
<script>
import {
  getRoleList,
  getAllPermissionList,
  addRole,
  editRole,
  deleteRole,
  setDefaultRole,
  editRolePerm,
  initDepartment,
@@ -186,9 +237,21 @@
  editRoleDep,
} from "@/api/index";
import {
  getAll,
  addCar,
  getCarList,
  editCar,
  deleteCar,
  getEquipment,
  addEquipment,
  getUser,
  getDriver,
  deleteEquipment,
} from "@/api/open";
import util from "@/libs/util.js";
export default {
  name: "role-manage",
  name: "car-manage",
  data() {
    return {
      maxHeight: 510,
@@ -204,6 +267,9 @@
      sortType: "desc",
      modalType: 0,
      roleModalVisible: false,
      addEquipmentVisible: false,
      equipmentVisible: false,
      carModalVisible: false,
      permModalVisible: false,
      depModalVisible: false,
      modalTitle: "",
@@ -215,11 +281,19 @@
        order: "desc", // 默认排序方式
        key: "",
      },
      roleForm: {
        name: "",
        description: "",
      carForm: {
        status : 0
      },
      roleFormValidate: {
      type: {
        type : 0
      },
      equipmentForm: {
        status : 0
      },
      removeForm: {
        status : 1
      },
      carFormValidate: {
        name: [
          { required: true, message: "角色名称不能为空", trigger: "change" },
        ],
@@ -238,35 +312,38 @@
          align: "center",
        },
        {
          title: "品牌",
          key: "brand",
          width: 100,
          sortable: true,
        },
        {
          title: "型号",
          key: "model",
          width: 100,
          sortable: true,
        },
        {
          title: "排量",
          key: "displacement",
          width: 100,
          sortable: true,
        },
        {
          title: "购置年份",
          key: "buyYear",
          minWidth: 150,
          sortable: true,
        },
        {
          title: "牌照",
          title: "车牌号",
          key: "carNo",
          width: 170,
          width: 110,
          sortable: true,
          sortType: "desc",
        },
        {
          title: "状态",
          key: "status",
          width: 100,
          sortable: true,
          render: (h, params) => {
            let re = "";
            if (params.row.status == 0) {
              return h("div", [
                h("Badge", {
                  props: {
                    status: "success",
                    text: "正常",
                  },
                }),
              ]);
            } else if (params.row.status == 1) {
              return h("div", [
                h("Badge", {
                  props: {
                    status: "error",
                    text: "移除",
                  },
                }),
              ]);
            }
          },
        },
        {
          title: "移除原因",
@@ -275,51 +352,48 @@
          sortable: true,
        },
        {
          title: "当前驾驶人ID",
          key: "userId",
          title: "司机",
          key: "nickName",
          width: 100,
        },
        {
          title: "配送员",
          key: "followNickName",
          width: 100,
        },
        {
          title: "品牌",
          key: "brand",
          width: 100,
        },
        {
          title: "型号",
          key: "model",
          width: 100,
        },
        {
          title: "排量",
          key: "displacement",
          width: 100,
          sortable: true,
        },
        {
          title: "当前跟车人ID",
          key: "followUserId",
          width: 100,
          title: "加油卡号",
          key: "addOilCode",
          minWidth: 120,
          sortable: true,
        },
        {
          title: "设置为注册用户默认角色",
          key: "defaultRole",
          align: "center",
          width: 200,
          render: (h, params) => {
            if (params.row.defaultRole) {
              return h("div", [
                h("Checkbox", {
                  props: {
                    value: true,
                  },
                  on: {
                    "on-change": () => {
                      this.cancelDefault(params.row);
                    },
                  },
                }),
              ]);
            } else {
              return h("div", [
                h("Checkbox", {
                  props: {
                    value: false,
                  },
                  on: {
                    "on-change": () => {
                      this.setDefault(params.row);
                    },
                  },
                }),
              ]);
            }
          },
          title: "购置年份",
          key: "buyYear",
          minWidth: 120,
          sortable: true,
        },
        {
          title: "登记日期",
          key: "createTime",
          minWidth: 180,
          sortable: true,
        },
        {
          title: "操作",
@@ -334,11 +408,11 @@
                {
                  on: {
                    click: () => {
                      this.editPerm(params.row);
                      this.equipment(params.row);
                    },
                  },
                },
                "菜单权限"
                "设备"
              ),
              h("Divider", {
                props: {
@@ -350,11 +424,11 @@
                {
                  on: {
                    click: () => {
                      this.editDep(params.row);
                      this.removeCar(params.row);
                    },
                  },
                },
                "数据权限"
                "移除车辆"
              ),
              h("Divider", {
                props: {
@@ -392,21 +466,165 @@
          },
        },
      ],
      columns2: [
        {
          type: "selection",
          width: 60,
          align: "center",
        },
        {
          type: "index",
          width: 60,
          align: "center",
        },
        {
          title: "设备类型",
          key: "type",
          width: 130,
          sortable: true,
          render: (h, params) => {
            let re = "";
            if (params.row.type == 0) {
              return h("div", [
                h("Badge", {
                  props: {
                    text: "车机",
                  },
                }),
              ]);
            } else if (params.row.type == 1) {
              return h("div", [
                h("Badge", {
                  props: {
                    text: "摄像机",
                  },
                }),
              ]);
            }else if (params.row.type == 2) {
              return h("div", [
                h("Badge", {
                  props: {
                    text: "抓拍机",
                  },
                }),
              ]);
            }else if (params.row.type == 3) {
              return h("div", [
                h("Badge", {
                  props: {
                    text: "pad",
                  },
                }),
              ]);
            }
          },
        },
        {
          title: "编号",
          key: "code",
          width: 120,
        },
        {
          title: "状态",
          key: "status",
          width: 120,
          sortable: true,
          render: (h, params) => {
            let re = "";
            if (params.row.status == 0) {
              return h("div", [
                h("Badge", {
                  props: {
                    status: "success",
                    text: "正常",
                  },
                }),
              ]);
            } else if (params.row.status == 1) {
              return h("div", [
                h("Badge", {
                  props: {
                    status: "error",
                    text: "停用",
                  },
                }),
              ]);
            }
          },
        },
        {
          title: "ip地址",
          key: "ip",
          width: 120,
        },
        {
          title: "端口号",
          key: "port",
          width: 120,
          sortable: true,
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          width: 280,
          render: (h, params) => {
            return h("div", [
              h(
                      "a",
                      {
                        on: {
                          click: () => {
                            this.editEquipment(params.row);
                          },
                        },
                      },
                      "编辑"
              ),
              h("Divider", {
                props: {
                  type: "vertical",
                },
              }),
              h(
                      "a",
                      {
                        on: {
                          click: () => {
                            this.removeEquipment(params.row);
                          },
                        },
                      },
                      "删除"
              ),
            ]);
          },
        },
      ],
      data: [],
      data2: [],
      total: 0,
      total2: 0,
      permData: [],
      editRolePermId: "",
      selectAllFlag: false,
      depData: [],
      dataType: 0,
      carId: '',
      driverList: [],
      userList: [],
      editDepartments: [],
      buyYear:''
    };
  },
  methods: {
    change1(e){
      this.buyYear = e;
    },
    init() {
      this.getDataList();
      // 获取所有菜单权限树
      this.getPermList();
    },
    renderContent(h, { root, node, data }) {
      let icon = "";
@@ -463,6 +681,22 @@
      this.searchForm.pageSize = v;
      this.getDataList();
    },
    getAllUser(){
      getDriver({type:0}).then((res)=>{
        if (res.success){
          this.userList=res.result;
        }
      });
      //this.type.type=1;
      getDriver({type:1}).then((res)=>{
        if (res.success){
          this.driverList=res.result;
        }
      });
      this.type.type=0;
      console.log(this.userList);
      console.log(this.driverList);
    },
    changeSort(e) {
      this.searchForm.sort = e.key;
      this.searchForm.order = e.order;
@@ -473,15 +707,21 @@
    },
    getDataList() {
      this.loading = true;
      getRoleList(this.searchForm).then((res) => {
      getCarList(this.searchForm).then((res) => {
        this.loading = false;
        if (res.success) {
          this.data = res.result.content;
          this.total = res.result.totalElements;
          if (this.data.length == 0 && this.searchForm.pageNumber > 1) {
            this.searchForm.pageNumber -= 1;
            this.getDataList();
          }
          this.data = res.result.records;
          this.total = res.result.total;
        }
      });
    },
    getEquipmentList(carId) {
      this.loading = true;
      this.searchForm.carId=carId;
      getEquipment(this.searchForm).then((res) => {
        this.loading = false;
        if (res.success) {
          this.data2 = res.result.records;
        }
      });
    },
@@ -509,16 +749,17 @@
        }
      });
    },
    cancelRole() {
    carRole() {
      this.roleModalVisible = false;
    },
    submitRole() {
      this.$refs.roleForm.validate((valid) => {
    submitCar() {
      this.carForm.buyYear = this.buyYear;
      this.$refs.carForm.validate((valid) => {
        if (valid) {
          if (this.modalType == 0) {
            // 添加
            this.submitLoading = true;
            addRole(this.roleForm).then((res) => {
            addCar(this.carForm).then((res) => {
              this.submitLoading = false;
              if (res.success) {
                this.$Message.success("操作成功");
@@ -528,7 +769,7 @@
            });
          } else {
            this.submitLoading = true;
            editRole(this.roleForm).then((res) => {
            editCar(this.carForm).then((res) => {
              this.submitLoading = false;
              if (res.success) {
                this.$Message.success("操作成功");
@@ -540,17 +781,83 @@
        }
      });
    },
    addRole() {
    submitEquipment() {
      this.$refs.equipmentForm.validate((valid) => {
        this.equipmentForm.carId = this.carId;
        if (valid) {
          if (this.modalType == 0) {
            // 添加
            this.submitLoading = true;
            addEquipment(this.equipmentForm).then((res) => {
              this.submitLoading = false;
              if (res.success) {
                this.$Message.success("操作成功");
                this.getEquipmentList(this.carId);
                this.addEquipmentVisible = false;
                this.getEquipmentList(this.carId);
              }
            });
          } else {
            this.submitLoading = true;
            addEquipment(this.equipmentForm).then((res) => {
              this.submitLoading = false;
              if (res.success) {
                this.$Message.success("操作成功");
                this.getEquipmentList(this.carId);
                this.addEquipmentVisible = false;
              }
            });
          }
        }
      });
    },
    submitRemove(){
      this.$refs.removeForm.validate((valid) => {
        if (valid) {
            this.submitLoading = true;
            editCar(this.removeForm).then((res) => {
              this.submitLoading = false;
              if (res.success) {
                this.$Message.success("操作成功");
                this.getDataList();
                this.carModalVisible = false;
              }
            });
        }
      });
    },
    equipment(row) {
      this.carId = row.id
      this.getEquipmentList(row.id);
      this.modalType = 0;
      this.modalTitle = "设备信息";
      this.$refs.carForm.resetFields();
      delete this.carForm.id;
      this.equipmentVisible = true;
    },
    addCar() {
      this.getAllUser();
      this.modalType = 0;
      this.modalTitle = "添加车辆";
      this.$refs.roleForm.resetFields();
      delete this.roleForm.id;
      this.$refs.carForm.resetFields();
      delete this.carForm.id;
      this.roleModalVisible = true;
    },
    addEquipment() {
      this.equipmentForm={};
      this.modalType = 0;
      this.modalTitle = "添加设备";
      this.$refs.carForm.resetFields();
      delete this.carForm.id;
      this.addEquipmentVisible = true;
    },
    edit(v) {
      this.getAllUser();
      this.buyYear = v.buyYear;
      this.modalType = 1;
      this.modalTitle = "编辑车辆";
      this.$refs.roleForm.resetFields();
      this.modalTitle = "编辑";
      this.$refs.carForm.resetFields();
      // 转换null为""
      for (let attr in v) {
        if (v[attr] == null) {
@@ -559,21 +866,70 @@
      }
      let str = JSON.stringify(v);
      let roleInfo = JSON.parse(str);
      this.roleForm = roleInfo;
      this.carForm = roleInfo;
      this.roleModalVisible = true;
    },
    editEquipment(v) {
      this.modalType = 1;
      this.modalTitle = "编辑设备";
      this.$refs.equipmentForm.resetFields();
      // 转换null为""
      for (let attr in v) {
        if (v[attr] == null) {
          v[attr] = "";
        }
      }
      let str = JSON.stringify(v);
      let roleInfo = JSON.parse(str);
      this.equipmentForm = roleInfo;
      this.addEquipmentVisible = true;
    },
    removeCar(v) {
      this.dataType = 0;
      this.modalTitle = "移除车辆";
      this.$refs.carForm.resetFields();
      // 转换null为""
      for (let attr in v) {
        if (v[attr] == null) {
          v[attr] = "";
        }
      }
      let str = JSON.stringify(v);
      let roleInfo = JSON.parse(str);
      roleInfo.status=1
      this.removeForm = roleInfo;
      this.carModalVisible = true;
    },
    remove(v) {
      this.$Modal.confirm({
        title: "确认删除",
        content: "您确认要删除车辆 " + v.name + " ?",
        content: "您确认要删除吗 ",
        loading: true,
        onOk: () => {
          deleteRole({ ids: v.id }).then((res) => {
          deleteCar({ ids: v.id }).then((res) => {
            this.$Modal.remove();
            if (res.success) {
              this.clearSelectAll();
              this.$Message.success("删除成功");
              this.getDataList();
            }
          });
        },
      });
    },
    removeEquipment(v) {
      this.$Modal.confirm({
        title: "确认删除",
        content: "您确认要删除吗 ",
        loading: true,
        onOk: () => {
          deleteEquipment({ ids: v.id }).then((res) => {
            this.$Modal.remove();
            if (res.success) {
              this.clearSelectAll();
              this.$Message.success("删除成功");
              this.getEquipmentList(this.carId);
            }
          });
        },
@@ -628,7 +984,7 @@
            ids += e.id + ",";
          });
          ids = ids.substring(0, ids.length - 1);
          deleteRole({ ids: ids }).then((res) => {
          deleteCar({ ids: ids }).then((res) => {
            this.$Modal.remove();
            if (res.success) {
              this.$Message.success("删除成功");
@@ -739,38 +1095,6 @@
          callback(res.result);
        }
      });
    },
    editDep(v) {
      this.dataType = 0;
      this.editRolePermId = v.id;
      this.modalTitle = "分配 " + v.name + " 的数据权限";
      if (v.dataType) {
        this.dataType = v.dataType;
      }
      // 匹配勾选
      let roleDepIds = v.departments;
      this.editDepartments = roleDepIds;
      this.depTreeLoading = true;
      initDepartment({ openDataFilter: false }).then((res) => {
        this.depTreeLoading = false;
        if (res.success) {
          res.result.forEach(function (e) {
            e.selected = false;
            if (e.isParent) {
              e.loading = false;
              e.children = [];
            }
            if (e.status == -1) {
              e.title = "[已禁用] " + e.title;
              e.disabled = true;
            }
          });
          this.depData = res.result;
          // 判断子节点
          this.checkDepTree(this.depData, roleDepIds);
        }
      });
      this.depModalVisible = true;
    },
    expandCheckDep(v) {
      // 判断展开子节点