index.vue 5.0 KB

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