zhanghua
2025-04-14 829f5116884f98643ffc5b2a548a600d40c0cedb
src/views/systemSetting/device/handheldTerminal/components/dialogForm.vue
@@ -40,21 +40,10 @@
          </el-form-item>
          <!-- 部门 -->
          <el-form-item class="optionItems" label="所属部门:" prop="departId">
            <el-select v-model="form.departName" placeholder="请输入所属部门">
              <el-option :value="mylabel">
                <el-tree
                  ref="tree"
                  :check-strictly="true"
                  :data="departList"
                  :props="defaultProps"
                  show-checkbox
                  @check-change="handleCheck"
                  default-expand-all
                  node-key="id"
                >
                </el-tree>
              </el-option>
            </el-select>
            <departTree
              :depart="userDepart"
              @selectDepart="selectDepart"
            ></departTree>
          </el-form-item>
          <el-form-item>
            <div class="optionBtn">
@@ -73,7 +62,14 @@
</template>
  <script>
import { validatePhone, validateName } from "@/utils/validate";
import { createNamespacedHelpers } from "vuex";
const { mapActions } = createNamespacedHelpers("handheldTerminal");
import departTree from "@/components/departTree/index.vue";
export default {
  components: {
    departTree,
  },
  data() {
    const checkName = (rule, value, callback) => {
      if (value) {
@@ -173,9 +169,7 @@
        //     }
        // ]
      },
      selectOrg: {
        orgsid: [],
      },
      userDepart: {},
      mylabel: "",
      departList: [],
      defaultProps: {
@@ -185,81 +179,57 @@
    };
  },
  created() {
    const { getDepartTree } = this;
    // 初始化部门树
    getDepartTree();
    // 初始化数据
    this.form = JSON.parse(JSON.stringify(this.info));
    this.form = this.info;
    if (!this.form.departName) {
      this.form.departName = this.form.pdepartName;
    }
    this.userDepart = {
      departId: this.form.departId,
      departName: this.form.departName,
    };
  },
  watch: {
    info(newVal) {
      this.form = newVal; //对父组件传过来的值进行监听,如果改变也对子组件内部的值进行改变
    },
  },
  methods: {
    ...mapActions(["saveHandheldTerminal", "updateHandheldTerminal"]),
    // 修改执法车
    handleUpdateLawCar() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          const { form } = this;
          this.$axios({
            method: "put",
            url: "sccg/car_Manage/modification_enforce",
            data: {
              ...form,
            },
          }).then((res) => {
            if (res.code === 200) {
          if (form.id > 0) {
            this.updateHandheldTerminal(form).then((res) => {
              this.$message({
                type: "success",
                message: "修改车辆成功",
                message: "修改手持设备成功",
              });
              this.$emit("closeDialog", { flag: false, index: 1 });
            } else {
            });
          } else {
            this.saveHandheldTerminal(form).then((res) => {
              this.$message({
                type: "error",
                message: res.message,
                type: "success",
                message: "保存手持设备成功",
              });
            }
          });
              this.$emit("closeDialog", { flag: false, index: 1 });
            });
          }
        } else {
          return false;
        }
      });
    },
    // 部门修改
    handleCheck(data, checked) {
      this.form.departId = data.id;
      this.form.departName = data.departName;
      // 获取当前选择的id在数组中的索引
      const indexs = this.selectOrg.orgsid.indexOf(data.id);
      // 如果不存在数组中,并且数组中已经有一个id并且checked为true的时候,代表不能再次选择。
      if (indexs < 0 && this.selectOrg.orgsid.length === 1 && checked) {
        this.$message({
          message: "只能选择一个部门!",
          type: "warning",
          showClose: true,
        });
        // 设置已选择的节点为false 很重要
        this.$refs.tree.setChecked(data, false);
      } else if (this.selectOrg.orgsid.length === 0 && checked) {
        // 发现数组为空 并且是已选择
        // 防止数组有值,首先清空,再push
        this.selectOrg.orgsid = [];
        this.selectOrg.orgsid.push(data.id);
      } else if (
        indexs >= 0 &&
        this.selectOrg.orgsid.length === 1 &&
        !checked
      ) {
        // 再次直接进行赋值为空操作
        this.selectOrg.orgsid = [];
        this.form.departName = "";
    selectDepart(depart) {
      if (depart) {
        this.form.departId = depart.departId;
        this.form.departName = depart.departName;
      }
    },
    // 获取部门树
    getDepartTree() {
      this.$axios.get("/sccg/depart/tree").then((res) => {
        this.departList = res.data;
      });
    },
  },
  props: ["info", "closeDialog"],
@@ -268,13 +238,13 @@
  <style lang="scss" scoped>
.create {
  border-radius: 1px;
  background-color: #09152f;
  // background-color: #09152f;
  main {
    // border: 1px solid #fff;
    text-align: left;
    padding: 0 55px;
    background-color: #09152f;
    // background-color: #09152f;
    padding-bottom: 50px;
    .mainContent {
@@ -314,18 +284,18 @@
    }
  }
  &::v-deep .el-textarea__inner {
    background-color: #09152f;
    border: 1px solid #17324c;
  }
  // &::v-deep .el-textarea__inner {
  //   background-color: #09152f;
  //   border: 1px solid #17324c;
  // }
  ::v-deep .el-form-item__label {
    color: #4b9bb7;
  }
  // ::v-deep .el-form-item__label {
  //   color: #4b9bb7;
  // }
  ::v-deep .el-input__inner {
    background-color: #09152f;
    border: 1px solid #17324c;
  }
  // ::v-deep .el-input__inner {
  //   background-color: #09152f;
  //   border: 1px solid #17324c;
  // }
}
</style>