fa-orderby.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <view>
  3. <view class="u-p-l-30 u-p-r-30 u-p-b-30 u-p-t-15 u-text-center" v-if="!filterList.length">
  4. <scroll-view scroll-x class="nav" scroll-with-animation :scroll-left="scrollLeft">
  5. <view class="u-flex u-row-around">
  6. <view
  7. class="item"
  8. :style="[{ color: tabIndex == index ? activeColor : color }]"
  9. v-for="(item, index) in tabList"
  10. :key="index"
  11. @click="cutTab(index)"
  12. >
  13. <view class="u-m-r-10" v-text="item[showField]"></view>
  14. <view class=""><u-icon :name="orderwayIcon(item)" :color="tabIndex == index ? activeColor : color" size="30"></u-icon></view>
  15. </view>
  16. </view>
  17. </scroll-view>
  18. </view>
  19. <view class="" v-else-if="is_show">
  20. <fa-dropdown :active-color="theme.bgColor">
  21. <u-dropdown-item v-model="value1" title="排序" :options="options1" @change="change1"></u-dropdown-item>
  22. <u-dropdown-item
  23. v-for="(item, index) in options2"
  24. :key="index"
  25. v-model="tabVal[item.name]"
  26. :title="item.title"
  27. :options="item.option"
  28. ></u-dropdown-item>
  29. </fa-dropdown>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. props: {
  36. tabList: {
  37. type: Array,
  38. default() {
  39. return [];
  40. }
  41. },
  42. filterList: {
  43. type: Array,
  44. default() {
  45. return [];
  46. }
  47. },
  48. showField: {
  49. type: String,
  50. default: 'name'
  51. },
  52. activeColor: {
  53. type: String,
  54. default: '#000'
  55. },
  56. color: {
  57. type: String,
  58. default: '#999'
  59. }
  60. },
  61. computed: {
  62. orderwayIcon() {
  63. return item => {
  64. let orderway = this.$util.getQueryString('orderway', item.url);
  65. if (orderway == 'asc') {
  66. return 'arrow-up';
  67. } else {
  68. return 'arrow-down';
  69. }
  70. };
  71. }
  72. },
  73. watch: {
  74. tabList: {
  75. immediate: true,
  76. handler: function(newValue) {
  77. if (newValue && !this.options1.length) {
  78. this.options1 = [];
  79. newValue.forEach(item => {
  80. this.options1.push({
  81. label: item.title,
  82. value: item.url
  83. });
  84. });
  85. }
  86. }
  87. },
  88. filterList: {
  89. immediate: true,
  90. handler: function(newValue) {
  91. if (newValue.length) {
  92. this.options2 = [];
  93. let val = {};
  94. newValue.forEach(item => {
  95. let op = {
  96. name: item.name,
  97. title: item.title,
  98. option: []
  99. };
  100. val[item.name] = '';
  101. item.content.forEach(it => {
  102. op.option.push({
  103. label: it.title,
  104. value: it.url
  105. });
  106. });
  107. this.options2.push(op);
  108. });
  109. this.tabVal = val;
  110. setTimeout(() => {
  111. this.is_show = true;
  112. }, 0);
  113. }
  114. }
  115. },
  116. tabVal: {
  117. deep: true,
  118. handler: function(newValue) {
  119. this.urls = '';
  120. for (let i in newValue) {
  121. if (newValue[i] && newValue[i] != '?') {
  122. let arr = decodeURIComponent(newValue[i])
  123. .replace('?', '')
  124. .split('=');
  125. this.urls += '&' + arr[0] + '=' + arr[1];
  126. }
  127. }
  128. this.$emit('change', {
  129. orderby: this.orderby,
  130. orderway: this.orderway,
  131. url: this.urls
  132. });
  133. }
  134. }
  135. },
  136. data() {
  137. return {
  138. tabIndex: 0,
  139. scrollLeft: 0,
  140. tabVal: {},
  141. value1: '',
  142. options1: [],
  143. options2: [],
  144. orderby: '',
  145. orderway: '',
  146. urls: '',
  147. is_show: false
  148. };
  149. },
  150. methods: {
  151. change1(value){
  152. this.goBy(value)
  153. },
  154. cutTab(index) {
  155. this.tabIndex = index;
  156. this.scrollLeft = (index - 1) * 60;
  157. this.goBy(this.tabList[index].url);
  158. },
  159. goBy(url) {
  160. this.orderby = this.$util.getQueryString('orderby', url);
  161. this.orderway = this.$util.getQueryString('orderway', url);
  162. this.$emit('change', {
  163. orderby: this.orderby,
  164. orderway: this.orderway,
  165. url: this.urls
  166. });
  167. }
  168. }
  169. };
  170. </script>
  171. <style lang="scss">
  172. .nav {
  173. white-space: nowrap;
  174. .item {
  175. display: inline-flex;
  176. margin: 0 10upx;
  177. padding: 0 20upx;
  178. }
  179. }
  180. </style>