mall.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <template>
  2. <view class="">
  3. <navBar title="商城" :back="false" color="black" flex="cen" background="#fff" />
  4. <view class="searchAndTab">
  5. <view class="searchBox">
  6. <uni-search-bar @confirm="search" @input="input" v-model="searchKey" placeholder="请输入关键词" radius="50"
  7. cancelButton="none" bgColor="#F3F4F6"></uni-search-bar>
  8. </view>
  9. <u-sticky bgColor="#fff" v-if="!searchKey">
  10. <u-tabs @click="handle1" :list="list1" :scrollable="true" :activeStyle='activeStyle'
  11. :inactiveStyle="inactiveStyle" @change="change"></u-tabs>
  12. </u-sticky>
  13. </view>
  14. <view class="content" v-if="searchKey" style="margin-top: 140rpx;">
  15. <view class="rightDes2" style="height: calc(100vh - 330rpx);">
  16. <u-loading-icon v-if="showLoading1&&resList.length==0" text="加载中" :vertical="true"></u-loading-icon>
  17. <view class="con" v-else>
  18. <view class="item" v-if="resList.length!=0" v-for="(item1,index) in resList"
  19. @click="goDetail(item1)">
  20. <view class="topBox">
  21. <image :src="picBase+item1.cover" mode=""></image>
  22. </view>
  23. <view class="bottom">
  24. <view class="txt" v-if="item1.name">
  25. {{item1.name}}
  26. </view>
  27. </view>
  28. </view>
  29. <view class="" v-else style="">
  30. <u-empty mode="data" text="暂无数据" width="100" height="100"
  31. :icon="picUrl+'/static/other/empty.png'">
  32. </u-empty>
  33. </view>
  34. </view>
  35. <u-loadmore v-if="resList.length!=0" style="" loadmoreText="已经到底啦" color="#CCCCCC" lineColor="#CCCCCC"
  36. line />
  37. </view>
  38. </view>
  39. <view class="content" v-else style="margin-top: 200rpx;">
  40. <view class="leftMenu">
  41. <view class="item" v-for="(item,index) in list2" :class="[index==currBrandIndex?'act':'']"
  42. @click=" change2(item.id,index)">
  43. <text style="position: relative;z-index: 1;">{{item.title}}</text>
  44. <image v-if="index==currBrandIndex" class="halfCircle" :src="picUrl+'/static/mall/circle.png'"
  45. mode="" style="width: 30rpx;height: 30rpx;">
  46. </image>
  47. </view>
  48. </view>
  49. <view class="rightDes">
  50. <u-loading-icon v-if="showLoading&&allTypes.length==0" text="加载中" :vertical="true"></u-loading-icon>
  51. <view class="item" v-else v-for="(item,index) in allTypes" :style="{marginTop:index>0?'22rpx':''}">
  52. <view class="top" @click="toList(item,allTypesValues[index])">
  53. <view class="name">
  54. {{allTypesValues[index]}}
  55. </view>
  56. <image src="/static/index/more.png" mode=""
  57. style="width: 40rpx;height: 40rpx;margin-right: 4rpx;">
  58. </image>
  59. </view>
  60. <view class="bottom" v-if="resList[item][0].id">
  61. <image @click="goDetail(item1)" :src="picBase+item1.cover" mode="" style="" class="img"
  62. v-for="(item1,index) in resList[item] ">
  63. </image>
  64. </view>
  65. <view class="bottom" v-else style="justify-content: center;">
  66. <u-empty mode="data" text="暂无数据" width="100" height="100"
  67. :icon="picUrl+'/static/other/empty.png'">
  68. </u-empty>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import classifyData from '@/common/classify.data.js';
  77. import uploadUrl from '@/common/config.js'
  78. import {
  79. getMallCatReq,
  80. getMallReq,
  81. } from '@/api/test/index.js'
  82. export default {
  83. data() {
  84. return {
  85. searchKey: '',
  86. showLoading: false,
  87. showLoading1: false,
  88. picUrl: this.$picUrl,
  89. picBase: this.$picBase,
  90. currBrandIndex: 0,
  91. list1: [],
  92. list2: [],
  93. activeStyle: {
  94. color: '#F7790C'
  95. },
  96. inactiveStyle: {
  97. color: '#080F18'
  98. },
  99. selTab: {
  100. type: 1,
  101. brand: 7
  102. },
  103. resList: [],
  104. allTypes: [],
  105. allTypesValues: [],
  106. tOList: [],
  107. pid: -1,
  108. catTabId: -1,
  109. initialPid: -1
  110. };
  111. },
  112. created() {
  113. },
  114. async onLoad() {
  115. let res = await getMallCatReq()
  116. if (res.code == 0) {
  117. console.log('获取商城顶部分类数据返回值: ', res);
  118. this.catTabId = res.data[0].id
  119. this.handle1({
  120. id: res.data[0].id
  121. })
  122. this.tOList = res.data
  123. let tL = []
  124. res.data.forEach((item, index) => {
  125. tL.push({
  126. id: item.id,
  127. name: item.title
  128. })
  129. })
  130. this.list1 = tL
  131. } else {
  132. uni.showToast({
  133. title: res.message,
  134. icon: 'none'
  135. })
  136. }
  137. },
  138. async onShow() {
  139. if (!uni.getStorageSync('switchs')) {
  140. uni.setStorageSync('switchs', [1, 0, 0])
  141. }
  142. // if (!uni.getStorageSync('priceConfig')) {
  143. uni.request({
  144. url: uploadUrl.baseUrl + '/api/common/getPriceConfig',
  145. method: "GET",
  146. success: (res) => {
  147. if (res.data.code == 0) {
  148. console.log('mall中获取的会员折扣数据', res.data.data)
  149. uni.setStorageSync('priceConfig', res.data.data)
  150. }
  151. }
  152. })
  153. // }
  154. },
  155. onReady() {
  156. },
  157. methods: {
  158. async handle1(e) {
  159. console.log('e', e.id);
  160. let res = await getMallCatReq({
  161. pid: e.id
  162. })
  163. if (res.code == 0) {
  164. this.list2 = res.data
  165. console.log('zhongxiang', res);
  166. this.currBrandIndex = 0
  167. this.getMall(res.data[0].id)
  168. }
  169. },
  170. async getMall(id) {
  171. this.showLoading = true
  172. this.pid = id
  173. let res = await getMallReq({
  174. pid: id
  175. })
  176. if (res.code == 0) {
  177. this.showLoading = false
  178. console.log('获取商城数据返回值: ', res);
  179. this.allTypes = Object.keys(res.data.typeName)
  180. this.allTypesValues = Object.values(res.data.typeName)
  181. this.resList = res.data
  182. console.log('获取商城数据返回值列表: ', this.resList, this.allTypes, this.allTypesValues);
  183. } else {
  184. uni.showToast({
  185. title: res.message,
  186. icon: 'none'
  187. })
  188. }
  189. },
  190. async getMall2(search) {
  191. this.showLoading1 = true
  192. let res = await getMallReq({
  193. // page: 1,
  194. search,
  195. })
  196. if (res.code == 0) {
  197. this.showLoading1 = false
  198. console.log('获取商城数据返回值2: ', res.data);
  199. this.resList = res.data
  200. // this.resList = []
  201. console.log('获取商城数据返回值列表2: ', this.resList);
  202. } else {
  203. uni.showToast({
  204. title: res.message,
  205. icon: 'none'
  206. })
  207. }
  208. },
  209. change2(id, index) {
  210. this.currBrandIndex = index
  211. this.getMall(id)
  212. },
  213. toList(id, name) {
  214. uni.navigateTo({
  215. url: '/pages/mall/goodsList/index?typeNameId=' + id + '&pid=' + this.pid + '&name=' + name
  216. })
  217. },
  218. goDetail(item) {
  219. console.log('item-------------------', item);
  220. getApp().mallItem = item
  221. uni.navigateTo({
  222. url: '/pages/mall/detail/index'
  223. })
  224. }
  225. },
  226. watch: {
  227. searchKey(n, o) {
  228. if (!n) {
  229. this.currBrandIndex = 0
  230. console.log('当搜索词为空时传递的pid', this.pid, this.initialPid, this.catTabId);
  231. this.handle1({
  232. id: this.catTabId
  233. })
  234. return
  235. }
  236. setTimeout(() => {
  237. this.getMall2(n)
  238. }, 0)
  239. },
  240. },
  241. components: {}
  242. };
  243. </script>
  244. <style lang="scss" scoped>
  245. @import "./mall.scss";
  246. </style>