addEdit.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :center="true"
  5. align="left"
  6. top="5vh"
  7. width="700px"
  8. @close="closeModel"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. v-loading="loading"
  12. element-loading-text="拼命加载中"
  13. element-loading-spinner="el-icon-loading"
  14. element-loading-background="rgba(0, 0, 0, 0.8)"
  15. >
  16. <el-card>
  17. <el-row :gutter="10">
  18. <el-col :span="24">
  19. <el-form
  20. v-if="isApproval"
  21. :model="cexForm"
  22. status-icon
  23. :rules="cexRules"
  24. ref="cexForm"
  25. label-width="80px"
  26. class="cexForm-ruleForm"
  27. ><el-row>
  28. <el-col :span="12">
  29. <el-row class="cexForm-div">
  30. <el-col :span="8" class="tr cexForm-label">所属企业:</el-col>
  31. <el-col :span="16" class="cexForm-main">{{
  32. dataInfo.company
  33. }}</el-col>
  34. </el-row>
  35. <el-row class="cexForm-div">
  36. <el-col :span="8" class="tr cexForm-label">账号:</el-col>
  37. <el-col :span="16" class="cexForm-main">{{
  38. dataInfo.username
  39. }}</el-col>
  40. </el-row>
  41. <el-row class="cexForm-div">
  42. <el-col :span="8" class="tr cexForm-label">真实姓名:</el-col>
  43. <el-col :span="16" class="cexForm-main">{{
  44. dataInfo.name
  45. }}</el-col>
  46. </el-row>
  47. <el-row class="cexForm-div">
  48. <el-col :span="8" class="tr cexForm-label">手机号:</el-col>
  49. <el-col :span="16" class="cexForm-main">{{
  50. dataInfo.mobile
  51. }}</el-col>
  52. </el-row>
  53. <el-row class="cexForm-div">
  54. <el-col :span="8" class="tr cexForm-label">邮箱:</el-col>
  55. <el-col :span="16" class="cexForm-main">{{
  56. dataInfo.email
  57. }}</el-col>
  58. </el-row>
  59. <el-row class="cexForm-div" v-if="dataInfo.company">
  60. <el-col :span="8" class="tr cexForm-label">备注:</el-col>
  61. <el-col :span="16" class="cexForm-main">{{
  62. dataInfo.remark
  63. }}</el-col>
  64. </el-row>
  65. </el-col>
  66. <el-col :span="12">
  67. <el-form-item label="审核状态" prop="status">
  68. <el-select
  69. v-model="cexForm.status"
  70. placeholder="请选择审核状态"
  71. @change="selectChange"
  72. >
  73. <el-option
  74. v-for="item in statusList"
  75. :key="item.code"
  76. :label="item.name"
  77. :value="item.code"
  78. >
  79. </el-option>
  80. </el-select>
  81. </el-form-item>
  82. <el-form-item label="审核说明" prop="remark">
  83. <el-input
  84. v-model="cexForm.remark"
  85. type="textarea"
  86. placeholder="请输入审核说明"
  87. :rows="5"
  88. maxlength="300"
  89. show-word-limit
  90. ></el-input>
  91. </el-form-item>
  92. <el-col :span="24" style="text-align: right">
  93. <el-button type="primary" @click="submitCexForm"
  94. >保 存
  95. </el-button>
  96. <el-button @click="showModelThis = false">取 消</el-button>
  97. </el-col>
  98. </el-col>
  99. </el-row></el-form
  100. >
  101. <el-form
  102. v-else
  103. :model="ruleForm"
  104. status-icon
  105. :rules="rulesThis"
  106. ref="ruleForm"
  107. label-width="80px"
  108. class="demo-ruleForm"
  109. ><el-row>
  110. <el-col :span="24">
  111. <el-form-item label="所属企业" prop="company_id">
  112. <el-select
  113. :disabled="isDetail"
  114. v-model="ruleForm.company_id"
  115. filterable
  116. clearable
  117. :size="searchSize"
  118. placeholder="请选择所属企业"
  119. style="width: 100%"
  120. >
  121. <el-option
  122. v-for="item in companyList"
  123. :key="'company' + item.id"
  124. :label="item.company"
  125. :value="item.id"
  126. :disabled="item.status === '0'"
  127. />
  128. </el-select>
  129. <!-- <el-input
  130. v-model="ruleForm.company_id"
  131. :disabled="isDetail"
  132. /> -->
  133. </el-form-item>
  134. </el-col>
  135. <el-col :span="24">
  136. <el-form-item
  137. v-if="id === 'add' || isDetail"
  138. label="账号"
  139. prop="username"
  140. >
  141. <el-input v-model="ruleForm.username" :disabled="isDetail" />
  142. </el-form-item>
  143. </el-col>
  144. <el-col :span="24">
  145. <el-form-item label="真实姓名" prop="contact">
  146. <el-input v-model="ruleForm.contact" :disabled="isDetail" />
  147. </el-form-item>
  148. </el-col>
  149. <el-col :span="24">
  150. <el-form-item label="手机号" prop="mobile">
  151. <el-input v-model="ruleForm.mobile" :disabled="isDetail" />
  152. </el-form-item>
  153. </el-col>
  154. <el-col :span="24">
  155. <el-form-item label="邮箱" prop="email">
  156. <el-input v-model="ruleForm.email" :disabled="isDetail" />
  157. </el-form-item>
  158. </el-col>
  159. </el-row>
  160. <el-form-item label="信息备注" prop="remark">
  161. <el-input
  162. v-model="ruleForm.remark"
  163. type="textarea"
  164. placeholder="请输入备注"
  165. :rows="5"
  166. maxlength="300"
  167. show-word-limit
  168. :disabled="isDetail"
  169. ></el-input>
  170. </el-form-item>
  171. <el-col :span="24" style="text-align: right">
  172. <el-tag
  173. type="warning"
  174. class="fl"
  175. style="max-width: 500px"
  176. v-if="dataInfo.ex_remark && dataInfo.ex_status === '2'"
  177. >审核备注:{{ dataInfo.ex_remark }}</el-tag
  178. >
  179. <el-button type="primary" @click="submitForm" v-if="!isDetail"
  180. >保 存
  181. </el-button>
  182. <el-button @click="showModelThis = false">{{
  183. isDetail ? "关 闭" : "取 消"
  184. }}</el-button>
  185. </el-col>
  186. </el-form>
  187. </el-col>
  188. </el-row>
  189. </el-card>
  190. </el-dialog>
  191. </template>
  192. <script>
  193. import asyncRequest from "@/apis/service/client/business";
  194. import {
  195. isnumber,
  196. isMobile,
  197. validEmail,
  198. isAlphanumeric,
  199. isChinese,
  200. isEmoticon,
  201. validAlphabets,
  202. } from "@/utils/validate";
  203. import statusList from "@/assets/js/cexStatusList";
  204. export default {
  205. name: "specs",
  206. props: ["showModel", "id", "isDetail", "isApproval"],
  207. data() {
  208. const validateusername = (rule, value, callback) => {
  209. if (value === "") {
  210. callback(new Error("账号不能为空!"));
  211. } else {
  212. if (value.lenght < 6 || value.lenght > 18) {
  213. callback(new Error("账号规则为6~18位数字与字母组合!"));
  214. } else {
  215. if (isnumber(value)) {
  216. callback(new Error("账号规则为6~18位数字与字母组合!"));
  217. } else if (validAlphabets(value)) {
  218. callback(new Error("账号规则为6~18位数字与字母组合!"));
  219. } else if (!isAlphanumeric(value)) {
  220. callback(new Error("账号规则为6~18位数字与字母组合!"));
  221. } else {
  222. callback();
  223. }
  224. }
  225. }
  226. };
  227. const validatecontact = (rule, value, callback) => {
  228. if (value === "") {
  229. callback(new Error("真实姓名不能为空!"));
  230. } else {
  231. if (value.lenght < 2 || value.lenght > 12) {
  232. callback(new Error("真实姓名规则为2~12位汉字!"));
  233. } else {
  234. if (!isChinese(value)) {
  235. callback(new Error("真实姓名为6~18位数字与字母组合!"));
  236. } else if (isEmoticon(value)) {
  237. callback(new Error("真实姓名为6~18位数字与字母组合!"));
  238. } else {
  239. callback();
  240. }
  241. }
  242. }
  243. };
  244. const validatemobile = (rule, value, callback) => {
  245. if (value === "") {
  246. callback(new Error("手机号不能为空!"));
  247. } else {
  248. if (!isMobile(value)) {
  249. callback(new Error("手机号格式不正确!"));
  250. } else {
  251. callback();
  252. }
  253. }
  254. };
  255. const validateEmail = (rule, value, callback) => {
  256. if (value === "") {
  257. callback(new Error("邮箱不能为空!"));
  258. } else {
  259. if (!validEmail(value)) {
  260. callback(new Error("邮箱格式不正确!"));
  261. } else {
  262. callback();
  263. }
  264. }
  265. };
  266. return {
  267. statusList: statusList,
  268. loading: false,
  269. title: "添加企业客户",
  270. showModelThis: this.showModel,
  271. dataInfo: {},
  272. companyList: [],
  273. cexForm: {
  274. id: this.id,
  275. remark: "",
  276. status: "1",
  277. },
  278. ruleForm: {
  279. id: this.id, //企业id
  280. company_id: "", //id
  281. type: "2",
  282. username: "", //账号
  283. contact: "", //真实姓名
  284. mobile: "", //手机号
  285. emailz: "", //邮箱
  286. remark: "",
  287. },
  288. cexRules: {
  289. status: {
  290. required: true,
  291. message: "请选择审核状态",
  292. trigger: "change",
  293. },
  294. remark: [
  295. {
  296. required: false,
  297. message: "请输入审核说明!",
  298. trigger: "blur",
  299. },
  300. ],
  301. },
  302. rulesThis: this.rules,
  303. rules: {
  304. company_id: [
  305. {
  306. required: true,
  307. message: "请选择企业!",
  308. trigger: "change",
  309. },
  310. ],
  311. username: [
  312. {
  313. required: true,
  314. validator: validateusername,
  315. trigger: "blur",
  316. },
  317. ],
  318. contact: [
  319. {
  320. required: true,
  321. validator: validatecontact,
  322. trigger: "blur",
  323. },
  324. ],
  325. mobile: [
  326. {
  327. required: true,
  328. validator: validatemobile,
  329. trigger: "blur",
  330. },
  331. ],
  332. email: [
  333. {
  334. required: true,
  335. validator: validateEmail,
  336. trigger: "blur",
  337. },
  338. ],
  339. remark: [
  340. {
  341. required: false,
  342. trigger: "blur",
  343. },
  344. ],
  345. },
  346. };
  347. },
  348. methods: {
  349. closeModel() {
  350. console.log("closeModel!!");
  351. },
  352. selectChange() {
  353. if (this.cexForm.status === "1") {
  354. this.cexRules.remark[0].required = false;
  355. } else {
  356. this.cexRules.remark[0].required = true;
  357. }
  358. },
  359. async initForm() {
  360. if (this.isApproval) {
  361. this.loading = true;
  362. this.title = "企业客户审核";
  363. await this.getCompanyList();
  364. await this.initData();
  365. await this.resetcexForm();
  366. this.selectChange();
  367. this.loading = false;
  368. } else {
  369. this.loading = true;
  370. await this.getCompanyList();
  371. if (this.id === "add") {
  372. this.title = "添加企业客户";
  373. // this.ruleForm.isAdmin = 0;
  374. this.rulesThis = this.rules;
  375. await this.resetForm();
  376. } else {
  377. if (this.isDetail) {
  378. this.title = "企业客户";
  379. this.rulesThis = {};
  380. } else {
  381. this.title = "修改企业客户";
  382. this.rulesThis = this.rules;
  383. }
  384. await this.resetForm();
  385. await this.initData();
  386. }
  387. this.loading = false;
  388. }
  389. },
  390. async resetcexForm() {
  391. if (this.$refs.cexForm) {
  392. this.$refs.cexForm.resetFields();
  393. this.$refs.cexForm.clearValidate();
  394. this.cexForm = {
  395. id: this.id,
  396. remark: "",
  397. status: "1",
  398. };
  399. }
  400. },
  401. async initData() {
  402. this.loading = true;
  403. let res = await asyncRequest.detail({ id: this.id });
  404. this.loading = false;
  405. if (res.code === 0) {
  406. let data = res.data;
  407. this.dataInfo = data;
  408. this.ruleForm = {
  409. id: this.id, //企业id
  410. type: "2",
  411. company_id: data.company_id, //企业id
  412. username: data.username, //账号
  413. contact: data.name, //真实姓名
  414. mobile: data.mobile, //手机号
  415. email: data.email, //邮箱
  416. remark: data.remark,
  417. };
  418. }
  419. },
  420. async resetForm() {
  421. // 重置
  422. await this.$nextTick(() => {
  423. if (this.$refs.ruleForm) {
  424. this.$refs.ruleForm.resetFields();
  425. this.$refs.ruleForm.clearValidate();
  426. this.ruleForm = {
  427. id: this.id, //企业id
  428. type: "2",
  429. company_id: "", //企业id
  430. username: "", //账号
  431. contact: "", //联系人
  432. mobile: "", //手机号
  433. emailz: "", //邮箱
  434. remark: "",
  435. };
  436. }
  437. });
  438. },
  439. async submitCexForm() {
  440. await this.$refs.cexForm.validate(async (valid) => {
  441. if (valid) {
  442. this.loading = true;
  443. console.log(this.id);
  444. console.log(this.cexForm);
  445. let obj = JSON.parse(JSON.stringify(this.cexForm));
  446. obj.id = this.id;
  447. console.log(obj);
  448. let res = await asyncRequest.exam(obj);
  449. this.loading = false;
  450. if (res.code === 0) {
  451. let title = "审核审批成功!";
  452. this.$notify.success({
  453. title,
  454. message: "",
  455. });
  456. this.showModelThis = false;
  457. // 刷新
  458. this.$emit("refresh");
  459. }
  460. } else {
  461. console.log("error submit!!");
  462. return false;
  463. }
  464. });
  465. },
  466. async submitForm() {
  467. await this.$refs.ruleForm.validate(async (valid) => {
  468. if (valid) {
  469. this.loading = true;
  470. let obj = JSON.parse(JSON.stringify(this.ruleForm));
  471. let res = {};
  472. if (this.id === "add") {
  473. delete obj["id"];
  474. res = await asyncRequest.add(obj);
  475. } else {
  476. res = await asyncRequest.update(obj);
  477. }
  478. this.loading = false;
  479. if (res.code === 0) {
  480. let title = this.id === "add" ? "添加成功" : "修改成功";
  481. this.$notify.success({
  482. title,
  483. message: "",
  484. });
  485. this.showModelThis = false;
  486. // 刷新
  487. this.$emit("refresh");
  488. }
  489. } else {
  490. console.log("error submit!!");
  491. return false;
  492. }
  493. });
  494. },
  495. async getCompanyList() {
  496. let res = await asyncRequest.companyall({ type: "2" });
  497. if (res.code === 0) {
  498. this.companyList = res.data;
  499. }
  500. },
  501. },
  502. watch: {
  503. showModel: function (val) {
  504. this.showModelThis = val;
  505. if (val) {
  506. this.initForm();
  507. }
  508. },
  509. showModelThis(val) {
  510. if (!val) {
  511. this.$emit("cancel");
  512. }
  513. },
  514. },
  515. };
  516. </script>
  517. <style lang="scss" scoped>
  518. .business {
  519. .cexForm-ruleForm {
  520. .cexForm-div {
  521. margin-bottom: 0px;
  522. .cexForm-label {
  523. padding-right: 12px;
  524. color: #606266;
  525. line-height: 40px;
  526. font-size: 14px;
  527. }
  528. .cexForm-main {
  529. line-height: 40px;
  530. color: rgb(151, 168, 190);
  531. line-height: 40px;
  532. font-size: 14px;
  533. }
  534. }
  535. }
  536. }
  537. </style>