index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <mobile-frame :frameStyle="frameStyle" @toPath="toPath">
  3. <view class="main">
  4. <view class="one">
  5. <input type="text" placeholder="搜索商品" @tap="toCommon('pagesHome/market/search')" placeholder-class="placss">
  6. </view>
  7. <view class="two">
  8. <view class="two_1">
  9. <scroll-view scroll-y="true" class="scroll-view">
  10. <view class="list-scroll-view">
  11. <view class="list" :class="[active==index?'listActive':'']" v-for="(item,index) in typeList" :key="index" @tap="toChange(index,item)">
  12. <text>{{item.label}}</text>
  13. </view>
  14. </view>
  15. </scroll-view>
  16. </view>
  17. <view class="two_2">
  18. <scroll-view scroll-y="true" class="scroll-view">
  19. <view class="list-scroll-view">
  20. <view class="list" v-for="(item,index) in list" :key="index" @tap="toCommon('pagesHome/market/search',item,'2')">
  21. <view class="title">
  22. {{item.label}}
  23. </view>
  24. <view class="market" v-if="item.children&&item.children.length>0">
  25. <view class="marketList" v-for="(tag,indexs) in item.children" :key="indexs" @tap.stop="toCommon('pagesHome/market/search',tag,'3')">
  26. <image class="image" :src="tag.file&&tag.file.length>0?tag.file[0].url:''" mode=""></image>
  27. <view class="name">
  28. {{tag.label}}
  29. </view>
  30. </view>
  31. </view>
  32. <view class="market" v-else>
  33. <view class="marketList" @tap.stop="toCommon('pagesHome/market/search',item,'3')">
  34. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode=""></image>
  35. <view class="name">
  36. {{item.label}}
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </scroll-view>
  43. </view>
  44. </view>
  45. </view>
  46. </mobile-frame>
  47. </template>
  48. <script>
  49. export default {
  50. data() {
  51. return {
  52. frameStyle: {
  53. useBar: true
  54. },
  55. active: '0',
  56. typeList: [],
  57. list: [],
  58. // 一级
  59. classa: {},
  60. };
  61. },
  62. onLoad: function() {
  63. const that = this;
  64. that.searchOther();
  65. },
  66. methods: {
  67. async searchOther() {
  68. const that = this;
  69. let res;
  70. res = await that.$api(`/goodsTags`, 'GET', {
  71. status: '0'
  72. })
  73. if (res.errcode == '0') {
  74. that.$set(that, `typeList`, res.data);
  75. if (res.total > 0) {
  76. that.searchRight(res.data[0]);
  77. that.$set(that, `classa`, res.data[0]);
  78. }
  79. }
  80. },
  81. toChange(index, e) {
  82. const that = this;
  83. that.$set(that, `list`, []);
  84. that.$set(that, `active`, index);
  85. that.searchRight(e);
  86. that.$set(that, `classa`, e);
  87. },
  88. // 查询左侧信息
  89. async searchRight(e) {
  90. const that = this;
  91. let info = {};
  92. if (e.id) info.pid = e.id;
  93. const res = await that.$api(`/goodsTags/tree`, 'GET', {
  94. ...info
  95. })
  96. if (res.errcode == '0' && res.data.length > 0) {
  97. that.$set(that, `list`, res.data[0].children)
  98. }
  99. },
  100. // 公共跳转
  101. toCommon(e, code, num) {
  102. const that = this;
  103. if (num == '2') {
  104. uni.navigateTo({
  105. url: `/${e}?tags=${code.code}&pid=${that.classa._id}`
  106. })
  107. } else if (num == '3') {
  108. uni.navigateTo({
  109. url: `/${e}?tags=${code.code}`
  110. })
  111. } else {
  112. uni.navigateTo({
  113. url: `/${e}`
  114. })
  115. }
  116. },
  117. // 菜单跳转
  118. toPath(e) {
  119. if (e && e.route && e.type == '0') {
  120. uni.redirectTo({
  121. url: `/${e.route}`
  122. })
  123. } else {
  124. uni.navigateTo({
  125. url: `/${e.route}`
  126. })
  127. }
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss">
  133. .main {
  134. display: flex;
  135. flex-direction: column;
  136. width: 100vw;
  137. height: 91vh;
  138. .one {
  139. padding: 2vw;
  140. border: 1px solid var(--f1Color);
  141. input {
  142. background-color: var(--fFB1Color);
  143. border-radius: 30px;
  144. padding: 2vw;
  145. color: var(--fffColor);
  146. font-size: var(--font15Size);
  147. }
  148. .placss {
  149. color: var(--fffColor);
  150. }
  151. }
  152. .two {
  153. height: 83vh;
  154. display: flex;
  155. flex-direction: row;
  156. .two_1 {
  157. position: relative;
  158. width: 25vw;
  159. background-color: #fafafa;
  160. display: flex;
  161. flex-direction: column;
  162. .list {
  163. text-align: center;
  164. padding: 2.5vw 0;
  165. border-bottom: 1px solid var(--f1Color);
  166. text {
  167. font-size: var(--font14Size);
  168. }
  169. }
  170. .listActive {
  171. background-color: var(--fffColor);
  172. }
  173. }
  174. .two_2 {
  175. padding: 2vw;
  176. flex-grow: 1;
  177. position: relative;
  178. display: flex;
  179. flex-direction: column;
  180. .list {
  181. margin: 0 0 2vw 0;
  182. padding: 2vw;
  183. .title {
  184. font-size: var(--font16Size);
  185. margin: 0 0 2vw 0;
  186. }
  187. .market {
  188. display: flex;
  189. flex-direction: row;
  190. flex-wrap: wrap;
  191. .marketList {
  192. text-align: center;
  193. margin: 0 2vw 2vw 0;
  194. width: 22vw;
  195. .image {
  196. width: 100%;
  197. height: 15vw;
  198. }
  199. .name {
  200. font-size: var(--font14Size);
  201. }
  202. }
  203. .marketList:nth-child(3n) {
  204. margin: 0 0 2vw 0;
  205. }
  206. }
  207. }
  208. }
  209. }
  210. }
  211. .scroll-view {
  212. position: absolute;
  213. top: 0;
  214. left: 0;
  215. right: 0;
  216. bottom: 0;
  217. .list-scroll-view {
  218. display: flex;
  219. flex-direction: column;
  220. }
  221. }
  222. </style>