ads.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <basic-container>
  3. <avue-crud :option="option"
  4. :table-loading="loading"
  5. :data="data"
  6. :page.sync="page"
  7. :permission="permissionList"
  8. :before-open="beforeOpen"
  9. :upload-after="uploadAfter"
  10. v-model="form"
  11. ref="crud"
  12. @row-update="rowUpdate"
  13. @row-save="rowSave"
  14. @row-del="rowDel"
  15. @search-change="searchChange"
  16. @search-reset="searchReset"
  17. @selection-change="selectionChange"
  18. @current-change="currentChange"
  19. @size-change="sizeChange"
  20. @refresh-change="refreshChange"
  21. @on-load="onLoad">
  22. <template slot="menuLeft">
  23. <el-button type="danger"
  24. size="small"
  25. icon="el-icon-delete"
  26. plain
  27. v-if="permission.ads_delete"
  28. @click="handleDelete">删 除
  29. </el-button>
  30. </template>
  31. </avue-crud>
  32. </basic-container>
  33. </template>
  34. <script>
  35. import {getList, getDetail, add, update, remove} from "@/api/platform/ads";
  36. import {mapGetters} from "vuex";
  37. export default {
  38. data() {
  39. return {
  40. form: {},
  41. query: {},
  42. loading: true,
  43. page: {
  44. pageSize: 10,
  45. currentPage: 1,
  46. total: 0
  47. },
  48. selectionList: [],
  49. option: {
  50. height:'auto',
  51. calcHeight: 30,
  52. tip: false,
  53. searchShow: true,
  54. searchMenuSpan: 6,
  55. border: true,
  56. index: true,
  57. viewBtn: true,
  58. selection: true,
  59. dialogClickModal: false,
  60. column: [
  61. {
  62. label: "标题",
  63. prop: "title",
  64. rules: [{
  65. required: true,
  66. message: "请输入主标题",
  67. trigger: "blur"
  68. }]
  69. },
  70. {
  71. label: "广告类型",
  72. prop: "typeDisplayName",
  73. display: false
  74. },
  75. {
  76. label: "广告类型",
  77. prop: "type",
  78. type: "select",
  79. dicUrl: "/api/blade-system/dict-biz/dictionary?code=ads_type",
  80. props: {
  81. label: "dictValue",
  82. value: "dictKey"
  83. },
  84. dataType: "number",
  85. search: true,
  86. hide: true,
  87. rules: [{
  88. required: true,
  89. message: "请选择类型",
  90. trigger: "blur"
  91. }]
  92. },
  93. {
  94. label: "跳转类型",
  95. prop: "skipType",
  96. type: "select",
  97. dicUrl: "/api/blade-system/dict-biz/dictionary?code=ads_skip_type",
  98. props: {
  99. label: "dictValue",
  100. value: "dictKey"
  101. },
  102. dataType: "number",
  103. search: true,
  104. hide: true,
  105. rules: [{
  106. required: true,
  107. message: "请选择跳转类型",
  108. trigger: "blur"
  109. }]
  110. },
  111. {
  112. label: "是否启用",
  113. prop: "isEnabledDisplayName",
  114. display: false
  115. },
  116. {
  117. label: "是否启用",
  118. prop: "isEnabled",
  119. type: "select",
  120. dicUrl: "/api/blade-system/dict/dictionary?code=yes_no",
  121. props: {
  122. label: "dictValue",
  123. value: "dictKey"
  124. },
  125. dataType: "number",
  126. search: true,
  127. hide: true,
  128. rules: [{
  129. required: true,
  130. message: "请选择是否启用",
  131. trigger: "blur"
  132. }]
  133. },
  134. {
  135. label: "团购",
  136. prop: "grouponId",
  137. addDisplay: false,
  138. editDisplay: false,
  139. viewDisplay: false,
  140. hide: true,
  141. type: "select",
  142. dicUrl: "/api/groupon/groupon/list?status=1&auditStatus=1&current=1&size=100",
  143. props: {
  144. label: "mainTitle",
  145. value: "id"
  146. },
  147. dicFormatter: function (res) {
  148. return res.data.records;
  149. },
  150. rules: [{
  151. required: true,
  152. message: "请选择团购",
  153. trigger: "blur"
  154. }]
  155. },
  156. {
  157. label: "文章",
  158. prop: "articleId",
  159. addDisplay: false,
  160. editDisplay: false,
  161. viewDisplay: false,
  162. hide: true,
  163. type: "select",
  164. dicUrl: "/api/platform/article/list?current=1&size=100",
  165. props: {
  166. label: "title",
  167. value: "id"
  168. },
  169. dicFormatter: function (res) {
  170. return res.data.records;
  171. },
  172. rules: [{
  173. required: true,
  174. message: "请选择团购",
  175. trigger: "blur"
  176. }]
  177. },
  178. {
  179. label: "排序",
  180. prop: "sort",
  181. rules: [{
  182. required: true,
  183. message: "请输入排序",
  184. trigger: "blur"
  185. }],
  186. type: "number"
  187. },
  188. {
  189. label: "广告图片",
  190. prop: "imageUrl",
  191. type: 'upload',
  192. addDisplay: false,
  193. editDisplay: false,
  194. listType: 'picture-img',
  195. span: 24,
  196. },
  197. {
  198. label: '广告图片',
  199. prop: 'attachUrl',
  200. type: 'upload',
  201. listType: 'picture-img',
  202. loadText: '上传中,请稍等',
  203. accept: 'image/png, image/jpeg',
  204. fileSize: 500,
  205. tip: '建议尺寸:750×420;只能上传jpg/png文件,且不超过500kb',
  206. span: 24,
  207. hide: true,
  208. viewDisplay: false,
  209. propsHttp: {
  210. res: 'data',
  211. url: 'link',
  212. },
  213. action: "/api/blade-resource/oss/endpoint/put-file-attach"
  214. },
  215. ]
  216. },
  217. data: []
  218. };
  219. },
  220. computed: {
  221. ...mapGetters(["permission"]),
  222. permissionList() {
  223. return {
  224. addBtn: this.vaildData(this.permission.ads_add, false),
  225. viewBtn: this.vaildData(this.permission.ads_view, false),
  226. delBtn: this.vaildData(this.permission.ads_delete, false),
  227. editBtn: this.vaildData(this.permission.ads_edit, false)
  228. };
  229. },
  230. ids() {
  231. let ids = [];
  232. this.selectionList.forEach(ele => {
  233. ids.push(ele.id);
  234. });
  235. return ids.join(",");
  236. }
  237. },
  238. created() {
  239. this.option.column[3].change = function (column) {
  240. const content = this.findObject(this.option.column, "articleId");
  241. const dataId = this.findObject(this.option.column, "grouponId");
  242. if (column.value === 1) {
  243. this.$set(content, 'addDisplay', false)
  244. this.$set(content, 'editDisplay', false)
  245. this.$set(content, 'viewDisplay', false)
  246. this.$set(dataId, 'addDisplay', false)
  247. this.$set(dataId, 'editDisplay', false)
  248. this.$set(dataId, 'viewDisplay', false)
  249. }
  250. if (column.value === 2) {//文章
  251. this.$set(content, 'addDisplay', true)
  252. this.$set(content, 'editDisplay', true)
  253. this.$set(content, 'viewDisplay', true)
  254. this.$set(dataId, 'addDisplay', false)
  255. this.$set(dataId, 'editDisplay', false)
  256. this.$set(dataId, 'viewDisplay', false)
  257. }
  258. if (column.value === 3) {// 团购
  259. this.$set(content, 'addDisplay', false)
  260. this.$set(content, 'editDisplay', false)
  261. this.$set(content, 'viewDisplay', false)
  262. this.$set(dataId, 'addDisplay', true)
  263. this.$set(dataId, 'editDisplay', true)
  264. this.$set(dataId, 'viewDisplay', true)
  265. }
  266. }.bind(this);
  267. },
  268. methods: {
  269. rowSave(row, done, loading) {
  270. if (row.skipType == 2) {
  271. row.dataId = row.articleId;
  272. }
  273. if (row.skipType == 3) {
  274. row.dataId = row.grouponId;
  275. }
  276. add(row).then(() => {
  277. this.onLoad(this.page);
  278. this.$message({
  279. type: "success",
  280. message: "操作成功!"
  281. });
  282. done();
  283. }, error => {
  284. loading();
  285. window.console.log(error);
  286. });
  287. },
  288. rowUpdate(row, index, done, loading) {
  289. if (row.skipType == 2) {
  290. row.dataId = row.articleId;
  291. }
  292. if (row.skipType == 3) {
  293. row.dataId = row.grouponId;
  294. }
  295. update(row).then(() => {
  296. this.onLoad(this.page);
  297. this.$message({
  298. type: "success",
  299. message: "操作成功!"
  300. });
  301. done();
  302. }, error => {
  303. loading();
  304. console.log(error);
  305. });
  306. },
  307. rowDel(row) {
  308. this.$confirm("确定将选择数据删除?", {
  309. confirmButtonText: "确定",
  310. cancelButtonText: "取消",
  311. type: "warning"
  312. })
  313. .then(() => {
  314. return remove(row.id);
  315. })
  316. .then(() => {
  317. this.onLoad(this.page);
  318. this.$message({
  319. type: "success",
  320. message: "操作成功!"
  321. });
  322. });
  323. },
  324. handleDelete() {
  325. if (this.selectionList.length === 0) {
  326. this.$message.warning("请选择至少一条数据");
  327. return;
  328. }
  329. this.$confirm("确定将选择数据删除?", {
  330. confirmButtonText: "确定",
  331. cancelButtonText: "取消",
  332. type: "warning"
  333. })
  334. .then(() => {
  335. return remove(this.ids);
  336. })
  337. .then(() => {
  338. this.onLoad(this.page);
  339. this.$message({
  340. type: "success",
  341. message: "操作成功!"
  342. });
  343. this.$refs.crud.toggleSelection();
  344. });
  345. },
  346. beforeOpen(done, type) {
  347. if (["edit", "view"].includes(type)) {
  348. getDetail(this.form.id).then(res => {
  349. this.form = res.data.data;
  350. this.form.attachUrl = this.form.imageUrl;
  351. if (this.form.skipType == 2) {
  352. this.form.articleId = this.form.dataId;
  353. }
  354. if (this.form.skipType == 3) {
  355. this.form.grouponId = this.form.dataId;
  356. }
  357. });
  358. }
  359. done();
  360. },
  361. uploadAfter(res, done, loading, column) {
  362. this.form.imageUrl = res.link;
  363. done()
  364. },
  365. searchReset() {
  366. this.query = {};
  367. this.onLoad(this.page);
  368. },
  369. searchChange(params, done) {
  370. this.query = params;
  371. this.page.currentPage = 1;
  372. this.onLoad(this.page, params);
  373. done();
  374. },
  375. selectionChange(list) {
  376. this.selectionList = list;
  377. },
  378. selectionClear() {
  379. this.selectionList = [];
  380. this.$refs.crud.toggleSelection();
  381. },
  382. currentChange(currentPage){
  383. this.page.currentPage = currentPage;
  384. },
  385. sizeChange(pageSize){
  386. this.page.pageSize = pageSize;
  387. },
  388. refreshChange() {
  389. this.onLoad(this.page, this.query);
  390. },
  391. onLoad(page, params = {}) {
  392. this.loading = true;
  393. getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
  394. const data = res.data.data;
  395. this.page.total = data.total;
  396. this.data = data.records;
  397. this.loading = false;
  398. this.selectionClear();
  399. });
  400. }
  401. }
  402. };
  403. </script>
  404. <style>
  405. </style>