education.vue 11 KB

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