BusinessData.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="business-data data-box">
  3. <view class="headline">经营数据</view>
  4. <!-- 选择今日则显示当天日期。
  5. 选择自定义,则显示请选择日期。 点击后选择日期时间段。 -->
  6. <view class="search-time">
  7. <view class="time-select" @click.stop="selectType">
  8. <text class="select-value one-row">{{TimeSelectAction[ActiveTimeAction].name}}</text>
  9. <text class="iconfont select-icon">&#xe671;</text>
  10. </view>
  11. <view class="time-picke" v-if="ActiveTimeAction === TimeSelectAction[1].value"
  12. @click.stop="handleCalendar()">
  13. <text class="iconfont picke-icon">&#xe651;</text>
  14. <text class="picke-text">{{ startTime }} ~ {{ endTime }}</text>
  15. </view>
  16. </view>
  17. <view class="num-statistics">
  18. <template v-for="item in valueLabel">
  19. <view class="num-item">
  20. <view class="num-item-num">
  21. <text class="num-item-tag" v-if="item.tag">{{item.tag}}</text>
  22. <text
  23. class="num-item-val one-row">{{ item.fn ? item.fn(StatisticsVo) : (StatisticsVo[item.key] || 0)}}</text>
  24. </view>
  25. <view class="num-item-name one-row">{{item.label}} </view>
  26. </view>
  27. </template>
  28. </view>
  29. </view>
  30. <uni-calendar ref="CalendarRef" range :insert="false" @confirm="ConfirmCalendar" />
  31. <uv-action-sheet ref="actionSheetRef" :actions="TimeSelectAction" @select="select" />
  32. </template>
  33. <script lang="ts" setup>
  34. import { onMounted, ref, unref, watch } from "vue";
  35. import { getTimeVal } from "@/util/tools.ts";
  36. import { getStatisticsApi } from "@/api/ShopContent.ts";
  37. const $Props = defineProps({
  38. valueLabel: {
  39. type: Array,
  40. default: []
  41. },
  42. businessId: {
  43. type: Number,
  44. default: null
  45. }
  46. });
  47. const TimeSelectAction = [
  48. {
  49. name: '今日',
  50. value: 0
  51. },
  52. {
  53. name: '自定义',
  54. value: 1
  55. }
  56. ];
  57. const ActiveTimeAction = ref(TimeSelectAction[0].value);
  58. const startTime = ref(getTimeVal({ format: 'YYYYMMDD' })); // 开始时间
  59. const endTime = ref(getTimeVal({ format: 'YYYYMMDD' })); // 结束时间
  60. const actionSheetRef = ref();
  61. const selectType = () => {
  62. actionSheetRef.value.open();
  63. };
  64. const select = (e) => {
  65. if (e.value === ActiveTimeAction.value) return
  66. ActiveTimeAction.value = e.value;
  67. if (e.value === TimeSelectAction[0].value) {
  68. startTime.value = getTimeVal({ format: 'YYYYMMDD' });
  69. endTime.value = getTimeVal({ format: 'YYYYMMDD' });
  70. getStatistics();
  71. };
  72. };
  73. const CalendarRef = ref();
  74. const handleCalendar = () => {
  75. CalendarRef.value?.open()
  76. };
  77. const ConfirmCalendar = (e) => {
  78. const { data } = e.range;
  79. if (data && data.length >= 2) {
  80. startTime.value = data[0] || getTimeVal({ format: 'YYYYMMDD' });
  81. endTime.value = data[data.length - 1] || getTimeVal({ format: 'YYYYMMDD' });
  82. getStatistics();
  83. }
  84. };
  85. const StatisticsVo = ref({})
  86. const getStatistics = async () => {
  87. try {
  88. const Parmas = {
  89. businessId: unref($Props.businessId),
  90. startTime: unref(startTime),
  91. endTime: unref(endTime),
  92. type: ActiveTimeAction.value == 0 ? "today" : "all"
  93. };
  94. const { data } = await getStatisticsApi(Parmas);
  95. StatisticsVo.value = data || {}
  96. } catch (error) {
  97. console.log('row error== ', error)
  98. }
  99. };
  100. watch(() => $Props.businessId, () => {
  101. getStatistics();
  102. });
  103. onMounted(() => {
  104. getStatistics();
  105. })
  106. </script>
  107. <style lang="scss" scoped>
  108. @import url("./index.scss");
  109. .business-data {
  110. .search-time {
  111. width: 100%;
  112. height: 70rpx;
  113. display: flex;
  114. align-items: center;
  115. .time-select {
  116. width: 33%;
  117. flex-shrink: 0;
  118. height: 70rpx;
  119. background: #ffffff;
  120. border: 1rpx solid #d9d9d9;
  121. border-radius: 10rpx;
  122. display: flex;
  123. align-items: center;
  124. padding: 0 20rpx;
  125. box-sizing: border-box;
  126. .select-value {
  127. flex: 1 0;
  128. font-size: 28rpx;
  129. font-family: PingFang SC, PingFang SC-Regular;
  130. font-weight: 400;
  131. color: #666666;
  132. }
  133. .select-icon {
  134. flex-shrink: 0;
  135. font-size: 28rpx;
  136. font-family: PingFang SC, PingFang SC-Regular;
  137. font-weight: 400;
  138. color: #666666;
  139. transform: rotate(90deg);
  140. padding-left: 5rpx;
  141. }
  142. }
  143. .time-picke {
  144. padding-left: 50rpx;
  145. flex: 1 0;
  146. display: flex;
  147. align-items: center;
  148. .picke-icon {
  149. color: #FFAD00;
  150. font-size: 40rpx;
  151. padding-right: 5rpx;
  152. }
  153. .picke-text {
  154. font-size: 28rpx;
  155. font-family: PingFang SC, PingFang SC-Regular;
  156. font-weight: 400;
  157. color: #1a1a1a;
  158. }
  159. }
  160. }
  161. .num-statistics {
  162. display: flex;
  163. align-items: center;
  164. flex-wrap: wrap;
  165. .num-item {
  166. width: calc(100% / 3);
  167. flex-shrink: 0;
  168. margin-top: 30rpx;
  169. padding: 0 10rpx;
  170. box-sizing: border-box;
  171. display: flex;
  172. flex-direction: column;
  173. justify-content: center;
  174. align-items: center;
  175. position: relative;
  176. &:before {
  177. content: '';
  178. position: absolute;
  179. right: 0;
  180. top: 50%;
  181. width: 1rpx;
  182. height: 60%;
  183. transform: translateY(-50%);
  184. background-color: #e6e6e6;
  185. }
  186. .num-item-num {
  187. width: 100%;
  188. display: flex;
  189. align-items: center;
  190. justify-content: center;
  191. .num-item-tag {
  192. font-size: 26rpx;
  193. font-weight: normal;
  194. color: #eb5153;
  195. }
  196. .num-item-val {
  197. font-size: 38rpx;
  198. font-weight: normal;
  199. color: #eb5153;
  200. }
  201. }
  202. .num-item-name {
  203. width: 100%;
  204. padding-top: 12rpx;
  205. font-size: 28rpx;
  206. font-family: PingFang SC, PingFang SC-Regular;
  207. font-weight: 400;
  208. text-align: center;
  209. color: #1a1a1a;
  210. line-height: 40rpx;
  211. box-sizing: border-box;
  212. }
  213. }
  214. }
  215. }
  216. </style>