good-dialog.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <el-dialog
  3. title="选择商品"
  4. :visible.sync="visible"
  5. width="1100px"
  6. :close-on-click-modal="false"
  7. :show-close="false"
  8. >
  9. <div class="filter-container">
  10. <div class="filter-control">
  11. <span>商品名称:</span>
  12. <el-input
  13. v-model="listQuery.productName"
  14. placeholder="商品名称"
  15. clearable
  16. @input="e => (listQuery.name= checkedInput(e,2))"
  17. />
  18. </div>
  19. <div class="filter-control">
  20. <span>供应商名称:</span>
  21. <el-input
  22. v-model="listQuery.shopName"
  23. placeholder="供应商名称"
  24. clearable
  25. style="width:160px;"
  26. @input="e => (listQuery.shopName= checkedInput(e,2))"
  27. />
  28. </div>
  29. <div class="filter-control">
  30. <el-button type="primary" @click="getList">查询</el-button>
  31. </div>
  32. </div>
  33. <el-table ref="table" v-loading="isLoading" :data="list" height="400px" border @select="handleSelect">
  34. <el-table-column type="selection" width="50" />
  35. <el-table-column prop="mainImage" label="商品图片" align="center" width="100">
  36. <template slot-scope="{ row }">
  37. <el-popover
  38. placement="top-start"
  39. title=""
  40. width="180"
  41. trigger="hover"
  42. >
  43. <img :src="row.mainImage" alt="" style="width:100px;height:100px;">
  44. <img slot="reference" :src="row.mainImage" alt="" style="width:50px;height:50px;">
  45. </el-popover>
  46. </template>
  47. </el-table-column>
  48. <el-table-column prop="productName" label="商品名称" align="center" />
  49. <el-table-column prop="shopName" label="供应商" align="center" width="250" />
  50. </el-table>
  51. <!-- 页码 -->
  52. <pagination
  53. :total="total"
  54. :page-sizes="[20]"
  55. :page-size="20"
  56. :page.sync="listQuery.index"
  57. :limit.sync="listQuery.pageSize"
  58. @pagination="getList"
  59. />
  60. <div slot="footer">
  61. <el-button @click="handleCanle">取 消</el-button>
  62. <el-button type="primary" :disabled="disabled" @click="handleAddProConfirm(productRadio)">确 定</el-button>
  63. </div>
  64. </el-dialog>
  65. </template>
  66. <script>
  67. import { getList } from '@/api/goods'
  68. export default {
  69. name: 'ProDialog',
  70. filters: {
  71. NumFormat(value) {
  72. // 处理金额
  73. return Number(value).toFixed(2)
  74. }
  75. },
  76. data() {
  77. return {
  78. visible: true,
  79. listQuery: {
  80. productName: '', // 商品名称
  81. shopName: '', // 供应商名称
  82. validFlag: 1,
  83. index: 1,
  84. organizeId: this.$store.getters.organizeId,
  85. pageSize: 20
  86. },
  87. list: [],
  88. total: 0,
  89. productRadio: null,
  90. isLoading: true
  91. }
  92. },
  93. computed: {
  94. disabled() {
  95. return this.productRadio === null
  96. }
  97. },
  98. created() {
  99. this.getList()
  100. },
  101. methods: {
  102. async getList() {
  103. // 获取商品列表
  104. try {
  105. this.isLoading = true
  106. const res = await getList(this.listQuery)
  107. console.log('res', res)
  108. this.list = res.data.results
  109. this.total = res.data.totalRecord
  110. this.isLoading = false
  111. } catch (error) {
  112. console.log('error', error)
  113. }
  114. },
  115. // 选择商品
  116. handleSelect(selection, row) {
  117. this.$refs.table.clearSelection()
  118. this.$refs.table.toggleRowSelection(row)
  119. this.productRadio = row
  120. },
  121. handleAddProConfirm() {
  122. // 确认选择商品
  123. this.$emit('confirm', this.productRadio)
  124. },
  125. handleCanle() {
  126. // 取消弹窗
  127. this.$emit('cancel')
  128. },
  129. checkedInput(event, type) {
  130. let pattern = ''
  131. switch (type) {
  132. case 1:
  133. pattern = /[^\d]/g
  134. break
  135. case 2:
  136. pattern = /[^u4E00-u9FA5|d|a-zA-Z|rns,.?!,。?!…—&$=()-+/*{}[]]|s/g
  137. break
  138. }
  139. return event.replace(pattern, '')
  140. }
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. ::v-deep{
  146. thead .el-checkbox{display: none !important;}
  147. }
  148. </style>