checkStatistics.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <view class="page" :style="{'min-height':(h)+'px','padding-top':mt+'px'}">
  3. <c-nav-bar title="核销统计"></c-nav-bar>
  4. <view class="top">
  5. <view class="time-container">
  6. <view class="time" @click="showStartDate=true">
  7. <u-icon name="calendar" :label="orderTimeStart || '开始时间'" labelPos="right" labelColor="#666" color="#666" space="7px"
  8. size="25px"></u-icon>
  9. <u-icon name="arrow-down" color="#999" size="20px" style="margin-left: 20rpx;"></u-icon>
  10. </view>
  11. <view class="time" @click="showEndDate=true">
  12. <u-icon name="calendar" :label="orderTimeEnd || '结束时间'" labelPos="right" labelColor="#666" color="#666" space="7px"
  13. size="25px"></u-icon>
  14. <u-icon name="arrow-down" color="#999" size="20px" style="margin-left: 20rpx;"></u-icon>
  15. </view>
  16. </view>
  17. <view class="search-btn" @tap="searchData">查询</view>
  18. </view>
  19. <view class="statistics-container">
  20. <view class="statistics-summary">
  21. <view class="summary-item">
  22. <view class="summary-label">总核销单</view>
  23. <view class="summary-value">{{totalNum}}</view>
  24. </view>
  25. <view class="summary-item">
  26. <view class="summary-label">总优惠金额</view>
  27. <view class="summary-amount">¥{{totalAmount}}</view>
  28. </view>
  29. </view>
  30. <view class="statistics-title">产品统计</view>
  31. <view class="statistics-card" v-for="(item,index) in checkInfo" :key="index">
  32. <view class="statistics-header" @tap="toggleExpand(item.productName)">
  33. <view class="statistics-product">{{item.productName}}</view>
  34. </view>
  35. <view class="statistics-info">
  36. <view class="statistics-item">
  37. <view class="statistics-label">核销数量</view>
  38. <view class="statistics-value">{{item.num}}</view>
  39. </view>
  40. <view class="statistics-item">
  41. <view class="statistics-label">优惠金额</view>
  42. <view class="statistics-amount">¥{{item.totalAmount}}</view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <u-datetime-picker :immediateChange="true" @confirm="confirmStartDate" @cancel="showStartDate=false" :show="showStartDate" v-model="startDate" visibleItemCount="10" mode="date"></u-datetime-picker>
  48. <u-datetime-picker :immediateChange="true" @confirm="confirmEndDate" @cancel="showEndDate=false" :show="showEndDate" v-model="endDate" visibleItemCount="10" mode="date"></u-datetime-picker>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. data() {
  54. return {
  55. dateStr: '请选择时间段',
  56. showStartDate: false,
  57. showEndDate: false,
  58. startDate: Number(new Date()) - 7 * 24 * 60 * 60 * 1000,
  59. endDate: Number(new Date()),
  60. orderTimeStart: '',
  61. orderTimeEnd: '',
  62. merchantId: uni.getStorageSync('merchantId'),
  63. totalAmount: 0,
  64. totalNum: 0,
  65. checkInfo:[],
  66. expandedItems: {}, // 存储展开状态
  67. h: 0,
  68. mt: 0
  69. }
  70. },
  71. onLoad() {
  72. this.initHeight();
  73. this.getStatisticsData();
  74. },
  75. methods: {
  76. initHeight() {
  77. uni.getSystemInfo({
  78. success: (res) => {
  79. this.h = res.windowHeight;
  80. this.mt = res.statusBarHeight + 44;
  81. }
  82. });
  83. },
  84. getStatisticsData() {
  85. const params = {
  86. merchantId: this.merchantId
  87. };
  88. // 添加时间段筛选参数
  89. if (this.orderTimeStart) {
  90. params.orderTimeStart = this.orderTimeStart;
  91. }
  92. if (this.orderTimeEnd) {
  93. params.orderTimeEnd = this.orderTimeEnd;
  94. }
  95. // 获取统计数据
  96. this.$api.get('/scenic/merchant/offline/order/count', params).then(res => {
  97. if(res.data.code==0){
  98. this.checkInfo = res.data.data;
  99. // 计算总计
  100. this.calculateTotal();
  101. }
  102. }).catch(() => {
  103. uni.showToast({
  104. title: '获取统计数据失败',
  105. icon: 'none'
  106. });
  107. });
  108. },
  109. calculateTotal() {
  110. this.totalNum = 0;
  111. this.totalAmount = 0;
  112. this.checkInfo.forEach(item => {
  113. this.totalNum += item.num || 0;
  114. this.totalAmount += parseFloat(item.totalAmount) || 0;
  115. });
  116. // 保留两位小数
  117. this.totalAmount = this.totalAmount.toFixed(2);
  118. },
  119. confirmStartDate(e) {
  120. // 处理开始时间选择
  121. const date = new Date(e.value);
  122. const year = date.getFullYear();
  123. const month = ('0' + (date.getMonth() + 1)).slice(-2);
  124. const day = ('0' + date.getDate()).slice(-2);
  125. this.orderTimeStart = `${year}-${month}-${day}`;
  126. this.showStartDate = false;
  127. },
  128. confirmEndDate(e) {
  129. // 处理结束时间选择
  130. const date = new Date(e.value);
  131. const year = date.getFullYear();
  132. const month = ('0' + (date.getMonth() + 1)).slice(-2);
  133. const day = ('0' + date.getDate()).slice(-2);
  134. this.orderTimeEnd = `${year}-${month}-${day}`;
  135. this.showEndDate = false;
  136. },
  137. searchData() {
  138. this.getStatisticsData();
  139. },
  140. toggleExpand(productName) {
  141. this.expandedItems[productName] = !this.expandedItems[productName];
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="less" scoped>
  147. .page {
  148. box-sizing: border-box;
  149. background-color: #F5F7FA;
  150. }
  151. .top {
  152. padding: 20rpx 30rpx;
  153. background-color: #FFFFFF;
  154. margin-bottom: 20rpx;
  155. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
  156. .time-container {
  157. display: flex;
  158. gap: 30rpx;
  159. margin-bottom: 20rpx;
  160. }
  161. .time {
  162. display: flex;
  163. align-items: center;
  164. gap: 0 10rpx;
  165. flex: 1;
  166. }
  167. .search-btn {
  168. background-color: #007A69;
  169. color: #FFFFFF;
  170. font-size: 28rpx;
  171. text-align: center;
  172. padding: 15rpx 0;
  173. border-radius: 10rpx;
  174. margin-top: 10rpx;
  175. cursor: pointer;
  176. transition: background-color 0.3s ease;
  177. }
  178. }
  179. /* 统计数据样式 */
  180. .statistics-container {
  181. padding: 0 30rpx 30rpx;
  182. }
  183. .statistics-summary {
  184. background: #FFFFFF;
  185. border-radius: 16rpx;
  186. padding: 30rpx;
  187. margin-bottom: 24rpx;
  188. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  189. display: flex;
  190. justify-content: space-around;
  191. align-items: center;
  192. }
  193. .summary-item {
  194. text-align: center;
  195. flex: 1;
  196. }
  197. .summary-label {
  198. font-size: 24rpx;
  199. color: #666666;
  200. margin-bottom: 12rpx;
  201. }
  202. .summary-value {
  203. font-size: 36rpx;
  204. font-weight: bold;
  205. color: #1E3A62;
  206. }
  207. .summary-amount {
  208. font-size: 36rpx;
  209. font-weight: bold;
  210. color: #FF6B6B;
  211. }
  212. .statistics-title {
  213. font-size: 32rpx;
  214. font-weight: bold;
  215. color: #333333;
  216. margin-bottom: 20rpx;
  217. padding-left: 10rpx;
  218. border-left: 6rpx solid #1E3A62;
  219. }
  220. .statistics-card {
  221. background: #FFFFFF;
  222. border-radius: 16rpx;
  223. padding: 30rpx;
  224. margin-bottom: 20rpx;
  225. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.08);
  226. transition: transform 0.3s ease, box-shadow 0.3s ease;
  227. }
  228. .statistics-card:hover {
  229. transform: translateY(-2rpx);
  230. box-shadow: 0 8rpx 16rpx rgba(0, 0, 0, 0.12);
  231. }
  232. .statistics-header {
  233. display: flex;
  234. justify-content: space-between;
  235. align-items: center;
  236. cursor: pointer;
  237. padding-right: 10rpx;
  238. }
  239. .statistics-product {
  240. font-size: 28rpx;
  241. font-weight: 600;
  242. color: #333333;
  243. margin-bottom: 24rpx;
  244. padding-bottom: 16rpx;
  245. border-bottom: 1rpx solid #F0F0F0;
  246. flex: 1;
  247. }
  248. .statistics-info {
  249. display: flex;
  250. justify-content: space-between;
  251. flex-wrap: nowrap;
  252. gap: 40rpx;
  253. }
  254. .statistics-item {
  255. flex: 1;
  256. min-width: 150rpx;
  257. max-width: calc(50% - 20rpx);
  258. }
  259. .statistics-label {
  260. font-size: 24rpx;
  261. color: #666666;
  262. margin-bottom: 8rpx;
  263. }
  264. .statistics-value {
  265. font-size: 32rpx;
  266. font-weight: bold;
  267. color: #1E3A62;
  268. }
  269. .statistics-amount {
  270. font-size: 32rpx;
  271. font-weight: bold;
  272. color: #FF6B6B;
  273. }
  274. </style>