orderstatatic.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. <template>
  2. <div class="order-statistics-container">
  3. <el-card class="search-card">
  4. <div class="search-header">
  5. <span class="title">订单统计</span>
  6. <div class="search-actions">
  7. <el-date-picker
  8. v-model="dateRange"
  9. type="daterange"
  10. align="right"
  11. unlink-panels
  12. range-separator="至"
  13. start-placeholder="开始日期"
  14. end-placeholder="结束日期"
  15. :picker-options="pickerOptions"
  16. @change="handleDateChange"
  17. />
  18. <el-button type="primary" @click="handleSearch" :loading="loading">查询</el-button>
  19. </div>
  20. </div>
  21. </el-card>
  22. <el-row :gutter="20" class="statistics-row">
  23. <el-col :span="6">
  24. <el-card shadow="hover">
  25. <div class="statistic-item">
  26. <div class="statistic-title">订单总量</div>
  27. <div class="statistic-value">{{ statistics.orderCount }}</div>
  28. </div>
  29. </el-card>
  30. </el-col>
  31. <el-col :span="6">
  32. <el-card shadow="hover">
  33. <div class="statistic-item" @click="fetchOrderDetails" style="cursor: pointer;">
  34. <div class="statistic-title">总金额</div>
  35. <div class="statistic-value">¥{{ statistics.totalAmount | formatMoney }}</div>
  36. </div>
  37. </el-card>
  38. </el-col>
  39. <el-col :span="6">
  40. <el-card shadow="hover">
  41. <div class="statistic-item">
  42. <div class="statistic-title">成交率</div>
  43. <div class="statistic-value">{{ statistics.successRate }}%</div>
  44. </div>
  45. </el-card>
  46. </el-col>
  47. <el-col :span="6">
  48. <el-card shadow="hover">
  49. <div class="statistic-item">
  50. <div class="statistic-title">退货率</div>
  51. <div class="statistic-value">{{ statistics.returnRate }}%</div>
  52. </div>
  53. </el-card>
  54. </el-col>
  55. </el-row>
  56. <!-- 订单详情对话框 -->
  57. <el-dialog
  58. title="订单详情"
  59. :visible.sync="detailModalVisible"
  60. width="85%"
  61. top="5vh"
  62. class="clean-dialog"
  63. >
  64. <div class="clean-container">
  65. <el-table
  66. :data="orderDetails"
  67. border
  68. style="width: 100%"
  69. v-loading="detailLoading"
  70. height="70vh"
  71. class="clean-table"
  72. >
  73. <el-table-column
  74. label="订单号"
  75. align="center"
  76. prop="orderCode"
  77. width="180"
  78. header-align="center"
  79. />
  80. <el-table-column
  81. label="所属公司"
  82. align="center"
  83. prop="companyName"
  84. header-align="center"
  85. show-overflow-tooltip
  86. />
  87. <el-table-column
  88. label="用户/收件人"
  89. align="center"
  90. header-align="center"
  91. width="150"
  92. >
  93. <template slot-scope="scope">
  94. <div class="compact-cell">
  95. <div>{{ scope.row.nickname || '-' }}</div>
  96. <div class="secondary-text">{{ scope.row.realName || '-' }}</div>
  97. </div>
  98. </template>
  99. </el-table-column>
  100. <el-table-column
  101. label="金额(元)"
  102. align="center"
  103. header-align="center"
  104. width="150"
  105. >
  106. <template slot-scope="scope">
  107. <div class="compact-cell">
  108. <div>总价: {{ scope.row.totalPrice ? scope.row.totalPrice.toFixed(2) : '0.00' }}</div>
  109. <div>实付: {{ scope.row.payPrice ? scope.row.payPrice.toFixed(2) : '0.00' }}</div>
  110. </div>
  111. </template>
  112. </el-table-column>
  113. <el-table-column
  114. label="时间"
  115. align="center"
  116. header-align="center"
  117. width="220"
  118. >
  119. <template slot-scope="scope">
  120. <div class="compact-cell">
  121. <div>{{ scope.row.createTime }}</div>
  122. <div class="secondary-text">{{ scope.row.payTime || '未支付' }}</div>
  123. </div>
  124. </template>
  125. </el-table-column>
  126. <el-table-column
  127. label="支付/类型"
  128. align="center"
  129. header-align="center"
  130. width="150"
  131. >
  132. <template slot-scope="scope">
  133. <div class="compact-cell">
  134. <el-tag
  135. size="small"
  136. style="display:block;margin:0 auto 4px;width:fit-content"
  137. v-for="item in payTypeOptions"
  138. v-if="scope.row.payType==item.dictValue"
  139. >{{item.dictLabel}}</el-tag>
  140. <el-tag
  141. size="small"
  142. style="display:block;margin:0 auto;width:fit-content"
  143. v-for="item in orderTypeOptions"
  144. v-if="scope.row.orderType==item.dictValue"
  145. >{{item.dictLabel}}</el-tag>
  146. </div>
  147. </template>
  148. </el-table-column>
  149. <el-table-column
  150. label="状态"
  151. align="center"
  152. header-align="center"
  153. width="150"
  154. >
  155. <template slot-scope="scope">
  156. <div class="compact-cell">
  157. <el-tag
  158. size="small"
  159. style="display:block;margin:0 auto 4px;width:fit-content"
  160. v-for="item in statusOptions"
  161. v-if="scope.row.status==item.dictValue"
  162. >{{item.dictLabel}}</el-tag>
  163. <el-tag
  164. size="small"
  165. style="display:block;margin:0 auto;width:fit-content"
  166. v-for="item in deliveryStatusOptions"
  167. v-if="scope.row.deliveryStatus==item.dictValue"
  168. >{{item.dictLabel}}</el-tag>
  169. </div>
  170. </template>
  171. </el-table-column>
  172. <el-table-column
  173. label="操作"
  174. fixed="right"
  175. width="90"
  176. align="center"
  177. header-align="center"
  178. >
  179. <template slot-scope="scope">
  180. <el-button
  181. size="mini"
  182. type="text"
  183. style="color:#409EFF;padding:5px 0"
  184. @click="handleDetails(scope.row)"
  185. v-hasPermi="['store:storeOrder:query']"
  186. >详情</el-button>
  187. </template>
  188. </el-table-column>
  189. </el-table>
  190. <div style="margin-top:15px">
  191. <pagination
  192. v-show="pagination.total>0"
  193. :total="pagination.total"
  194. :page.sync="pagination.currentPage"
  195. :limit.sync="pagination.pageSize"
  196. @pagination="fetchOrderDetails"
  197. />
  198. </div>
  199. </div>
  200. <el-drawer
  201. :title="show.title"
  202. :visible.sync="show.open"
  203. size="65%"
  204. :modal="false"
  205. :wrapper-closable="false"
  206. :append-to-body="true"
  207. custom-class="safe-drawer"
  208. >
  209. <product-order ref="order" />
  210. </el-drawer>
  211. </el-dialog>
  212. </div>
  213. </template>
  214. <script>
  215. import { getOrderStatistics } from "@/api/hisStore/statistics";
  216. import { listStoreOrder } from "@/api/hisStore/storeOrder";
  217. import productOrder from "../components/productOrder";
  218. export default {
  219. components: { productOrder },
  220. name: 'OrderStatistics',
  221. data() {
  222. return {
  223. deliveryPayStatusOptions:[],
  224. deliveryStatusOptions:[],
  225. orderTypeOptions:[],
  226. payTypeOptions:[],
  227. show:{
  228. open:false,
  229. title:"订单详情"
  230. },
  231. statusOptions:[],
  232. dateRange: [],
  233. pickerOptions: {
  234. shortcuts: [{
  235. text: '最近一周',
  236. onClick(picker) {
  237. const end = new Date();
  238. const start = new Date();
  239. start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
  240. picker.$emit('pick', [start, end]);
  241. }
  242. }, {
  243. text: '最近一个月',
  244. onClick(picker) {
  245. const end = new Date();
  246. const start = new Date();
  247. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  248. picker.$emit('pick', [start, end]);
  249. }
  250. }, {
  251. text: '最近三个月',
  252. onClick(picker) {
  253. const end = new Date();
  254. const start = new Date();
  255. start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
  256. picker.$emit('pick', [start, end]);
  257. }
  258. }]
  259. },
  260. loading: false,
  261. detailLoading: false,
  262. statistics: {
  263. orderCount: 0,
  264. totalAmount: 0,
  265. successRate: 0,
  266. returnRate: 0
  267. },
  268. orderDetails: [],
  269. detailModalVisible: false,
  270. pagination: {
  271. currentPage: 1,
  272. pageSize: 10,
  273. total: 0
  274. },
  275. };
  276. },
  277. filters: {
  278. formatMoney(value) {
  279. if (!value) return '0.00';
  280. return parseFloat(value).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
  281. }
  282. },
  283. created() {
  284. this.getDicts("store_order_type").then((response) => {
  285. this.orderTypeOptions = response.data;
  286. });
  287. this.getDicts("user_status").then((response) => {
  288. this.userStatusOptions = response.data;
  289. });
  290. this.getDicts("store_pay_type").then((response) => {
  291. this.payTypeOptions = response.data;
  292. });
  293. this.getDicts("store_order_status").then((response) => {
  294. this.statusOptions = response.data;
  295. });
  296. this.getDicts("store_order_delivery_status").then((response) => {
  297. this.deliveryStatusOptions = response.data;
  298. });
  299. this.getDicts("store_delivery_pay_status").then((response) => {
  300. this.deliveryPayStatusOptions = response.data;
  301. });
  302. // 默认查询最近30天数据
  303. const end = new Date();
  304. const start = new Date();
  305. start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
  306. this.dateRange = [start, end];
  307. this.fetchStatistics();
  308. },
  309. methods: {
  310. handleDetails(row){
  311. this.show.open=true;
  312. const orderId = row.id ;
  313. setTimeout(() => {
  314. this.$refs.order.getOrder(orderId);
  315. }, 500);
  316. },
  317. /**
  318. * 格式化日期(内置方法,替代外部工具函数)
  319. * @param {Date|string} date 日期对象或字符串
  320. * @param {string} [fmt='yyyy-MM-dd HH:mm:ss'] 格式字符串
  321. * @returns {string} 格式化后的日期字符串
  322. */
  323. formatDate(date, fmt = 'yyyy-MM-dd HH:mm:ss') {
  324. if (!date) return '';
  325. if (typeof date === 'string') {
  326. date = new Date(date.replace(/-/g, '/'));
  327. }
  328. if (!(date instanceof Date)) {
  329. date = new Date(date);
  330. }
  331. const o = {
  332. 'M+': date.getMonth() + 1, // 月份
  333. 'd+': date.getDate(), // 日
  334. 'H+': date.getHours(), // 小时
  335. 'm+': date.getMinutes(), // 分
  336. 's+': date.getSeconds(), // 秒
  337. 'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
  338. 'S': date.getMilliseconds() // 毫秒
  339. };
  340. if (/(y+)/.test(fmt)) {
  341. fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
  342. }
  343. for (const k in o) {
  344. if (new RegExp('(' + k + ')').test(fmt)) {
  345. fmt = fmt.replace(
  346. RegExp.$1,
  347. RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
  348. );
  349. }
  350. }
  351. return fmt;
  352. },
  353. handleDateChange(val) {
  354. this.dateRange = val;
  355. this.fetchStatistics();
  356. },
  357. handleSearch() {
  358. this.fetchStatistics();
  359. },
  360. async fetchStatistics() {
  361. if (!this.dateRange || this.dateRange.length !== 2) {
  362. this.$message.warning('请选择日期范围');
  363. return;
  364. }
  365. this.loading = true;
  366. try {
  367. const params = {
  368. startTime: this.formatDate(this.dateRange[0], 'yyyy-MM-dd'),
  369. endTime: this.formatDate(this.dateRange[1], 'yyyy-MM-dd')
  370. };
  371. const response = await getOrderStatistics(params);
  372. this.statistics = response.data;
  373. } catch (error) {
  374. this.$message.error('获取统计数据失败');
  375. } finally {
  376. this.loading = false;
  377. }
  378. },
  379. async fetchOrderDetails() {
  380. if (!this.dateRange || this.dateRange.length !== 2) return;
  381. this.detailLoading = true;
  382. try {
  383. const params = {
  384. createTimeRange: this.formatDate(this.dateRange[0], 'yyyy-MM-dd')+"--"+this.formatDate(this.dateRange[1], 'yyyy-MM-dd'),
  385. pageNum: this.pagination.currentPage,
  386. pageSize: this.pagination.pageSize,
  387. paidStatus:1
  388. };
  389. const response = await listStoreOrder(params);
  390. this.orderDetails = response.rows;
  391. this.pagination.total = response.total;
  392. this.detailModalVisible = true;
  393. } catch (error) {
  394. this.$message.error('获取订单详情失败');
  395. } finally {
  396. this.detailLoading = false;
  397. }
  398. },
  399. handleSizeChange(val) {
  400. this.pagination.pageSize = val;
  401. this.fetchOrderDetails();
  402. },
  403. handleCurrentChange(val) {
  404. this.pagination.currentPage = val;
  405. this.fetchOrderDetails();
  406. }
  407. }
  408. };
  409. </script>
  410. <style scoped>
  411. .order-statistics-container {
  412. padding: 20px;
  413. }
  414. .search-card {
  415. margin-bottom: 20px;
  416. }
  417. .search-header {
  418. display: flex;
  419. justify-content: space-between;
  420. align-items: center;
  421. }
  422. .title {
  423. font-size: 18px;
  424. font-weight: bold;
  425. }
  426. .statistics-row {
  427. margin-bottom: 20px;
  428. }
  429. .statistic-item {
  430. padding: 10px;
  431. }
  432. .statistic-title {
  433. font-size: 14px;
  434. color: #999;
  435. margin-bottom: 10px;
  436. }
  437. .statistic-value {
  438. font-size: 24px;
  439. font-weight: bold;
  440. margin-bottom: 10px;
  441. }
  442. .statistic-compare .up {
  443. color: #f56c6c;
  444. margin-left: 5px;
  445. }
  446. .statistic-compare .down {
  447. color: #67c23a;
  448. margin-left: 5px;
  449. }
  450. .clean-dialog {
  451. border-radius: 8px;
  452. }
  453. .clean-table .el-table__header th {
  454. background-color: #f8f8f9;
  455. }
  456. .compact-cell {
  457. padding: 4px 0;
  458. line-height: 1.4;
  459. }
  460. .secondary-text {
  461. color: #909399;
  462. font-size: 0.9em;
  463. }
  464. </style>