organList.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. <template>
  2. <div class="list_container">
  3. <div class="title_examine">
  4. <div class="pub_title">组织列表</div>
  5. <div style="margin-left: auto;">
  6. <el-input v-model="checkOrg" placeholder="请输入组织" size="normal" clearable @input="changeOrg"
  7. style="margin-right: 10px; width: 200px"></el-input>
  8. <el-select v-model="checkArea" placeholder="选择区域" clearable filterable @change="changeArea"
  9. style="margin-right: 10px">
  10. <el-option v-for="item in regionCList" :key="item.id" :label="item.name" :value="item.name">
  11. </el-option>
  12. </el-select>
  13. <el-button type="primary" size="small" @click="add_organ_dialog = true;">新增组织</el-button>
  14. </div>
  15. </div>
  16. <div class="tableBox">
  17. <el-table :data="organizations" stripe border style="width: 100%" :header-cell-style="headerCellStyle">
  18. <el-table-column show-overflow-tooltip prop="name" label="组织名称" min-width="45"></el-table-column>
  19. <el-table-column show-overflow-tooltip prop="code" label="编码" min-width="45">
  20. <template slot-scope="scope">
  21. {{ scope.row.code || '-' }} <!-- 如果 org 为空,显示 '-' -->
  22. </template>
  23. </el-table-column>
  24. <el-table-column show-overflow-tooltip prop="detail" label="描述" min-width="45">
  25. <template slot-scope="scope">
  26. {{ scope.row.detail || '-' }} <!-- 如果 org 为空,显示 '-' -->
  27. </template>
  28. </el-table-column>
  29. <el-table-column show-overflow-tooltip prop="area" label="区域" min-width="45"></el-table-column>
  30. <el-table-column show-overflow-tooltip prop="ctime" label="创建时间" min-width="45"></el-table-column>
  31. <el-table-column label="是否禁用/使用期限" min-width="45">
  32. <template #default="scope">
  33. <span v-if="scope.row.isLogin === '1'">启用</span>
  34. <span v-else-if="scope.row.isLogin === '2'">禁用</span>
  35. <span v-else>{{ scope.row.isLogin }}</span>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="操作" width="220px">
  39. <template slot-scope="scope">
  40. <div class="operate">
  41. <button @click="update(scope.row)">编辑</button>
  42. <button @click="enable(scope.row)">
  43. {{ scope.row.isLogin === '2' ? '启用' : '禁用' }}
  44. </button>
  45. <button @click="toPage(scope.row)">批量创建</button>
  46. <button @click="permissionSetting(scope.row)"
  47. v-show="!unShowJurUser.includes(userid)">权限设置</button>
  48. <button @click="delete_organ(scope.row)" style="color:red;">删除</button>
  49. </div>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. </div>
  54. <!-- 分页组件 -->
  55. <el-pagination :current-page="currentPage" :page-size="pageSize" :total="total"
  56. @current-change="handlePageChange" layout="total,prev, pager, next, jumper">
  57. </el-pagination>
  58. <!-- 新增组织弹窗 -->
  59. <el-dialog title="新增组织" class="table" :visible.sync="add_organ_dialog" :before-close="close_add_organ"
  60. width="700px">
  61. <div class="el_dialog_org_content">
  62. <form class="el-form">
  63. <!-- 组织名称 -->
  64. <div class="el-form-item" style="margin-top: 15px">
  65. <label class="el-form-item__label" style="width: 100px">组织名称</label>
  66. <div class="el-form-item__content" style="margin-left: 5px">
  67. <span>
  68. <div class="add_input el-input el-input--suffix">
  69. <input v-model="orgName" type="text" autocomplete="off" placeholder="组织名称"
  70. class="el-input__inner" />
  71. </div>
  72. </span>
  73. </div>
  74. </div>
  75. <!-- 地区 -->
  76. <div class="el-form-item">
  77. <label class="el-form-item__label" style="width: 100px">组织编码</label>
  78. <div class="el-form-item__content" style="margin-left: 5px">
  79. <span>
  80. <div class="add_input el-input el-input--suffix">
  81. <input v-model="randomCode" type="text" autocomplete="off" placeholder="请输入随机码"
  82. class="el-input__inner" />
  83. </div>
  84. </span>
  85. </div>
  86. </div>
  87. <!-- 描述 -->
  88. <div class="el-form-item">
  89. <label class="el-form-item__label" style="width: 100px">描述</label>
  90. <div class="el-form-item__content" style="margin-left: 5px">
  91. <span>
  92. <div class="add_input el-input el-input--suffix">
  93. <input v-model="orgDetail" type="text" autocomplete="off" placeholder="请输入描述"
  94. class="el-input__inner" />
  95. </div>
  96. </span>
  97. </div>
  98. </div>
  99. <!-- 区域 -->
  100. <div class="el-form-item">
  101. <label class="el-form-item__label" style="width: 100px">区域</label>
  102. <div class="el-form-item__content" style="margin-left: 5px">
  103. <span>
  104. <div class="add_input el-input el-input--suffix">
  105. <el-select v-model="regionC" placeholder="请选择区域" class="custom-select" filterable>
  106. <el-option v-for="(org, index) in regionCList" :key="index" :label="org.name"
  107. :value="org.name">
  108. {{ org.name }}
  109. </el-option>
  110. </el-select>
  111. </div>
  112. </span>
  113. </div>
  114. </div>
  115. </form>
  116. </div>
  117. <!-- 按钮区域 -->
  118. <div slot="footer" class="el-dialog__footer" style="margin-top: 88px;">
  119. <el-button @click="close_add_organ">取 消</el-button>
  120. <el-button type="primary" @click="ajax_add_org">确认</el-button>
  121. </div>
  122. </el-dialog>
  123. <!-- 修改组织弹窗 -->
  124. <el-dialog title="修改组织" class="table" :visible.sync="add_organ_dialog2" :before-close="close_add_organ2"
  125. width="700px">
  126. <div class="el_dialog_org_content">
  127. <form class="el-form">
  128. <!-- 组织名称 -->
  129. <div class="el-form-item" style="margin-top: 15px">
  130. <label class="el-form-item__label" style="width: 100px">组织名称</label>
  131. <div class="el-form-item__content" style="margin-left: 5px">
  132. <span>
  133. <div class="add_input el-input el-input--suffix">
  134. <input v-model="orgName" type="text" autocomplete="off" placeholder="组织名称"
  135. class="el-input__inner" />
  136. </div>
  137. </span>
  138. </div>
  139. </div>
  140. <!-- 地区 -->
  141. <div class="el-form-item">
  142. <label class="el-form-item__label" style="width: 100px">组织编码</label>
  143. <div class="el-form-item__content" style="margin-left: 5px">
  144. <span>
  145. <div class="add_input el-input el-input--suffix">
  146. <input v-model="randomCode" type="text" autocomplete="off" placeholder="请输入随机码"
  147. class="el-input__inner" />
  148. </div>
  149. </span>
  150. </div>
  151. </div>
  152. <!-- 描述 -->
  153. <div class="el-form-item">
  154. <label class="el-form-item__label" style="width: 100px">描述</label>
  155. <div class="el-form-item__content" style="margin-left: 5px">
  156. <span>
  157. <div class="add_input el-input el-input--suffix">
  158. <input v-model="orgDetail" type="text" autocomplete="off" placeholder="请输入描述"
  159. class="el-input__inner" />
  160. </div>
  161. </span>
  162. </div>
  163. </div>
  164. <!-- 区域 -->
  165. <div class="el-form-item">
  166. <label class="el-form-item__label" style="width: 100px">区域</label>
  167. <div class="el-form-item__content" style="margin-left: 5px">
  168. <span>
  169. <div class="add_input el-input el-input--suffix">
  170. <el-select v-model="regionC" placeholder="请选择区域" class="custom-select" filterable>
  171. <el-option v-for="(org, index) in regionCList" :key="index" :label="org.name"
  172. :value="org.name">
  173. {{ org.name }}
  174. </el-option>
  175. </el-select>
  176. </div>
  177. </span>
  178. </div>
  179. </div>
  180. </form>
  181. </div>
  182. <!-- 按钮区域 -->
  183. <div slot="footer" class="el-dialog__footer" style="margin-top: 88px;">
  184. <el-button @click="close_add_organ2">取 消</el-button>
  185. <el-button type="primary" @click="updateOrgan">确认</el-button>
  186. </div>
  187. </el-dialog>
  188. <!-- 启用弹窗 -->
  189. <el-dialog title="启用组织" class="table" :visible.sync="enable_organ_dialog" :before-close="close_enable_organ"
  190. width="700px">
  191. <div class="el_dialog_org_content">
  192. <form class="el-form">
  193. <!-- 使用期限 -->
  194. <div class="el-form-item">
  195. <label class="el-form-item__label">使用期限</label>
  196. <div class="el-form-item__content">
  197. <el-date-picker v-model="useDate" format="yyyy-MM-dd" type="date" value-format="yyyy-MM-dd"
  198. placeholder="请选择使用期限" />
  199. </div>
  200. </div>
  201. </form>
  202. </div>
  203. <!-- 按钮区域 -->
  204. <div slot="footer" class="dialog-footer">
  205. <el-button @click="close_enable_organ">取 消</el-button>
  206. <el-button type="primary" @click="enable_organ">确认</el-button>
  207. </div>
  208. </el-dialog>
  209. <permissionSettingDialog ref="permissionSettingDialogRef" @getData="getOrgan" />
  210. </div>
  211. </template>
  212. <script>
  213. import { API_CONFIG } from '@/common/apiConfig';
  214. import { addOp } from "@/api/user";
  215. import { mapGetters } from 'vuex';
  216. import permissionSettingDialog from './dialog/permissionSettingDialog'
  217. export default {
  218. name: 'onList',
  219. components: {
  220. permissionSettingDialog
  221. },
  222. data() {
  223. return {
  224. organizations: [],
  225. organList: [],
  226. checkOrg: "",
  227. checkArea: "",
  228. currentPage: 1,
  229. pageSize: 10,
  230. total: 0,
  231. add_organ_dialog: false,
  232. add_organ_dialog2: false,
  233. enable_organ_dialog: false,
  234. useDate: "",
  235. orgName: "",
  236. randomCode: "",
  237. orgDetail: "",
  238. regionC: 'cn',
  239. uLogin: "1", // 登录状态 (1 或 2)
  240. radio: "1",
  241. regionCList: [
  242. { id: 1, name: 'hk' },
  243. { id: 2, name: 'cn' }
  244. ], //区域列表
  245. form: {
  246. organ: ""
  247. },
  248. organ: {},
  249. unShowJurUser: ['0abcb118-9110-11eb-80ad-005056b86db5']
  250. }
  251. },
  252. computed: {
  253. ...mapGetters(['userid']),
  254. },
  255. // created() {
  256. // this.formatDate();
  257. // },
  258. methods: {
  259. // 表头的背景色
  260. headerCellStyle() {
  261. return { backgroundColor: "#f1f1f1" };
  262. },
  263. changeOrg() {
  264. this.currentPage = 1;
  265. this.getOrgan();
  266. },
  267. changeArea() {
  268. this.currentPage = 1;
  269. this.getOrgan();
  270. },
  271. getOrgan() {
  272. let params = [
  273. {
  274. functionName: "getOrgan",
  275. org: this.checkOrg,
  276. area: this.checkArea,
  277. page: this.currentPage,
  278. num: this.pageSize,
  279. }
  280. ];
  281. this.$ajax
  282. .post(API_CONFIG.baseUrl, params)
  283. .then((res) => {
  284. // console.log("返回的数据为:", res.data); // 检查返回的数据
  285. if (res.data && Array.isArray(res.data[0])) {
  286. // 使用 map() 提取所有组织名称
  287. this.organizations = res.data[0]
  288. this.total = res.data[0][0].num
  289. console.log(this.organizations);
  290. }
  291. })
  292. .catch((err) => {
  293. this.$message.error("查询失败");
  294. console.error("请求失败,错误信息:", err);
  295. });
  296. },
  297. ajax_org() {
  298. const params = [API_CONFIG.ajax_org]; // 使用配置中的接口参数
  299. this.$ajax
  300. .post(API_CONFIG.baseUrl, params)
  301. .then((res) => {
  302. // console.log("返回的数据为:", res.data); // 检查返回的数据
  303. if (res.data && Array.isArray(res.data[0])) {
  304. // 使用 map() 提取所有组织名称
  305. this.organList = res.data[0].map((item) => ({
  306. name: item.name,
  307. id: item.id,
  308. }));
  309. }
  310. // console.log("返回的结果为:",this.organizations);
  311. })
  312. .catch((err) => {
  313. this.$message.error("查询失败");
  314. console.error("请求失败,错误信息:", err);
  315. });
  316. },
  317. // 页码扩展按钮
  318. handlePageChange(page) {
  319. this.currentPage = page;
  320. this.getOrgan();
  321. },
  322. //新增学校关闭
  323. close_add_organ() {
  324. this.regionC = 'cn'
  325. this.add_organ_dialog = false;
  326. },
  327. //修改学校关闭
  328. close_add_organ2() {
  329. this.orgName = "";
  330. this.randomCode = "";
  331. this.orgDetail = "";
  332. this.regionC = 'cn'
  333. this.add_organ_dialog2 = false;
  334. },
  335. close_enable_organ() {
  336. this.enable_organ_dialog = false;
  337. },
  338. //新增组织
  339. ajax_add_org() {
  340. // 获取弹窗中的输入内容
  341. let orgName = this.orgName; // 组织名称
  342. let randomCode = this.randomCode || ""; // 随机码(可为空)
  343. let uLogin = this.radio; // 获取复选框选中的值(1 或 2)
  344. // 验证组织名称不能为空
  345. if (!orgName) {
  346. this.$message.error("组织名称不能为空");
  347. return;
  348. }
  349. // 构造请求参数
  350. let params = [
  351. {
  352. functionName: API_CONFIG.ajax_add_org.functionName, // 调用存储过程的名称
  353. u_name: orgName, // 组织名称
  354. u_create: this.userid, // u_create 固定为0
  355. u_code: randomCode, // 随机码(可以为空)
  356. u_detail: this.orgDetail, // 描述
  357. u_regionC: this.regionC,
  358. u_login: uLogin, // 登录状态
  359. },
  360. ];
  361. // 发起请求
  362. this.$ajax
  363. .post(API_CONFIG.baseUrl, params)
  364. .then(async (res) => {
  365. console.log(res.data);
  366. // 检查返回的结果
  367. if (res.data && res.data[0] && res.data[0][0]) {
  368. if (res.data[0][0].name === 1) {
  369. this.$message({
  370. type: "error",
  371. message: "该组织已存在,请重新选择!",
  372. });
  373. return;
  374. } else {
  375. this.$message({
  376. type: "success",
  377. message: "添加成功!",
  378. });
  379. await addOp({
  380. uid: this.userid,
  381. cid: "",
  382. type: "user_op",
  383. content: `添加了组织 ${orgName}`,
  384. });
  385. }
  386. } else {
  387. this.$message.error("插入失败,未返回有效结果");
  388. }
  389. // 刷新组织列表
  390. this.getOrgan();
  391. //关闭弹窗
  392. this.add_organ_dialog = false;
  393. // 清空输入框、下拉菜单选择和单选框
  394. this.orgName = ""; // 清空学校名称
  395. this.orgDetail = ""; // 清空学校描述
  396. this.regionC = 'cn'
  397. this.randomCode = ""; // 清空地区选择
  398. this.uLogin = "1"; // 清空学校类型选择
  399. })
  400. .catch((err) => {
  401. this.$message.error("插入失败");
  402. console.error("请求失败,错误信息:", err);
  403. });
  404. },
  405. update(row) {
  406. this.add_organ_dialog2 = true;
  407. this.nid = row.id;
  408. this.orgName = row.name;
  409. this.randomCode = row.code;
  410. this.regionC = row.area;
  411. this.orgDetail = row.detail;
  412. console.log(row);
  413. },
  414. updateOrgan() {
  415. let params = [
  416. {
  417. functionName: "updateOrgan2",
  418. id: this.nid,
  419. name: this.orgName,
  420. code: this.randomCode,
  421. detail: this.orgDetail,
  422. area: this.regionC
  423. }
  424. ];
  425. this.$ajax
  426. .post(API_CONFIG.baseUrl, params)
  427. .then(async (res) => {
  428. console.log("👉", res.data);
  429. this.add_organ_dialog2 = false;
  430. this.$message({
  431. message: '修改成功',
  432. type: 'success'
  433. });
  434. this.getOrgan();
  435. await addOp({
  436. uid: this.userid,
  437. cid: "",
  438. type: "user_op",
  439. content: `修改了组织 ${this.orgName} ${this.nid}`,
  440. });
  441. })
  442. .catch((err) => {
  443. this.$message.error("修改失败");
  444. console.log(err);
  445. });
  446. },
  447. formatDate() {
  448. // 使用示例
  449. const today = new Date(); // 获取当前日期
  450. const year = today.getFullYear(); // 获取年份
  451. const month = String(today.getMonth() + 1).padStart(2, '0'); // 获取月份,注意月份从0开始,所以要加1,并确保是两位数
  452. const day = String(today.getDate()).padStart(2, '0'); // 获取日期,并确保是两位数
  453. this.useDate = `${year}-${month}-${day}`; // 返回格式化后的日期字符串
  454. },
  455. enable(row) {
  456. if (row.isLogin === '2') {
  457. this.enable_organ_dialog = true;
  458. this.nid = row.id;
  459. }
  460. else {
  461. this.disableOrgan(row);
  462. }
  463. },
  464. enable_organ() {
  465. let params = [
  466. {
  467. functionName: "enableOrgan",
  468. id: this.nid,
  469. date: this.useDate
  470. }
  471. ];
  472. this.$ajax
  473. .post(API_CONFIG.baseUrl, params)
  474. .then(async (res) => {
  475. console.log("👉", res.data);
  476. this.enable_organ_dialog = false;
  477. this.useDate = "";
  478. this.$message({
  479. message: '启用成功',
  480. type: 'success'
  481. });
  482. // this.formatDate();
  483. this.getOrgan();
  484. await addOp({
  485. uid: this.userid,
  486. cid: "",
  487. type: "user_op",
  488. content: `启用了组织 ${this.orgName} ${this.nid}`,
  489. });
  490. })
  491. .catch((err) => {
  492. this.$message.error("启用失败");
  493. console.log(err);
  494. });
  495. },
  496. disableOrgan(row) {
  497. this.nid = row.id;
  498. let params = [
  499. {
  500. functionName: "disableOrgan",
  501. id: this.nid
  502. }
  503. ];
  504. this.$confirm("确定禁用此组织记录吗?", "提示", {
  505. confirmButtonText: "确定",
  506. cancelButtonText: "取消",
  507. type: "warning",
  508. })
  509. .then(() => {
  510. this.$ajax
  511. .post(API_CONFIG.baseUrl, params)
  512. .then(async (res) => {
  513. console.log("👉", res.data);
  514. this.$message({
  515. message: '禁用成功',
  516. type: 'success'
  517. });
  518. this.getOrgan();
  519. await addOp({
  520. uid: this.userid,
  521. cid: "",
  522. type: "user_op",
  523. content: `禁用了组织 ${row.name} ${row.id}`,
  524. });
  525. })
  526. })
  527. .catch((err) => {
  528. console.log(err);
  529. });
  530. },
  531. delete_organ(row) {
  532. this.nid = row.id;
  533. let params = [
  534. {
  535. functionName: "deleteOrgan",
  536. id: this.nid
  537. }
  538. ];
  539. this.$confirm("确定删除此组织记录吗?", "提示", {
  540. confirmButtonText: "确定",
  541. cancelButtonText: "取消",
  542. type: "warning",
  543. })
  544. .then(() => {
  545. this.$ajax
  546. .post(API_CONFIG.baseUrl, params)
  547. .then(async (res) => {
  548. console.log("👉", res.data);
  549. this.$message({
  550. message: '删除成功',
  551. type: 'success'
  552. });
  553. this.getOrgan();
  554. await addOp({
  555. uid: this.userid,
  556. cid: "",
  557. type: "user_op",
  558. content: `删除了组织 ${row.name} ${row.id}`,
  559. });
  560. })
  561. })
  562. .catch((err) => {
  563. this.$message.error("删除失败");
  564. console.log(err);
  565. });
  566. },
  567. async getUserId(oid, org) {
  568. let params = [
  569. {
  570. functionName: "select_Suffix", // 调用存储过程的名称
  571. org: org, //组织id
  572. oid: oid, //学校id
  573. },
  574. ];
  575. try {
  576. const res = await this.$ajax.post(API_CONFIG.baseUrl, params);
  577. console.log('getSuffix', res);
  578. let data = res.data[0];
  579. let orgData = res.data[1];
  580. let ap = data.length > 0 ? data[0].userid : orgData.length > 0 ? orgData[0].userid : "";
  581. return ap
  582. } catch (err) {
  583. console.error("请求失败,错误信息:", err);
  584. }
  585. },
  586. async toPage(row) {
  587. const oid = "";
  588. const org = row.id;
  589. await addOp({
  590. uid: this.userid,
  591. cid: "",
  592. type: "user_op",
  593. content: `点击了批量添加 ${row.name}${row.id}`,
  594. });
  595. let userid = await this.getUserId(oid, org);
  596. const url = `https://beta.pbl.cocorobo.cn/pbl-teacher-table/dist/?#/teacher?userid=${userid ? userid : this.userid}&oid=${oid}&org=${org}`;
  597. window.open(url, '_blank');
  598. },
  599. permissionSetting(data) {
  600. this.$refs.permissionSettingDialogRef.open(data, "org");
  601. }
  602. },
  603. mounted() {
  604. this.getOrgan();
  605. this.ajax_org();
  606. }
  607. }
  608. </script>
  609. <style scoped>
  610. .list_container {
  611. width: 100%;
  612. height: 100%;
  613. padding: 10px;
  614. box-sizing: border-box;
  615. overflow: auto;
  616. }
  617. .tableBox {
  618. margin: 10px 0;
  619. }
  620. .operate {
  621. display: flex;
  622. gap: 3px;
  623. }
  624. /* 新增组织的内容容器 */
  625. .el_dialog_org_content {
  626. color: #606266;
  627. font-size: 14px;
  628. height: 120px;
  629. }
  630. .el-form-item {
  631. margin-bottom: 22px;
  632. display: flex;
  633. align-items: center;
  634. /* border: 1px solid black; */
  635. }
  636. .el-form-item__label {
  637. font-size: 14px;
  638. color: #606266;
  639. line-height: 40px;
  640. margin-left: 20px;
  641. width: 70px;
  642. }
  643. .el-form-item__content {
  644. line-height: 40px;
  645. position: relative;
  646. font-size: 14px;
  647. }
  648. .table>>>.el-dialog__header {
  649. padding: 15px 20px;
  650. background: #454545;
  651. }
  652. .table>>>.el-dialog__title {
  653. color: #fff;
  654. }
  655. .operate button {
  656. background: none;
  657. border: none;
  658. cursor: pointer;
  659. color: #308fff;
  660. }
  661. </style>