aaa
doum
2026-06-04 08e9a67dd679f311e79a27b04cd0c53a30b4bccf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<template>
  <GlobalWindow
    title="从企业商品库选择"
    width="70%"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="confirm">
    <el-form :inline="true" :model="searchForm" class="search-form">
      <el-form-item label="商品名称">
        <el-input v-model="searchForm.name" placeholder="请输入商品名称" clearable @keyup.enter.native="search" />
      </el-form-item>
      <el-form-item label="类别">
        <el-select v-model="searchForm.categoryId" clearable placeholder="全部">
          <el-option
            v-for="item in categoryList"
            :key="item.id"
            :label="item.name"
            :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="品牌">
        <el-select v-model="searchForm.brandId" clearable placeholder="全部">
          <el-option
            v-for="item in brandList"
            :key="item.id"
            :label="item.name"
            :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="search">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="isWorking"
      :data="tableData"
      stripe
      border
      highlight-current-row
      @current-change="handleCurrentChange">
      <el-table-column label="" width="55">
        <template slot-scope="{ row }">
          <el-radio v-model="selectedId" :label="row.id">&nbsp;</el-radio>
        </template>
      </el-table-column>
      <el-table-column prop="id" label="商品ID" min-width="90" />
      <el-table-column prop="name" label="商品名称/型号" min-width="220" show-overflow-tooltip>
        <template slot-scope="{ row }">
          <div class="goods-cell">
            <el-image
              v-if="row.imgurl"
              class="goods-thumb"
              :src="row.prefixUrl + row.imgurl"
              fit="cover" />
            <span>{{ row.name }}</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="brandName" label="品牌" min-width="100" show-overflow-tooltip />
      <el-table-column prop="categoryName" label="类别" min-width="100" show-overflow-tooltip />
      <el-table-column label="指导价(元)" min-width="110">
        <template slot-scope="{ row }">
          {{ row.type === 0 ? row.zdPrice : row.baseZdPrice }}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pager"
      @size-change="handleSizeChange"
      @current-change="handlePageChange"
      :current-page="page"
      :page-sizes="[10, 20, 30]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total" />
  </GlobalWindow>
</template>
 
<script>
import GlobalWindow from '@/components/common/GlobalWindow'
import { fetchList } from '@/api/business/goods'
import { brand, category } from '@/api/system/common.js'
 
export default {
  name: 'FeaturedGoodsPicker',
  components: { GlobalWindow },
  data () {
    return {
      visible: false,
      isWorking: false,
      searchForm: {
        name: '',
        categoryId: '',
        brandId: '',
        status: 0
      },
      categoryList: [],
      brandList: [],
      tableData: [],
      page: 1,
      pageSize: 10,
      total: 0,
      selectedId: '',
      selectedRow: null
    }
  },
  methods: {
    open () {
      this.visible = true
      this.selectedId = ''
      this.selectedRow = null
      this.page = 1
      this.searchForm.name = ''
      this.searchForm.categoryId = ''
      this.searchForm.brandId = ''
      this.loadOptions()
      this.getList()
    },
    loadOptions () {
      if (!this.categoryList.length) {
        category().then(res => { this.categoryList = res || [] })
      }
      if (!this.brandList.length) {
        brand().then(res => { this.brandList = res || [] })
      }
    },
    search () {
      this.page = 1
      this.getList()
    },
    getList () {
      this.isWorking = true
      fetchList({
        page: this.page,
        capacity: this.pageSize,
        model: { ...this.searchForm }
      }).then(res => {
        this.tableData = res.records || []
        this.total = res.total || 0
      }).catch(e => {
        this.$tip.apiFailed(e)
      }).finally(() => {
        this.isWorking = false
      })
    },
    handleSizeChange (size) {
      this.pageSize = size
      this.page = 1
      this.getList()
    },
    handlePageChange (page) {
      this.page = page
      this.getList()
    },
    handleCurrentChange (row) {
      if (!row) return
      this.selectedId = row.id
      this.selectedRow = row
    },
    confirm () {
      if (!this.selectedRow) {
        this.$message.warning('请选择商品')
        return
      }
      this.$emit('select', { ...this.selectedRow })
      this.visible = false
    }
  }
}
</script>
 
<style scoped lang="scss">
.search-form {
  margin-bottom: 12px;
}
.goods-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}
.goods-thumb {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
}
.pager {
  margin-top: 12px;
  text-align: right;
}
</style>