RongshuProductDialog.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <el-dialog
  3. title="选择荣数商品"
  4. v-model="dialogVisible"
  5. width="900px"
  6. @open="onOpen"
  7. >
  8. <el-form :model="filter" inline>
  9. <el-form-item label="商品名称">
  10. <el-input
  11. v-model="filter.name"
  12. placeholder="请输入"
  13. clearable
  14. style="width: 220px"
  15. @keyup.enter="handleSearch"
  16. />
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button type="primary" @click="handleSearch">查询</el-button>
  20. <el-button @click="handleReset">重置</el-button>
  21. </el-form-item>
  22. </el-form>
  23. <el-table :data="pagedData" border stripe size="small" style="width: 100%">
  24. <el-table-column prop="name" label="商品名称" min-width="180" show-overflow-tooltip />
  25. <el-table-column prop="merchant" label="商户名称" width="160" show-overflow-tooltip />
  26. <el-table-column label="银行结算价" width="120" align="right">
  27. <template #default="{ row }">¥{{ row.settlePrice.toFixed(2) }}</template>
  28. </el-table-column>
  29. <el-table-column prop="stock" label="库存数" width="100" align="right" />
  30. <el-table-column label="操作" width="80" align="center" fixed="right">
  31. <template #default="{ row }">
  32. <el-button type="text" size="small" @click="handleSelect(row)">选择</el-button>
  33. </template>
  34. </el-table-column>
  35. </el-table>
  36. <div class="pagination-bar">
  37. <el-pagination
  38. background
  39. layout="total, prev, pager, next"
  40. :page-size="10"
  41. v-model:current-page="currentPage"
  42. :total="filteredData.length"
  43. />
  44. </div>
  45. </el-dialog>
  46. </template>
  47. <script>
  48. const MOCK_PRODUCTS = [
  49. { name: '微信立减金 5元(满10减5)', merchant: '微信支付', settlePrice: 5, stock: 2000, mainImage: [{ name: 'wx-5.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A55' }] },
  50. { name: '微信立减金 8元(满30减8)', merchant: '微信支付', settlePrice: 8, stock: 1500, mainImage: [{ name: 'wx-8.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A58' }] },
  51. { name: '微信立减金 10元(满50减10)', merchant: '微信支付', settlePrice: 10, stock: 1200, mainImage: [{ name: 'wx-10.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A510' }] },
  52. { name: '微信立减金 18元(满88减18)', merchant: '微信支付', settlePrice: 18, stock: 1000, mainImage: [{ name: 'wx-18.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A518' }] },
  53. { name: '微信立减金 20元(满100减20)', merchant: '微信支付', settlePrice: 20, stock: 800, mainImage: [{ name: 'wx-20.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A520' }] },
  54. { name: '微信立减金 30元(满150减30)', merchant: '微信支付', settlePrice: 30, stock: 600, mainImage: [{ name: 'wx-30.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A530' }] },
  55. { name: '微信立减金 50元(满200减50)', merchant: '微信支付', settlePrice: 50, stock: 400, mainImage: [{ name: 'wx-50.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A550' }] },
  56. { name: '微信立减金 66元(满300减66)', merchant: '微信支付', settlePrice: 66, stock: 300, mainImage: [{ name: 'wx-66.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A566' }] },
  57. { name: '微信立减金 88元(满388减88)', merchant: '微信支付', settlePrice: 88, stock: 200, mainImage: [{ name: 'wx-88.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A588' }] },
  58. { name: '微信立减金 100元(满500减100)', merchant: '微信支付', settlePrice: 100, stock: 150, mainImage: [{ name: 'wx-100.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A5100' }] },
  59. { name: '微信立减金 128元(满600减128)', merchant: '微信支付', settlePrice: 128, stock: 100, mainImage: [{ name: 'wx-128.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A5128' }] },
  60. { name: '微信立减金 200元(满800减200)', merchant: '微信支付', settlePrice: 200, stock: 80, mainImage: [{ name: 'wx-200.png', url: 'https://placehold.co/200x200/07c160/ffffff?text=%C2%A5200' }] }
  61. ]
  62. export default {
  63. name: 'RongshuProductDialog',
  64. props: {
  65. modelValue: { type: Boolean, default: false }
  66. },
  67. emits: ['update:modelValue', 'select'],
  68. data() {
  69. return {
  70. filter: { name: '' },
  71. currentPage: 1,
  72. products: MOCK_PRODUCTS
  73. }
  74. },
  75. computed: {
  76. dialogVisible: {
  77. get() { return this.modelValue },
  78. set(v) { this.$emit('update:modelValue', v) }
  79. },
  80. filteredData() {
  81. if (!this.filter.name) return this.products
  82. const kw = this.filter.name.trim()
  83. return this.products.filter(p => p.name.includes(kw))
  84. },
  85. pagedData() {
  86. const start = (this.currentPage - 1) * 10
  87. return this.filteredData.slice(start, start + 10)
  88. }
  89. },
  90. methods: {
  91. onOpen() {
  92. this.filter = { name: '' }
  93. this.currentPage = 1
  94. },
  95. handleSearch() {
  96. this.currentPage = 1
  97. },
  98. handleReset() {
  99. this.filter = { name: '' }
  100. this.currentPage = 1
  101. },
  102. handleSelect(row) {
  103. this.$emit('select', { ...row })
  104. this.dialogVisible = false
  105. }
  106. }
  107. }
  108. </script>
  109. <style scoped>
  110. .pagination-bar {
  111. margin-top: 12px;
  112. display: flex;
  113. justify-content: flex-end;
  114. }
  115. </style>