cate-two.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="cate-two flex" style="height: 100%;">
  3. <view class="aside bg-white">
  4. <scroll-view style="height: 100%" scroll-y="true" scroll-with-animation="true">
  5. <block v-for="(item, index) in cateList" :key="index">
  6. <view :class="'one-item sm ' + (index == selectIndex ? 'active' : '')" @click="changeActive(index)">
  7. <text class="name">{{ item.name }}</text>
  8. <view v-if="index == selectIndex" class="active-line bg-primary"></view>
  9. </view>
  10. </block>
  11. </scroll-view>
  12. </view>
  13. <view class="main bg-body">
  14. <scroll-view style="height: 100%" scroll-y="true" scroll-with-animation="true"
  15. @scrolltolower="getGoodsListFun">
  16. <view class="main-wrap">
  17. <ad-swipers :pid="11" height="200rpx" previous-margin="0" padding="0 0 20rpx" radius="10rpx">
  18. </ad-swipers>
  19. <view class="cate-two" v-if="appConfig.cate_style == 4">
  20. <view v-for="(sitem, sindex) in cateTwoList" :key="sindex" class="two-item bg-white m-b-20">
  21. <router-link :to="{path: '/pages/goods_search/goods_search', query: {
  22. id: sitem.id,
  23. name: sitem.name,
  24. type: 1
  25. }}">
  26. <view class="title flex row-between">
  27. <text class="name bold sm">{{sitem.name}}</text>
  28. <u-icon name="arrow-right"></u-icon>
  29. </view>
  30. </router-link>
  31. <view class="three-list flex flex-wrap">
  32. <router-link class="three-item" v-for="(titem, tindex) in sitem.children" :key="tindex"
  33. :to="{path: '/pages/goods_search/goods_search', query: {
  34. id: titem.id,
  35. name: titem.name,
  36. type: 1
  37. }}">
  38. <view class=" flex-col col-center m-b-20">
  39. <u-image mode="aspectFit" width="150rpx" height="150rpx" :src="titem.image">
  40. </u-image>
  41. <view class="text m-t-20 xs">{{ titem.name }}</view>
  42. </view>
  43. </router-link>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="goods" v-if="appConfig.cate_style == 1 && hasData">
  48. <view class="sort-nav-wrap">
  49. <sort-nav v-model="sortConfig" :show-type="false"></sort-nav>
  50. </view>
  51. <view class="goods">
  52. <view class="goods-list">
  53. <router-link v-for="(item, index) in goodsList" :key="index"
  54. :to="`/pages/goods_details/goods_details?id=${item.id}`">
  55. <view class="flex item bg-white m-t-20">
  56. <u-image width="200rpx" height="200rpx" border-radius="14rpx" :src="item.image">
  57. </u-image>
  58. <view class="flex-1 m-l-20 m-r-10">
  59. <view class="line-2">{{item.name}}</view>
  60. <view class="muted">
  61. <text class="xxs">原价</text>
  62. <price-format :subscript-size="22" :first-size="22" :second-size="22"
  63. :price="item.market_price"></price-format>
  64. </view>
  65. <view class="primary mt10">
  66. <price-format :price="item.min_price" :subscript-size="22"
  67. :first-size="34" :second-size="26"></price-format>
  68. </view>
  69. <view class="power-tags" v-show='item.use_energy > 0'>
  70. {{(item.min_price * item.use_energy / 100 / appConfig.energyprice).toFixed(6) }}抵用券抵¥{{(item.min_price * item.use_energy / 100).toFixed(2)}}
  71. </view>
  72. </view>
  73. </view>
  74. </router-link>
  75. </view>
  76. <loading-footer :status="status" :slot-empty="true">
  77. <view slot="empty" class="flex-col col-center" style="padding: 200rpx 0 0">
  78. <image class="img-null" src="/static/images/goods_null.png"></image>
  79. <text class="lighter sm">暂无商品</text>
  80. </view>
  81. </loading-footer>
  82. </view>
  83. </view>
  84. </view>
  85. </scroll-view>
  86. </view>
  87. </view>
  88. </template>
  89. <script>
  90. import {
  91. getListByLevelOne,
  92. getGoodsList
  93. } from '@/api/store'
  94. import {
  95. mapGetters,
  96. mapActions
  97. } from 'vuex'
  98. import {
  99. loadingType
  100. } from '@/utils/type.js'
  101. export default {
  102. name: "cate-two",
  103. props: {
  104. cateList: {
  105. type: Array,
  106. default: () => ([])
  107. }
  108. },
  109. data() {
  110. return {
  111. selectIndex: 0,
  112. cateTwoList: [],
  113. goodsList: [],
  114. sortConfig: {
  115. goodsType: 'double',
  116. priceSort: '',
  117. saleSort: '',
  118. },
  119. status: loadingType.LOADING,
  120. hasData: true
  121. };
  122. },
  123. methods: {
  124. changeActive(index) {
  125. this.selectIndex = index
  126. },
  127. async getListByLevelOneFun() {
  128. const {
  129. selectIndex,
  130. cateList
  131. } = this
  132. if (!cateList.length) return
  133. const id = cateList[selectIndex].id
  134. const {
  135. code,
  136. data
  137. } = await getListByLevelOne({
  138. id
  139. })
  140. if (code == 1) {
  141. this.cateTwoList = data
  142. }
  143. },
  144. getGoodsListFun() {
  145. let {
  146. page,
  147. cateList,
  148. status,
  149. selectIndex,
  150. goodsList,
  151. sortConfig: {
  152. priceSort,
  153. saleSort,
  154. }
  155. } = this;
  156. if (!cateList.length) return
  157. const id = cateList[selectIndex].id
  158. if (status == loadingType.FINISHED || this.appConfig.cate_style == 4) return;
  159. let data = {}
  160. if (id != 40) {
  161. data = {
  162. page_no: page,
  163. platform_cate_id: id,
  164. sort_by_price: priceSort,
  165. sort_by_sales: saleSort,
  166. }
  167. } else {
  168. data = {
  169. page_no: page,
  170. sort_by_price: priceSort,
  171. sort_by_sales: saleSort,
  172. use_energy: 1
  173. }
  174. }
  175. console.log(data);
  176. getGoodsList(data).then(res => {
  177. if (res.code == 1) {
  178. let {
  179. more,
  180. lists,
  181. } = res.data;
  182. goodsList.push(...lists);
  183. this.page++;
  184. if (!more) {
  185. this.status = loadingType.FINISHED;
  186. }
  187. if (goodsList.length <= 0) {
  188. this.status = loadingType.EMPTY
  189. return;
  190. }
  191. } else {
  192. this.status = loadingType.ERROR
  193. }
  194. });
  195. },
  196. onRefresh() {
  197. this.status = loadingType.LOADING
  198. this.page = 1
  199. this.goodsList = []
  200. this.getGoodsListFun()
  201. },
  202. },
  203. watch: {
  204. selectIndex() {
  205. this.appConfig.cate_style == 1 ? this.onRefresh() : this.getListByLevelOneFun()
  206. },
  207. cateList: {
  208. immediate: true,
  209. handler(val) {
  210. this.hasData = val.length ? true : false
  211. this.appConfig.cate_style == 1 ? this.onRefresh() : this.getListByLevelOneFun()
  212. }
  213. },
  214. 'sortConfig.saleSort'() {
  215. this.onRefresh()
  216. },
  217. 'sortConfig.priceSort'() {
  218. this.onRefresh()
  219. }
  220. },
  221. computed: {
  222. ...mapGetters(['appConfig']),
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .power-tags {
  228. font-size: 20rpx;
  229. color: #0EB5F1;
  230. margin: 20rpx auto;
  231. text-align: center;
  232. border-radius: 8rpx;
  233. background-color: #DDF6FF;
  234. height: 36rpx;
  235. line-height: 36rpx;
  236. }
  237. .cate-two {
  238. .aside {
  239. width: 180rpx;
  240. flex: none;
  241. height: 100%;
  242. .one-item {
  243. position: relative;
  244. text-align: center;
  245. padding: 26rpx 10rpx;
  246. &.active {
  247. color: $-color-primary;
  248. font-size: 26rpx;
  249. font-weight: bold;
  250. }
  251. .active-line {
  252. position: absolute;
  253. width: 6rpx;
  254. height: 30rpx;
  255. left: 4rpx;
  256. top: 50%;
  257. transform: translateY(-50%);
  258. }
  259. }
  260. }
  261. .main {
  262. height: 100%;
  263. flex: 1;
  264. .main-wrap {
  265. position: relative;
  266. padding: 20rpx 20rpx 0;
  267. .two-item {
  268. border-radius: 10rpx;
  269. .title {
  270. height: 90rpx;
  271. padding: 0 20rpx;
  272. .line {
  273. width: 40rpx;
  274. height: 1px;
  275. background-color: #BBBBBB;
  276. }
  277. }
  278. .three-list {
  279. align-items: flex-start;
  280. padding: 0 10rpx;
  281. .three-item {
  282. width: 33%;
  283. .text {
  284. text-align: center;
  285. }
  286. }
  287. }
  288. }
  289. }
  290. .goods .item {
  291. border-radius: 14rpx;
  292. }
  293. }
  294. }
  295. </style>