education.vue 12 KB

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