works.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <div class="works" id="works">
  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="works.length > 0">
  10. <template v-for="(item, idx) in works">
  11. <div v-if="editingItem.indexOf(idx) < 0" :key="`works_${idx}`" class="show">
  12. <span class="star">
  13. <img src="~@/assets/img/sign/star.png" srcset="~@/assets/img/sign/star@2x.png" alt />
  14. 赞({{works[idx].hit}})
  15. </span>
  16. <span class="image" v-if="works[idx].image_list && works[idx].image_list[0]">
  17. <img :src="works[idx].image_list[0].url" alt />
  18. </span>
  19. <span class="des">
  20. <h4>
  21. <span>{{item.name}}</span>
  22. <el-button @click="editItem(idx)" type="text">修改</el-button>
  23. </h4>
  24. <p style="word-break: break-all">{{item.description}}</p>
  25. </span>
  26. </div>
  27. <work-form
  28. v-else
  29. :key="`works_edit_${idx}`"
  30. :idx="idx"
  31. :work="works[idx]"
  32. :industries="industries"
  33. :functions="functions"
  34. :handleCancel="handleCancel"
  35. :onSubmit="onSubmit"
  36. :handleDelete="handleDelete"
  37. ></work-form>
  38. </template>
  39. </div>
  40. <div v-else class="empty">点击右上角“添加”按钮添加作品(至少添加3项)</div>
  41. </div>
  42. </template>
  43. <script>
  44. import { mapState } from "vuex";
  45. import qs from "qs";
  46. import workForm from "./work-form";
  47. export default {
  48. data() {
  49. return {
  50. // editing: true,
  51. editingItem: [],
  52. init: {
  53. name: "",
  54. industry_id: "",
  55. function_ops: "",
  56. duty: "",
  57. description: "",
  58. url: "",
  59. image_list: [],
  60. },
  61. works: [],
  62. current: null,
  63. originWorks: [],
  64. industries: [],
  65. functions: [],
  66. };
  67. },
  68. components: {
  69. workForm,
  70. },
  71. computed: {
  72. ...mapState(["userinfo"]),
  73. },
  74. watch: {},
  75. async mounted() {
  76. await this.getIndustry();
  77. this.getFunction();
  78. this.getData();
  79. },
  80. methods: {
  81. async onSubmit(work, idx) {
  82. const queryParams = {
  83. ...work,
  84. // id: 1, //传ID是更新,不传ID是新增
  85. // name: "作品名称",
  86. // duty: "作品指责",
  87. // description: "作品描述",
  88. function_ops: work.function_ops.join(","), //是多个ID,用英文逗号分割,关键功能
  89. industry_id: parseInt(work.industry_id[1]), //id,是int类型啊,不是文字
  90. // url: "https://a.com",
  91. image_list: work.image_list.map((it) => it.url).join(","), //是图片地址,多个图片用逗号分割,
  92. };
  93. const res = await this.$axios.$post(`/api/user_works/save`, queryParams);
  94. if (res.status === 1) {
  95. this.$message.success("保存成功!");
  96. this.init = {
  97. name: "",
  98. industry_id: "",
  99. function_ops: "",
  100. duty: "",
  101. description: "",
  102. url: "",
  103. image_list: [],
  104. };
  105. this.editingItem = [];
  106. this.getData();
  107. }
  108. },
  109. async getData() {
  110. const res = await this.$axios.$post("/api/user_works/get_list");
  111. const data = !res.data ? [] : res.data;
  112. this.works = data.map((it) => {
  113. const image_list = it.image_list
  114. ? it.image_list.split(",").map((it) => ({ name: it, url: it }))
  115. : [];
  116. let industry_id;
  117. this.industries.map((item1) => {
  118. return item1.children.map((item2) => {
  119. if (item2.value == it.industry_id) {
  120. industry_id = [item1.value, item2.value];
  121. }
  122. });
  123. });
  124. console.log(industry_id);
  125. return {
  126. ...it,
  127. industry_id,
  128. function_ops: it.function_ops ? it.function_ops.split(",") : [],
  129. image_list,
  130. };
  131. });
  132. },
  133. async getIndustry() {
  134. const res = await this.$axios.$post("/api/user_works/get_industry");
  135. const data = !res.data ? [] : res.data;
  136. this.industries = data.map((it) => ({
  137. label: it.name,
  138. value: it.id,
  139. children: it.child.map((it) => ({
  140. label: it.name,
  141. value: it.id,
  142. })),
  143. }));
  144. return this.industries;
  145. },
  146. async getFunction() {
  147. const res = await this.$axios.$post("/api/user_works/get_function");
  148. const data = !res.data ? [] : res.data;
  149. this.functions = data.map((it) => ({
  150. label: it.outsourcefunc_name,
  151. value: it.outsourcefunc_id,
  152. }));
  153. },
  154. async fetchWork(keyword) {
  155. // console.log(keyword);
  156. // this.loadingWork = true;
  157. // const res = await this.$axios.$post("/api/simple_data/select_skill", {
  158. // keyword
  159. // });
  160. // this.loadingWork = false;
  161. // const data = res.data || [];
  162. // this.skillList = data.map(it => ({ value: it.id, label: it.name }));
  163. },
  164. handleAdd() {
  165. if (this.userinfo && this.userinfo.realname_verify_status === "0") {
  166. this.$message.error("请先进行实名认证");
  167. return;
  168. }
  169. if (this.editingItem.length > 0 && !this.works[this.editingItem[0]].id) {
  170. this.$message.error("请先保存现有修改");
  171. return;
  172. }
  173. // this.works.push(this.init);
  174. // this.editingItem = [this.works.length - 1];
  175. window.location.href= "/otherpage/works/create";
  176. },
  177. async handleDelete(work, idx) {
  178. const deleteComplete = () => {
  179. this.$message({
  180. type: "success",
  181. message: "删除成功!",
  182. });
  183. this.works.splice(idx, 1);
  184. this.editingItem = [];
  185. };
  186. this.$confirm("确认删除该作品?", "提示", {
  187. confirmButtonText: "确定",
  188. cancelButtonText: "取消",
  189. type: "warning",
  190. })
  191. .then(async () => {
  192. if (work.wid) {
  193. const res = await this.$axios.$post(`/api/user_works/delete`, {
  194. id: work.wid,
  195. });
  196. if (res.status === 1) {
  197. deleteComplete();
  198. // this.$message.success(res.info);
  199. this.getData();
  200. }
  201. } else {
  202. deleteComplete();
  203. }
  204. })
  205. .catch((err) => {
  206. console.log(err);
  207. this.$message({
  208. type: "info",
  209. message: "已取消删除",
  210. });
  211. });
  212. },
  213. handleCancel(work, idx) {
  214. this.editingItem = [];
  215. if (!work.wid) {
  216. this.works.splice(idx, 1);
  217. }
  218. },
  219. editItem(idx) {
  220. // this.editingItem = [idx];
  221. window.location.href= "/otherpage/works/create?wid="+this.works[idx].wid;
  222. },
  223. },
  224. };
  225. </script>
  226. <style lang="scss" scoped>
  227. .works {
  228. header .el-icon-plus {
  229. font-size: 18px;
  230. }
  231. .show {
  232. display: flex;
  233. justify-content: space-between;
  234. padding: 23px 33px 23px 20px;
  235. border-bottom: 1px solid #ebeef5;
  236. &:last-of-type {
  237. /* border: 0; */
  238. margin-bottom: 30px;
  239. }
  240. .star {
  241. display: flex;
  242. flex-direction: column;
  243. align-items: center;
  244. justify-content: center;
  245. width: 100px;
  246. img {
  247. margin-bottom: 5px;
  248. width: 26px;
  249. height: 26px;
  250. }
  251. }
  252. .image {
  253. margin-right: 10px;
  254. width: 100px;
  255. height: 100px;
  256. overflow: hidden;
  257. }
  258. .des {
  259. flex: 1;
  260. }
  261. h4 {
  262. display: flex;
  263. justify-content: space-between;
  264. align-items: center;
  265. height: 24px;
  266. font-size: 14px;
  267. font-family: PingFangSC-Medium;
  268. font-weight: 500;
  269. color: #308eff;
  270. line-height: 24px;
  271. }
  272. p {
  273. font-size: 14px;
  274. font-family: PingFangSC-Regular;
  275. font-weight: 400;
  276. color: rgba(102, 102, 102, 1);
  277. line-height: 24px;
  278. }
  279. }
  280. .empty {
  281. margin: 112px auto 104px;
  282. font-size: 27px;
  283. font-family: PingFangSC-Regular;
  284. font-weight: 400;
  285. text-align: center;
  286. color: rgba(205, 205, 205, 1);
  287. line-height: 38px;
  288. }
  289. footer p {
  290. margin-top: 15px;
  291. width: 766px;
  292. font-size: 12px;
  293. font-family: PingFangSC-Regular;
  294. font-weight: 400;
  295. color: rgba(145, 154, 167, 1);
  296. line-height: 17px;
  297. }
  298. }
  299. </style>