prodList.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <div class="mod-prod">
  3. <avue-crud ref="crud"
  4. :page="page"
  5. :data="dataList"
  6. :table-loading="dataListLoading"
  7. :permission="permission"
  8. :option="tableOption"
  9. @search-change="searchChange"
  10. @selection-change="selectionChange"
  11. @on-load="getDataList"
  12. >
  13. <template slot="menuLeft">
  14. <el-button type="primary"
  15. icon="el-icon-plus"
  16. size="small"
  17. v-if="isAuth('shop:pickAddr:save')"
  18. @click.stop="addOrUpdateHandle()">新增</el-button>
  19. <el-button type="danger"
  20. @click="deleteHandle()"
  21. size="small"
  22. v-if="isAuth('shop:pickAddr:delete')"
  23. :disabled="dataListSelections.length <= 0">批量删除</el-button>
  24. </template>
  25. <template slot-scope="scope"
  26. slot="status">
  27. <el-tag v-if="scope.row.status === 1"
  28. size="small">上架</el-tag>
  29. <el-tag v-else
  30. size="small">未上架</el-tag>
  31. </template>
  32. <template slot-scope="scope"
  33. slot="menu">
  34. <el-button type="primary"
  35. icon="el-icon-edit"
  36. size="small"
  37. v-if="isAuth('prod:prod:update')"
  38. @click="addOrUpdateHandle(scope.row.prodId)">修改</el-button>
  39. <el-button type="danger"
  40. icon="el-icon-delete"
  41. size="small"
  42. v-if="isAuth('prod:prod:delete')"
  43. @click="deleteHandle(scope.row.prodId)">删除</el-button>
  44. </template>
  45. </avue-crud>
  46. </div>
  47. </template>
  48. <script>
  49. import { tableOption } from '@/crud/prod/prodList'
  50. export default {
  51. data () {
  52. return {
  53. dataForm: {
  54. prodName: ''
  55. },
  56. permission: {
  57. delBtn: this.isAuth('prod:prod:delete')
  58. },
  59. dataList: [],
  60. page: {
  61. total: 0, // 总页数
  62. currentPage: 1, // 当前页数
  63. pageSize: 10 // 每页显示多少条
  64. },
  65. dataListSelections: [],
  66. dataListLoading: false,
  67. tableOption: tableOption,
  68. resourcesUrl: process.env.VUE_APP_RESOURCES_URL
  69. }
  70. },
  71. methods: {
  72. onedit(...data){
  73. console.log(...data)
  74. },
  75. // 获取数据列表
  76. getDataList (page, params, done) {
  77. this.dataListLoading = true
  78. this.$http({
  79. url: this.$http.adornUrl('/prod/prod/page'),
  80. method: 'get',
  81. params: this.$http.adornParams(
  82. Object.assign(
  83. {
  84. current: page == null ? this.page.currentPage : page.currentPage,
  85. size: page == null ? this.page.pageSize : page.pageSize
  86. },
  87. params
  88. )
  89. )
  90. }).then(({ data }) => {
  91. this.dataList = data.records
  92. for (const key in this.dataList) {
  93. if (this.dataList.hasOwnProperty(key)) {
  94. const element = this.dataList[key]
  95. element.imgs = element.imgs.split(',')[0]
  96. }
  97. }
  98. this.page.total = data.total
  99. this.dataListLoading = false
  100. if (done) {
  101. done()
  102. }
  103. })
  104. },
  105. // 新增 / 修改
  106. addOrUpdateHandle (id) {
  107. this.$router.push({
  108. path: '/prodInfo',
  109. query: { prodId: id }
  110. })
  111. },
  112. // 删除和批量删除
  113. deleteHandle (id) {
  114. let prodIds = this.getSeleProdIds()
  115. if (id) {
  116. prodIds.push(id)
  117. }
  118. this.$confirm(`确定进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
  119. confirmButtonText: '确定',
  120. cancelButtonText: '取消',
  121. type: 'warning'
  122. })
  123. .then(() => {
  124. this.$http({
  125. url: this.$http.adornUrl(`/prod/prod`),
  126. method: 'delete',
  127. data: this.$http.adornData(prodIds, false)
  128. }).then(({ data }) => {
  129. this.$message({
  130. message: '操作成功',
  131. type: 'success',
  132. duration: 1500,
  133. onClose: () => {
  134. this.getDataList(this.page)
  135. }
  136. })
  137. })
  138. })
  139. .catch(() => { })
  140. },
  141. // 条件查询
  142. searchChange (params, done) {
  143. this.getDataList(this.page, params, done)
  144. },
  145. // 多选变化
  146. selectionChange (val) {
  147. this.dataListSelections = val
  148. },
  149. // 获取选中的商品Id列表
  150. getSeleProdIds () {
  151. return this.dataListSelections.map(item => {
  152. return item.prodId
  153. })
  154. }
  155. }
  156. }
  157. </script>