education.vue 11 KB

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