GoodsList.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <!--
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: zhuyijun
  5. * @Date: 2021-11-28 15:48:07
  6. * @LastEditTime: 2022-02-20 17:14:17
  7. -->
  8. <template>
  9. <div>
  10. <!-- 面包屑导航区 -->
  11. <el-breadcrumb separator-class="el-icon-arrow-right">
  12. <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
  13. <el-breadcrumb-item>商品管理</el-breadcrumb-item>
  14. <el-breadcrumb-item>商品列表</el-breadcrumb-item>
  15. </el-breadcrumb>
  16. <!-- 卡片区域 -->
  17. <el-card>
  18. <el-row :gutter="20">
  19. <el-col :span="8">
  20. <el-input placeholder="请输入内容"
  21. v-model="queryInfo.query"
  22. clearable
  23. @clear="getGoodsList">
  24. <el-button slot="append"
  25. icon="el-icon-search"
  26. @click="getGoodsList"></el-button>
  27. </el-input>
  28. </el-col>
  29. <el-col :span="4">
  30. <el-button type="primary"
  31. icon="el-icon-search"
  32. @click="goAddPage">添加商品</el-button>
  33. </el-col>
  34. </el-row>
  35. <el-table :data="goodsList"
  36. border
  37. stripe>
  38. <el-table-column label="#"
  39. type="index"
  40. width="50px">
  41. </el-table-column>
  42. <!-- <el-table-column label="商品编号"
  43. prop="goods_id"
  44. width="90px">
  45. </el-table-column> -->
  46. <el-table-column label="商品名称"
  47. prop="goods_name">
  48. </el-table-column>
  49. <el-table-column label="商品价格(元)"
  50. prop="goods_price"
  51. width="90px">
  52. </el-table-column>
  53. <el-table-column label="商品数量(个)"
  54. prop="goods_number"
  55. width="70px">
  56. </el-table-column>
  57. <el-table-column label="商品重量"
  58. prop="goods_weight"
  59. width="70px">
  60. </el-table-column>
  61. <el-table-column label="
  62. 创建时间"
  63. prop="add_time"
  64. width="140px">
  65. <template slot-scope="scope">
  66. {{scope.row.add_time | dateFormat}}
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="操作"
  70. width="130px">
  71. <template slot-scope="scope">
  72. <el-button type="primary"
  73. icon="el-icon-edit"
  74. size="mini"
  75. @click="goEditPage(scope.row.goods_id)">编辑</el-button>
  76. <el-button type="danger"
  77. icon="el-icon-delete"
  78. size="mini"
  79. @click="removeById(scope.row.goods_id)">删除</el-button>
  80. </template>
  81. </el-table-column>
  82. </el-table>
  83. <!-- 分页 -->
  84. <el-pagination @size-change="handleSizeChange"
  85. @current-change="handleCurrentChange"
  86. :current-page="queryInfo.pagenum"
  87. :page-sizes="[10, 20, 50, 100]"
  88. :page-size="queryInfo.pagesize"
  89. layout="total, sizes, prev, pager, next, jumper"
  90. :total="total">
  91. </el-pagination>
  92. </el-card>
  93. </div>
  94. </template>
  95. <script>
  96. export default {
  97. data () {
  98. return {
  99. queryInfo: {
  100. query: '',
  101. pagenum: 1,
  102. pagesize: 10
  103. },
  104. goodsList: [],
  105. total: 0
  106. }
  107. },
  108. created () {
  109. this.getGoodsList()
  110. },
  111. methods: {
  112. async getGoodsList () {
  113. const { data: res } = await this.$http.get('goods', { params: this.queryInfo })
  114. if (res.meta.status !== 200) {
  115. return this.$message.error(res.meta.msg)
  116. }
  117. this.goodsList = res.data.goods
  118. this.total = res.data.total
  119. },
  120. handleSizeChange (newSize) {
  121. this.queryInfo.pagesize = newSize
  122. this.getGoodsList()
  123. },
  124. handleCurrentChange (newPage) {
  125. this.queryInfo.pagenum = newPage
  126. this.getGoodsList()
  127. },
  128. async removeById (id) {
  129. const confirmResule = await this.$confirm('此操作将永久删除该分类, 是否继续?', '提示', {
  130. confirmButtonText: '确定',
  131. cancelButtonText: '取消',
  132. type: 'warning'
  133. }).catch(err => err)
  134. if (confirmResule !== 'confirm') {
  135. return this.$message.info('取消删除')
  136. }
  137. const { data: res } = await this.$http.delete(`goods/${id}`)
  138. if (res.meta.status !== 200) {
  139. return this.$message.error(res.meta.msg)
  140. }
  141. this.$message.success(res.meta.msg)
  142. this.getGoodsList()
  143. },
  144. // 路由转跳
  145. goAddPage () {
  146. this.$router.push('/goods/add')
  147. },
  148. // 路由转跳
  149. goEditPage (goods_id) {
  150. this.$router.push({ path: '/goods/edit', query: { id: goods_id } })
  151. }
  152. },
  153. computed: {
  154. }
  155. }
  156. </script>
  157. <style lang="less" scoped>
  158. </style>