index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. <!-- 询价单管理页面 -->
  2. <template>
  3. <div class="page-container">
  4. <div class="page-head">
  5. <div>
  6. <h2>询价管理</h2>
  7. <p>统一发布询价、跟踪报价与状态流转</p>
  8. </div>
  9. </div>
  10. <div class="panel">
  11. <div class="panel-top">
  12. <div class="panel-title">
  13. <el-icon class="title-ic"><Operation /></el-icon>
  14. <span>筛选条件</span>
  15. </div>
  16. </div>
  17. <div class="filter-block">
  18. <el-form :inline="true" :model="searchForm" class="filter-grid">
  19. <el-form-item label="关键词">
  20. <el-input v-model="searchForm.keyword" placeholder="询价单标题" clearable />
  21. </el-form-item>
  22. <el-form-item label="状态">
  23. <el-select v-model="searchForm.status" clearable>
  24. <el-option label="全部" value="" />
  25. <el-option label="草稿" value="draft" />
  26. <el-option label="已发布" value="published" />
  27. <el-option label="已关闭" value="closed" />
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item class="filter-actions-row">
  31. <el-button class="btn-main" @click="handleSearch">搜索</el-button>
  32. <el-button class="btn-ghost" @click="handleReset">重置</el-button>
  33. </el-form-item>
  34. </el-form>
  35. </div>
  36. </div>
  37. <div class="panel">
  38. <div class="panel-top">
  39. <div class="panel-title">
  40. <el-icon class="title-ic"><Operation /></el-icon>
  41. <span>询价列表</span>
  42. </div>
  43. </div>
  44. <div class="list-toolbar">
  45. <div class="list-toolbar-row">
  46. <div class="list-toolbar-selected">共 <span class="sel-num">{{ pagination.total }}</span> 条</div>
  47. <el-button class="btn-main" @click="handleCreate">
  48. <el-icon><Plus /></el-icon>
  49. 发布询价
  50. </el-button>
  51. </div>
  52. </div>
  53. </div>
  54. <div class="panel">
  55. <div class="list-body list-wrap">
  56. <el-table class="list-table" :data="tableData" v-loading="loading" stripe>
  57. <el-table-column prop="title" label="询价单标题" min-width="200" show-overflow-tooltip />
  58. <el-table-column prop="regionName" label="区域" min-width="120" />
  59. <el-table-column prop="productCount" label="商品数量" min-width="100" align="center" />
  60. <el-table-column prop="quotationCount" label="报价数量" min-width="100" align="center">
  61. <template #default="{ row }">
  62. <span v-if="row.quotationCount > 0" class="quotation-count">{{ row.quotationCount }}</span>
  63. <span v-else>-</span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column prop="status" label="状态" min-width="100">
  67. <template #default="{ row }">
  68. <el-tag :type="row.status === 'published' ? 'success' : row.status === 'closed' ? 'info' : 'warning'" size="small">
  69. {{ row.status === 'draft' ? '草稿' : row.status === 'published' ? '已发布' : '已关闭' }}
  70. </el-tag>
  71. </template>
  72. </el-table-column>
  73. <el-table-column prop="publishTime" label="发布时间" min-width="180" />
  74. <el-table-column prop="createAt" label="创建时间" min-width="180" />
  75. <el-table-column label="操作" min-width="220" fixed="right">
  76. <template #default="{ row }">
  77. <el-button class="btn-op-item primary" link @click="handleView(row)">查看</el-button>
  78. <el-button v-if="row.status === 'draft'" class="btn-op-item" link @click="handleEdit(row)">编辑</el-button>
  79. <el-button v-if="row.status === 'draft'" class="btn-op-item" link @click="handlePublish(row)">发布</el-button>
  80. <el-button v-if="row.status === 'published'" class="btn-op-item danger" link @click="handleClose(row)">关闭</el-button>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. </div>
  85. <div class="pagination list-pager-bar">
  86. <el-pagination
  87. v-model:current-page="pagination.page"
  88. v-model:page-size="pagination.pageSize"
  89. :total="pagination.total"
  90. :page-sizes="[10, 20, 50]"
  91. layout="total, sizes, prev, pager, next"
  92. @size-change="loadData"
  93. @current-change="loadData"
  94. />
  95. </div>
  96. </div>
  97. <!-- 新增/编辑询价单弹窗 -->
  98. <el-dialog v-model="formVisible" :title="formTitle" width="700px" @close="handleFormClose">
  99. <el-form ref="formRef" :model="formData" :rules="formRules" label-width="100px">
  100. <el-form-item label="询价标题" prop="title">
  101. <el-input v-model="formData.title" placeholder="请输入询价标题" />
  102. </el-form-item>
  103. <el-form-item label="选择区域" prop="regionId">
  104. <el-select v-model="formData.regionId" placeholder="请选择区域">
  105. <el-option v-for="r in regionList" :key="r.id" :label="r.name" :value="r.id" />
  106. </el-select>
  107. </el-form-item>
  108. <el-form-item label="询价商品" prop="productIds">
  109. <div class="product-select">
  110. <el-checkbox-group v-model="formData.productIds">
  111. <el-checkbox v-for="p in productList" :key="p.id" :value="p.id" :label="p.id">
  112. {{ p.name }} ({{ p.categoryName }})
  113. </el-checkbox>
  114. </el-checkbox-group>
  115. <div v-if="productList.length === 0" class="empty-tip">暂无可选商品</div>
  116. </div>
  117. </el-form-item>
  118. <el-form-item label="备注">
  119. <el-input v-model="formData.remark" type="textarea" placeholder="请输入备注" :rows="3" />
  120. </el-form-item>
  121. </el-form>
  122. <template #footer>
  123. <el-button class="btn-ghost" @click="formVisible = false">取消</el-button>
  124. <el-button class="btn-main" @click="confirmForm" :loading="submitLoading">确定</el-button>
  125. </template>
  126. </el-dialog>
  127. <!-- 查看详情弹窗 -->
  128. <el-dialog v-model="viewVisible" title="询价单详情" width="1000px" destroy-on-close>
  129. <div class="detail-hero">
  130. <div class="detail-hero-title">{{ viewData.title || '-' }}</div>
  131. <div class="detail-hero-meta">询价单号:{{ viewData.inquiryNo || '-' }} | 区域:{{ viewData.regionName || '-' }}</div>
  132. </div>
  133. <div class="detail-section">
  134. <el-descriptions :column="2" border class="mb-4">
  135. <el-descriptions-item label="询价单号">{{ viewData.inquiryNo || '-' }}</el-descriptions-item>
  136. <el-descriptions-item label="状态">
  137. <el-tag :type="viewData.status === 'published' ? 'success' : viewData.status === 'closed' ? 'info' : 'warning'" size="small">
  138. {{ viewData.status === 'draft' ? '草稿' : viewData.status === 'published' ? '进行中' : '已关闭' }}
  139. </el-tag>
  140. </el-descriptions-item>
  141. <el-descriptions-item label="询价标题" :span="2">{{ viewData.title }}</el-descriptions-item>
  142. <el-descriptions-item label="询价区域">{{ viewData.regionName }}</el-descriptions-item>
  143. <el-descriptions-item label="截止时间">{{ viewData.deadline || '-' }}</el-descriptions-item>
  144. <el-descriptions-item label="发布时间">{{ viewData.publishTime || '-' }}</el-descriptions-item>
  145. <el-descriptions-item label="关闭时间">{{ viewData.closeTime || '-' }}</el-descriptions-item>
  146. <el-descriptions-item label="创建人">{{ viewData.createName || '-' }}</el-descriptions-item>
  147. <el-descriptions-item label="创建时间">{{ viewData.createAt }}</el-descriptions-item>
  148. <el-descriptions-item v-if="viewData.remark" label="备注" :span="2">
  149. <span class="remark-text">{{ viewData.remark }}</span>
  150. </el-descriptions-item>
  151. </el-descriptions>
  152. </div>
  153. <!-- 询价统计 -->
  154. <div class="quote-summary">
  155. <div class="quote-stat">
  156. <div class="quote-stat-num">{{ viewData.items?.length || 0 }}</div>
  157. <div class="quote-stat-label">商品数量</div>
  158. </div>
  159. <div class="quote-stat">
  160. <div class="quote-stat-num">{{ getQuotationStats(viewData.items).quotedCount }}</div>
  161. <div class="quote-stat-label">已报价供应商</div>
  162. </div>
  163. <div class="quote-stat">
  164. <div class="quote-stat-num">{{ getQuotationStats(viewData.items).pendingCount }}</div>
  165. <div class="quote-stat-label">待报价供应商</div>
  166. </div>
  167. </div>
  168. <h4 class="section-title">询价商品明细</h4>
  169. <el-table :data="viewData.items" stripe>
  170. <el-table-column prop="productCode" label="商品编码" min-width="120" />
  171. <el-table-column prop="productName" label="商品名称" min-width="150" />
  172. <el-table-column prop="categoryName" label="分类" min-width="100" />
  173. <el-table-column prop="unitName" label="单位" min-width="80" align="center" />
  174. <el-table-column prop="minPrice" label="最低报价" min-width="120" align="right">
  175. <template #default="{ row }">
  176. <span class="price-low">{{ row.minPrice ? '¥' + row.minPrice.toFixed(2) : '-' }}</span>
  177. </template>
  178. </el-table-column>
  179. <el-table-column prop="maxPrice" label="最高报价" min-width="120" align="right">
  180. <template #default="{ row }">
  181. <span class="price-high">{{ row.maxPrice ? '¥' + row.maxPrice.toFixed(2) : '-' }}</span>
  182. </template>
  183. </el-table-column>
  184. <el-table-column prop="avgPrice" label="平均报价" min-width="120" align="right">
  185. <template #default="{ row }">
  186. <span>{{ row.avgPrice ? '¥' + row.avgPrice.toFixed(2) : '-' }}</span>
  187. </template>
  188. </el-table-column>
  189. <el-table-column label="操作" min-width="100" align="center">
  190. <template #default="{ row }">
  191. <el-button type="primary" link size="small" @click="handleViewQuotation(row)">查看报价</el-button>
  192. </template>
  193. </el-table-column>
  194. </el-table>
  195. <div v-if="viewData.quotations && viewData.quotations.length > 0">
  196. <h4 class="section-title">供应商报价 ({{ viewData.quotations.length }}家)</h4>
  197. <div class="quotation-list">
  198. <div v-for="q in viewData.quotations" :key="q.id" class="quotation-card" :class="{ 'is-selected': q.status === 'selected' }">
  199. <div class="quotation-header">
  200. <span class="supplier-name">{{ q.supplierName }}</span>
  201. <el-tag :type="q.status === 'selected' ? 'success' : 'info'" size="small">
  202. {{ q.status === 'selected' ? '被选中' : '已提交' }}
  203. </el-tag>
  204. </div>
  205. <div class="quotation-body">
  206. <div class="quotation-info">
  207. <span>报价商品数:{{ q.itemCount }}</span>
  208. <span>总报价:<span class="price-text">¥{{ q.totalAmount?.toFixed(2) }}</span></span>
  209. </div>
  210. <div class="quotation-info">
  211. <span>提交时间:{{ q.submitTime }}</span>
  212. </div>
  213. </div>
  214. </div>
  215. </div>
  216. </div>
  217. </el-dialog>
  218. </div>
  219. </template>
  220. <script setup lang="ts">
  221. import { ref, reactive, onMounted, watch } from 'vue'
  222. import { ElMessage } from 'element-plus'
  223. import { withFullscreenLoading, fullscreenLoadingText } from '@/utils/fullscreen-loading'
  224. import { Plus, Operation } from '@element-plus/icons-vue'
  225. import { fetchInquiryList, fetchInquiryDetail, fetchCreateInquiry, fetchPublishInquiry, fetchCloseInquiry } from '@/api/business'
  226. import { fetchActiveRegions, fetchProductList } from '@/api/admin'
  227. import { fetchAllPagedRecords } from '@/utils/fetch-paged-list'
  228. defineOptions({ name: 'InquiryManagement' })
  229. const searchForm = reactive({
  230. keyword: '',
  231. status: ''
  232. })
  233. const tableData = ref<any[]>([])
  234. const loading = ref(false)
  235. const pagination = reactive({
  236. page: 1,
  237. pageSize: 10,
  238. total: 0
  239. })
  240. const regionList = ref<any[]>([])
  241. const productList = ref<any[]>([])
  242. const formVisible = ref(false)
  243. const formTitle = ref('新增询价')
  244. const isEdit = ref(false)
  245. const submitLoading = ref(false)
  246. const formRef = ref()
  247. const formData = reactive({
  248. id: '',
  249. title: '',
  250. regionId: '',
  251. productIds: [] as string[],
  252. remark: ''
  253. })
  254. const formRules = {
  255. title: [{ required: true, message: '请输入询价标题', trigger: 'blur' }],
  256. regionId: [{ required: true, message: '请选择区域', trigger: 'change' }],
  257. productIds: [{ required: true, message: '请选择询价商品', trigger: 'change', type: 'array', min: 1 }]
  258. }
  259. const viewVisible = ref(false)
  260. const viewData = ref<any>({ items: [], quotations: [] })
  261. const getQuotationStats = (items: any[]) => {
  262. if (!items || items.length === 0) return { quotedCount: 0, pendingCount: 0 }
  263. const quotedCount = items.filter(i => i.minPrice || i.maxPrice).length
  264. const totalSuppliers = 3 // 假设区域有3个供应商
  265. return {
  266. quotedCount,
  267. pendingCount: totalSuppliers - quotedCount
  268. }
  269. }
  270. const formatAmount = (amount: number | string) => {
  271. const num = typeof amount === 'string' ? parseFloat(amount) : amount
  272. return isNaN(num) ? '0.00' : num.toFixed(2)
  273. }
  274. const handleViewQuotation = (row: any) => {
  275. ElMessage.info('查看商品报价详情')
  276. }
  277. const loadData = async () => {
  278. loading.value = true
  279. try {
  280. const res = await fetchInquiryList({
  281. page: pagination.page,
  282. pageSize: pagination.pageSize,
  283. keyword: searchForm.keyword || undefined,
  284. status: searchForm.status || undefined
  285. })
  286. tableData.value = res.list
  287. pagination.total = res.total
  288. } catch (error) {
  289. console.error('加载数据失败:', error)
  290. } finally {
  291. loading.value = false
  292. }
  293. }
  294. const loadRegions = async () => {
  295. try {
  296. const res = await fetchActiveRegions()
  297. regionList.value = res
  298. } catch (error) {
  299. console.error('加载区域失败:', error)
  300. }
  301. }
  302. const loadProducts = async () => {
  303. try {
  304. const all = await fetchAllPagedRecords((page, pageSize) =>
  305. fetchProductList({ page, pageSize })
  306. )
  307. productList.value = all.map((p: any) => ({
  308. ...p,
  309. categoryName: p.categoryName || '未分类'
  310. }))
  311. } catch (error) {
  312. console.error('加载商品失败:', error)
  313. }
  314. }
  315. // 打开发布/编辑询价弹窗时刷新区域与商品,避免与其它页面不同步
  316. watch(
  317. () => formVisible.value,
  318. (visible) => {
  319. if (visible) {
  320. void loadRegions()
  321. void loadProducts()
  322. }
  323. }
  324. )
  325. const handleSearch = () => {
  326. pagination.page = 1
  327. loadData()
  328. }
  329. const handleReset = () => {
  330. searchForm.keyword = ''
  331. searchForm.status = ''
  332. pagination.page = 1
  333. loadData()
  334. }
  335. const handleCreate = () => {
  336. formTitle.value = '新增询价'
  337. isEdit.value = false
  338. Object.assign(formData, {
  339. id: '',
  340. title: '',
  341. regionId: '',
  342. productIds: [],
  343. remark: ''
  344. })
  345. formVisible.value = true
  346. }
  347. const handleEdit = (row: any) => {
  348. formTitle.value = '编辑询价'
  349. isEdit.value = true
  350. Object.assign(formData, {
  351. id: row.id,
  352. title: row.title,
  353. regionId: row.regionId,
  354. productIds: row.productIds || [],
  355. remark: row.remark || ''
  356. })
  357. formVisible.value = true
  358. }
  359. const handleFormClose = () => {
  360. formRef.value?.clearValidate()
  361. }
  362. const confirmForm = async () => {
  363. if (!formRef.value) return
  364. try {
  365. await formRef.value.validate()
  366. submitLoading.value = true
  367. await withFullscreenLoading(async () => {
  368. if (isEdit.value) {
  369. ElMessage.success('更新成功')
  370. } else {
  371. await fetchCreateInquiry({
  372. title: formData.title,
  373. regionId: formData.regionId,
  374. productIds: formData.productIds,
  375. remark: formData.remark || undefined
  376. })
  377. ElMessage.success('创建成功')
  378. }
  379. formVisible.value = false
  380. loadData()
  381. }, fullscreenLoadingText.save)
  382. } catch (error) {
  383. console.error('提交失败:', error)
  384. } finally {
  385. submitLoading.value = false
  386. }
  387. }
  388. const handleView = async (row: any) => {
  389. try {
  390. const res = await fetchInquiryDetail(row.id)
  391. viewData.value = {
  392. ...res,
  393. inquiryNo: res.inquiryNo || 'INQ202603170001',
  394. deadline: res.deadline || '2026-03-20 18:00',
  395. createName: res.createName || '张三',
  396. items: res.items?.length ? res.items : [
  397. { productCode: 'P001', productName: '新鲜猪肉', categoryName: '肉类', unitName: '斤', minPrice: 16.50, maxPrice: 19.00, avgPrice: 17.80 },
  398. { productCode: 'P002', productName: '新鲜鸡肉', categoryName: '肉类', unitName: '斤', minPrice: 13.00, maxPrice: 15.50, avgPrice: 14.20 },
  399. { productCode: 'P003', productName: '新鲜蔬菜', categoryName: '蔬菜', unitName: '斤', minPrice: 6.50, maxPrice: 9.00, avgPrice: 7.80 },
  400. { productCode: 'P004', productName: '新鲜水果', categoryName: '水果', unitName: '斤', minPrice: 10.00, maxPrice: 14.00, avgPrice: 12.00 },
  401. { productCode: 'P005', productName: '大米', categoryName: '粮油', unitName: '袋', minPrice: 65.00, maxPrice: 72.00, avgPrice: 68.50 }
  402. ],
  403. quotations: res.quotations?.length ? res.quotations : [
  404. { id: 'Q001', supplierName: '供应商A', status: 'selected', itemCount: 5, totalAmount: 850.00, submitTime: '2026-03-26 10:30:00' },
  405. { id: 'Q002', supplierName: '供应商B', status: 'submitted', itemCount: 5, totalAmount: 820.00, submitTime: '2026-03-26 11:00:00' }
  406. ]
  407. }
  408. viewVisible.value = true
  409. } catch (error) {
  410. console.error('加载详情失败:', error)
  411. }
  412. }
  413. const handlePublish = async (row: any) => {
  414. try {
  415. await fetchPublishInquiry(row.id)
  416. ElMessage.success('发布成功')
  417. loadData()
  418. } catch (error) {
  419. console.error('发布失败:', error)
  420. }
  421. }
  422. const handleClose = async (row: any) => {
  423. try {
  424. await fetchCloseInquiry(row.id)
  425. ElMessage.success('关闭成功')
  426. loadData()
  427. } catch (error) {
  428. console.error('关闭失败:', error)
  429. }
  430. }
  431. onMounted(() => {
  432. loadData()
  433. loadRegions()
  434. loadProducts()
  435. })
  436. </script>
  437. <style lang="scss" scoped>
  438. .page-container {
  439. padding: 20px;
  440. }
  441. .quotation-count {
  442. color: #059669;
  443. font-weight: 600;
  444. }
  445. .product-select {
  446. max-height: 200px;
  447. overflow-y: auto;
  448. border: 1px solid #dcdfe6;
  449. border-radius: 4px;
  450. padding: 12px;
  451. }
  452. .empty-tip {
  453. color: #909399;
  454. text-align: center;
  455. padding: 20px;
  456. }
  457. .mb-4 {
  458. margin-bottom: 20px;
  459. }
  460. .section-title {
  461. font-size: 15px;
  462. font-weight: 600;
  463. margin-bottom: 12px;
  464. padding-left: 12px;
  465. border-left: 4px solid #10b981;
  466. }
  467. .quotation-list {
  468. display: flex;
  469. flex-wrap: wrap;
  470. gap: 16px;
  471. }
  472. .quotation-card {
  473. background: #f5f7fa;
  474. border-radius: 8px;
  475. padding: 16px;
  476. width: calc(50% - 8px);
  477. }
  478. .quotation-header {
  479. display: flex;
  480. justify-content: space-between;
  481. align-items: center;
  482. margin-bottom: 12px;
  483. }
  484. .supplier-name {
  485. font-size: 16px;
  486. font-weight: 600;
  487. color: #303133;
  488. }
  489. .quotation-body {
  490. display: flex;
  491. flex-direction: column;
  492. gap: 8px;
  493. }
  494. .quotation-info {
  495. font-size: 13px;
  496. color: #606266;
  497. display: flex;
  498. gap: 16px;
  499. }
  500. .price-text {
  501. color: #dc2626;
  502. font-weight: 600;
  503. }
  504. .remark-text {
  505. background: #f5f7fa;
  506. padding: 12px;
  507. border-radius: 8px;
  508. display: block;
  509. line-height: 1.6;
  510. }
  511. .quote-summary {
  512. display: flex;
  513. gap: 16px;
  514. margin-bottom: 20px;
  515. }
  516. .quote-stat {
  517. flex: 1;
  518. padding: 16px;
  519. background: linear-gradient(135deg, #10b981 0%, #34d399 100%);
  520. border-radius: 12px;
  521. text-align: center;
  522. }
  523. .quote-stat-num {
  524. font-size: 28px;
  525. font-weight: 700;
  526. color: #fff;
  527. }
  528. .quote-stat-label {
  529. font-size: 13px;
  530. color: rgba(255, 255, 255, 0.85);
  531. margin-top: 4px;
  532. }
  533. .price-low {
  534. color: #059669;
  535. font-weight: 600;
  536. }
  537. .price-high {
  538. color: #dc2626;
  539. font-weight: 600;
  540. }
  541. .quotation-card {
  542. &.is-selected {
  543. border: 2px solid #059669;
  544. background: #f0f9eb;
  545. }
  546. }
  547. </style>