index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <!-- 使用 type="home" 属性设置首页,其他页面不需要设置,默认为page;推荐使用json5,更强大,且允许注释 -->
  2. <route lang="json5" type="home">
  3. {
  4. style: {
  5. navigationStyle: 'custom',
  6. navigationBarTitleText: '首页',
  7. },
  8. }
  9. </route>
  10. <template>
  11. <view
  12. class="bg-white overflow-hidden pt-2 px-4"
  13. :style="{ marginTop: safeAreaInsets?.top + 'px' }"
  14. >
  15. <!-- 顶部标题 -->
  16. <view class="text-xl font-bold text-center py-3 bg-white">达州农机优惠券</view>
  17. <wd-swiper
  18. :list="swiperList"
  19. autoplay
  20. v-model:current="current"
  21. :indicator="{ type: 'dots-bar' } as any"
  22. @click="handleSwiperClick"
  23. @change="handleSwiperChange"
  24. v-if="!statisticsDataShow"
  25. ></wd-swiper>
  26. <!-- 数据统计卡片 -->
  27. <view class="grid grid-cols-2 gap-3 mb-4" v-else>
  28. <!-- 总销售额 -->
  29. <statistics-card
  30. title="总销售额"
  31. :value="statisticsData[0]"
  32. suffix="万元"
  33. color="blue"
  34. :duration="2000"
  35. />
  36. <!-- 总订单数 -->
  37. <statistics-card
  38. title="总订单数"
  39. :value="statisticsData[1]"
  40. suffix="单"
  41. color="amber"
  42. :duration="4000"
  43. />
  44. <!-- 本季度销售额 -->
  45. <statistics-card
  46. title="本季度销售额"
  47. :value="statisticsData[2]"
  48. suffix="万元"
  49. color="emerald"
  50. :duration="4000"
  51. />
  52. <!-- 本季度订单数 -->
  53. <statistics-card
  54. title="本季度订单数"
  55. :value="statisticsData[3]"
  56. suffix="单"
  57. color="indigo"
  58. :duration="4000"
  59. />
  60. <!-- 本月销售额 -->
  61. <statistics-card
  62. title="本月销售额"
  63. :value="statisticsData[4]"
  64. suffix="万元"
  65. color="purple"
  66. :duration="4000"
  67. />
  68. <!-- 本月订单数 -->
  69. <statistics-card
  70. title="本月订单数"
  71. :value="statisticsData[5]"
  72. suffix="单"
  73. color="rose"
  74. :duration="2000"
  75. />
  76. </view>
  77. <view class="pb-4">
  78. <!-- 网点地址标题 -->
  79. <view class="text-lg font-bold py-4 border-b border-gray-100">农机销售网点</view>
  80. <wd-status-tip image="comment" tip="暂无数据" v-if="locationList.length === 0" />
  81. <!-- 网点列表 -->
  82. <view class="divide-y divide-gray-100" v-else>
  83. <view
  84. v-for="(item, index) in locationList"
  85. :key="index"
  86. class="py-3 flex items-center justify-between"
  87. >
  88. <view class="flex items-start gap-2">
  89. <wd-icon name="location" class="text-green-500 mt-1" />
  90. <view>
  91. <view class="font-medium">{{ item.name }}</view>
  92. <view class="text-sm text-gray-500">{{ item.address }}</view>
  93. </view>
  94. </view>
  95. <view class="flex gap-2">
  96. <view class="p-1 mr-1">
  97. <wd-icon
  98. name="call"
  99. class="bg-green-500 text-white rounded-md"
  100. @tap="handleCall(item.phone)"
  101. />
  102. </view>
  103. <view class="p-1">
  104. <wd-icon
  105. name="cart"
  106. class="bg-green-500 text-white rounded-md"
  107. @tap="handleGoods(item)"
  108. />
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. <!-- 申请记录 -->
  114. <view class="mt-4">
  115. <view class="flex items-center justify-between border-b border-gray-100 py-4">
  116. <text class="text-lg font-bold">最近申请</text>
  117. <view class="ml-auto">
  118. <wd-button type="success" size="small" round @tap="handleApply">我要申请</wd-button>
  119. </view>
  120. </view>
  121. <view class="bg-white border border-gray-200 rounded-lg p-2">
  122. <view
  123. v-for="(record, index) in applyRecords"
  124. :key="index"
  125. class="flex items-center gap-2 py-1"
  126. >
  127. <text class="text-sm">{{ desensitizeName(record.name) }}</text>
  128. <text class="text-xs text-green-500">申请</text>
  129. <text class="text-xs text-gray-400 ml-auto">
  130. {{ formatTimeText(record.time) }}已申请优惠劵
  131. </text>
  132. </view>
  133. </view>
  134. </view>
  135. </view>
  136. </view>
  137. </template>
  138. <script lang="ts" setup>
  139. import banner1 from '@/static/banner1.png'
  140. import { ref } from 'vue'
  141. import { useUserStore } from '@/store/user'
  142. import { useDictStore } from '@/store/dict'
  143. import StatisticsCard from '@/components/StatisticsCard.vue'
  144. const userStore = useUserStore()
  145. const dictStore = useDictStore()
  146. const statisticsDataShow = ref(false)
  147. const current = ref<number>(0)
  148. const swiperList = ref([banner1, banner1, banner1])
  149. const statisticsData = ref([0, 0, 0, 0, 0, 0])
  150. // 获取安全区域距离
  151. const { safeAreaInsets } = uni.getWindowInfo()
  152. // 轮播图事件处理
  153. function handleSwiperClick(e: any) {
  154. // console.log('轮播图点击', e)
  155. }
  156. function handleSwiperChange(e: any) {
  157. // console.log('轮播图切换', e)
  158. }
  159. // 网点数据
  160. const locationList = ref([])
  161. // 获取销售点列表(users表,usersnature=渠道)
  162. const getUserList = async () => {
  163. const userList = await userStore.getSellUserList()
  164. locationList.value = userList.map((item: any) => ({
  165. name: item.usersname,
  166. address: item.usersaddress,
  167. phone: item.usersphone,
  168. usersid: item.usersid,
  169. }))
  170. }
  171. // 格式化时间文本
  172. function formatTimeText(time: Date) {
  173. const diffMinutes = Math.floor((Date.now() - time.getTime()) / (1000 * 60))
  174. if (diffMinutes < 60) {
  175. return `${diffMinutes}分钟前`
  176. } else {
  177. const hours = Math.floor(diffMinutes / 60)
  178. return `${hours}小时前`
  179. }
  180. }
  181. // 申请记录
  182. const applyRecords = ref([
  183. { name: '王思聪', time: new Date(Date.now() - 5 * 60 * 1000) },
  184. { name: '李美丽', time: new Date(Date.now() - 15 * 60 * 1000) },
  185. { name: '张三', time: new Date(Date.now() - 30 * 60 * 1000) },
  186. { name: '王五', time: new Date(Date.now() - 60 * 60 * 1000) },
  187. { name: '赵六', time: new Date(Date.now() - 2 * 60 * 60 * 1000) },
  188. ])
  189. // 脱敏name字段 如果姓名2个字,最后一个字替换为*;如果大于3个字,保留第一个和最后一个字,中间全部替换为*;
  190. function desensitizeName(name: string) {
  191. if (name.length === 2) {
  192. return name.substring(0, 1) + '*'
  193. } else if (name.length >= 3) {
  194. const stars = '*'.repeat(name.length - 2)
  195. return name.charAt(0) + stars + name.charAt(name.length - 1)
  196. }
  197. return name
  198. }
  199. // 处理拨打电话
  200. function handleCall(phone: string) {
  201. uni.makePhoneCall({
  202. phoneNumber: phone,
  203. })
  204. }
  205. // 销售网点跳转
  206. function handleGoods(location: any) {
  207. console.log(location)
  208. uni.navigateTo({
  209. url: `/pages/form/formStep2?usersid=${location.usersid}`,
  210. })
  211. }
  212. // 处理申请
  213. function handleApply() {
  214. uni.navigateTo({
  215. url: '/pages/form/formStep1',
  216. })
  217. }
  218. // 获取统计数据
  219. const getStatisticsData = async () => {
  220. const configList = await dictStore.getConfigList('mini_program_index_sumary')
  221. if (configList.length > 0) {
  222. // 获取统计数据是否显示配置
  223. const statisticsDataShowConfig = configList.find(
  224. (item) => item.groupname === 'mini_program_index_sumary_show',
  225. )
  226. statisticsDataShow.value = statisticsDataShowConfig?.substance === '1'
  227. // 统计数据项
  228. const statisticsDataConfig = configList.find(
  229. (item) => item.groupname === 'mini_program_index_sumary_data',
  230. )
  231. statisticsData.value = statisticsDataConfig?.substance.split(',').map((item) => Number(item))
  232. }
  233. }
  234. // // 获取统计数据是否显示配置
  235. // const getStatisticsDataShow = async () => {
  236. // const configList = await dictStore.getConfigList('mini_program_index_sumary_show')
  237. // if (configList.length > 0) {
  238. // // 将字符串分割后转换为数字类型
  239. // statisticsDataShow.value = configList[0].substance === '1'
  240. // }
  241. // }
  242. onShow(() => {
  243. getUserList()
  244. getStatisticsData()
  245. // getStatisticsDataShow()
  246. })
  247. </script>
  248. <style>
  249. .main-title-color {
  250. color: #d14328;
  251. }
  252. </style>
  253. <style lang="scss">
  254. .wd-icon {
  255. font-size: 20px;
  256. }
  257. </style>