step-work-experience.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <div class="info" id="workexp">
  3. <header class="sign-new-header">
  4. <div class="sign-new-header-title">工作经历(必填)</div>
  5. <span>
  6. <el-button
  7. v-if="experience.length > 0"
  8. @click="showRankDialog"
  9. type="text"
  10. >设置优先展示</el-button
  11. >
  12. <el-dialog
  13. title="设置优先展示工作经历"
  14. :visible.sync="rankDialog"
  15. :before-close="handleRankClose"
  16. >
  17. <el-form ref="form" :model="rankForm" class="first-form">
  18. <el-radio-group v-model="rankForm.first">
  19. <template v-for="(item, idx) in experience">
  20. <el-radio :label="item.id" :value="item.id" :key="item.id">
  21. <div class="first-radio">
  22. <span class="des">
  23. <span>{{ item.company }}</span>
  24. <span>{{ item.title }}</span>
  25. </span>
  26. <el-button @click="editItem(item, idx)" type="text"
  27. >编辑</el-button
  28. >
  29. </div>
  30. </el-radio>
  31. </template>
  32. </el-radio-group>
  33. </el-form>
  34. <div class="first-tips">
  35. <h6>温馨提示</h6>
  36. <p>
  37. 1.
  38. 只有上传过工作证明且通过认证的工作经历,才可选择设置为"优先展示工作经历"
  39. <br />2. 修改公司,
  40. 职位信息,"保存"成功后,客栈将在一个工作日内完成审核,审核通过后,即可生效
  41. </p>
  42. </div>
  43. <span slot="footer" class="dialog-footer">
  44. <el-button @click="rankDialog = false">取 消</el-button>
  45. <el-button type="primary" @click="handleRank">确 定</el-button>
  46. </span>
  47. </el-dialog>
  48. <el-button @click="handleAdd" type="text" icon="el-icon-plus"
  49. >添加</el-button
  50. >
  51. </span>
  52. </header>
  53. <div v-if="experience.length > 0">
  54. <template v-for="(item, idx) in experience">
  55. <div v-if="editingItem.indexOf(idx) < 0" :key="item.id" class="show">
  56. <h4>
  57. <span>{{
  58. `${item.start_time} - ${item.end_time || "至今"} ${
  59. item.company
  60. } ${item.title}`
  61. }}</span>
  62. <span v-if="item.is_main == '1'" class="first">优先展示</span>
  63. <span v-if="item.isAuth == 1" class="verify">已认证</span>
  64. <img
  65. @click="editItem(item, idx)"
  66. src="~/assets/img/svg/edit.svg"
  67. class="sign-edit-icon"
  68. />
  69. </h4>
  70. <p>{{ item.description }}</p>
  71. </div>
  72. <stepExperienceForm
  73. v-else
  74. :key="`experience${idx}`"
  75. :idx="idx"
  76. :item="item"
  77. :handleCancel="handleCancel"
  78. :handleConfirm="handleConfirm"
  79. :handleDelete="handleDelete"
  80. ></stepExperienceForm>
  81. </template>
  82. </div>
  83. <div v-else class="empty">点击右上角“添加”按钮添加工作经历</div>
  84. </div>
  85. </template>
  86. <script>
  87. import { mapState } from "vuex";
  88. import experienceForm from "./experience-form";
  89. import stepExperienceForm from "./step-experience-form";
  90. export default {
  91. data() {
  92. return {
  93. // editing: true,
  94. editingItem: [],
  95. rules: {},
  96. init: {
  97. work_certify_img: "",
  98. start_time: "",
  99. date: [],
  100. end_time: "",
  101. company: "",
  102. title: "",
  103. is_main: 0,
  104. description: ""
  105. },
  106. experience: [],
  107. originExperience: [],
  108. current: null,
  109. rankDialog: false,
  110. rankForm: {
  111. first: ""
  112. }
  113. };
  114. },
  115. components: {
  116. experienceForm,
  117. stepExperienceForm
  118. },
  119. computed: {
  120. ...mapState(["userinfo"])
  121. },
  122. watch: {
  123. experience: function(val) {
  124. this.$emit("workExperienceChange", val);
  125. }
  126. },
  127. async mounted() {
  128. this.getData();
  129. },
  130. methods: {
  131. async onSubmit() {
  132. console.log("submit!", this.originExperience);
  133. if (this.originExperience.length > 10) {
  134. this.$message.error("最多可添加10项工作经历!");
  135. }
  136. const res = await this.$axios.$post("/api/user_experience/save_all", {
  137. data: JSON.stringify(this.originExperience)
  138. });
  139. if (res.status === 1) {
  140. this.$message.success("保存成功!");
  141. this.getData();
  142. } else if (res.status === 2 && res.info.indexOf("管理员审核") > -1) {
  143. // 保存工作经历,需要审核时,同样重新获取数据
  144. this.getData();
  145. }
  146. else{
  147. this.getData();
  148. }
  149. },
  150. async getData() {
  151. const res = await this.$axios.$post("/api/user_experience/get_my_list");
  152. const data = res.data || [];
  153. const experience = data.map((it, index) => {
  154. if (it.is_main == "1") {
  155. this.rankForm.first = it.id;
  156. }
  157. return {
  158. ...it,
  159. date: [it.start_time, it.end_time]
  160. };
  161. });
  162. this.experience = experience;
  163. this.originExperience = data;
  164. },
  165. handleRankClose() {
  166. this.rankDialog = false;
  167. // this.rankForm = {
  168. // first: ""
  169. // };
  170. },
  171. handleRank() {
  172. let idx = 0;
  173. this.experience.map((it, index) => {
  174. if (it.id == this.rankForm.first) {
  175. idx = index;
  176. }
  177. return it;
  178. });
  179. // this.experience.forEach((item, index) => {
  180. // if (idx === index) {
  181. // item.is_main = 1;
  182. // } else {
  183. // item.is_main = 0;
  184. // }
  185. // })
  186. this.originExperience.forEach((item, index) => {
  187. if (idx === index) {
  188. item.is_main = 1;
  189. } else {
  190. item.is_main = 0;
  191. }
  192. });
  193. this.onSubmit();
  194. this.rankDialog = false;
  195. },
  196. handleAdd() {
  197. if (this.userinfo && this.userinfo.realname_verify_status === "0") {
  198. this.$message.error("请先进行实名认证");
  199. return;
  200. }
  201. if (
  202. this.editingItem.length > 0 &&
  203. !this.experience[this.editingItem[0]].id
  204. ) {
  205. this.$message.error("请先保存现有修改");
  206. return;
  207. }
  208. const _init = JSON.parse(JSON.stringify(this.init));
  209. this.experience.push(_init);
  210. this.editingItem = [this.experience.length - 1];
  211. },
  212. handleDelete(item, idx) {
  213. this.experience.splice(idx, 1);
  214. this.originExperience.splice(idx, 1);
  215. this.editingItem = [];
  216. this.onSubmit();
  217. },
  218. handleCancel(item, idx) {
  219. const origin = this.originExperience.slice(idx, idx + 1)[0];
  220. if (!origin) {
  221. this.editingItem = [];
  222. this.experience.splice(idx, 1);
  223. } else {
  224. const originCopy = JSON.parse(JSON.stringify(origin));
  225. originCopy.date = [origin.start_time, origin.end_time];
  226. this.editingItem = [];
  227. if (!item.id) {
  228. this.experience.splice(idx, 1);
  229. } else {
  230. this.experience.splice(idx, 1, originCopy);
  231. }
  232. }
  233. },
  234. handleConfirm(item, idx) {
  235. this.cnzz("签约", "签约页面+工作经历保存", "");
  236. const origin = this.originExperience.slice(idx, idx + 1)[0];
  237. // 编辑 item 时,item 对象中的 key 顺序均相同,可直接使用 JSON.stringify 做比较
  238. let itemCopy = JSON.parse(JSON.stringify(item));
  239. delete itemCopy["date"];
  240. if (JSON.stringify(itemCopy) == JSON.stringify(origin)) {
  241. this.$message.error("请修改后保存!");
  242. return;
  243. }
  244. // if (item == origin) {
  245. // this.$message.error("请修改后保存!");
  246. // return;
  247. // }
  248. console.log(item.date);
  249. if (!item.date) {
  250. this.$message.error("请设置开始时间/结束时间!");
  251. return;
  252. } else if (
  253. item.date &&
  254. item.date[0] &&
  255. item.date[1] &&
  256. item.date[0] > item.date[1]
  257. ) {
  258. this.$message.error("请设置开始时间小于结束时间!");
  259. return;
  260. }
  261. if (!item.company || !item.title) {
  262. this.$message.error("请设置公司名称/职位!");
  263. return;
  264. }
  265. if (!item.description || item.description.length < 40) {
  266. this.$message.error("经历描述不少于40字符!");
  267. return;
  268. }
  269. this.editingItem = [];
  270. item.start_time = item.date[0];
  271. item.end_time = item.date[1];
  272. this.originExperience.splice(idx, 1, item);
  273. this.onSubmit();
  274. },
  275. editItem(item, idx) {
  276. this.rankDialog = false;
  277. this.editingItem = [idx];
  278. },
  279. showRankDialog() {
  280. if (this.experience.length < 1) {
  281. this.$message.error("请先添加工作经历");
  282. return false;
  283. }
  284. this.rankDialog = true;
  285. }
  286. }
  287. };
  288. </script>
  289. <style lang="scss" scoped>
  290. .info {
  291. header .el-icon-plus {
  292. font-size: 18px;
  293. }
  294. .first,
  295. .verify {
  296. width: 70px;
  297. height: 32px;
  298. background: rgba(48, 142, 255, 1);
  299. border-radius: 2px;
  300. text-align: center;
  301. font-size: 12px;
  302. font-family: PingFangSC-Medium;
  303. font-weight: 500;
  304. color: rgba(255, 255, 255, 1);
  305. line-height: 32px;
  306. }
  307. .verify {
  308. background: #fff;
  309. border-radius: 2px;
  310. color: rgba(16, 185, 106, 1);
  311. border: 1px solid rgba(16, 185, 106, 1);
  312. }
  313. .show {
  314. // padding: 18px 0;
  315. border-bottom: 1px solid #ebeef5;
  316. word-break: break-all;
  317. h4 {
  318. position: relative;
  319. display: flex;
  320. justify-content: flex-start;
  321. align-items: center;
  322. height: 60px;
  323. line-height: 60px;
  324. font-size: 15px;
  325. font-family: PingFangSC-Regular, PingFang SC;
  326. font-weight: 400;
  327. color: #0b121a;
  328. span {
  329. margin-right: 20px;
  330. }
  331. button {
  332. position: absolute;
  333. right: 0;
  334. }
  335. }
  336. p {
  337. border-top: 1px solid #ebeef5;
  338. font-size: 14px;
  339. font-family: PingFangSC-Regular;
  340. font-weight: 400;
  341. color: rgba(102, 102, 102, 1);
  342. line-height: 24px;
  343. padding: 18px 0;
  344. }
  345. }
  346. .empty {
  347. margin: 112px auto 104px;
  348. font-size: 27px;
  349. font-family: PingFangSC-Regular;
  350. font-weight: 400;
  351. text-align: center;
  352. color: rgba(205, 205, 205, 1);
  353. line-height: 38px;
  354. }
  355. .first-form {
  356. margin-left: 40px;
  357. .el-radio-group {
  358. display: flex;
  359. flex-direction: column;
  360. }
  361. }
  362. .first-radio {
  363. position: relative;
  364. display: inline-flex;
  365. justify-content: space-between;
  366. align-items: center;
  367. width: 350px;
  368. margin: 0 20px 20px;
  369. .des span {
  370. margin-right: 40px;
  371. }
  372. }
  373. .first-tips {
  374. margin-top: 10px;
  375. h6 {
  376. font-size: 16px;
  377. margin-bottom: 20px;
  378. }
  379. p {
  380. font-size: 14px;
  381. line-height: 1.4;
  382. }
  383. }
  384. .sign-edit-icon {
  385. position: absolute;
  386. right: 20px;
  387. }
  388. }
  389. </style>