goodsList.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <div class="container">
  3. <Breadcrumb :items="['网站管理', '商品管理']" />
  4. <a-card title="商品列表">
  5. <a-row>
  6. <a-col :flex="1">
  7. <a-form :model="queryData" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 18 }"
  8. label-align="left">
  9. <a-row :gutter="16">
  10. <a-col :span="8">
  11. <a-form-item field="id" label="商品名称">
  12. <a-input-number v-model="queryData.id" placeholder="请输入商品名称关键词" :step="1"
  13. :precision="0" />
  14. </a-form-item>
  15. </a-col>
  16. </a-row>
  17. </a-form>
  18. </a-col>
  19. <a-divider style="height: 84px" direction="vertical" />
  20. <a-col :flex="'86px'" style="text-align: right">
  21. <a-space direction="vertical" :size="18">
  22. <a-button type="primary" @click="search">
  23. <template #icon>
  24. <icon-search />
  25. </template>
  26. 搜索
  27. </a-button>
  28. <a-button @click="reset">
  29. <template #icon>
  30. <icon-refresh />
  31. </template>
  32. 重置
  33. </a-button>
  34. </a-space>
  35. </a-col>
  36. </a-row>
  37. <a-table :data="data" stripe hoverable column-resizable class="table" :loading="loading" :columns="columns"
  38. :pagination="{
  39. showPageSize: true,
  40. showJumper: true,
  41. showTotal: true,
  42. pageSize: pagination.pagesize,
  43. current: pagination.current,
  44. total: pagination.total
  45. }" @page-change="handlePageChange" @page-size-change="handlePageSizeChange">
  46. <template #username="{ record }">
  47. <a-avatar :size="30">
  48. <IconUser v-if="!record.avatar" />
  49. <img :alt="record.username ?? ''" :src="record.avatar" v-else />
  50. </a-avatar>
  51. {{ record.username }}
  52. </template>
  53. <template #create_time="{ record }">
  54. {{ stramptoTime(record.create_time) }}
  55. </template>
  56. <template #update_time="{ record }">
  57. {{ stramptoTime(record.update_time) }}
  58. </template>
  59. <template #state="{ record }">
  60. <a-tag color="orangered" v-if="record.state === 0">
  61. 已下架
  62. </a-tag>
  63. <a-tag color="green" v-else-if="record.state === 1">
  64. 正常
  65. </a-tag>
  66. </template>
  67. <template #optional="{ record }">
  68. <a-button @click="$router.push(`/admin/goods/addGoods/${record.id}`)">编辑商品</a-button>
  69. </template>
  70. </a-table>
  71. </a-card>
  72. </div>
  73. </template>
  74. <script setup>
  75. import { ref, reactive, onMounted } from 'vue'
  76. import { adminGetGoodsList } from '@/api/goods'
  77. import { Notification } from '@arco-design/web-vue'
  78. const pagination = reactive({
  79. total: 0,
  80. current: 1,
  81. pagesize: 20
  82. })
  83. const queryData = reactive({
  84. keyword: '',
  85. })
  86. const search = () => {
  87. pagination.current = 1
  88. getList()
  89. }
  90. const reset = () => {
  91. pagination.current = 1
  92. queryData.id = ''
  93. queryData.state = -1
  94. getList()
  95. }
  96. const columns = [
  97. {
  98. title: '商品ID',
  99. dataIndex: 'id',
  100. },
  101. {
  102. title: '商品名称',
  103. dataIndex: 'name',
  104. }, {
  105. title: '商品价格',
  106. dataIndex: 'price',
  107. },
  108. {
  109. title: '库存数量',
  110. dataIndex: 'num',
  111. }, {
  112. title: '乐跑次数',
  113. dataIndex: 'lepao_count',
  114. }, {
  115. title: '浏览量',
  116. dataIndex: 'views',
  117. }, {
  118. title: '创建时间',
  119. slotName: 'create_time'
  120. },
  121. {
  122. title: '创建人',
  123. dataIndex: 'create_user',
  124. },{
  125. title: '最后更新时间',
  126. slotName: 'update_time'
  127. }, {
  128. title: '更新人',
  129. dataIndex: 'update_user',
  130. },{
  131. title: '状态',
  132. slotName: 'state'
  133. }, {
  134. title: '操作',
  135. slotName: 'optional'
  136. }
  137. ]
  138. const loading = ref(false)
  139. const data = ref([])
  140. const getList = async () => {
  141. try {
  142. loading.value = true
  143. const reqData = {
  144. ...queryData,
  145. pagesize: pagination.pagesize,
  146. current: pagination.current
  147. }
  148. const res = await adminGetGoodsList(reqData)
  149. if (!res || res.code !== 0)
  150. return Notification.error({
  151. title: '获取商品失败!',
  152. content: res?.msg ?? '请稍后再试'
  153. })
  154. data.value = res.data
  155. console.log(res.data)
  156. pagination.total = res.pagination.total
  157. } catch (error) {
  158. Notification.error({
  159. title: '获取商品失败!',
  160. content: error.message || '请稍后再试'
  161. })
  162. } finally {
  163. loading.value = false
  164. }
  165. }
  166. // 分页 - 页码变化
  167. const handlePageChange = (page) => {
  168. pagination.current = page
  169. getOrderList()
  170. }
  171. // 分页 - 每页条数变化
  172. const handlePageSizeChange = (size) => {
  173. pagination.pagesize = size
  174. pagination.current = 1 // 页大小变化后回到第一页
  175. getList()
  176. }
  177. onMounted(() => {
  178. getList()
  179. })
  180. const stramptoTime = (time) => {
  181. return new Date(time).toLocaleString('zh-CN', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit' })
  182. }
  183. </script>
  184. <style scoped>
  185. .container {
  186. padding: 0 20px 20px 20px;
  187. }
  188. .table {
  189. margin-top: 15px;
  190. }
  191. </style>