sales.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <view class="container">
  3. <!-- 搜索区域 -->
  4. <view class="search">
  5. <view class="picker_key">规格属性名</view>
  6. <view class="picker">
  7. <input type="text" placeholder="请输入规格属性名" v-model="skuName" />
  8. </view>
  9. <view class="searchBtn" @click="handleSearch">查询</view>
  10. </view>
  11. <!-- 时间筛选区域 -->
  12. <view class="search_time">
  13. <picker @change="bindPickerChangeTime" :value="currentIndexTime" :range="arrayTime">
  14. <view class="picker">
  15. <view class="picker_text">
  16. {{ currentIndexTime != null ? arrayTime[currentIndexTime] : '请选择时间区间' }}
  17. </view>
  18. <u-icon name="arrow-down" color="#111111" size="28"></u-icon>
  19. </view>
  20. </picker>
  21. <view class="datetime" @click="open" v-if="currentIndexTime != 3">
  22. <uv-datetime-picker :value="Date.now() - 1000 * 60 * 60 * 24" ref="datetimePicker" :mode="mode" @confirm="confirm"></uv-datetime-picker>
  23. {{ timeValue ? timeValue : '请选择时间' }}
  24. <u-icon name="calendar" color="#111111" size="28"></u-icon>
  25. </view>
  26. <view v-else>
  27. <uni-datetime-picker type="daterange" @change="confirm">
  28. <view class="datetimeRange">
  29. {{ timeValue ? timeValue : '请选择时间' }}
  30. <u-icon name="calendar" color="#111111" size="28"></u-icon>
  31. </view>
  32. </uni-datetime-picker>
  33. </view>
  34. </view>
  35. <!-- 数据展示区域 -->
  36. <view class="body">
  37. <view class="body_header">
  38. <view class="">编号</view>
  39. <view class="">规格属姓名</view>
  40. <view class="">销量</view>
  41. </view>
  42. <view class="body_box" v-for="(item, index) in dataList" :key="index">
  43. <view class="">{{ index + 1 }}</view>
  44. <view class="">{{ item.shopName }}</view>
  45. <view class="">{{ item.value }}</view>
  46. </view>
  47. <view class="body_no" v-if="!dataList.length">暂无数据</view>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import dayjs from 'dayjs'
  53. import { join } from 'path'
  54. export default {
  55. data() {
  56. return {
  57. currentIndexTime: 0,
  58. arrayTime: ['按天查询', '按月查询', '按年查询', '按时间段查询'],
  59. timeValue: '',
  60. startTime: '',
  61. endTime: '',
  62. mode: 'date',
  63. skuName: '',
  64. dataList: []
  65. }
  66. },
  67. onLoad() {
  68. this.timeValue = dayjs(Date.now() - 1000 * 60 * 60 * 24).format('YYYY-MM-DD')
  69. this.startTime = this.timeValue + ' 00:00:00'
  70. this.endTime = this.timeValue + ' 23:59:59'
  71. this.getData()
  72. },
  73. methods: {
  74. async getData() {
  75. let data = {
  76. startTime: this.startTime,
  77. endTime: this.endTime,
  78. shopld: uni.getStorageSync('shopId'),
  79. skuName: this.skuName
  80. }
  81. // console.log(data)
  82. let res = await this.$Request.getA('/app/order/goods-sku-sales-count', data)
  83. // console.log(res)
  84. if (res.code == 0) {
  85. this.dataList = res.data.list
  86. // console.log(this.dataList)
  87. }
  88. },
  89. handleSearch() {
  90. this.getData()
  91. },
  92. // 时间区域切换回调
  93. bindPickerChangeTime(e) {
  94. this.timeValue = ''
  95. this.currentIndexTime = e.detail.value
  96. if (this.currentIndexTime == 0) {
  97. this.mode = 'date'
  98. } else if (this.currentIndexTime == 1) {
  99. this.mode = 'year-month'
  100. } else if (this.currentIndexTime == 2) {
  101. this.mode = 'year'
  102. }
  103. },
  104. // 选择时间确定回调
  105. confirm(e) {
  106. // console.log(e.value)
  107. if (this.currentIndexTime == 0) {
  108. this.timeValue = dayjs(e.value).format('YYYY-MM-DD')
  109. this.startTime = this.timeValue + ' 00:00:00'
  110. this.endTime = this.timeValue + ' 23:59:59'
  111. } else if (this.currentIndexTime == 1) {
  112. this.timeValue = dayjs(e.value).format('YYYY-MM')
  113. let year = dayjs(e.value).get('year')
  114. let month = dayjs(e.value).get('month')
  115. let firstDay = new Date(year, month, 1)
  116. let lastDay = new Date(year, month + 1, 0, 23, 59, 59)
  117. this.startTime = dayjs(firstDay).format('YYYY-MM-DD HH:mm:ss')
  118. this.endTime = dayjs(lastDay).format('YYYY-MM-DD HH:mm:ss')
  119. // console.log(this.startTime)
  120. // console.log(this.endTime)
  121. } else if (this.currentIndexTime == 2) {
  122. this.timeValue = dayjs(e.value).format('YYYY')
  123. this.startTime = this.timeValue + '-01-01 00:00:00'
  124. this.endTime = this.timeValue + '-12-31 23:59:59'
  125. } else if (this.currentIndexTime == 3) {
  126. this.timeValue = e.join(' - ')
  127. this.startTime = e[0] + ' 00:00:00'
  128. this.endTime = e[1] + ' 23:59:59'
  129. }
  130. },
  131. open() {
  132. this.$refs.datetimePicker.open()
  133. }
  134. }
  135. }
  136. </script>
  137. <style>
  138. .container {
  139. padding: 20rpx 15rpx;
  140. min-height: 100vh;
  141. background-color: #fff;
  142. }
  143. .search {
  144. display: flex;
  145. align-items: center;
  146. height: 60rpx;
  147. font-size: 28rpx;
  148. color: #666666;
  149. }
  150. .picker {
  151. display: flex;
  152. align-items: center;
  153. justify-content: space-between;
  154. box-sizing: border-box;
  155. padding: 0 10rpx;
  156. margin-left: 10rpx;
  157. width: 220rpx;
  158. height: 60rpx;
  159. border: 2rpx solid #808080;
  160. border-radius: 6rpx;
  161. }
  162. .picker_text {
  163. width: 160rpx;
  164. white-space: nowrap;
  165. text-overflow: ellipsis;
  166. overflow: hidden;
  167. }
  168. .picker_key {
  169. margin: 0 10rpx 0 22rpx;
  170. }
  171. .searchBtn {
  172. display: flex;
  173. align-items: center;
  174. justify-content: center;
  175. margin-left: 50rpx;
  176. width: 150rpx;
  177. height: 60rpx;
  178. color: #fff;
  179. border-radius: 15rpx;
  180. background-color: #f18731;
  181. }
  182. .search_time {
  183. display: flex;
  184. align-items: center;
  185. margin-top: 30rpx;
  186. height: 60rpx;
  187. font-size: 28rpx;
  188. color: #666666;
  189. }
  190. .datetime {
  191. display: flex;
  192. align-items: center;
  193. justify-content: space-between;
  194. box-sizing: border-box;
  195. padding: 0 10rpx;
  196. margin-left: 25rpx;
  197. width: 355rpx;
  198. height: 60rpx;
  199. border: 2rpx solid #808080;
  200. border-radius: 6rpx;
  201. }
  202. .datetimeRange {
  203. display: flex;
  204. align-items: center;
  205. justify-content: space-between;
  206. box-sizing: border-box;
  207. padding: 0 10rpx;
  208. margin-left: 25rpx;
  209. width: 455rpx;
  210. height: 60rpx;
  211. border: 2rpx solid #808080;
  212. border-radius: 6rpx;
  213. }
  214. .body {
  215. margin-top: 30rpx;
  216. font-size: 28rpx;
  217. color: #000;
  218. }
  219. .body_header {
  220. display: flex;
  221. align-items: center;
  222. justify-content: space-between;
  223. box-sizing: border-box;
  224. padding: 0 20rpx;
  225. width: 706rpx;
  226. height: 82rpx;
  227. border-radius: 4rpx;
  228. background-color: #faf2eb;
  229. }
  230. .body_box {
  231. display: flex;
  232. align-items: center;
  233. justify-content: space-between;
  234. box-sizing: border-box;
  235. padding: 0 20rpx;
  236. width: 706rpx;
  237. height: 82rpx;
  238. border-bottom: 2rpx solid #e6e6e6;
  239. }
  240. .body_no {
  241. height: 82rpx;
  242. line-height: 82rpx;
  243. text-align: center;
  244. }
  245. </style>