experience.vue 10 KB

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