template2.vue 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. <template>
  2. <view>
  3. <view class="flex-col bg--w111-fff lei" :style="[pageHeight]">
  4. <view :style="{height: headerHeight + 'px'}">
  5. <view :style="{paddingTop: sysHeight + 'px'}" :class="{fixed: headerFixed}" id="mp-header" class="text--w111-999 mp-header">
  6. <view class="h-80 px-32 flex-y-center">
  7. <!-- #ifdef MP -->
  8. <view class="flex-1 h-58 flex-y-center rd-30rpx bg--w111-f5f5f5 px-32" @tap="goSearch">
  9. <!-- #endif -->
  10. <!-- #ifndef MP -->
  11. <view class="w-full h-58 flex-y-center rd-30rpx bg--w111-f5f5f5 px-32" @tap="goSearch">
  12. <!-- #endif -->
  13. <text class="iconfont icon-ic_search fs-28"></text>
  14. <text class="fs-24 pl-18">请输入商品名称</text>
  15. </view>
  16. <!-- 胶囊占据的位置 -->
  17. <!-- #ifdef MP -->
  18. <view class="ml-12" :style="'width:'+getHeight.barWidth+'px'"></view>
  19. <!-- #endif -->
  20. </view>
  21. </view>
  22. </view>
  23. <view class="flex border_e">
  24. <scroll-view scroll-x="true" class="white-nowrap vertical-middle w-678 pl-20 pt-24 pb-24"
  25. show-scrollbar="false">
  26. <view class="inline-block mr-8" v-for="(item,index) in categoryList" :key="index"
  27. @tap="tapNav(index,item)">
  28. <view class="flex-col flex-center">
  29. <view :class="index == navActive ? 'active_pic' : 'scroll_pic'">
  30. <image :src="item.pic" mode="aspectFill"></image>
  31. </view>
  32. <view class="w-120 h-40 flex-center fs-24 text--w111-333"
  33. :class="index == navActive ? 'active_cate_text' : ''">{{item.cate_name}}</view>
  34. </view>
  35. </view>
  36. </scroll-view>
  37. <view class="bntAll flex-1 flex-col flex-center fs-24" @tap="openCateDrawer(true)">
  38. <text>全</text>
  39. <text>部</text>
  40. <image class="w-28 h-28 block mt-8" src="@/static/img/all_pic.png"></image>
  41. </view>
  42. </view>
  43. <view class="scroll_box flex flex-1" id="conter-box">
  44. <view class="w-168 bg--w111-f5f5f5">
  45. <view class="w-168 h-full bg--w111-f5f5f5" :class="{ fixed: conterFixed }" :style="{ top: headerHeight+'px' }">
  46. <scroll-view :scroll-top="0" scroll-y="true" class="h-full">
  47. <view class="w-168 h-96 flex-center fs-26 text--w111-666"
  48. v-for="(item,index) in categoryErList"
  49. :key="index"
  50. :class="[{'aside_active': index===tabClick},'aside_' + index]"
  51. @tap="longClick(index,item)">
  52. <view class="top-ra">
  53. <text></text>
  54. </view>
  55. {{item.cate_name}}
  56. <view class="bottom-ra">
  57. <text></text>
  58. </view>
  59. </view>
  60. <view class="white-box"></view>
  61. </scroll-view>
  62. </view>
  63. </view>
  64. <view class="relative flex-1 flex-col">
  65. <view class="flex-1 pl-24 pr-20 abs-lt bg--w111-fff z-4" v-if="threeCateList.length && level == 3" :class="{ fixed: conterFixed }" :style="{ top: scrollTop && conterTop <= headerHeight ? headerHeight+'px' : 0, left: scrollTop && conterTop <= headerHeight ? '168rpx' : 0 }">
  66. <view class="flex mt-24 mb-16">
  67. <scroll-view scroll-x="true" class="white-nowrap vertical-middle w-464"
  68. show-scrollbar="false">
  69. <view class="inline-block mr-16" v-for="(item,index) in threeCateList" :key="index"
  70. @tap="threeCateClick(index,item)">
  71. <view
  72. class="w-144 h-56 rd-30rpx bg--w111-f5f5f5 flex-center fs-24 text--w111-333"
  73. :class="index===threeClick?'cate_active':''">{{item.cate_name}}</view>
  74. </view>
  75. </scroll-view>
  76. <view class="bntCon w-56 h-56 rd-30rpx bg--w111-f5f5f5 flex-center ml-16"
  77. v-if="threeCateList.length && level == 3"
  78. @tap="openCateDrawer(false)">
  79. <text class="iconfont icon-ic_downarrow fs-32 text--w111-333"></text>
  80. </view>
  81. </view>
  82. </view>
  83. <view class="h-96" v-if="threeCateList.length && level == 3"></view>
  84. <view v-else class="mt-24"></view>
  85. <view class="pl-24 pr-20 flex-1 flex-col" style="min-height: 0;" :class="!threeCateList.length ? 'mt-24' : ''">
  86. <scroll-view class="h-full" :scroll-top="0" scroll-y="true" @scrolltolower="lower" @scroll="scroll"
  87. >
  88. <!-- 大图模板 -->
  89. <view class="pb-36" v-if="(showType == 3 && level == 2) || (showType == 1 && level == 3)">
  90. <view class="mb-24" v-for="(item,index) in tempArr" :key="index"
  91. @tap="goDetail(item)">
  92. <easy-loadimage
  93. :image-src="item.recommend_image ? item.recommend_image : item.image"
  94. :borderSrc="item.recommend_image ? '' :item.activity_frame.image"
  95. width="540rpx"
  96. :height="item.recommend_image ? '216rpx' : '540rpx'"
  97. borderRadius="20rpx 20rpx 0 0"></easy-loadimage>
  98. <view class="bg--w111-fff rd-b-20rpx pt-16 pl-24 pr-24 pb-24">
  99. <view class="w-full line2 fs-28 text--w111-333 lh-40rpx">{{item.store_name}}
  100. </view>
  101. <view class="flex-between-center mt-20">
  102. <view class="flex items-baseline">
  103. <baseMoney :money="item.price" symbolSize="28" integerSize="44"
  104. decimalSize="28" incolor="var(--primary-theme-con)" weight>
  105. </baseMoney>
  106. <text class="fs-22 text--w111-8e8e8e pl-12">已售{{item.sales}}</text>
  107. </view>
  108. <view
  109. class="w-172 h-58 rd-30rpx bg-color flex-center fs-24 text--w111-fff relative"
  110. v-if="item.spec_type" @tap.stop="goCartDuo(item)">
  111. <text>{{item.cart_button == 0 ? '立即购买' : '加入购物车'}}</text>
  112. <uni-badge class="badge-style" :custom-style="{background: 'var(--view-theme)'}" v-if="item.cart_num > 0" :text="item.cart_num"></uni-badge>
  113. </view>
  114. <view v-if="!item.spec_type && !item.cart_num">
  115. <view class="flex-center w-48 h-48 rd-30rpx bg-color text--w111-fff "
  116. @tap.stop="goCartDan(item,index)">
  117. <text class="iconfont icon-ic_ShoppingCart1 fs-30"></text>
  118. </view>
  119. </view>
  120. <view class="flex-y-center" v-if="!item.spec_type && item.cart_num">
  121. <view
  122. class="flex-center w-48 h-48 rd-30rpx bg--w111-f5f5f5 text--w111-333"
  123. @tap.stop="ChangeCartNumDan(false,index,item)">
  124. <text class="iconfont icon-ic_Reduce fs-32"></text>
  125. </view>
  126. <view class="fs-30 text--w111-333 px-20">{{item.cart_num}}</view>
  127. <view class="flex-center w-48 h-48 rd-30rpx bg-color text--w111-fff"
  128. @tap.stop="CartNumAdd(index,item)">
  129. <text class="iconfont icon-ic_increase fs-32"></text>
  130. </view>
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. </view>
  136. <!-- 小图模板 -->
  137. <view class="pb-36" v-else-if="(showType == 2 && level == 2) || (showType == 2 && level == 3)">
  138. <view class="mb-24 flex justify-between" v-for="(item,index) in tempArr" :key="index"
  139. @tap="goDetail(item)">
  140. <easy-loadimage
  141. :image-src="item.image"
  142. :borderSrc="item.activity_frame.image"
  143. width="176rpx"
  144. height="176rpx"
  145. borderRadius="16rpx"></easy-loadimage>
  146. <view class="flex-1 flex-col justify-between pl-20">
  147. <view class="w-full">
  148. <view class="line1 w-346 fs-28 text-#333 lh-40rpx">{{item.store_name}}</view>
  149. <view class="flex items-end flex-wrap mt-12 w-full">
  150. <BaseTag
  151. :text="label.label_name"
  152. :color="label.color"
  153. :background="label.bg_color"
  154. :borderColor="label.border_color"
  155. :circle="label.border_color ? true : false"
  156. :imgSrc="label.icon"
  157. v-for="(label, idx) in item.store_label" :key="idx"></BaseTag>
  158. </view>
  159. </view>
  160. <view class="flex-between-center">
  161. <view class="flex items-baseline">
  162. <baseMoney :money="item.price" symbolSize="24" integerSize="40"
  163. decimalSize="24" weight>
  164. </baseMoney>
  165. </view>
  166. <view class="flex-center w-48 h-48 rd-30rpx bg-color text--w111-fff"
  167. @tap.stop="goCartDuo(item)" v-if="item.spec_type">
  168. <text class="iconfont icon-ic_ShoppingCart1 fs-30"></text>
  169. </view>
  170. <view v-if="!item.spec_type && !item.cart_num">
  171. <view
  172. class="flex-center w-48 h-48 rd-30rpx bg-color text--w111-fff "
  173. @tap.stop="goCartDan(item,index)">
  174. <text class="iconfont icon-ic_ShoppingCart1 fs-30"></text>
  175. </view>
  176. </view>
  177. <view class="flex-y-center" v-if="!item.spec_type && item.cart_num">
  178. <view
  179. class="flex-center w-48 h-48 rd-30rpx bg--w111-f5f5f5 text--w111-333"
  180. @tap.stop="ChangeCartNumDan(false,index,item)">
  181. <text class="iconfont icon-ic_Reduce fs-32"></text>
  182. </view>
  183. <view class="fs-30 text--w111-333 px-20">{{item.cart_num}}</view>
  184. <view class="flex-center w-48 h-48 rd-30rpx bg-color text--w111-fff"
  185. @tap.stop="CartNumAdd(index,item)">
  186. <text class="iconfont icon-ic_increase fs-32"></text>
  187. </view>
  188. </view>
  189. </view>
  190. </view>
  191. </view>
  192. </view>
  193. <view v-if="!tempArr.length && !loading">
  194. <emptyPage title="暂无商品,去看点别的吧~" ></emptyPage>
  195. </view>
  196. <view class="white-box"></view>
  197. </scroll-view>
  198. </view>
  199. </view>
  200. </view>
  201. </view>
  202. <view class="h-96 footer" :class="isFooter == 1 ? 'show-footer' : ''">
  203. <view class="w-100 h-100 rd-50rpx bg-gradient1 flex-center abs-lt top-2 ml--4" @tap="openCart">
  204. <image src="@/static/img/cart_pic.png" class="w-54 h-54"></image>
  205. <uni-badge class="badge-style" :custom-style="{background: 'var(--view-theme)'}" v-if="cartNum > 0" :text="cartNum"></uni-badge>
  206. </view>
  207. <view class="w-710 h-full flex-between-center overflow cart_box" :class="{ open: footerOpen }">
  208. <view class="flex-y-center" @tap="getCartList(0)">
  209. <view class="items-baseline ml-32 inline-flex h-60 lh-60rpx overflow">
  210. <baseMoney :money="totalPrice" symbolSize="32" integerSize="48" decimalSize="32"
  211. incolor="#fff" weight></baseMoney>
  212. <view class="fs-24 text--w111-fff lh-34rpx pl-16" v-show="totalPrice > 0 && !cartData.iScart">查看明细 <text
  213. class="iconfont icon-ic_uparrow fs-24"></text> </view>
  214. </view>
  215. </view>
  216. <view class="w-186 h-72 lh-72rpx text-center rd-40rpx text--w111-fff fs-26 fw-500 bg-gradient1 mr-12"
  217. @tap="subOrder">去结算({{cartNum}})</view>
  218. </view>
  219. </view>
  220. <view class="more_box fixed-lt w-full bg--w111-fff rd-b-32rpx z-20" v-show="showCateDrawer">
  221. <view :style="{paddingTop: sysHeight + 'px'}">
  222. <view class="h-80 px-32 flex-y-center">
  223. <!-- #ifdef MP -->
  224. <view class="flex-1 h-58 flex-y-center rd-30rpx bg--w111-f5f5f5 px-32" @tap="goSearch">
  225. <!-- #endif -->
  226. <!-- #ifndef MP -->
  227. <view class="w-full h-58 flex-y-center rd-30rpx bg--w111-f5f5f5 px-32" @tap="goSearch">
  228. <!-- #endif -->
  229. <text class="iconfont icon-ic_search fs-28"></text>
  230. <text class="fs-24 text--w111-999 pl-18">请输入商品名称</text>
  231. </view>
  232. <!-- 胶囊占据的位置 -->
  233. <!-- #ifdef MP -->
  234. <view class="ml-12" :style="'width:'+getHeight.barWidth+'px'"></view>
  235. <!-- #endif -->
  236. </view>
  237. </view>
  238. <view class="pt-32 pl-30 pr-30">
  239. <view v-if="!topNavShow">
  240. <view class="fs-32 text--w111-333" v-if="categoryList.length">
  241. {{categoryList[navActive].cate_name}}
  242. </view>
  243. <view class="grid-column-4 grid-gap-24rpx mt-24">
  244. <view class="w-154 h-56 rd-30rpx flex-center fs-24 text--w111-333 bg--w111-f5f5f5"
  245. v-for="(item,index) in threeCateList" :key="index"
  246. @tap="threeCateClick(index,item)" :class="index===threeClick?'cate_active':''">
  247. {{item.cate_name}}
  248. </view>
  249. </view>
  250. </view>
  251. <view class="grid-column-5 grid-gap-x-22rpx grid-gap-y-32rpx" v-if="topNavShow">
  252. <view class="flex-col flex-center" v-for="(item,index) in categoryList" :key="index"
  253. @tap="tapNav(index,item)">
  254. <view :class="index == navActive ? 'active_pic' : 'scroll_pic'">
  255. <image :src="item.pic" mode="aspectFill"></image>
  256. </view>
  257. <view class="w-120 h-40 flex-center fs-24 text--w111-333"
  258. :class="index == navActive ? 'active_cate_text' : ''">{{item.cate_name}}</view>
  259. </view>
  260. </view>
  261. <view class="flex-center fs-24 text--w111-999 h-80 mt-32" @tap="closeCateDrawer">
  262. <text>点击收起 <text class="iconfont icon-ic_uparrow pl-4 fs-24"></text> </text>
  263. </view>
  264. </view>
  265. </view>
  266. <view class="mask" v-show="showCateDrawer" @tap="closeCateDrawer" @touchmove.stop.prevent="moveHandle"></view>
  267. <cartList :cartData="cartData" :isFooter='isFooter' @closeList="closeList"
  268. @ChangeCartNumDan="ChangeCartList" @ChangeSubDel="ChangeSubDel" @ChangeOneDel="ChangeOneDel">
  269. </cartList>
  270. <productWindow
  271. :attr="attr"
  272. :isShow='1'
  273. :iSplus='1'
  274. :iScart='1'
  275. :is_vip="is_vip"
  276. :type="2"
  277. @myevent="onMyEvent"
  278. @ChangeAttr="ChangeAttr"
  279. @ChangeCartNum="ChangeCartNumDuo"
  280. @attrVal="attrVal"
  281. @iptCartNum="iptCartNum"
  282. @goCat="goCatNum"
  283. @getImg="showImg"
  284. id='product-window' ></productWindow>
  285. <cusPreviewImg ref="cusPreviewImg" :list="skuArr" @changeSwitch="changeSwitch"></cusPreviewImg>
  286. </view>
  287. </template>
  288. <script>
  289. let windowHeight = uni.getSystemInfoSync().screenHeight;
  290. let sysHeight = uni.getSystemInfoSync().statusBarHeight;
  291. import {
  292. getCategoryList,
  293. getProductslist,
  294. getAttr,
  295. postCartNum
  296. } from '@/api/store.js';
  297. import {
  298. vcartList,
  299. getCartCounts,
  300. cartDel
  301. } from '@/api/order.js';
  302. import productWindow from '@/components/productWindow';
  303. import cusPreviewImg from '@/components/cusPreviewImg';
  304. import cartList from '@/components/cartList';
  305. import {
  306. mapState,
  307. mapGetters
  308. } from 'vuex';
  309. import {
  310. goShopDetail
  311. } from '@/libs/order.js';
  312. import {
  313. toLogin
  314. } from '@/libs/login.js';
  315. import skuSelect from '@/mixins/skuSelect.js'
  316. import emptyPage from '@/components/emptyPage.vue';
  317. export default {
  318. props: {
  319. level: {
  320. type: Number,
  321. default: 2
  322. },
  323. showType:{
  324. type: Number,
  325. default: 2
  326. },
  327. isFooter:{
  328. type: Boolean,
  329. default: false
  330. }
  331. },
  332. data() {
  333. return {
  334. windowHeight: this.isFooter?windowHeight:windowHeight-50,
  335. showCateDrawer: false,
  336. sysHeight: sysHeight,
  337. categoryList: [],
  338. navActive: 0,
  339. categoryTitle: '',
  340. categoryErList: [],
  341. tabLeft: 0,
  342. isWidth: 0, //每个导航栏占位
  343. tabClick: 0, //导航栏被点击
  344. iSlong: false,
  345. tempArr: [],
  346. loading: false,
  347. loadend: false,
  348. loadTitle: '加载更多',
  349. page: 1,
  350. limit: 10,
  351. cid: 0, //一级分类
  352. sid: 0, //二级分类
  353. tid: 0, //三级分类
  354. isAuto: false, //没有授权的不会自动授权
  355. isShowAuth: false, //是否隐藏授权
  356. attr: {
  357. cartAttr: false,
  358. productAttr: [],
  359. productSelect: {}
  360. },
  361. productValue: [],
  362. attrValue: '', //已选属性
  363. storeName: '', //多属性产品名称
  364. id: 0,
  365. cartData: {
  366. cartList: [],
  367. iScart: false
  368. },
  369. totalPrice: 0.00,
  370. lengthCart: 0,
  371. is_vip: 0, //是否是会员
  372. cart_num: 0,
  373. storeInfo: {},
  374. scrollHeight: 0,
  375. threeCateList: [],
  376. threeClick: 0,
  377. topNavShow: true,
  378. selectSku: {},
  379. skuArr: [],
  380. getHeight: this.$util.getWXStatusHeight(),
  381. footerOpen:true,
  382. headerHeight: 0,
  383. conterTop: 0,
  384. scrollTop: 0,
  385. }
  386. },
  387. components: {
  388. productWindow,
  389. cartList,
  390. emptyPage,
  391. cusPreviewImg
  392. },
  393. mixins: [skuSelect],
  394. computed: {
  395. ...mapState({
  396. cartNum: state => state.indexData.cartNum
  397. }),
  398. ...mapGetters(['isLogin', 'uid', 'cartNum', 'diyCategory']),
  399. headerFixed() {
  400. let isFixed = false;
  401. if (this.diyCategory.level == 3 && (this.diyCategory.index == 1 || this.diyCategory.index == 2)) {
  402. isFixed = this.scrollTop > 0;
  403. }
  404. return isFixed;
  405. },
  406. conterFixed() {
  407. let isFixed = false;
  408. if (this.diyCategory.level == 3 && (this.diyCategory.index == 1 || this.diyCategory.index == 2)) {
  409. isFixed = this.scrollTop && this.conterTop <= this.headerHeight;
  410. }
  411. return isFixed;
  412. },
  413. pageHeight() {
  414. let styleObject = {};
  415. if (this.diyCategory.level == 2 && (this.diyCategory.index == 2 || this.diyCategory.index == 3)) {
  416. styleObject['height'] = this.windowHeight + 'px';
  417. }
  418. if (this.diyCategory.level == 3 && (this.diyCategory.index == 1 || this.diyCategory.index == 2)) {
  419. styleObject['min-height'] = this.windowHeight + 'px';
  420. }
  421. return styleObject;
  422. },
  423. },
  424. watch:{
  425. cartNum(){
  426. this.getCartList(1);
  427. }
  428. },
  429. mounted() {
  430. this.getAllCategory();
  431. setTimeout(() => {
  432. this.getScrollHeight();
  433. }, 500);
  434. if(this.isLogin){
  435. this.getCartList(1);
  436. }
  437. uni.$on('newAttrNum', (data) => {
  438. if (data.length) {
  439. this.tempArr.forEach((item) => {
  440. data.forEach(j => {
  441. if (item.id == j.id) {
  442. item.cart_num = j.num
  443. }
  444. })
  445. })
  446. }
  447. })
  448. uni.$on('newCartNum', (data) => {
  449. if (data.length) {
  450. this.tempArr.forEach((item) => {
  451. data.forEach(j => {
  452. if (item.id == j.product_id) {
  453. item.cart_num = 0
  454. }
  455. })
  456. })
  457. }
  458. })
  459. // 三级分类样式2、样式3页面滚动和滚动到底部
  460. if (this.diyCategory.level == 3 && (this.diyCategory.index == 1 || this.diyCategory.index == 2)) {
  461. const query = uni.createSelectorQuery().in(this);
  462. query
  463. .select("#mp-header")
  464. .boundingClientRect((data) => {
  465. this.headerHeight = data.height;
  466. })
  467. .exec();
  468. uni.$on('scroll', (scrollTop) => {
  469. this.scrollTop = scrollTop;
  470. this.footerOpen = false;
  471. query
  472. .select("#conter-box")
  473. .boundingClientRect((data) => {
  474. this.conterTop = data.top;
  475. })
  476. .exec();
  477. })
  478. uni.$on('onReachBottom', () => {
  479. this.productslist();
  480. })
  481. }
  482. },
  483. methods: {
  484. openCart(){
  485. if(this.footerOpen){
  486. this.getCartList(0)
  487. }else{
  488. this.footerOpen = true
  489. }
  490. },
  491. getScrollHeight() {
  492. let sysH = uni.getSystemInfoSync().statusBarHeight;
  493. this.scrollHeight = windowHeight - 138 - sysH;
  494. },
  495. getAllCategory() {
  496. let that = this;
  497. getCategoryList().then(res => {
  498. if (!res.data.length) return
  499. let data = res.data;
  500. that.categoryTitle = data[0].cate_name;
  501. that.cid = data[0].id;
  502. that.sid = data[0].children[0].id;
  503. that.tid = 0;
  504. that.navActive = 0;
  505. that.tabClick = 0;
  506. that.categoryList = data;
  507. that.categoryErList = res.data[0].children ? res.data[0].children : [];
  508. that.threeCateList = res.data[0].children[0].children ? res.data[0].children[0].children : [];
  509. if (this.threeCateList.length) {
  510. this.threeCateList.unshift({
  511. cate_name: '全部商品',
  512. id: 0
  513. })
  514. }
  515. that.page = 1;
  516. that.loadend = false;
  517. that.tempArr = [];
  518. that.productslist();
  519. })
  520. },
  521. // 产品列表
  522. productslist() {
  523. let that = this;
  524. if (that.loadend) return;
  525. if (that.loading) return;
  526. that.loading = true;
  527. that.loadTitle = '';
  528. getProductslist({
  529. page: that.page,
  530. limit: that.limit,
  531. type: 1,
  532. cid: that.cid,
  533. sid: that.sid,
  534. tid: that.tid
  535. }).then(res => {
  536. let list = res.data,
  537. loadend = list.length < that.limit;
  538. that.tempArr = that.$util.SplitArray(list, that.tempArr);
  539. that.$set(that, 'tempArr', that.tempArr);
  540. that.loading = false;
  541. that.loadend = loadend;
  542. that.loadTitle = loadend ? "没有更多内容啦~" : "加载更多";
  543. that.page = that.page + 1;
  544. }).catch(err => {
  545. that.loading = false;
  546. that.loadTitle = '加载更多'
  547. });
  548. },
  549. tapNav(index, item) {
  550. uni.pageScrollTo({
  551. duration: 0,
  552. scrollTop: 0
  553. })
  554. let list = this.categoryList[index];
  555. this.navActive = index;
  556. this.categoryTitle = list.cate_name;
  557. this.categoryErList = item.children ? item.children : [];
  558. this.threeCateList = [];
  559. if (this.categoryErList.length) {
  560. this.threeCateList = item.children[0].children ? item.children[0].children : [];
  561. if (this.threeCateList && !this.haveAll(this.threeCateList)) {
  562. this.threeCateList.unshift({
  563. cate_name: '全部商品',
  564. id: 0
  565. })
  566. }
  567. }
  568. this.tabClick = 0;
  569. this.tabLeft = 0;
  570. this.cid = list.id;
  571. this.sid = list.children[0].id;
  572. this.tid = 0;
  573. this.page = 1;
  574. this.loadend = false;
  575. this.tempArr = [];
  576. this.productslist();
  577. },
  578. // 导航栏点击
  579. longClick(index, item) {
  580. this.tabClick = index; //设置导航点击了哪一个
  581. this.threeClick = 0;
  582. this.sid = this.categoryErList[index].id;
  583. this.tid = 0;
  584. this.threeCateList = item.children && item.children.length ? item.children : [];
  585. if (this.threeCateList && this.threeCateList.length && !this.haveAll(this.threeCateList)) {
  586. this.threeCateList.unshift({
  587. cate_name: '全部商品',
  588. id: 0
  589. })
  590. }
  591. this.page = 1;
  592. this.loadend = false;
  593. this.tempArr = [];
  594. this.productslist();
  595. },
  596. threeCateClick(index, item) {
  597. this.threeClick = index;
  598. this.tid = item.id;
  599. this.page = 1;
  600. this.loadend = false;
  601. this.tempArr = [];
  602. this.productslist();
  603. },
  604. deepClone(obj) {
  605. let newObj = Array.isArray(obj) ? [] : {}
  606. if (obj && typeof obj === "object") {
  607. for (let key in obj) {
  608. if (obj.hasOwnProperty(key)) {
  609. newObj[key] = (obj && typeof obj[key] === 'object') ? this.deepClone(obj[key]) : obj[key];
  610. }
  611. }
  612. }
  613. return newObj
  614. },
  615. haveAll(arr) {
  616. let cloneMap = this.deepClone(arr),
  617. list = [];
  618. cloneMap.forEach(item => {
  619. list.push(item.id);
  620. })
  621. return list.includes(0) ? true : false
  622. },
  623. // 生成订单;
  624. subOrder() {
  625. let that = this,
  626. list = that.cartData.cartList,
  627. ids = [];
  628. if (list.length) {
  629. list.forEach(item => {
  630. if (item.attrStatus && item.status) {
  631. ids.push(item.id)
  632. }
  633. });
  634. uni.navigateTo({
  635. url: '/pages/goods/order_confirm/index?cartId=' + ids.join(',')
  636. });
  637. that.cartData.iScart = false;
  638. } else {
  639. return that.$util.Tips({
  640. title: '请选择产品'
  641. });
  642. }
  643. },
  644. // 计算总价;
  645. getTotalPrice() {
  646. let that = this,
  647. list = that.cartData.cartList,
  648. totalPrice = 0.00;
  649. list.forEach(item => {
  650. if (item.attrStatus && item.status) {
  651. totalPrice = that.$util.$h.Add(totalPrice, that.$util.$h.Mul(item.cart_num, item
  652. .truePrice));
  653. }
  654. })
  655. that.$set(that, 'totalPrice', totalPrice);
  656. },
  657. getCartList(iSshow) {
  658. let that = this;
  659. vcartList().then(res => {
  660. that.$set(that.cartData, 'cartList', res.data);
  661. if (res.data.length) {
  662. that.$set(that.cartData, 'iScart', iSshow ? false : !that.cartData.iScart);
  663. } else {
  664. that.$set(that.cartData, 'iScart', false);
  665. }
  666. if (!res.data.length) {
  667. this.$store.commit('indexData/setCartNum', 0);
  668. this.tempArr.forEach((item) => {
  669. item.cart_num = 0
  670. })
  671. }
  672. that.getTotalPrice();
  673. })
  674. },
  675. getCartNum() {
  676. let that = this;
  677. getCartCounts().then(res => {
  678. this.$store.commit('indexData/setCartNum', res.data.count)
  679. });
  680. },
  681. CartNumAdd(index, item) {
  682. if (item.is_limit && item.cart_num >= item.limit_num) {
  683. this.$util.Tips({
  684. title: "购买最多不能超过" + item.limit_num
  685. });
  686. } else {
  687. this.ChangeCartNumDan(true, index, item);
  688. }
  689. },
  690. // 商品详情接口;
  691. getAttrs(id) {
  692. let that = this;
  693. getAttr(id, 0).then(res => {
  694. // uni.hideLoading();
  695. that.$set(that.attr, 'productAttr', res.data.productAttr);
  696. that.$set(that, 'productValue', res.data.productValue);
  697. that.$set(that, 'is_vip', res.data.storeInfo.is_vip);
  698. that.$set(that, 'storeInfo', res.data.storeInfo);
  699. that.skuArr = [];
  700. for (let key in res.data.productValue) {
  701. let obj = res.data.productValue[key];
  702. that.skuArr.push(obj)
  703. }
  704. if (!that.skuArr.length) {
  705. that.skuArr = [{
  706. image: this.storeInfo.image,
  707. suk: this.storeInfo.store_name,
  708. price: this.storeInfo.price
  709. }];
  710. }
  711. this.$set(this, "selectSku", that.skuArr[0]);
  712. that.DefaultSelect();
  713. })
  714. },
  715. //点击sku图片打开轮播图
  716. showImg(index) {
  717. this.$refs.cusPreviewImg.open(this.selectSku.suk)
  718. },
  719. //滑动轮播图选择商品
  720. changeSwitch(e) {
  721. let productSelect = this.skuArr[e];
  722. this.$set(this, 'selectSku', productSelect);
  723. var skuList = productSelect.suk.split(',');
  724. skuList.forEach((i, index) => {
  725. this.$set(this.attr.productAttr[index], 'index', skuList[index]);
  726. })
  727. if (productSelect) {
  728. this.$set(this.attr.productSelect, 'image', productSelect.image);
  729. this.$set(this.attr.productSelect, 'price', productSelect.price);
  730. this.$set(this.attr.productSelect, 'stock', productSelect.stock);
  731. this.$set(this.attr.productSelect, 'unique', productSelect.unique);
  732. this.$set(this.attr.productSelect, 'cart_num', 1);
  733. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  734. this.$set(this, 'attrValue', productSelect.suk);
  735. this.$set(this, 'attrTxt', '已选择');
  736. }
  737. },
  738. // 去详情页
  739. goDetail(item) {
  740. goShopDetail(item, this.uid).catch(res => {
  741. uni.navigateTo({
  742. url: `/pages/goods_details/index?id=${item.id}&fromType=1`
  743. });
  744. });
  745. },
  746. closeCateDrawer() {
  747. this.showCateDrawer = false;
  748. },
  749. openCateDrawer(type) {
  750. this.topNavShow = type;
  751. this.showCateDrawer = true;
  752. },
  753. lower(e) {
  754. this.productslist();
  755. },
  756. scroll(e) {
  757. this.footerOpen = false;
  758. uni.$emit('scroll');
  759. },
  760. goSearch() {
  761. uni.navigateTo({
  762. url: '/pages/goods/goods_search/index'
  763. })
  764. },
  765. moveHandle() {}
  766. }
  767. }
  768. </script>
  769. <style lang="scss" scoped>
  770. /deep/.base-tag{
  771. background-color: #f5f5f5;
  772. }
  773. .bntCon{
  774. position: relative;
  775. &:before{
  776. position: absolute;
  777. content: '';
  778. width: 6rpx;
  779. height: 80rpx;
  780. background: radial-gradient( rgba(0,0,0,0.082) 0%, rgba(0,0,0,0) 100%);
  781. left:-22rpx;
  782. }
  783. }
  784. .bntAll{
  785. position: relative;
  786. &:before{
  787. position: absolute;
  788. content: '';
  789. width: 6rpx;
  790. height: 136rpx;
  791. background: radial-gradient( rgba(0,0,0,0.082) 0%, rgba(0,0,0,0) 100%);
  792. left:-6rpx;
  793. }
  794. }
  795. .scroll_box {
  796. overflow: hidden;
  797. }
  798. .aside_active {
  799. background-color: #fff;
  800. width: 100%;
  801. text-align: center;
  802. color: var(--view-theme);
  803. font-weight: 500;
  804. position: relative;
  805. &::after {
  806. content: '';
  807. width: 6rpx;
  808. height: 48rpx;
  809. background-color: var(--view-theme);
  810. position: absolute;
  811. left: 0;
  812. top: 50%;
  813. transform: translateY(-50%);
  814. border-radius: 0 10rpx 10rpx 0;
  815. }
  816. .top-ra{
  817. width: 32rpx;
  818. height: 32rpx;
  819. background-color: #fff;
  820. position: absolute;
  821. right: 0;
  822. top:-32rpx;
  823. text{
  824. position: absolute;
  825. top:0;
  826. right: 0;
  827. width: 100%;
  828. height: 100%;
  829. background-color: #f5f5f5;
  830. display: inline-block;
  831. border-radius: 0 0 24rpx 0;
  832. }
  833. }
  834. .bottom-ra{
  835. width: 32rpx;
  836. height: 32rpx;
  837. background-color: #fff;
  838. position: absolute;
  839. right: 0;
  840. bottom:-32rpx;
  841. text{
  842. position: absolute;
  843. top:0;
  844. right: 0;
  845. width: 100%;
  846. height: 100%;
  847. background-color: #f5f5f5;
  848. display: inline-block;
  849. border-radius: 0 24rpx 0 0;
  850. }
  851. }
  852. }
  853. .cate_active {
  854. color: var(--view-theme);
  855. background: var(--view-minorColorT);
  856. border: 1rpx solid var(--view-theme);
  857. }
  858. .footer{
  859. position: fixed;
  860. /* #ifdef H5 */
  861. bottom: 140rpx;
  862. /* #endif */
  863. /* #ifdef MP || APP-PLUS */
  864. bottom: 20px;
  865. /* #endif */
  866. left: 20rpx;
  867. z-index: 101;
  868. }
  869. .cart_box {
  870. width: 0;
  871. height: 96rpx;
  872. border-radius: 48rpx;
  873. background-color: rgba(0, 0, 0, 0.83);
  874. padding-left: 94rpx;
  875. transition: 0.3s;
  876. &.open{
  877. width: 710rpx;
  878. }
  879. }
  880. .show-footer{
  881. /* #ifdef MP || APP-PLUS */
  882. bottom: calc(140rpx + env(safe-area-inset-bottom));
  883. /* #endif */
  884. }
  885. .text-primary-con {
  886. color: var(--view-theme);
  887. }
  888. .bg-primary-light {
  889. background: var(--view-minorColorT);
  890. }
  891. .pl-30 {
  892. padding-left: 30rpx;
  893. }
  894. .border_e {
  895. border-bottom: 1px solid #eee;
  896. }
  897. .active_pic {
  898. width: 104rpx;
  899. height: 104rpx;
  900. background-color: #fff;
  901. padding: 3rpx;
  902. border-radius: 50%;
  903. border: 3rpx solid var(--view-theme);
  904. image {
  905. width: 100%;
  906. height: 100%;
  907. border-radius: 50%;
  908. }
  909. }
  910. .scroll_pic {
  911. image {
  912. width: 92rpx;
  913. height: 92rpx;
  914. border-radius: 50%;
  915. }
  916. }
  917. .active_cate_text {
  918. background: linear-gradient(90deg, var(--view-gradient) 0, var(--view-theme) 100%);
  919. color: #fff;
  920. border-radius: 20rpx;
  921. margin-top: 8rpx;
  922. }
  923. .badge-style {
  924. position: absolute;
  925. top: -2rpx;
  926. right: -14rpx;
  927. /deep/ .uni-badge--error {
  928. background-color: var(--view-theme) !important;
  929. }
  930. .uni-badge {
  931. color: var(--view-theme);
  932. border: 1px solid var(--view-theme);
  933. z-index: 29;
  934. }
  935. }
  936. .white-box{
  937. height: calc(300rpx + env(safe-area-inset-bottom));
  938. }
  939. .mp-header.fixed{
  940. top: 0;
  941. right: 0;
  942. left: 0;
  943. z-index: 10;
  944. background: #FFFFFF;
  945. }
  946. </style>