WXL
2026-05-17 d4b9b197632366be60796f059030394aef6802ea
src/views/project/externalperson/index.vue
@@ -31,6 +31,8 @@
          placeholder="请选择账号类别"
          clearable
          size="small"
          multiple
          collapse-tags
        >
          <el-option
            v-for="dict in dict.type.sys_UserType"
@@ -114,12 +116,19 @@
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="账号类别" align="center" prop="usertype">
      <el-table-column label="账号类别" align="center" prop="usertype" width="200">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.sys_UserType"
            :value="scope.row.usertype"
          />
          <div v-if="scope.row.usertype">
            <el-tag
              v-for="type in getTypeList(scope.row.usertype)"
              :key="type"
              size="small"
              style="margin-right: 5px; margin-bottom: 3px"
            >
              {{ getTypeLabel(type) }}
            </el-tag>
          </div>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="账号编号" align="center" prop="userno" />
@@ -143,24 +152,11 @@
        align="center"
        prop="unitname"
      />
      <!--
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" />
        </template>
      </el-table-column>
      <el-table-column label="单位工作编号" align="center" prop="personnelunitno" />
      <el-table-column label="在职状态" align="center" prop="userstatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_0_1" :value="scope.row.userstatus" />
        </template>
      </el-table-column>
      <el-table-column label="联系电话" width="200" align="center" prop="telephone" />
      <el-table-column label="联系地址" width="250" align="center" prop="address" />-->x
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="150"
      >
        <template slot-scope="scope">
          <el-button
@@ -200,9 +196,15 @@
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12"
            ><el-form-item label="账号类别" prop="usertype">
              <el-select v-model="form.usertype" placeholder="请选择账号类别">
          <el-col :span="12">
            <el-form-item label="账号类别" prop="usertype">
              <el-select
                v-model="form.usertype"
                placeholder="请选择账号类别"
                multiple
                collapse-tags
                style="width: 100%"
              >
                <el-option
                  v-for="dict in dict.type.sys_UserType"
                  :key="dict.value"
@@ -232,7 +234,7 @@
            <el-form-item
              label="启用状态"
              prop="userstatus"
              :disabled="ismanager == false"
              :disabled="!ismanager"
            >
              <el-radio-group v-model="form.userstatus">
                <el-radio
@@ -245,78 +247,87 @@
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.usertype != 'org'">
          <el-col :span="24">
            <el-form-item label="身份证号" prop="idcardno">
              <el-input v-model="form.idcardno" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.usertype != 'org'"
          ><el-col :span="12">
            <el-form-item label="性别" prop="sex">
              <el-select v-model="form.sex" placeholder="请选择性别">
                <el-option
                  v-for="dict in dict.type.sys_user_sex"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                ></el-option> </el-select
            ></el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职称" prop="title">
              <el-select v-model="form.title" placeholder="请选择人员职称">
                <el-option
                  v-for="dict in dict.type.sys_professionaltitle"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.label"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-if="form.usertype != 'org'">
          <el-col :span="12">
            <el-form-item label="所在单位" prop="unitname">
              <el-select
                v-model="form.unitno"
                placeholder="所在单位"
                clearable
                filterable
                allow-create
                style="width: 100%"
              >
                <el-option
                  v-for="(spec, index) in unitList"
                  :key="index"
                  :label="spec.organizationname"
                  :value="spec.organizationid"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单位工号" prop="personnelunitno">
              <el-input
                v-model="form.personnelunitno"
                placeholder="请输入所在单位的工号"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 个人信息(当不包含'org'类型时显示) -->
        <div v-if="!hasOrgType(form.usertype)">
          <el-row>
            <el-col :span="24">
              <el-form-item label="身份证号" prop="idcardno">
                <el-input v-model="form.idcardno" placeholder="请输入身份证号" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="性别" prop="sex">
                <el-select v-model="form.sex" placeholder="请选择性别" style="width: 100%">
                  <el-option
                    v-for="dict in dict.type.sys_user_sex"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="职称" prop="title">
                <el-select v-model="form.title" placeholder="请选择人员职称" style="width: 100%">
                  <el-option
                    v-for="dict in dict.type.sys_professionaltitle"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.label"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="所在单位" prop="unitname">
                <el-select
                  v-model="form.unitno"
                  placeholder="所在单位"
                  clearable
                  filterable
                  allow-create
                  style="width: 100%"
                >
                  <el-option
                    v-for="(spec, index) in unitList"
                    :key="index"
                    :label="spec.organizationname"
                    :value="spec.organizationid"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="单位工号" prop="personnelunitno">
                <el-input
                  v-model="form.personnelunitno"
                  placeholder="请输入所在单位的工号"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </div>
        <!-- 银行信息(所有类型都显示) -->
        <el-row>
          <el-col :span="24"
            ><el-form-item label="开户银行" prop="depositbank">
          <el-col :span="24">
            <el-form-item label="开户银行" prop="depositbank">
              <el-input
                v-model="form.depositbank"
                placeholder="请输入开户银行名称"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24"
            ><el-form-item label="银行卡号" prop="bankcardno">
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="银行卡号" prop="bankcardno">
              <el-input
                v-model="form.bankcardno"
                placeholder="请输入银行卡号"
@@ -324,6 +335,8 @@
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 联系信息 -->
        <el-row>
          <el-col :span="24">
            <el-form-item label="联系地址" prop="address">
@@ -338,13 +351,6 @@
            </el-form-item>
          </el-col>
        </el-row>
        <!--
          <el-row>
            <el-col :span="24"><el-form-item label="开户支行" prop="branchbankname">
              <el-input v-model="form.branchbankname" placeholder="请输入开户支行" /> </el-form-item>
            </el-col>
          </el-row>
            -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
@@ -417,17 +423,42 @@
        datequery: false
      },
      // 表单参数
      form: {},
      form: {
        usertype: []  // 初始化为数组
      },
      // 表单校验
      rules: {
        usertype: [
          { required: true, message: "请输入账户类型", trigger: "blur" }
          {
            required: true,
            message: "请至少选择一个账号类别",
            trigger: "change",
            validator: (rule, value, callback) => {
              if (!value || (Array.isArray(value) && value.length === 0)) {
                callback(new Error("请至少选择一个账号类别"));
              } else {
                callback();
              }
            }
          }
        ],
        username: [
          { required: true, message: "请输入账户名称", trigger: "blur" }
        ],
        idcardno: [
          { required: true, message: "请输入身份证号码", trigger: "blur" }
          {
            required: true,
            message: "请输入身份证号码",
            trigger: "blur",
            validator: (rule, value, callback) => {
              // 当不包含'org'类型时,身份证号为必填
              if (!this.hasOrgType(this.form.usertype) && (!value || value.trim() === '')) {
                callback(new Error("请输入身份证号码"));
              } else {
                callback();
              }
            }
          }
        ],
        bankcardno: [
          { required: true, message: "请输入银行账号", trigger: "blur" }
@@ -447,6 +478,38 @@
    this.getList();
  },
  methods: {
    // 检查是否包含'org'类型
    hasOrgType(usertype) {
      if (!usertype) return false;
      if (Array.isArray(usertype)) {
        return usertype.includes('org');
      } else if (typeof usertype === 'string') {
        return usertype.includes('org');
      }
      return false;
    },
    // 将逗号分隔的字符串转换为数组
    getTypeList(usertypeStr) {
      if (!usertypeStr) return [];
      if (typeof usertypeStr === 'string') {
        return usertypeStr.split(',').filter(item => item.trim() !== '');
      } else if (Array.isArray(usertypeStr)) {
        return usertypeStr;
      }
      return [];
    },
    // 获取类型标签
    getTypeLabel(type) {
      const dict = this.dict.type.sys_UserType;
      if (dict) {
        const item = dict.find(item => item.value === type);
        return item ? item.label : type;
      }
      return type;
    },
    //获取当前用户信息
    getUserProfile() {
      getUserProfile().then(res => {
@@ -464,28 +527,28 @@
    /** 查询单位、人员账号列表 */
    getList() {
      // if (
      //   this.queryParams.username === null ||
      //   this.queryParams.username.replace(/\s/g, "") == ""
      // ) {
      //   this.$modal.msgWarning(
      //     "查找账户时,账户名称不能为空,请输入账户名称!"
      //   );
      //   return;
      // }
      this.loading = true;
      // 处理查询参数,如果是数组则转换为逗号分隔的字符串
      const params = { ...this.queryParams };
      if (Array.isArray(params.usertype) && params.usertype.length > 0) {
        params.usertype = params.usertype.join(',');
      }
      // this.loading = true;
      listExternalperson(this.queryParams).then(response => {
      listExternalperson(params).then(response => {
        this.externalpersonList = response.rows;
        this.total = response.total;
        // this.loading = false;
        this.loading = false;
      }).catch(() => {
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
@@ -493,7 +556,7 @@
        userno: null,
        username: null,
        userstatus: 0,
        usertype: null,
        usertype: [],  // 重置为数组
        personnelunitno: null,
        delFlag: null,
        createBy: null,
@@ -505,81 +568,103 @@
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log("handleQuery", this.queryParams);
      if (
        this.queryParams.username === null ||
        this.queryParams.username.replace(/\s/g, "") == ""
      ) {
        this.$modal.msgWarning(
          "为限制批量查找账户信息,限制账户名称为必输项,请输入账户名称后再搜索!"
        );
        return;
      }
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.usertype = [];  // 重置为数组
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加人员/单位账号信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getExternalperson(id).then(response => {
        this.form = response.data;
        const data = response.data;
        // 将数据库中的逗号分隔字符串转换为数组
        if (data.usertype && typeof data.usertype === 'string') {
          data.usertype = data.usertype.split(',').filter(item => item.trim() !== '');
        } else if (!data.usertype) {
          data.usertype = [];
        }
        this.form = data;
        this.open = true;
        this.title = "人员/单位账号信息修改";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          console.log("unitList", this.unitList);
          // 处理单位信息
          this.unitList.map(res => {
            if (res.organizationid == this.form.unitno)
            if (res.organizationid == this.form.unitno) {
              this.form.unitname = res.organizationname;
            }
          });
          console.log(this.form);
          if (this.form.id != null) {
            updateExternalperson(this.form).then(response => {
          // 将数组转换为逗号分隔的字符串
          const submitData = { ...this.form };
          if (Array.isArray(submitData.usertype) && submitData.usertype.length > 0) {
            submitData.usertype = submitData.usertype.join(',');
          } else {
            submitData.usertype = '';
          }
          console.log("提交数据:", submitData);
          if (submitData.id != null) {
            updateExternalperson(submitData).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.queryParams.username = this.form.username;
              this.queryParams.username = submitData.username;
              this.getList();
            }).catch(error => {
              console.error("修改失败:", error);
            });
          } else {
            getOnlyCode(this.seqnoParams).then(res => {
              this.form.userno = res.data.currentvalue;
              submitData.userno = res.data.currentvalue;
              addExternalperson(this.form).then(response => {
              addExternalperson(submitData).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.queryParams.username = this.form.username;
                this.queryParams.username = submitData.username;
                this.getList();
              }).catch(error => {
                console.error("新增失败:", error);
              });
            }).catch(error => {
              console.error("获取编号失败:", error);
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
@@ -594,9 +679,15 @@
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      const queryParams = { ...this.queryParams };
      // 处理查询参数,如果是数组则转换为逗号分隔的字符串
      if (Array.isArray(queryParams.usertype) && queryParams.usertype.length > 0) {
        queryParams.usertype = queryParams.usertype.join(',');
      }
      this.$modal
        .confirm("是否确认导出所有人员/单位账号信息数据项?")
        .then(() => {
@@ -607,22 +698,31 @@
          this.$download.name(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
        .catch(() => {
          this.exportLoading = false;
        });
    },
    //获取医疗机构列表
    getUnitList() {
      listOrganization(3).then(response => {
        for (let i = 0; i < response.rows.length; i++) {
          this.unitList.push({
            //organizationid: response.rows[i].organizationid,
            organizationid: response.rows[i].id.toString(),
            organizationname: response.rows[i].organizationname
          });
          console.log(this.unitList);
        }
        this.unitList = response.rows.map(item => ({
          organizationid: item.id.toString(),
          organizationname: item.organizationname
        }));
        console.log("医疗机构列表:", this.unitList);
      });
    }
  }
};
</script>
<style scoped>
::v-deep .el-select .el-tag {
  margin: 2px 6px 2px 0;
}
::v-deep .el-select .el-tag__close {
  margin-left: 4px;
}
</style>