experience.vue 9.5 KB

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