mngAdd.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <template>
  2. <div>
  3. <div class="inner--headers">
  4. <h2>{{ pageId }}</h2>
  5. <div class="bread--crumbs--wrap">
  6. <span>홈</span>
  7. <span>관리자 관리</span>
  8. <span>{{ pageId }}</span>
  9. </div>
  10. </div>
  11. <div class="view-wrap mt--45">
  12. <div class="view-box">
  13. <div class="view-box-top">
  14. <h3 v-if="pageType == 'I'">관리자 등록</h3>
  15. <h3 v-else>관리자 수정</h3>
  16. </div>
  17. <div class="view-box-btm">
  18. <div class="form-style1">
  19. <v-form ref="addForm">
  20. <table>
  21. <colgroup>
  22. <col style="width: 12.5rem" />
  23. <col />
  24. </colgroup>
  25. <tbody>
  26. <tr v-if="useAuthStore().getCompanyId == '0-000000'">
  27. <th>회사명<span class="bul">*</span></th>
  28. <td>
  29. <v-text-field
  30. v-model="form.companyName"
  31. maxlength="10"
  32. class="custom-input mini"
  33. style="max-width: 200px"
  34. :readonly="pageType == 'U'"
  35. :rules="[useValid.required('회사명')]"
  36. ></v-text-field>
  37. </td>
  38. </tr>
  39. <tr>
  40. <th>아이디<span class="bul">*</span></th>
  41. <td>
  42. <div class="form--group--inner align-start">
  43. <v-text-field
  44. v-model="form.id"
  45. class="custom-input mini"
  46. style="max-width: 200px"
  47. :readonly="isReadonly"
  48. placeholder=""
  49. :rules="[useValid.required('아이디')]"
  50. ></v-text-field>
  51. <v-btn
  52. v-if="!isReadonly"
  53. class="custom-btn mini btn-black"
  54. @click="idCheck"
  55. :class="{ disabled: form.idCheck }"
  56. >중복 확인</v-btn
  57. >
  58. </div>
  59. </td>
  60. </tr>
  61. <tr>
  62. <th>패스워드<span v-if="pageType == 'I'" class="bul">*</span></th>
  63. <td>
  64. <v-text-field
  65. v-model="form.passWord"
  66. class="custom-input mini"
  67. type="password"
  68. style="max-width: 200px"
  69. :rules="
  70. pageType == 'U'
  71. ? form.passWord.length > 0
  72. ? [useValid.passWordChk(form.passWord)]
  73. : []
  74. : [useValid.passWordChk(form.passWord)]
  75. "
  76. ></v-text-field>
  77. </td>
  78. </tr>
  79. <tr>
  80. <th>
  81. 패스워드 확인<span v-if="pageType == 'I'" class="bul">*</span>
  82. </th>
  83. <td>
  84. <v-text-field
  85. v-model="form.passWordCheck"
  86. type="password"
  87. class="custom-input mini"
  88. style="max-width: 200px"
  89. :rules="
  90. pageType == 'U' && form.passWord.length == 0
  91. ? []
  92. : [useValid.passWordConfirm(form.passWord)]
  93. "
  94. ></v-text-field>
  95. </td>
  96. </tr>
  97. <tr>
  98. <th>이름<span class="bul">*</span></th>
  99. <td>
  100. <v-text-field
  101. v-model="form.name"
  102. maxlength="10"
  103. :readonly="isReadonly"
  104. class="custom-input mini"
  105. style="max-width: 200px"
  106. :rules="[useValid.required('이름')]"
  107. ></v-text-field>
  108. </td>
  109. </tr>
  110. <tr>
  111. <th>연락처<span class="bul">*</span></th>
  112. <td>
  113. <div class="form--group--inner">
  114. <v-text-field
  115. v-model="form.phone[0]"
  116. class="custom-input mini"
  117. style="max-width: 150px"
  118. maxlength="4"
  119. :rules="[useValid.required('연락처')]"
  120. ></v-text-field>
  121. -
  122. <v-text-field
  123. v-model="form.phone[1]"
  124. class="custom-input mini"
  125. maxlength="4"
  126. :rules="[useValid.required('연락처')]"
  127. style="max-width: 150px"
  128. ></v-text-field>
  129. -
  130. <v-text-field
  131. v-model="form.phone[2]"
  132. maxlength="4"
  133. :rules="[useValid.required('연락처')]"
  134. class="custom-input mini"
  135. style="max-width: 150px"
  136. ></v-text-field>
  137. </div>
  138. </td>
  139. </tr>
  140. <tr>
  141. <th>이메일<span class="bul">*</span></th>
  142. <td>
  143. <div class="form--group--inner">
  144. <v-text-field
  145. v-model="form.email[0]"
  146. class="custom-input mini"
  147. :rules="[useValid.required('이메일')]"
  148. style="width: 200px"
  149. ></v-text-field>
  150. @
  151. <v-text-field
  152. :class="{ visible: hide }"
  153. v-model="form.email[1]"
  154. class="custom-input mini"
  155. :rules="[useValid.required('이메일')]"
  156. style="width: 250px"
  157. ></v-text-field>
  158. <v-select
  159. v-model="form.emailSet"
  160. variant="outlined"
  161. style="max-width: 250px"
  162. class="custom-select"
  163. :items="form.emailArr"
  164. @update:modelValue="emailPush(form.emailSet)"
  165. >
  166. </v-select>
  167. </div>
  168. </td>
  169. </tr>
  170. <tr v-if="useAuthStore().getCompanyId == '0-000000'">
  171. <th class="bg le">기업코드<span class="bul">*</span></th>
  172. <td>
  173. <div class="form--group--inner">
  174. <v-text-field
  175. class="custom-input mini"
  176. v-model="form.companyId"
  177. style="max-width: 200px"
  178. :readonly="pageType == 'U'"
  179. ></v-text-field>
  180. <span class="caution--text fts--14"
  181. >* 0-000000 형식의 자릿수 맞추어 등록(주의 : 등록 후
  182. 수정불가능!)</span
  183. >
  184. </div>
  185. </td>
  186. </tr>
  187. <tr v-if="pageType == 'U'">
  188. <th>상태<span class="bul">*</span></th>
  189. <td>
  190. <v-select
  191. variant="outlined"
  192. style="width: 250px"
  193. class="custom-select"
  194. v-model="form.status"
  195. :items="form.statusArr"
  196. >
  197. </v-select>
  198. </td>
  199. </tr>
  200. </tbody>
  201. </table>
  202. </v-form>
  203. </div>
  204. </div>
  205. </div>
  206. <div class="view-btm-btn">
  207. <div class="btn-l">
  208. <v-btn class="custom-btn btn-list" @click="listLocated"
  209. ><i class="ico"></i>목록</v-btn
  210. >
  211. </div>
  212. <div class="btn-r">
  213. <v-btn v-show="pageType == 'I'" class="custom-btn btn-blue2" @click="fnRegCheck"
  214. ><i class="ico"></i>저장</v-btn
  215. >
  216. <v-btn v-show="pageType == 'U'" class="custom-btn btn-blue2" @click="fnRegCheck"
  217. ><i class="ico"></i>수정</v-btn
  218. >
  219. </div>
  220. </div>
  221. </div>
  222. </div>
  223. </template>
  224. <script setup>
  225. import VueDatePicker from "@vuepic/vue-datepicker";
  226. import "@vuepic/vue-datepicker/dist/main.css";
  227. import { now } from "lodash";
  228. /************************************************************************
  229. | 레이아웃
  230. ************************************************************************/
  231. definePageMeta({
  232. layout: "default",
  233. });
  234. /************************************************************************
  235. | 스토어
  236. ************************************************************************/
  237. const useDtStore = useDetailStore();
  238. /************************************************************************
  239. | 전역
  240. ************************************************************************/
  241. const hide = ref(null);
  242. const addForm = ref(null);
  243. const router = useRouter();
  244. const { $eventBus } = useNuxtApp();
  245. const isReadonly = ref(false);
  246. const pageType = ref("");
  247. const adminId = ref("");
  248. const pageId = ref("");
  249. const datePickerFormat = "yyyy-MM-dd";
  250. const today = new Date().toISOString().slice(0, 10);
  251. const form = ref({
  252. companyId: "",
  253. companyName: "",
  254. id: "",
  255. passWord: "",
  256. passWordCheck: "",
  257. name: "",
  258. phone: ["", "", ""],
  259. email: ["", ""],
  260. emailSet: "직접 입력",
  261. emailArr: [
  262. { title: "직접 입력", value: "" },
  263. { title: "naver.com", value: "naver.com" },
  264. { title: "gmail.com", value: "gmail.com" },
  265. { title: "daum.net", value: "daum.net" },
  266. { title: "yahoo.com", value: "yahoo.com" },
  267. { title: "icloud.com", value: "icloud.com" },
  268. { title: "hotmail.com", value: "hotmail.com" },
  269. { title: "outlook.com", value: "outlook.com" },
  270. ],
  271. regDate: today,
  272. status: "",
  273. statusArr: [
  274. { title: "사용중", value: "0" },
  275. { title: "정지", value: "1" },
  276. ],
  277. idCheck: false,
  278. });
  279. const fnUpdEvt = () => {
  280. let param = {
  281. id: pageId,
  282. title: "관리자 수정",
  283. content: "저장하시겠습니까?",
  284. yes: {
  285. text: "저장",
  286. isProc: true,
  287. event: "FN_UPDATE",
  288. param: "",
  289. },
  290. no: {
  291. text: "취소",
  292. isProc: false,
  293. },
  294. };
  295. $eventBus.emit("OPEN_CONFIRM_POP_UP", param);
  296. };
  297. const fnRegCheck = () => {
  298. nextTick(() => {
  299. if (addForm.value && typeof addForm.value.validate === "function") {
  300. addForm.value
  301. .validate()
  302. .then((isValid) => {
  303. if (isValid.valid) {
  304. if (pageType.value == "I") {
  305. if (form.value.idCheck) {
  306. fnRegEvt();
  307. }
  308. } else {
  309. fnUpdEvt();
  310. }
  311. } else {
  312. if (pageType.value == "I") {
  313. if (form.value.idCheck == false) {
  314. let param = {
  315. id: pageId,
  316. title: "관리자 등록",
  317. content: "중복 여부를 체크한 뒤 다시 시도해주세요.",
  318. yes: {
  319. text: "확인",
  320. isProc: false,
  321. },
  322. };
  323. $eventBus.emit("OPEN_CONFIRM_POP_UP", param);
  324. } else {
  325. let param = {
  326. id: pageId,
  327. title: "관리자 등록",
  328. content: "필수항목을 입력해주세요.",
  329. yes: {
  330. text: "확인",
  331. isProc: false,
  332. },
  333. };
  334. $eventBus.emit("OPEN_CONFIRM_POP_UP", param);
  335. }
  336. } else {
  337. let param = {
  338. id: pageId,
  339. title: "관리자 수정",
  340. content: "필수항목을 입력해주세요.",
  341. yes: {
  342. text: "확인",
  343. isProc: false,
  344. },
  345. };
  346. $eventBus.emit("OPEN_CONFIRM_POP_UP", param);
  347. }
  348. }
  349. })
  350. .catch((err) => {
  351. console.error("벨리데이션 에러", err);
  352. });
  353. } else {
  354. console.error("항목 누락체크[fnRegCheck]]");
  355. }
  356. });
  357. };
  358. const fnRegEvt = () => {
  359. let param = {
  360. id: pageId,
  361. title: "관리자 등록",
  362. content: "등록하시겠습니까?",
  363. yes: {
  364. text: "등록",
  365. isProc: true,
  366. event: "FN_INSERT",
  367. param: "",
  368. },
  369. no: {
  370. text: "취소",
  371. isProc: false,
  372. },
  373. };
  374. $eventBus.emit("OPEN_CONFIRM_POP_UP", param);
  375. };
  376. const fnInsert = () => {
  377. let params = {
  378. id: form.value.id,
  379. password: form.value.passWord,
  380. name: form.value.name,
  381. phone: form.value.phone[0] + "-" + form.value.phone[1] + "-" + form.value.phone[2],
  382. email: form.value.email[0] + "@" + form.value.email[1],
  383. regdate: Date.now(),
  384. comp_name:
  385. useAuthStore().getCompanyId == "0-000000"
  386. ? form.value.companyName
  387. : useAuthStore().getCompanyName,
  388. comp_id:
  389. useAuthStore().getCompanyId == "0-000000"
  390. ? form.value.companyId
  391. : useAuthStore().getCompanyId,
  392. };
  393. useAxios()
  394. .post("/mng/reg", params)
  395. .then((res) => {
  396. router.push("/view/mng");
  397. })
  398. .catch((error) => {
  399. //$log.debug("[equipMgmtReg][fnGetTenantList][error]");
  400. //useErrorHandler().fnSetCommErrorHandle(error, fnGetTenantList);
  401. })
  402. .finally(() => {
  403. //$log.debug("[equipMgmtReg][fnGetTenantList][finished]");
  404. //objSlt.value.tenantNameList = _cloneDeep(temp);
  405. });
  406. };
  407. const fnUpdate = () => {
  408. let params = {
  409. id: useDtStore.adminInfo.adminId,
  410. password: form.value.passWord,
  411. name: form.value.name,
  412. phone: form.value.phone[0] + "-" + form.value.phone[1] + "-" + form.value.phone[2],
  413. email: form.value.email[0] + "@" + form.value.email[1],
  414. regdate: form.value.regDate,
  415. status: form.value.status,
  416. comp_name:
  417. useAuthStore().getCompanyId == "0-000000"
  418. ? form.value.companyName
  419. : useAuthStore().getCompanyName,
  420. comp_id:
  421. useAuthStore().getCompanyId == "0-000000"
  422. ? form.value.companyId
  423. : useAuthStore().getCompanyId,
  424. };
  425. useAxios()
  426. .post("/mng/update", params)
  427. .then((res) => {
  428. window.location.reload();
  429. })
  430. .catch((error) => {})
  431. .finally(() => {});
  432. };
  433. const fnDetail = () => {
  434. let _req = {
  435. id: useDtStore.adminInfo.adminId,
  436. };
  437. useAxios()
  438. .get(`/mng/detail/${_req.id}`)
  439. .then((res) => {
  440. form.value.companyId = res.data.COMP_ID;
  441. form.value.companyName = res.data.COMP_NAME;
  442. form.value.id = res.data.ID;
  443. form.value.name = res.data.NAME;
  444. form.value.phone[0] = res.data.PHONE.split("-")[0];
  445. form.value.phone[1] = res.data.PHONE.split("-")[1];
  446. form.value.phone[2] = res.data.PHONE.split("-")[2];
  447. form.value.email[0] = res.data.EMAIL.split("@")[0];
  448. form.value.email[1] = res.data.EMAIL.split("@")[1];
  449. form.value.regDate = new Date(res.data.REGDATE);
  450. form.value.status = res.data.STATUS;
  451. })
  452. .catch((error) => {})
  453. .finally(() => {});
  454. };
  455. const emailPush = (__VAL) => {
  456. form.value.email[1] = __VAL;
  457. hide.value = __VAL.length > 0 ? true : false;
  458. };
  459. /************************************************************************
  460. | 함수(METHODS)
  461. ************************************************************************/
  462. const listLocated = () => {
  463. router.push({
  464. path: "/view/mng",
  465. });
  466. };
  467. const idCheck = () => {
  468. let params = {
  469. id: form.value.id,
  470. };
  471. if (form.value.id.length > 0) {
  472. useAxios()
  473. .post("/mng/chk", params)
  474. .then((res) => {
  475. let param = {
  476. id: pageId,
  477. title: "아이디 중복체크",
  478. content: "사용가능한 아이디입니다.",
  479. yes: {
  480. text: "확인",
  481. isProc: false,
  482. },
  483. };
  484. $eventBus.emit("OPEN_CONFIRM_POP_UP", param);
  485. form.value.idCheck = true;
  486. })
  487. .catch((error) => {
  488. let param = {
  489. id: pageId,
  490. title: "아이디 중복체크",
  491. content: "사용할 수 없는 아이디입니다.",
  492. yes: {
  493. text: "확인",
  494. isProc: false,
  495. },
  496. };
  497. $eventBus.emit("OPEN_CONFIRM_POP_UP", param);
  498. form.value.idCheck = false;
  499. //$log.debug("[equipMgmtReg][fnGetTenantList][error]");
  500. //useErrorHandler().fnSetCommErrorHandle(error, fnGetTenantList);
  501. })
  502. .finally(() => {
  503. //$log.debug("[equipMgmtReg][fnGetTenantList][finished]");
  504. //objSlt.value.tenantNameList = _cloneDeep(temp);
  505. });
  506. } else {
  507. let param = {
  508. id: pageId,
  509. title: "아이디 중복체크",
  510. content: "아이디를 입력해주세요.",
  511. yes: {
  512. text: "확인",
  513. isProc: false,
  514. },
  515. };
  516. $eventBus.emit("OPEN_CONFIRM_POP_UP", param);
  517. }
  518. };
  519. /************************************************************************
  520. | 라이프사이클
  521. ************************************************************************/
  522. onMounted(() => {
  523. pageType.value = useDtStore.adminInfo.pageType;
  524. //관리자 등록/수정 분기처리
  525. if (pageType.value == "U") {
  526. adminId.value = useDtStore.adminInfo.adminId;
  527. pageId.value = "관리자 수정";
  528. isReadonly.value = true;
  529. fnDetail();
  530. } else {
  531. pageId.value = "관리자 등록";
  532. }
  533. });
  534. /************************************************************************
  535. | 팝업 이벤트버스 정의
  536. ************************************************************************/
  537. $eventBus.off("FN_INSERT");
  538. $eventBus.on("FN_INSERT", () => {
  539. fnInsert();
  540. });
  541. $eventBus.off("FN_UPDATE");
  542. $eventBus.on("FN_UPDATE", () => {
  543. fnUpdate();
  544. });
  545. /************************************************************************
  546. | WATCH
  547. ************************************************************************/
  548. </script>