indexContent.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view class="list-content-wrap">
  3. <view class="top-box">
  4. <text style="margin-right:20rpx">{{num}}品种</text>
  5. <text>{{time}}</text>
  6. </view>
  7. <view style="display: flex;align-items:center;padding:40rpx 34rpx">
  8. <van-switch active-color="#E3B377" size="20px" :checked="isHistory" @change="onChange" />
  9. <text style="margin:-8rpx 0 0 10rpx">历史合约</text>
  10. </view>
  11. <view class="list-wrap">
  12. <view class="flex item" v-for="item in clist" :key="item.classify_name">
  13. <view class="label">{{item.classify_name}}</view>
  14. <view style="flex:1">
  15. <view
  16. class="opt"
  17. v-for="_item in item.items"
  18. :key="_item.classify_type"
  19. @click="goDetail(_item,item)"
  20. >{{_item.classify_type}}</view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="empty-box" v-if="!clist||clist.length===0">
  25. <image
  26. :src="globalImgUrls.chartEmpty"
  27. mode="widthFix"
  28. />
  29. <view>无数据~</view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. const dayjs=require('@/utils/dayjs.min')
  35. export default {
  36. name:'IndexContent',
  37. props:{
  38. time:{
  39. default:''
  40. },
  41. num:{
  42. default:''
  43. },
  44. list:{
  45. default:null
  46. },
  47. exchange:{
  48. default:''
  49. },
  50. now: {
  51. default: ''
  52. }
  53. },
  54. computed:{
  55. clist(){
  56. if(this.isHistory){
  57. console.log('看历史');
  58. return this.list
  59. }
  60. const now=dayjs(this.now).format('YYMM')//当前时间
  61. const arr=this.list?JSON.parse(JSON.stringify(this.list)):[]
  62. let resArr=[]
  63. if(this.exchange!='郑商所'){
  64. resArr=arr.map(item=>{
  65. item.items=item.items.filter(_item=>{
  66. const t=_item.classify_type.substr(-4)
  67. //15号之后过滤非当月合约
  68. return Number(this.now.substr(-2)) <= 15 ? Number(t)>=now : Number(t)>now;
  69. })
  70. return item
  71. })
  72. }else{
  73. resArr=arr.map(item=>{
  74. item.items=item.items.filter(_item=>{
  75. // 如果合约编号没有含日期 肯定是少于4位的 因为至少为一个字母加三位数的日期
  76. if(_item.classify_type.length<4) return true
  77. const t=2+_item.classify_type.substr(-3)
  78. //15号之后过滤非当月合约
  79. return Number(this.now.substr(-2)) <= 15 ? Number(t)>=now : Number(t)>now;
  80. })
  81. return item
  82. })
  83. }
  84. return resArr
  85. }
  86. },
  87. data() {
  88. return {
  89. isHistory:false
  90. }
  91. },
  92. methods: {
  93. onChange(e){
  94. console.log(e);
  95. this.isHistory=e.detail
  96. },
  97. goDetail(_item,item){
  98. const queryObj={
  99. classify_name:item.classify_name,
  100. classify_type:_item.classify_type,
  101. exchange:this.exchange
  102. }
  103. let queryObjStr=''
  104. for (const key in queryObj) {
  105. if(!queryObjStr){
  106. queryObjStr=`${key}=${queryObj[key]}`
  107. }else{
  108. queryObjStr=`${queryObjStr}&${key}=${queryObj[key]}`
  109. }
  110. }
  111. uni.navigateTo({
  112. url: `/pages/positionAnalysis/detail?${queryObjStr}`,
  113. success: (result) => {},
  114. fail: () => {},
  115. complete: () => {}
  116. });
  117. }
  118. },
  119. }
  120. </script>
  121. <style lang="scss" scoped>
  122. .list-content-wrap{
  123. .top-box{
  124. background: rgba(207, 192, 159, 0.1);
  125. padding: 15rpx 45rpx;
  126. }
  127. .list-wrap{
  128. padding: 34rpx 0 34rpx 34rpx;
  129. .item{
  130. margin-bottom: 40rpx;
  131. .label{
  132. color: #666;
  133. width: 150rpx;
  134. padding-top: 15rpx;
  135. }
  136. .opt{
  137. padding: 15rpx 10rpx;
  138. width: 28%;
  139. text-align: center;
  140. display: inline-block;
  141. margin-right: 20rpx;
  142. margin-bottom: 20rpx;
  143. background: #F5EFE2;
  144. font-size: 24rpx;
  145. }
  146. }
  147. }
  148. }
  149. .empty-box{
  150. text-align: center;
  151. font-size: 32rpx;
  152. color: #999;
  153. padding-top: 150rpx;
  154. image{
  155. width: 346rpx;
  156. margin-bottom: 57rpx;
  157. }
  158. }
  159. </style>