zhangzeli
2021-10-27 596df047f3351c364896245c63c42c5c545ff7c9
src/views/your/car-manage/carManage.vue
@@ -7,14 +7,14 @@
  <div class="search">
    <Card>
      <Row class="operation">
        <Button @click="addRole" type="primary" icon="md-add">添加角色</Button>
        <Button @click="addCar" type="primary" icon="md-add">添加车辆</Button>
        <Button @click="delAll" icon="md-trash">批量删除</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="输入关键词搜索"
@@ -61,24 +61,36 @@
      :width="500"
    >
      <Form
        ref="roleForm"
        :model="roleForm"
        ref="carForm"
        :model="carForm"
        :label-width="80"
        :rules="roleFormValidate"
        :rules="carFormValidate"
      >
        <FormItem label="角色名称" prop="name">
          <Input
            v-model="roleForm.name"
            placeholder="按照Spring Security约定建议以‘ROLE_’开头"
          />
        <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>
      </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>
@@ -174,11 +186,7 @@
<script>
import {
  getRoleList,
  getAllPermissionList,
  addRole,
  editRole,
  deleteRole,
  setDefaultRole,
  editRolePerm,
  initDepartment,
@@ -186,9 +194,16 @@
  editRoleDep,
} from "@/api/index";
import {
  getAll,
  addCar,
  getCarList,
  editCar,
  deleteCar,
} from "@/api/open";
import util from "@/libs/util.js";
export default {
  name: "role-manage",
  name: "car-manage",
  data() {
    return {
      maxHeight: 510,
@@ -211,15 +226,15 @@
        // 搜索框初始化对象
        pageNumber: 1, // 当前页数
        pageSize: 10, // 页面大小
        sort: "createTime", // 默认排序字段
        sort: "carNo", // 默认排序字段
        order: "desc", // 默认排序方式
        key: "",
      },
      roleForm: {
        name: "",
        description: "",
      carForm: {
        type : 0,
        status : 0
      },
      roleFormValidate: {
      carFormValidate: {
        name: [
          { required: true, message: "角色名称不能为空", trigger: "change" },
        ],
@@ -269,57 +284,38 @@
          sortType: "desc",
        },
        {
          title: "移除原因",
          key: "removeReason",
          title: "状态",
          key: "status",
          width: 170,
          sortable: true,
        },
        {
          title: "当前驾驶人ID",
          key: "userId",
          width: 100,
          sortable: true,
        },
        {
          title: "当前跟车人ID",
          key: "followUserId",
          width: 100,
          sortable: true,
        },
        {
          title: "设置为注册用户默认角色",
          key: "defaultRole",
          align: "center",
          width: 200,
          render: (h, params) => {
            if (params.row.defaultRole) {
            let re = "";
            if (params.row.status == 0) {
              return h("div", [
                h("Checkbox", {
                h("Badge", {
                  props: {
                    value: true,
                  },
                  on: {
                    "on-change": () => {
                      this.cancelDefault(params.row);
                    },
                    status: "success",
                    text: "正常",
                  },
                }),
              ]);
            } else {
            } else if (params.row.status == 1) {
              return h("div", [
                h("Checkbox", {
                h("Badge", {
                  props: {
                    value: false,
                  },
                  on: {
                    "on-change": () => {
                      this.setDefault(params.row);
                    },
                    status: "error",
                    text: "移除",
                  },
                }),
              ]);
            }
          },
        },
        {
          title: "移除原因",
          key: "removeReason",
          width: 170,
          sortable: true,
        },
        {
          title: "操作",
@@ -403,6 +399,9 @@
    };
  },
  methods: {
    change1(e){
      this.carForm.buyYear = e;
    },
    init() {
      this.getDataList();
      // 获取所有菜单权限树
@@ -473,15 +472,11 @@
    },
    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;
        }
      });
    },
@@ -509,16 +504,17 @@
        }
      });
    },
    cancelRole() {
    carRole() {
      this.roleModalVisible = false;
    },
    submitRole() {
      this.$refs.roleForm.validate((valid) => {
    submitCar() {
      this.$refs.carForm.validate((valid) => {
        this.carForm.buyYear = this.carForm.buyYear.toString()
        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 +524,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 +536,17 @@
        }
      });
    },
    addRole() {
    addCar() {
      this.modalType = 0;
      this.modalTitle = "添加车辆";
      this.$refs.roleForm.resetFields();
      delete this.roleForm.id;
      this.$refs.carForm.resetFields();
      delete this.carForm.id;
      this.roleModalVisible = true;
    },
    edit(v) {
      this.modalType = 1;
      this.modalTitle = "编辑车辆";
      this.$refs.roleForm.resetFields();
      this.$refs.carForm.resetFields();
      // 转换null为""
      for (let attr in v) {
        if (v[attr] == null) {
@@ -559,7 +555,7 @@
      }
      let str = JSON.stringify(v);
      let roleInfo = JSON.parse(str);
      this.roleForm = roleInfo;
      this.carForm = roleInfo;
      this.roleModalVisible = true;
    },
    remove(v) {
@@ -568,7 +564,7 @@
        content: "您确认要删除车辆 " + v.name + " ?",
        loading: true,
        onOk: () => {
          deleteRole({ ids: v.id }).then((res) => {
          deleteCar({ ids: v.id }).then((res) => {
            this.$Modal.remove();
            if (res.success) {
              this.clearSelectAll();
@@ -628,7 +624,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("删除成功");