index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="">
  3. <toolbar @on-filter="filterData" @on-reset="filterData" />
  4. <base-table
  5. class="m-10 bg-w p-20 br-10"
  6. :columns="columns"
  7. :items="items"
  8. :pagination="pagination"
  9. :page-change="pageChange"
  10. />
  11. </div>
  12. </template>
  13. <script>
  14. import toolbar from './toolbar';
  15. import mxFilterList from '@/mixins/filterList';
  16. import { getPage, delItem, updateItem } from '@/api/photoWarehouse';
  17. export default {
  18. name: 'ImageGoodsManagement',
  19. components: { toolbar },
  20. mixins: [
  21. mxFilterList({
  22. fetchList: getPage, // 在下方data再声明一个 fetchList: iGetList 同等效果
  23. internalFilterObj: {
  24. auditStatus: 1
  25. }
  26. })
  27. ],
  28. data() {
  29. return {
  30. columns: [
  31. {
  32. key: 'id',
  33. name: '标识',
  34. width: this.$col.b
  35. },
  36. {
  37. key: 'location',
  38. name: '上传位置',
  39. minWidth: this.$col.b,
  40. render: (h, { row }) =>
  41. h(
  42. 'span',
  43. `${row.kindergartenName}${
  44. row.activityName ? '/' + row.activityName : ''
  45. }`
  46. )
  47. },
  48. {
  49. key: 'listPreview',
  50. name: '列表缩略图',
  51. minWidth: this.$col.b,
  52. render: (h, { row }) => {
  53. if (!row.listPreview) {
  54. return h('span', '图片正在处理中请稍等...');
  55. }
  56. return h('img', {
  57. style: {
  58. width: '160px',
  59. height: '90px'
  60. },
  61. class: 'pre-img',
  62. attrs: {
  63. src: row.listPreview
  64. },
  65. on: {
  66. click: () =>
  67. this.$AdvanceViewImageModal({
  68. items: [{ src: row.listPreview }]
  69. })
  70. }
  71. });
  72. }
  73. },
  74. {
  75. key: 'detailPreview',
  76. name: '详情缩略图',
  77. minWidth: this.$col.b,
  78. render: (h, { row }) => {
  79. if (!row.detailPreview) {
  80. return h('span', '图片正在处理中请稍等...');
  81. }
  82. return h('img', {
  83. style: {
  84. width: '160px',
  85. height: '90px'
  86. },
  87. class: 'pre-img',
  88. attrs: {
  89. src: row.detailPreview
  90. },
  91. on: {
  92. click: () =>
  93. this.$AdvanceViewImageModal({
  94. items: [{ src: row.detailPreview }]
  95. })
  96. }
  97. });
  98. }
  99. },
  100. {
  101. key: 'createAt',
  102. name: '上传时间',
  103. minWidth: this.$col.b
  104. },
  105. {
  106. key: 'likes',
  107. name: '点赞数',
  108. width: this.$col.m
  109. },
  110. {
  111. key: 'collections',
  112. name: '收藏数',
  113. width: this.$col.m
  114. },
  115. {
  116. key: 'isBeautiful',
  117. name: '精选',
  118. width: this.$col.m,
  119. type: 'switch',
  120. switchName: ['是', '否'],
  121. api: async row => {
  122. console.log(row);
  123. row.isBeautiful = !row.isBeautiful;
  124. const { success } = await updateItem(row);
  125. if (success) {
  126. this.$success('修改成功!');
  127. }
  128. this.$g_emit('photo_reload');
  129. }
  130. // type: 'tag',
  131. // fetchTagType: val => (val ? 'success' : 'info'),
  132. // tagName: row => (row.isBeautiful ? '是' : '否')
  133. },
  134. {
  135. key: 'isTake',
  136. name: '随手拍',
  137. width: this.$col.s,
  138. type: 'tag',
  139. fetchTagType: val => (val ? 'success' : 'info'),
  140. tagName: row => (row.isTake ? '是' : '否')
  141. },
  142. {
  143. key: 'isShow',
  144. name: '状态',
  145. width: this.$col.b,
  146. type: 'switch',
  147. switchName: ['上架', '下架'],
  148. api: async row => {
  149. console.log(row);
  150. row.isShow = !row.isShow;
  151. const { success } = await updateItem(row);
  152. if (success) {
  153. this.$success('修改成功!');
  154. }
  155. this.$g_emit('photo_reload');
  156. }
  157. // width: this.$col.s,
  158. // type: 'tag',
  159. // fetchTagType: val => (val ? 'success' : 'info'),
  160. // tagName: row => (row.isShow ? '上架' : '下架')
  161. },
  162. {
  163. key: 'action',
  164. name: '操作',
  165. width: '120',
  166. render: (h, { row }) => {
  167. const action = [];
  168. action.push(
  169. h(
  170. 'el-button',
  171. {
  172. props: {
  173. type: 'text'
  174. },
  175. on: {
  176. click: () =>
  177. this.$ImageGoodsItemModal({
  178. id: row.id
  179. })
  180. }
  181. },
  182. '编辑'
  183. )
  184. );
  185. action.push(
  186. h(
  187. 'BaseBtn',
  188. {
  189. props: {
  190. popip: true,
  191. txt: '删除',
  192. type: 'text'
  193. },
  194. class: 'ml-10',
  195. on: {
  196. ok: () => this.handleDelItem(row)
  197. }
  198. },
  199. '删除'
  200. )
  201. );
  202. return h('div', action);
  203. }
  204. }
  205. ]
  206. };
  207. },
  208. created() {
  209. this.$g_on('photo_reload', this.reload);
  210. },
  211. beforeDestroy() {
  212. this.$g_off('photo_reload', this.reload);
  213. },
  214. methods: {
  215. async handleDelItem(item) {
  216. const { success, msg } = await delItem({
  217. id: item.id
  218. });
  219. if (success) {
  220. this.$success('删除成功!');
  221. this.$g_emit('photo_reload');
  222. }
  223. }
  224. }
  225. };
  226. </script>
  227. <style type="scss" scoped></style>