step-education.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <div class="education" id="education">
  3. <header class="sign-new-header">
  4. <div class="sign-new-header-title">教育经历</div>
  5. <span>
  6. <el-button @click="handleAdd" type="text" icon="el-icon-plus"
  7. >添加</el-button
  8. >
  9. </span>
  10. </header>
  11. <div v-if="education.length > 0">
  12. <template v-for="(item, idx) in education">
  13. <div
  14. v-if="editingItem.indexOf(idx) < 0"
  15. :key="item.university"
  16. class="show"
  17. >
  18. <h4>
  19. <span>{{
  20. `${item.start_time} - ${item.end_time || "至今"} ${
  21. item.university
  22. } ${item.major}`
  23. }}</span>
  24. <img
  25. @click="editItem(idx)"
  26. src="~/assets/img/svg/edit.svg"
  27. class="sign-edit-icon"
  28. />
  29. <!-- <el-button @click="editItem(idx)" type="text">编辑</el-button> -->
  30. </h4>
  31. <!-- <p>{{ item.description }}</p> -->
  32. </div>
  33. <div v-else :key="'education' + idx" class="edit">
  34. <el-form ref="form" :rules="rules" :model="item" label-width="147px">
  35. <div class="header">
  36. <date-range class="range" v-model="item.date"></date-range>
  37. <el-select
  38. v-model="item.university"
  39. allow-create
  40. filterable
  41. remote
  42. default-first-option
  43. placeholder="学校名称"
  44. :remote-method="fetchUniversity"
  45. :loading="loadingUniversity"
  46. >
  47. <el-option
  48. v-for="item in universities"
  49. :key="item.label"
  50. :label="item.label"
  51. :value="item.label"
  52. ></el-option>
  53. </el-select>
  54. <!-- reserve-keyword -->
  55. <el-select
  56. class="small"
  57. v-model="item.major"
  58. allow-create
  59. filterable
  60. remote
  61. default-first-option
  62. placeholder="选择专业"
  63. :remote-method="fetchMajor"
  64. :loading="loadingMajor"
  65. >
  66. <el-option
  67. v-for="item in majors"
  68. :key="item.label"
  69. :label="item.label"
  70. :value="item.label"
  71. ></el-option>
  72. </el-select>
  73. <el-select
  74. class="small"
  75. v-model="item.education_background"
  76. placeholder="学历"
  77. >
  78. <el-option
  79. v-for="educationBackground in educationBackgrounds"
  80. :key="educationBackground.value"
  81. :label="educationBackground.label"
  82. :value="educationBackground.label"
  83. ></el-option>
  84. </el-select>
  85. </div>
  86. <!-- <div>
  87. <el-input
  88. class="big"
  89. v-model="item.diploma_url"
  90. placeholder="请输入学信网在线验证报告地址"
  91. ></el-input>
  92. </div> -->
  93. <div class="content">
  94. <el-input
  95. type="textarea"
  96. :rows="7"
  97. maxlength="140"
  98. show-word-limit
  99. placeholder="经历简介(选填)"
  100. v-model="item.description"
  101. ></el-input>
  102. <!-- <uploader
  103. :imageUrl="item.diploma_photo"
  104. title="毕业证图片"
  105. @change="val => handleImageUrl(idx, val)"
  106. ></uploader> -->
  107. </div>
  108. <footer class="sign-new-form-footer">
  109. <div class="sign-new-form-tips">
  110. <!-- <p>学信网在线验证报告, 例如:https://www.proginn.com</p>
  111. <p>
  112. 注:学历证明可以是毕业证图片或学信网在线验证报告(二选一即可)
  113. </p> -->
  114. </div>
  115. <div class="sign-new-btn-area">
  116. <span class="opts">
  117. <el-button type="danger" @click="handleDelete(idx, item)"
  118. >删除</el-button
  119. >
  120. <el-button type="info" @click="handleCancel(idx, item)"
  121. >取消</el-button
  122. >
  123. <el-button type="primary" @click="handleConfirm(idx, item)"
  124. >保存</el-button
  125. >
  126. </span>
  127. </div>
  128. </footer>
  129. </el-form>
  130. </div>
  131. </template>
  132. </div>
  133. <div v-else class="empty">点击右上角“添加”按钮添加教育经历</div>
  134. </div>
  135. </template>
  136. <script>
  137. import uploader from "@/components/uploader";
  138. import dateRange from "@/components/date-range";
  139. import { mapState } from "vuex";
  140. export default {
  141. data() {
  142. return {
  143. // editing: true,
  144. editingModel: null,
  145. editingItem: [],
  146. rules: {
  147. name: ""
  148. },
  149. education: [],
  150. current: null,
  151. originEducation: [],
  152. universities: [],
  153. loadingUniversity: false,
  154. majors: [],
  155. loadingMajor: false,
  156. educationBackgrounds: [],
  157. init: {
  158. diploma_photo: "",
  159. diploma_url: "",
  160. start_time: "",
  161. end_time: "",
  162. date: [],
  163. university: "",
  164. major: "",
  165. education_background: "",
  166. description: ""
  167. }
  168. };
  169. },
  170. components: {
  171. uploader,
  172. dateRange
  173. },
  174. computed: {
  175. ...mapState(["userinfo"])
  176. },
  177. watch: {
  178. education: function(val) {
  179. this.$emit("educationChange", val);
  180. }
  181. },
  182. async mounted() {
  183. this.getData();
  184. this.getEducationBackground();
  185. },
  186. methods: {
  187. async onSubmit(idx) {
  188. console.log("submit!", this.education);
  189. if (this.education.length > 10) {
  190. this.$message.error("最多可添加10项工作经历!");
  191. }
  192. const data = this.education.map(it => {
  193. let item1 = {
  194. diploma_photo: it.diploma_photo,
  195. diploma_url: it.diploma_url,
  196. start_time: it.date[0],
  197. end_time: it.date[1],
  198. university: it.university,
  199. major: it.major,
  200. education_background: it.education_background,
  201. description: it.description
  202. };
  203. if (it.id) {
  204. item1.id = it.id;
  205. }
  206. return {
  207. ...it,
  208. ...item1
  209. };
  210. });
  211. const res = await this.$axios.$post("/api/user_education/save_all", {
  212. data: JSON.stringify(data)
  213. });
  214. if (res.status === 1) {
  215. this.$message.success("保存成功!");
  216. this.getData();
  217. return true;
  218. } else {
  219. this.$message.error(res.info);
  220. return false;
  221. }
  222. },
  223. async getData() {
  224. const res = await this.$axios.$post("/api/user_education/list");
  225. const data = res.data || [];
  226. const education = data.map(it => ({
  227. ...it,
  228. date: [it.start_time || "", it.end_time || ""]
  229. }));
  230. console.log("education", education);
  231. this.education = education;
  232. },
  233. async getEducationBackground() {
  234. const res = await this.$axios.$post(
  235. "/api/simple_data/select_education_background"
  236. );
  237. const data = res.data || [];
  238. this.educationBackgrounds = data.map(it => ({
  239. value: it.id,
  240. label: it.name
  241. }));
  242. },
  243. async fetchUniversity(keyword) {
  244. console.log(keyword);
  245. this.loadingUniversity = true;
  246. const res = await this.$axios.$post(
  247. "/api/simple_data/select_university",
  248. { keyword }
  249. );
  250. this.loadingUniversity = false;
  251. const data = res.data || [];
  252. this.universities = data.map(it => ({ value: it.id, label: it.name }));
  253. },
  254. async fetchMajor(keyword) {
  255. console.log(keyword);
  256. this.loadingMajor = true;
  257. const res = await this.$axios.$post("/api/simple_data/select_major", {
  258. keyword
  259. });
  260. this.loadingMajor = false;
  261. const data = res.data || [];
  262. this.majors = data.map(it => ({ value: it.id, label: it.name }));
  263. },
  264. handleRankClose() {
  265. this.rankForm = {
  266. first: ""
  267. };
  268. },
  269. handleRank() {
  270. this.rankDialog = false;
  271. },
  272. handleAdd() {
  273. if (this.userinfo && this.userinfo.realname_verify_status === "0") {
  274. this.$message.error("请先进行实名认证");
  275. return;
  276. }
  277. if (
  278. this.editingItem.length > 0 &&
  279. !this.education[this.editingItem[0]].id
  280. ) {
  281. this.$message.error("请先保存现有修改");
  282. return;
  283. }
  284. const _init = JSON.parse(JSON.stringify(this.init));
  285. this.education.push(_init);
  286. this.editingModel = _init;
  287. this.editingItem = [this.education.length - 1];
  288. },
  289. handleImageUrl(idx, url) {
  290. this.education[idx].diploma_photo = url;
  291. },
  292. async handleDelete(idx) {
  293. this.editingItem = [];
  294. this.education.splice(idx, 1);
  295. this.editingModel = null;
  296. await this.onSubmit();
  297. },
  298. handleCancel(idx, item) {
  299. if (!item.id) {
  300. this.education.splice(idx, 1);
  301. } else {
  302. this.education.splice(idx, 1, this.editingModel);
  303. }
  304. this.editingItem = [];
  305. this.editingModel = null;
  306. },
  307. handleConfirm(idx, item) {
  308. this.cnzz("签约", "签约页面+教育经历保存", "");
  309. // const item = this.education.slice(idx, idx + 1)[0];
  310. if (!item.date) {
  311. this.$message.error("请设置开始时间/结束时间!");
  312. return;
  313. } else if (
  314. item.date &&
  315. item.date[0] &&
  316. item.date[1] &&
  317. item.date[0] > item.date[1]
  318. ) {
  319. this.$message.error("请设置开始时间小于结束时间!");
  320. return;
  321. }
  322. if (!item.university || !item.major || !item.education_background) {
  323. this.$message.error("请设置学校名称/专业/学历!");
  324. return;
  325. }
  326. // if (item.description !== "" && item.description.length < 15) {
  327. // this.$message.error("教育经历不得低于15个字符");
  328. // return;
  329. // }
  330. if (item.description.length > 140) {
  331. this.$message.error("教育经历不得多于140个字符");
  332. return;
  333. }
  334. // if (!item.diploma_url && !item.diploma_photo) {
  335. // this.$message.error("请提供学历证明!");
  336. // return;
  337. // }
  338. this.editingItem = [];
  339. // const submitItem = {
  340. // ...item,
  341. // start_time: item.date[0],
  342. // end_time: item.date[1]
  343. // };
  344. this.onSubmit();
  345. },
  346. editItem(idx) {
  347. if (this.userinfo && this.userinfo.realname_verify_status === "0") {
  348. this.$message.error("请先进行实名认证");
  349. return;
  350. }
  351. this.editingItem = [idx];
  352. const origin = this.education.slice(idx, idx + 1)[0];
  353. this.editingModel = JSON.parse(JSON.stringify(origin));
  354. }
  355. }
  356. };
  357. </script>
  358. <style lang="scss" scoped>
  359. .education {
  360. .sign-edit-icon {
  361. margin-right: 20px;
  362. }
  363. .header .el-icon-plus {
  364. font-size: 18px;
  365. }
  366. .edit {
  367. padding: 20px 0;
  368. > form {
  369. .header {
  370. display: flex;
  371. align-items: center;
  372. justify-content: space-between;
  373. margin-bottom: 10px;
  374. }
  375. .range {
  376. margin-right: 10px;
  377. }
  378. .opts {
  379. display: flex;
  380. align-items: center;
  381. .el-button {
  382. margin-left: 5px;
  383. }
  384. }
  385. .el-select,
  386. .el-input {
  387. width: 136px;
  388. margin-right: 10px;
  389. .el-input--suffix .el-input__inner {
  390. padding-right: 0;
  391. }
  392. }
  393. .small {
  394. width: 140px;
  395. }
  396. .big {
  397. width: 100%;
  398. }
  399. .times {
  400. .el-checkbox {
  401. width: 88px;
  402. }
  403. .el-input {
  404. width: 160px;
  405. }
  406. }
  407. .content {
  408. display: flex;
  409. justify-content: space-between;
  410. align-items: flex-start;
  411. margin-top: 10px;
  412. .el-textarea {
  413. display: flex;
  414. // width: 620px;
  415. // height: 162px;
  416. height: 80px;
  417. }
  418. }
  419. }
  420. }
  421. .show {
  422. // padding: 18px 0;
  423. border-bottom: 1px solid #ebeef5;
  424. h4 {
  425. display: flex;
  426. justify-content: space-between;
  427. align-items: center;
  428. height: 60px;
  429. line-height: 60px;
  430. font-size: 15px;
  431. font-family: PingFangSC-Regular, PingFang SC;
  432. font-weight: 400;
  433. color: #0b121a;
  434. }
  435. p {
  436. word-break: break-all;
  437. margin-top: 8px;
  438. font-size: 14px;
  439. font-family: PingFangSC-Regular;
  440. font-weight: 400;
  441. color: rgba(102, 102, 102, 1);
  442. line-height: 24px;
  443. }
  444. }
  445. .empty {
  446. margin: 112px auto 104px;
  447. font-size: 27px;
  448. font-family: PingFangSC-Regular;
  449. font-weight: 400;
  450. text-align: center;
  451. color: rgba(205, 205, 205, 1);
  452. line-height: 38px;
  453. }
  454. footer p {
  455. margin-top: 15px;
  456. font-size: 12px;
  457. font-family: PingFangSC-Regular;
  458. font-weight: 400;
  459. color: rgba(145, 154, 167, 1);
  460. line-height: 17px;
  461. }
  462. }
  463. </style>