skills.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div class="skill">
  3. <header>
  4. <h5>技能</h5>
  5. <span>
  6. <el-button @click="handleAdd" type="text" icon="el-icon-plus"></el-button>
  7. </span>
  8. </header>
  9. <div v-if="skills.length > 0">
  10. <template v-for="(item, idx) in skills">
  11. <div v-if="editingItem.indexOf(idx) < 0" :key="item.skill_name" class="show">
  12. <h4>
  13. <span>{{`技能名称: ${item.skill_name} 经验自评:${item.skill_level}分 `}}</span>
  14. <el-button @click="editItem(idx)" type="text">编辑</el-button>
  15. </h4>
  16. </div>
  17. <div v-else :key="`skill_${item.skill_id}`" class="edit">
  18. <el-form ref="form" :rules="rules" :model="item" label-width="80px">
  19. <div class="header">
  20. <el-form-item label="技能名称" prop="skill_name">
  21. <el-select
  22. :style="{width: '250px'}"
  23. v-model="item.skill_name"
  24. allow-create
  25. filterable
  26. remote
  27. reserve-keyword
  28. placeholder="填写单个技能全名"
  29. :remote-method="fetchSkill"
  30. :loading="loadingSkill"
  31. >
  32. <el-option
  33. v-for="skil in skillList"
  34. :key="skil.id"
  35. :label="skil.name"
  36. :value="skil.name"
  37. ></el-option>
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item label="经验自评" prop="skill_level">
  41. <el-select :style="{width: '130px'}" v-model="item.skill_level" placeholder="选择分数">
  42. <el-option v-for="level in 5" :label="`${level}分`" :key="level" :value="level"></el-option>
  43. </el-select>
  44. </el-form-item>
  45. <span class="tips">1分为新入门,5分为满分</span>
  46. <span class="opts">
  47. <el-button type="danger" @click="handleDelete(item, idx)">删除</el-button>
  48. <el-button type="info" @click="handleCancel(item, idx)">取消</el-button>
  49. <el-button type="primary" @click="onSubmit(item, idx)">确认</el-button>
  50. </span>
  51. </div>
  52. </el-form>
  53. </div>
  54. </template>
  55. </div>
  56. <div v-else class="empty">点击右上角“添加”按钮添加技能</div>
  57. </div>
  58. </template>
  59. <script>
  60. import uploader from "@/components/uploader";
  61. export default {
  62. data() {
  63. return {
  64. // editing: true,
  65. editingItem: [],
  66. rules: {
  67. // skill_name: [{ required: true, message: "请输入技能全名", trigger: "blur" }]
  68. },
  69. init: {
  70. skill_name: "",
  71. skill_level: "",
  72. skill_id: ""
  73. },
  74. skills: [
  75. // {
  76. // skill_name: "Javscript",
  77. // skill_level: "5"
  78. // }
  79. ],
  80. originSkills: [],
  81. current: null,
  82. skillList: [],
  83. loadingSkill: false
  84. };
  85. },
  86. components: {
  87. uploader
  88. },
  89. computed: {},
  90. watch: {},
  91. async mounted() {
  92. this.getData();
  93. },
  94. methods: {
  95. async getData() {
  96. let res = await this.$axios.$post("/api/user_skills/list_by_user");
  97. this.skills = res.data || [];
  98. },
  99. async onSubmit(item, idx) {
  100. console.log("submit!", item);
  101. if (!item.skill_name) {
  102. this.$message.error("请填写技能名称!");
  103. return;
  104. }
  105. if (!item.skill_level) {
  106. this.$message.error("请选择技能自评!");
  107. return;
  108. }
  109. const data = {
  110. skill_level: item.skill_level,
  111. skill_name: item.skill_name
  112. };
  113. if (item.skill_id) {
  114. data.skill_id = item.skill_id;
  115. }
  116. if (item.id) {
  117. data.id = item.id;
  118. }
  119. const res = await this.$axios.$post("/api/user_skills/save", data);
  120. if (res.status === 1) {
  121. this.$message.success(res.info);
  122. this.editingItem = [];
  123. this.originSkills.splice(idx, 1, item);
  124. } else {
  125. // this.$message.error(res.info);
  126. }
  127. },
  128. async fetchSkill(keyword) {
  129. this.loadingSkill = true;
  130. const res = await this.$axios.$post("/api/simple_data/select_skill", {
  131. keyword
  132. });
  133. this.loadingSkill = false;
  134. const data = res.data || [];
  135. this.skillList = data.map(it => ({ id: it.id, name: it.name }));
  136. },
  137. handleAdd() {
  138. if (this.editingItem.length > 0 && !this.skills[this.editingItem[0]].id) {
  139. this.$message.error("请先保存现有修改");
  140. return;
  141. }
  142. this.skills.push(this.init);
  143. this.editingItem = [this.skills.length - 1];
  144. },
  145. async handleDelete(item, idx) {
  146. const deleteComplete = () => {
  147. this.$message({
  148. type: "success",
  149. message: "删除成功!"
  150. });
  151. this.skills.splice(idx, 1);
  152. this.editingItem = [];
  153. };
  154. this.$confirm("确认删除该技能?", "提示", {
  155. confirmButtonText: "确定",
  156. cancelButtonText: "取消",
  157. type: "warning"
  158. })
  159. .then(async () => {
  160. if (item.id) {
  161. const res = await this.$axios.$post("/api/user_skills/delete", {
  162. id: item.id
  163. });
  164. if (res.status === 1) {
  165. deleteComplete();
  166. this.getData();
  167. }
  168. } else {
  169. deleteComplete();
  170. }
  171. })
  172. .catch(err => {
  173. console.log(err);
  174. this.$message({
  175. type: "info",
  176. message: "已取消删除"
  177. });
  178. });
  179. },
  180. handleCancel(item, idx) {
  181. this.editingItem = [];
  182. if (!item.skill_id) {
  183. this.skills.splice(idx, 1);
  184. }
  185. },
  186. editItem(idx) {
  187. console.log("editItem:" + idx);
  188. this.editingItem = [idx];
  189. }
  190. }
  191. };
  192. </script>
  193. <style lang="scss" scoped>
  194. .skill {
  195. header .el-icon-plus {
  196. font-size: 18px;
  197. }
  198. .edit {
  199. padding: 20px;
  200. .header {
  201. display: flex;
  202. align-items: center;
  203. .tips {
  204. margin-right: 5px;
  205. }
  206. }
  207. > form {
  208. .el-form-item {
  209. margin-bottom: 0;
  210. }
  211. .header {
  212. display: flex;
  213. justify-content: space-between;
  214. align-items: center;
  215. margin-bottom: 10px;
  216. }
  217. .opts {
  218. display: flex;
  219. align-items: center;
  220. .el-button {
  221. margin-left: 5px;
  222. }
  223. }
  224. .el-select,
  225. .el-input {
  226. width: 136px;
  227. margin-right: 10px;
  228. .el-input--suffix .el-input__inner {
  229. padding-right: 0;
  230. }
  231. }
  232. .to {
  233. margin-right: 10px;
  234. }
  235. .times {
  236. .el-checkbox {
  237. width: 88px;
  238. }
  239. .el-input {
  240. width: 136px;
  241. }
  242. }
  243. .content {
  244. display: flex;
  245. justify-content: space-between;
  246. align-items: flex-start;
  247. margin-top: 10px;
  248. .el-textarea {
  249. display: flex;
  250. width: 766px;
  251. height: 162px;
  252. }
  253. }
  254. }
  255. }
  256. .show {
  257. padding: 23px 33px 23px 20px;
  258. border-bottom: 1px solid #ebeef5;
  259. &:last-of-type {
  260. border: 0;
  261. }
  262. h4 {
  263. display: flex;
  264. justify-content: space-between;
  265. height: 44px;
  266. font-size: 14px;
  267. font-family: PingFangSC-Medium;
  268. font-weight: 500;
  269. /* color: #308eff; */
  270. line-height: 44px;
  271. }
  272. p {
  273. margin-top: 8px;
  274. font-size: 14px;
  275. font-family: PingFangSC-Regular;
  276. font-weight: 400;
  277. color: rgba(102, 102, 102, 1);
  278. line-height: 24px;
  279. }
  280. }
  281. .empty {
  282. margin: 112px auto 104px;
  283. font-size: 27px;
  284. font-family: PingFangSC-Regular;
  285. font-weight: 400;
  286. text-align: center;
  287. color: rgba(205, 205, 205, 1);
  288. line-height: 38px;
  289. }
  290. footer p {
  291. margin-top: 15px;
  292. width: 766px;
  293. font-size: 12px;
  294. font-family: PingFangSC-Regular;
  295. font-weight: 400;
  296. color: rgba(145, 154, 167, 1);
  297. line-height: 17px;
  298. }
  299. }
  300. </style>