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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<template>
  <div class="product-table-container">
    <el-table
      :data="list"
      v-loading="loading"
      size="small"
      border
      class="custom-table"
      :height="tableHeight"
    >
      <el-table-column label="合同号" prop="salesContractNo" width="160" show-overflow-tooltip>
        <template #default="{ row }">
          <span class="contract-no">{{ row.salesContractNo || '--' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="产品名称" prop="productName" min-width="180" show-overflow-tooltip />
      <el-table-column label="规格型号" prop="model" width="140" show-overflow-tooltip>
        <template #default="{ row }">
          <span class="model-text">{{ row.model || '--' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单位" prop="unit" width="80" align="center" />
      <el-table-column label="合同数量" prop="contractQuantity" align="right" width="100">
        <template #default="{ row }">
          <span class="quantity">{{ formatNumber(row.contractQuantity) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同单价" prop="taxInclusiveUnitPrice" align="right" width="110">
        <template #default="{ row }">
          <span class="price">¥{{ formatMoney(row.taxInclusiveUnitPrice) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同金额" prop="contractAmount" align="right" width="130">
        <template #default="{ row }">
          <span class="amount">¥{{ formatMoney(row.contractAmount) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="已发货数量" prop="shippedQuantity" align="right" width="100">
        <template #default="{ row }">
          <span class="shipped-qty">{{ formatNumber(row.shippedQuantity) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="已发货金额" prop="shippedAmount" align="right" width="130">
        <template #default="{ row }">
          <span class="shipped-amt">¥{{ formatMoney(row.shippedAmount) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="发货进度" width="180" align="center">
        <template #default="{ row }">
          <div class="progress-cell">
            <el-progress
              :percentage="calcPercent(row.shippedQuantity, row.contractQuantity)"
              :stroke-width="8"
              :show-text="false"
              :color="getProgressColor(calcPercent(row.shippedQuantity, row.contractQuantity))"
            />
            <span class="progress-text">{{ calcPercent(row.shippedQuantity, row.contractQuantity) }}%</span>
          </div>
        </template>
      </el-table-column>
    </el-table>
 
    <div class="pagination-wrapper">
      <pagination
        v-show="total > 0"
        :total="total"
        :page="queryParams.pageNum"
        :limit="queryParams.pageSize"
        @pagination="handlePagination"
      />
    </div>
  </div>
</template>
 
<script setup>
import { ref, watch, computed } from 'vue'
import { customerTransactionsProducts } from '@/api/salesManagement/indicatorStats.js'
import Pagination from '@/components/PIMTable/Pagination.vue'
 
const props = defineProps({
  customerId: {
    type: [Number, String],
    required: true
  }
})
 
const loading = ref(false)
const list = ref([])
const total = ref(0)
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  customerId: null
})
 
const tableHeight = computed(() => `calc(100vh - 32em)`)
 
const getList = () => {
  loading.value = true
  queryParams.value.customerId = props.customerId
  customerTransactionsProducts(queryParams.value)
    .then(res => {
      if (res.code === 200) {
        list.value = res.data?.records || []
        total.value = res.data?.total || 0
      }
    })
    .finally(() => {
      loading.value = false
    })
}
 
const handlePagination = ({ page, limit }) => {
  queryParams.value.pageNum = page
  queryParams.value.pageSize = limit
  getList()
}
 
const formatMoney = (value) => {
  if (!value) return '0.00'
  return Number(value).toLocaleString('zh-CN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })
}
 
const formatNumber = (value) => {
  if (!value) return '0'
  return Number(value).toLocaleString('zh-CN')
}
 
const calcPercent = (shipped, total) => {
  if (!total || total === 0) return 0
  return Math.min(100, Math.round((shipped / total) * 100))
}
 
const getProgressColor = (percent) => {
  if (percent < 30) return '#f56c6c'
  if (percent < 60) return '#e6a23c'
  if (percent < 80) return '#409eff'
  return '#67c23a'
}
 
watch(() => props.customerId, (val) => {
  if (val) {
    queryParams.value.pageNum = 1
    getList()
  }
}, { immediate: true })
</script>
 
<style scoped lang="scss">
.product-table-container {
  .custom-table {
    border-radius: 8px;
    overflow: hidden;
 
    :deep(.el-table__header-wrapper) {
      th {
        background: #f8f9fb !important;
        font-weight: 600;
        color: #303133;
      }
    }
 
    :deep(.el-table__row) {
      transition: all 0.2s;
 
      &:hover > td {
        background: #f5f7fa !important;
      }
    }
 
    .contract-no {
      color: #409eff;
      font-weight: 500;
    }
 
    .model-text {
      color: #606266;
    }
 
    .quantity {
      font-weight: 500;
      color: #303133;
    }
 
    .price {
      color: #606266;
    }
 
    .amount {
      font-weight: 600;
      color: #303133;
    }
 
    .shipped-qty {
      color: #67c23a;
      font-weight: 500;
    }
 
    .shipped-amt {
      color: #67c23a;
      font-weight: 500;
    }
 
    .progress-cell {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 0 10px;
 
      .el-progress {
        flex: 1;
      }
 
      .progress-text {
        font-size: 12px;
        color: #606266;
        min-width: 32px;
        text-align: right;
      }
    }
  }
}
 
.pagination-wrapper {
  padding: 16px 0 0;
  display: flex;
  justify-content: flex-end;
}
</style>