step-work-experience.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. },
  147. async getData() {
  148. const res = await this.$axios.$post("/api/user_experience/get_my_list");
  149. const data = res.data || [];
  150. const experience = data.map((it, index) => {
  151. if (it.is_main == "1") {
  152. this.rankForm.first = it.id;
  153. }
  154. return {
  155. ...it,
  156. date: [it.start_time, it.end_time]
  157. };
  158. });
  159. this.experience = experience;
  160. this.originExperience = data;
  161. },
  162. handleRankClose() {
  163. this.rankDialog = false;
  164. // this.rankForm = {
  165. // first: ""
  166. // };
  167. },
  168. handleRank() {
  169. let idx = 0;
  170. this.experience.map((it, index) => {
  171. if (it.id == this.rankForm.first) {
  172. idx = index;
  173. }
  174. return it;
  175. });
  176. // this.experience.forEach((item, index) => {
  177. // if (idx === index) {
  178. // item.is_main = 1;
  179. // } else {
  180. // item.is_main = 0;
  181. // }
  182. // })
  183. this.originExperience.forEach((item, index) => {
  184. if (idx === index) {
  185. item.is_main = 1;
  186. } else {
  187. item.is_main = 0;
  188. }
  189. });
  190. this.onSubmit();
  191. this.rankDialog = false;
  192. },
  193. handleAdd() {
  194. if (this.userinfo && this.userinfo.realname_verify_status === "0") {
  195. this.$message.error("请先进行实名认证");
  196. return;
  197. }
  198. if (
  199. this.editingItem.length > 0 &&
  200. !this.experience[this.editingItem[0]].id
  201. ) {
  202. this.$message.error("请先保存现有修改");
  203. return;
  204. }
  205. const _init = JSON.parse(JSON.stringify(this.init));
  206. this.experience.push(_init);
  207. this.editingItem = [this.experience.length - 1];
  208. },
  209. handleDelete(item, idx) {
  210. this.experience.splice(idx, 1);
  211. this.originExperience.splice(idx, 1);
  212. this.editingItem = [];
  213. this.onSubmit();
  214. },
  215. handleCancel(item, idx) {
  216. const origin = this.originExperience.slice(idx, idx + 1)[0];
  217. if (!origin) {
  218. this.editingItem = [];
  219. this.experience.splice(idx, 1);
  220. } else {
  221. const originCopy = JSON.parse(JSON.stringify(origin));
  222. originCopy.date = [origin.start_time, origin.end_time];
  223. this.editingItem = [];
  224. if (!item.id) {
  225. this.experience.splice(idx, 1);
  226. } else {
  227. this.experience.splice(idx, 1, originCopy);
  228. }
  229. }
  230. },
  231. handleConfirm(item, idx) {
  232. this.cnzz("签约", "签约页面+工作经历保存", "");
  233. const origin = this.originExperience.slice(idx, idx + 1)[0];
  234. // 编辑 item 时,item 对象中的 key 顺序均相同,可直接使用 JSON.stringify 做比较
  235. let itemCopy = JSON.parse(JSON.stringify(item));
  236. delete itemCopy["date"];
  237. if (JSON.stringify(itemCopy) == JSON.stringify(origin)) {
  238. this.$message.error("请修改后保存!");
  239. return;
  240. }
  241. // if (item == origin) {
  242. // this.$message.error("请修改后保存!");
  243. // return;
  244. // }
  245. console.log(item.date);
  246. if (!item.date) {
  247. this.$message.error("请设置开始时间/结束时间!");
  248. return;
  249. } else if (
  250. item.date &&
  251. item.date[0] &&
  252. item.date[1] &&
  253. item.date[0] > item.date[1]
  254. ) {
  255. this.$message.error("请设置开始时间小于结束时间!");
  256. return;
  257. }
  258. if (!item.company || !item.title) {
  259. this.$message.error("请设置公司名称/职位!");
  260. return;
  261. }
  262. if (!item.description || item.description.length < 40) {
  263. this.$message.error("经历描述不少于40字符!");
  264. return;
  265. }
  266. this.editingItem = [];
  267. item.start_time = item.date[0];
  268. item.end_time = item.date[1];
  269. this.originExperience.splice(idx, 1, item);
  270. this.onSubmit();
  271. },
  272. editItem(item, idx) {
  273. this.rankDialog = false;
  274. this.editingItem = [idx];
  275. },
  276. showRankDialog() {
  277. if (this.experience.length < 1) {
  278. this.$message.error("请先添加工作经历");
  279. return false;
  280. }
  281. this.rankDialog = true;
  282. }
  283. }
  284. };
  285. </script>
  286. <style lang="scss" scoped>
  287. .info {
  288. header .el-icon-plus {
  289. font-size: 18px;
  290. }
  291. .first,
  292. .verify {
  293. width: 70px;
  294. height: 32px;
  295. background: rgba(48, 142, 255, 1);
  296. border-radius: 2px;
  297. text-align: center;
  298. font-size: 12px;
  299. font-family: PingFangSC-Medium;
  300. font-weight: 500;
  301. color: rgba(255, 255, 255, 1);
  302. line-height: 32px;
  303. }
  304. .verify {
  305. background: #fff;
  306. border-radius: 2px;
  307. color: rgba(16, 185, 106, 1);
  308. border: 1px solid rgba(16, 185, 106, 1);
  309. }
  310. .show {
  311. // padding: 18px 0;
  312. border-bottom: 1px solid #ebeef5;
  313. word-break: break-all;
  314. h4 {
  315. position: relative;
  316. display: flex;
  317. justify-content: flex-start;
  318. align-items: center;
  319. height: 60px;
  320. line-height: 60px;
  321. font-size: 15px;
  322. font-family: PingFangSC-Regular, PingFang SC;
  323. font-weight: 400;
  324. color: #0b121a;
  325. span {
  326. margin-right: 20px;
  327. }
  328. button {
  329. position: absolute;
  330. right: 0;
  331. }
  332. }
  333. p {
  334. border-top: 1px solid #ebeef5;
  335. font-size: 14px;
  336. font-family: PingFangSC-Regular;
  337. font-weight: 400;
  338. color: rgba(102, 102, 102, 1);
  339. line-height: 24px;
  340. padding: 18px 0;
  341. }
  342. }
  343. .empty {
  344. margin: 112px auto 104px;
  345. font-size: 27px;
  346. font-family: PingFangSC-Regular;
  347. font-weight: 400;
  348. text-align: center;
  349. color: rgba(205, 205, 205, 1);
  350. line-height: 38px;
  351. }
  352. .first-form {
  353. margin-left: 40px;
  354. .el-radio-group {
  355. display: flex;
  356. flex-direction: column;
  357. }
  358. }
  359. .first-radio {
  360. position: relative;
  361. display: inline-flex;
  362. justify-content: space-between;
  363. align-items: center;
  364. width: 350px;
  365. margin: 0 20px 20px;
  366. .des span {
  367. margin-right: 40px;
  368. }
  369. }
  370. .first-tips {
  371. margin-top: 10px;
  372. h6 {
  373. font-size: 16px;
  374. margin-bottom: 20px;
  375. }
  376. p {
  377. font-size: 14px;
  378. line-height: 1.4;
  379. }
  380. }
  381. .sign-edit-icon {
  382. position: absolute;
  383. right: 20px;
  384. }
  385. }
  386. </style>