experience.vue 10.0 KB

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