experience.vue 9.2 KB

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