displayCard.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. <template>
  2. <div class="display-card" v-if="cardShow">
  3. <span @click="cardClose" v-if="cardShow" class="cardClose"><img src="/images/all/close.png"></span>
  4. <div class="content" v-if="cardShow">
  5. <div>
  6. <ul class="list-unstyled">
  7. <li ref="pingdanListWrapper" v-for="item in title" :style="'top: -' + 30 * timerIndex + 'px'" :class="{'top': isTop}">
  8. <span>{{item}}</span>
  9. </li>
  10. </ul>
  11. <ul class="list-unstyled">
  12. <li ref="pingdanListWrapper" v-for="c in counts" v-if="c" :style="'top: -' + 30 * timerIndex + 'px'" :class="{'top': isTop}">
  13. <span v-for="(item, index) in formatScrollNumber(c.count, c.logo, c)" class="count-distance" :class="'count' + index">{{item}}</span>
  14. </li>
  15. </ul>
  16. </div>
  17. <div v-for="item in itemCounts">
  18. <p>
  19. <span v-html="item.count"></span>
  20. <span style="color: #333" v-if="item.type === 3">家</span>
  21. <span style="color: #333" v-if="item.type === 2">条</span>
  22. </p>
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. export default {
  29. name: 'display-card',
  30. data () {
  31. return {
  32. cardShow: true,
  33. timerIndex: 0,
  34. isTop: false, // 判断是否滚动至顶,
  35. timer: {}, // 定时器实体
  36. title: ['品 牌', '现 货', '规格书', '店 铺']
  37. }
  38. },
  39. mounted () {
  40. this.$nextTick(() => {
  41. this.changeInterval(true)
  42. })
  43. },
  44. methods: {
  45. changeInterval: function (flag) {
  46. if (flag) {
  47. this.timer = setInterval(() => {
  48. this.isTop = false
  49. let isChange = true
  50. this.timerIndex++
  51. if (this.$refs.pingdanListWrapper[0]) {
  52. let _transitionEvent = this.baseUtils.whichTransitionEvent()
  53. _transitionEvent && this.$refs.pingdanListWrapper[0].addEventListener(
  54. _transitionEvent, () => {
  55. if (isChange) {
  56. let title = this.title.shift()
  57. let count = this.counts.shift()
  58. this.title.push(title)
  59. this.counts.push(count)
  60. this.timerIndex = 0
  61. isChange = false
  62. this.isTop = true
  63. }
  64. })
  65. }
  66. }, 3000)
  67. } else {
  68. clearInterval(this.timer)
  69. }
  70. },
  71. cardClose () {
  72. this.cardShow = false
  73. },
  74. formatScrollNumber (num, logo, name) {
  75. if (num) {
  76. // console.log(num, logo, name)
  77. if (num > 99999999) {
  78. let str2 = num.toString()
  79. num = Math.floor(num / 100000000)
  80. if (parseInt(str2.charAt(str2.length - 8)) > 8) {
  81. num = num + 1
  82. }
  83. let length = String(num).length
  84. this.len = length > 3 ? length + 1 : length
  85. num = (Array(7 - length).join(0) + num)
  86. num = num.toString() + '亿'
  87. } else if (num > 9999) {
  88. let str = num.toString()
  89. num = Math.floor(num / 10000)
  90. if (parseInt(str.charAt(str.length - 4)) > 4) {
  91. num = num + 1
  92. }
  93. let length = String(num).length
  94. this.len = length > 3 ? length + 1 : length
  95. num = (Array(7 - length).join(0) + num)
  96. num = num.toString() + '万'
  97. } else {
  98. let length = String(num).length
  99. this.len = length > 3 ? length + 1 : length
  100. num = (Array(7 - length).join(0) + num)
  101. if (logo === 0) {
  102. num = num.toString() + '家'
  103. } else {
  104. num = num.toString() + '个'
  105. }
  106. }
  107. }
  108. let _arr = []
  109. for (let i = 0; i < num.length; i++) {
  110. _arr.push(num[i])
  111. }
  112. return _arr
  113. },
  114. formatNumber (num, type) {
  115. if (num) {
  116. if (num.toString().indexOf('E') !== -1) {
  117. let arr = num.toString().split('E')
  118. num = arr[0] * Math.pow(10, arr[1])
  119. }
  120. if (num > 99999999) {
  121. let str2 = num.toString()
  122. num = Math.floor(num / 100000000)
  123. if (parseInt(str2.charAt(str2.length - 8)) > 8) {
  124. num = num + 1
  125. }
  126. num += '<span style="color: #333">亿</span>'
  127. } else if (num > 9999) {
  128. let str = num.toString()
  129. num = Math.floor(num / 10000)
  130. if (parseInt(str.charAt(str.length - 4)) > 4) {
  131. num = num + 1
  132. }
  133. num += '<span style="color: #333">万</span>'
  134. } else {
  135. if (type === 1) {
  136. num += '<span style="color: #333">元</span>'
  137. } else {
  138. num += ''
  139. }
  140. }
  141. }
  142. return num || 0
  143. },
  144. formatDouble (num) {
  145. if (num) {
  146. if (num.toString().indexOf('E') !== -1) {
  147. let arr = num.toString().split('E')
  148. num = arr[0] * Math.pow(10, arr[1])
  149. }
  150. if (num > 99999999) {
  151. num = (num / 100000000).toFixed(2).slice(num.length - 1, 4) + '<span style="color: #333">亿</span>'
  152. } else if (num > 9999) {
  153. num = (num / 10000).toFixed(2).slice(num.length - 1, 4) + '<span style="color: #333">万</span>'
  154. } else {
  155. num += ''
  156. }
  157. }
  158. return num || 0
  159. }
  160. },
  161. computed: {
  162. counter () {
  163. return this.$store.state.option.counter.data
  164. },
  165. inquirySheet () {
  166. let sheetNum = this.$store.state.count.inquirySheet.data
  167. return sheetNum ? this.formatDouble(sheetNum.count) : 0
  168. },
  169. inquirySheetLast () {
  170. let lastSheetNum = this.$store.state.count.inquirySheetLast.data
  171. return lastSheetNum ? this.formatDouble(lastSheetNum.count) : 0
  172. },
  173. itemCounts () {
  174. let arr = []
  175. let count = this.baseUtils.deepCopy(this.counter)
  176. if(count.length){
  177. count.forEach((value) => {
  178. if (value.item === '供应商') {
  179. arr[0] = {id: value.item, count: this.formatNumber(value.count), type: 3}
  180. } else if (value.item === '本年交易金额') {
  181. arr[1] = {id: value.item, count: this.formatNumber(value.count), type: 1}
  182. } else if (value.item === '上年交易金额') {
  183. arr[2] = {id: value.item, count: this.formatNumber(value.count), type: 1}
  184. }
  185. })
  186. arr[3] = {id: '本月求购数', count: this.inquirySheet ? this.inquirySheet : 0, type: 2}
  187. arr[4] = {id: '上月求购数', count: this.inquirySheetLast ? this.inquirySheetLast : 0, type: 2}
  188. }
  189. return arr
  190. },
  191. counts () {
  192. let arr = []
  193. let count = this.baseUtils.deepCopy(this.counter)
  194. if(count.length) {
  195. count.forEach((value) => {
  196. if (value.item === '品牌') {
  197. arr[0] = {id: value.item, count: value.count, logo: 1}
  198. } else if (value.item === '现货') {
  199. arr[1] = {id: value.item, count: value.count, logo: 1}
  200. } else if (value.item === '规格书') {
  201. arr[2] = {id: value.item, count: value.count, logo: 1}
  202. } else if (value.item === '店铺') {
  203. arr[3] = {id: value.item, count: value.count, logo: 0}
  204. }
  205. })
  206. }
  207. return arr
  208. }
  209. }
  210. }
  211. </script>
  212. <style lang="scss" scoped>
  213. .display-card{
  214. position: fixed;
  215. right: 80px;
  216. top: 182px;
  217. z-index: 10000;
  218. .cardClose{
  219. position: absolute;
  220. right: -5px;
  221. top: 12px;
  222. opacity: 0.8;
  223. &:hover{
  224. cursor: pointer;
  225. }
  226. }
  227. .content{
  228. margin-top: 10px;
  229. /*width: 178px;*/
  230. /*height: 536px;*/
  231. background: url('/images/all/countBg.png') no-repeat;
  232. div{
  233. height: 56px;
  234. width: 158px;
  235. padding-top: 19px;
  236. margin-left: 16px;
  237. &:first-child{
  238. height: 109px;
  239. padding-top: 1px;
  240. ul{
  241. &:first-child{
  242. max-height: 30px;
  243. width: 100%;
  244. text-align: center;
  245. overflow: hidden;
  246. position: relative;
  247. top: 16px;
  248. li{
  249. height: 30px;
  250. line-height: 30px;
  251. font-weight: bold;
  252. font-size: 21px;
  253. letter-spacing: 0px;
  254. color: #ff3600;
  255. position: relative;
  256. top: 0;
  257. transition: top 1s;
  258. -moz-transition: top 1s; /* Firefox 4 */
  259. -webkit-transition: top 1s; /* Safari and Chrome */
  260. -o-transition: top 1s; /* Opera */
  261. &.top {
  262. transition: top 0s;
  263. -moz-transition: top 0s; /* Firefox 4 */
  264. -webkit-transition: top 0s; /* Safari and Chrome */
  265. -o-transition: top 0s; /* Opera */
  266. }
  267. }
  268. }
  269. &:last-child{
  270. max-height: 30px;
  271. width: 100%;
  272. overflow: hidden;
  273. position: relative;
  274. top: 21px;
  275. text-align: right;
  276. li{
  277. position: relative;
  278. top: 0;
  279. left: 0;
  280. margin: 0 auto;
  281. width: 141px;
  282. height: 30px;
  283. line-height: 28px;
  284. font-weight: bold;
  285. font-size: 21px;
  286. text-align: left;
  287. color: #bc1b1c;
  288. transition: top 1s;
  289. -moz-transition: top 1s;
  290. -webkit-transition: top 1s;
  291. -o-transition: top 1s;
  292. &.top {
  293. transition: top 0s;
  294. -moz-transition: top 0s; /* Firefox 4 */
  295. -webkit-transition: top 0s; /* Safari and Chrome */
  296. -o-transition: top 0s; /* Opera */
  297. }
  298. span.count-distance{
  299. display: inline-block;
  300. padding-left: 3.3px;
  301. margin-left: 2px;
  302. font-size: 18px;
  303. color: #bc1b1c;
  304. width: 17px;
  305. }
  306. span.count-distance.count6{
  307. position:relative;
  308. top: -2px;
  309. padding-left: 0;
  310. font-weight: bold;
  311. color: #fff;
  312. }
  313. }
  314. }
  315. }
  316. }
  317. p{
  318. width: 100%;
  319. text-align: center;
  320. font-size: 20px;
  321. color: #f14e4e;
  322. }
  323. }
  324. .enter{
  325. width: 100%;
  326. display: inline-block;
  327. position: absolute;
  328. bottom: 35px;
  329. left: -5px;
  330. text-align: center;
  331. }
  332. }
  333. }
  334. </style>