StatisticsMobile.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <div class="statistics">
  3. <ul class="list-inline pull-left" ref="pingdanListWrapperL" :style="'top: -' + 0.7 * timerIndexL + 'rem'" :class="{'topL': isTopL}">
  4. <li v-for="(item, index) in itemLeft">
  5. <span class="number">
  6. <span class="name" v-html="nameLeft[index]"></span>
  7. <span class="num" v-html="formatNumber(item.count, item.type)"></span>
  8. <span class="unit" v-if="item.type === 3">家</span>
  9. </span>
  10. </li>
  11. </ul>
  12. <ul class="list-inline pull-right" ref="pingdanListWrapperR" :style="'top: -' + 0.7 * timerIndexR + 'rem'" :class="{'topR': isTopR}">
  13. <li v-for="(item, index) in itemRight">
  14. <span class="number" v-if="item.type === 2">
  15. <span class="name" v-html="nameRight[index]"></span>
  16. <span class="month" v-if="item.id === '上月询价单'">(上月)</span>
  17. <span class="month" v-if="item.id === '本月询价单'">(本月)</span>
  18. <span class="num" v-html="formatDouble(item.count)"></span>
  19. <span class="unit">条</span>
  20. </span>
  21. <span class="number" v-else>
  22. <span class="name" v-html="nameRight[index]"></span>
  23. <span class="num" v-html="formatNumber(item.count, item.type)"></span>
  24. </span>
  25. </li>
  26. </ul>
  27. </div>
  28. </template>
  29. <script>
  30. import {whichTransitionEvent} from '~utils/baseUtils.js'
  31. export default {
  32. name: 'StatisticsView',
  33. data () {
  34. return {
  35. step: 1,
  36. nameLeft: ['现货', '品牌', '规格书', '供应商', '店铺'],
  37. nameRight: ['询价求购', '询价求购', '上年交易', '本年交易'],
  38. topLeft: 0,
  39. topRight: 0,
  40. // timer: {},
  41. // timerIndex: 0,
  42. timerIndexL: 0,
  43. timerIndexR: 0,
  44. isTopL: false,
  45. isTopR: false,
  46. timerL: {},
  47. timerR: {}, // 定时器实体
  48. imgbox: {
  49. 'src': ''
  50. }
  51. }
  52. },
  53. mounted () {
  54. this.$nextTick(() => {
  55. this.changeIntervalL(true)
  56. this.changeIntervalR(true)
  57. })
  58. },
  59. methods: {
  60. changeIntervalL: function (flag) {
  61. if (flag) {
  62. this.timerL = setInterval(() => {
  63. this.isTopL = false
  64. let isChange = true
  65. this.timerIndexL++
  66. if (this.$refs.pingdanListWrapperL) {
  67. let _transitionEvent = whichTransitionEvent()
  68. _transitionEvent && this.$refs.pingdanListWrapperL.addEventListener(
  69. _transitionEvent, () => {
  70. if (isChange) {
  71. let title = this.itemLeft.shift()
  72. let name = this.nameLeft.shift()
  73. this.itemLeft.push(title)
  74. this.nameLeft.push(name)
  75. this.timerIndexL = 0
  76. isChange = false
  77. this.isTopL = true
  78. }
  79. })
  80. }
  81. }, 2400)
  82. } else {
  83. clearInterval(this.timerL)
  84. }
  85. },
  86. changeIntervalR: function (flag) {
  87. if (flag) {
  88. this.timerR = setInterval(() => {
  89. this.isTopR = false
  90. let isChange = true
  91. this.timerIndexR++
  92. if (this.$refs.pingdanListWrapperR) {
  93. let _transitionEvent = whichTransitionEvent()
  94. _transitionEvent && this.$refs.pingdanListWrapperR.addEventListener(
  95. _transitionEvent, () => {
  96. if (isChange) {
  97. let title = this.itemRight.shift()
  98. let name = this.nameRight.shift()
  99. this.itemRight.push(title)
  100. this.nameRight.push(name)
  101. this.timerIndexR = 0
  102. isChange = false
  103. this.isTopR = true
  104. }
  105. })
  106. }
  107. }, 3000)
  108. } else {
  109. clearInterval(this.timerR)
  110. }
  111. },
  112. formatNumber (num, type) {
  113. if (num === '' || !num) return false
  114. if (num.toString().indexOf('E') !== -1) {
  115. let arr = num.toString().split('E')
  116. num = arr[0] * Math.pow(10, arr[1])
  117. }
  118. if (num > 99999999) {
  119. let str2 = num.toString()
  120. num = Math.floor(num / 100000000)
  121. if (parseInt(str2.charAt(str2.length - 8)) > 8) {
  122. num = num + 1
  123. }
  124. num = num + '亿'
  125. } else if (num > 9999) {
  126. let str = num.toString()
  127. num = Math.floor(num / 10000)
  128. if (parseInt(str.charAt(str.length - 4)) > 4) {
  129. num = num + 1
  130. }
  131. num += '万'
  132. } else {
  133. if (type === 4) {
  134. num += '元'
  135. } else if (type === 1) {
  136. num += '个'
  137. } else {
  138. num += ''
  139. }
  140. }
  141. return num
  142. },
  143. formatDouble (num) {
  144. if (num === '' || !num) return false
  145. if (num.toString().indexOf('E') !== -1) {
  146. let arr = num.toString().split('E')
  147. num = arr[0] * Math.pow(10, arr[1])
  148. }
  149. if (num > 99999999) {
  150. num = (num / 100000000).toFixed(2).slice(num.length - 1, 4) + '亿'
  151. } else if (num > 9999) {
  152. num = (num / 10000).toFixed(2).slice(num.length - 1, 4) + '万'
  153. } else {
  154. num += ''
  155. }
  156. return num
  157. }
  158. },
  159. computed: {
  160. allCount () {
  161. return this.$store.state.count.allCount.data
  162. },
  163. inquirySheet () {
  164. let sheetNum = this.$store.state.count.inquirySheet.data.count
  165. return this.formatDouble(sheetNum)
  166. },
  167. inquirySheetLast () {
  168. let lastSheetNum = this.$store.state.count.inquirySheetLast.data.count
  169. return this.formatDouble(lastSheetNum)
  170. },
  171. all () {
  172. let count = this.$store.state.supplier.merchant.merchantAll.data
  173. return count.content ? count.totalElements : '0'
  174. },
  175. counts () {
  176. return this.$store.state.product.common.counts
  177. },
  178. list () {
  179. let list = JSON.parse(JSON.stringify(this.$store.state.provider.stores.storeList.data))
  180. // console.log(list)
  181. return list.totalElements
  182. },
  183. itemData () {
  184. let str = []
  185. if (this.counts.data) {
  186. this.counts.data.forEach((value, key, $data) => {
  187. str.push({id: $data[key].item, count: $data[key].count, type: 1})
  188. })
  189. }
  190. str.push({id: '供应商', count: this.all ? this.all : 0, type: 3})
  191. str.push({id: '本月询价单', count: this.$store.state.count.inquirySheet.data ? this.$store.state.count.inquirySheet.data.count : 0, type: 2})
  192. str.push({id: '上月询价单', count: this.$store.state.count.inquirySheetLast.data ? this.$store.state.count.inquirySheetLast.data.count : 0, type: 2})
  193. if (this.allCount) {
  194. this.allCount.forEach((value, key, $data) => {
  195. str.push({id: $data[key].item, count: $data[key].count, type: 4})
  196. })
  197. }
  198. str.push({id: '店铺', count: this.list ? this.list : 0, type: 3})
  199. str = [str[1], str[0], str[2], str[3], str[8], str[5], str[4], str[6], str[7]]
  200. return str
  201. },
  202. itemLeft () {
  203. return this.itemData.slice(0, 5)
  204. },
  205. itemRight () {
  206. return this.itemData.slice(5, 9)
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss" scoped>
  212. .statistics{
  213. position:relative;
  214. height: 0.7rem;
  215. border-radius:.48rem;
  216. background: #fff;
  217. margin:0 .05rem .2rem;
  218. overflow: hidden;
  219. background: url('/images/mobile/@2x/home/countnewbg1.png') no-repeat center;
  220. background-size: auto 0.69rem;
  221. ul{
  222. width:50%;
  223. position:relative;
  224. transition: .5s all linear;
  225. &.topL {
  226. transition: top 0s;
  227. -moz-transition: top 0s; /* Firefox 4 */
  228. -webkit-transition: top 0s; /* Safari and Chrome */
  229. -o-transition: top 0s; /* Opera */
  230. }
  231. &.topR {
  232. transition: top 0s;
  233. -moz-transition: top 0s; /* Firefox 4 */
  234. -webkit-transition: top 0s; /* Safari and Chrome */
  235. -o-transition: top 0s; /* Opera */
  236. }
  237. &:first-child{
  238. margin-left: .0rem;
  239. }
  240. &:no_tran{
  241. transition:none;
  242. }
  243. li{
  244. width:100%;
  245. text-align: center;
  246. height:0.7rem;
  247. line-height: 0.7rem;
  248. font-size: .28rem;
  249. font-weight: bold;
  250. white-space: nowrap;
  251. overflow: hidden;
  252. vertical-align:top;
  253. span{
  254. &.number{
  255. display: inline-block;
  256. color:red;
  257. font-size: 0.32rem;
  258. height: .7rem;
  259. line-height:.7rem;
  260. font-weight: bold;
  261. .name, .month{
  262. color: #fff;
  263. }
  264. .month{
  265. font-size: 0.22rem;
  266. }
  267. .unit, .num{
  268. color: #feff00;
  269. }
  270. .num{
  271. padding-left: .1rem;
  272. }
  273. }
  274. }
  275. }
  276. }
  277. }
  278. </style>