store_cate1.vue 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376
  1. <template>
  2. <!-- 商品分类第三种布局样式 -->
  3. <view class="goodCate">
  4. <!-- #ifdef MP || APP-PLUS -->
  5. <view class="mp-header">
  6. <view class="sys-head" :style="{ height: sysHeight }"></view>
  7. <view class="serch-box" style="height: 43px;">
  8. <view class="serch-wrapper acea-row row-middle">
  9. <navigator url="/pages/goods/goods_search/index" class="input acea-row row-center-wrapper"
  10. hover-class="none">
  11. <text class="iconfont icon-xiazai5"></text>
  12. 搜索商品信息
  13. </navigator>
  14. </view>
  15. </view>
  16. <!-- 门店地址详情 -->
  17. <view class="store-address">
  18. <view class="address acea-row row-middle" @click="goMap()">
  19. <view class="name line1">{{info.name || '暂无门店'}}</view>
  20. <text class="iconfont icon-xiangyou" />
  21. </view>
  22. <view class="distance">
  23. 门店距您{{info.range||0}}km
  24. </view>
  25. <view class="time">
  26. 营业时间:{{info.day_time || '-'}}
  27. </view>
  28. <view class="switch" :class='switchNum==2?"rightAdd":""'>
  29. <!-- <view class="delivery " :class="switchNum==1?'activeColor':''" @click="swithFn(1)">
  30. 配送
  31. </view> -->
  32. <view class="delivery" :class="switchNum==2?'activeColor2':''" @click="swithFn(2)">
  33. 自提
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 门店详情 -->
  38. </view>
  39. <!-- #endif -->
  40. <!-- #ifdef H5 -->
  41. <view class="header acea-row row-center-wrapper">
  42. <navigator url="/pages/goods/goods_search/index" class="search acea-row row-middle" hover-class="none">
  43. <text class="iconfont icon-sousuo5"></text>
  44. 搜索商品信息
  45. </navigator>
  46. <view class="store-address">
  47. <view class="address acea-row row-middle" @click="goMap()">
  48. <view class="name line1">{{info.name || '暂无门店'}}</view>
  49. <text class="iconfont icon-xiangyou" />
  50. </view>
  51. <view class="distance">
  52. 门店距您{{info.range||0}}km
  53. </view>
  54. <view class="time">
  55. 营业时间:{{info.day_time || '-'}}
  56. </view>
  57. <view class="switch" :class='switchNum==2?"rightAdd":""'>
  58. <view class="delivery " :class="switchNum==1?'activeColor':''" @click="swithFn(1)">
  59. 配送
  60. </view>
  61. <view class="delivery" :class="switchNum==2?'activeColor2':''" @click="swithFn(2)">
  62. 自提
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="conter">
  68. <!-- #endif -->
  69. <!-- #ifndef H5 -->
  70. <view class="conter" :style="'padding-top:'+(marTop+86)+'rpx'">
  71. <!-- #endif -->
  72. <!-- #ifndef H5 -->
  73. <view class='aside'>
  74. <!-- #endif -->
  75. <!-- #ifdef H5 -->
  76. <view class='aside'>
  77. <!-- #endif -->
  78. <view class='item acea-row row-center-wrapper' :class='index==navActive?"on":""'
  79. v-for="(item,index) in categoryList" :key="index" @click="tapNav(index,item)">
  80. <text>{{item.cate_name}}</text>
  81. </view>
  82. </view>
  83. <view class="wrapper">
  84. <view class="bgcolor" v-if="iSlong">
  85. <!-- #ifndef H5 -->
  86. <view class="longTab acea-row row-middle">
  87. <!-- #endif -->
  88. <!-- #ifdef H5 -->
  89. <view class="longTab acea-row row-middle">
  90. <!-- #endif -->
  91. <scroll-view scroll-x="true"
  92. style="white-space: nowrap; display: flex;height:44rpx;" scroll-with-animation
  93. :scroll-left="tabLeft" show-scrollbar="true">
  94. <view class="longItem" :style='"width:"+isWidth+"px"'
  95. :class="index===tabClick?'click':''" v-for="(item,index) in categoryErList"
  96. :key="index" @click="longClick(index)">
  97. {{item.cate_name}}
  98. </view>
  99. </scroll-view>
  100. </view>
  101. <!-- #ifndef H5 -->
  102. <view class="openList" @click="openTap"><text class="iconfont icon-xiangxia"></text>
  103. </view>
  104. <!-- #endif -->
  105. <!-- #ifdef H5 -->
  106. <view class="openList" @click="openTap"><text class="iconfont icon-xiangxia"></text>
  107. </view>
  108. <!-- #endif -->
  109. </view>
  110. <view v-else>
  111. <!-- #ifndef H5 -->
  112. <view class="downTab" :style="'margin-top:'+marTop+'px'">
  113. <!-- #endif -->
  114. <!-- #ifdef H5 -->
  115. <view class="downTab">
  116. <!-- #endif -->
  117. <view class="title acea-row row-between-wrapper">
  118. <view>{{categoryTitle}}</view>
  119. <view class="closeList" @click="closeTap"><text
  120. class="iconfont icon-xiangxia"></text>
  121. </view>
  122. </view>
  123. <view class="children">
  124. <view class="acea-row row-middle">
  125. <view class="item line1" :class="index===tabClick?'click':''"
  126. v-for="(item,index) in categoryErList" :key="index"
  127. @click="longClick(index)">
  128. {{item.cate_name}}
  129. </view>
  130. </view>
  131. </view>
  132. </view>
  133. <view class="mask" @click="closeTap"></view>
  134. </view>
  135. <!--商品列表 -->
  136. <goodClass :tempArr="tempArr" :isLogin="isLogin" @gocartduo="goCartDuo"
  137. @gocartdan="goCartDan" @ChangeCartNumDan="ChangeCartNumDan" @detail="goDetail">
  138. </goodClass>
  139. <view class='loadingicon acea-row row-center-wrapper'>
  140. <text class='loading iconfont icon-jiazai'
  141. :hidden='loading==false'></text>{{loadTitle}}
  142. </view>
  143. </view>
  144. </view>
  145. <view class="footer acea-row row-between-wrapper" :class="isFooter?'':'on'">
  146. <view class="cartIcon acea-row row-center-wrapper" @click="getCartList(0)" v-if="cartNum>0">
  147. <view class="iconfont icon-gouwuche-yangshi2"></view>
  148. <text class="num">{{cartNum}}</text>
  149. </view>
  150. <view class="cartIcon acea-row row-center-wrapper noCart" v-else>
  151. <view class="iconfont icon-gouwuche-yangshi2"></view>
  152. </view>
  153. <view class="acea-row row-middle" :class="cartNum>0?'':'noCart'">
  154. <view class="money">¥<text class="num">{{totalPrice}}</text></view>
  155. <view class="bnt" @click="subOrder">去结算</view>
  156. </view>
  157. </view>
  158. <!-- 分类购物车下拉列表 -->
  159. <cartList :cartData="cartData" @closeList="closeList" @ChangeCartNumDan="ChangeCartList"
  160. @ChangeSubDel="ChangeSubDel" @ChangeOneDel="ChangeOneDel"></cartList>
  161. <!-- 产品属性组件 -->
  162. <productWindow :attr="attr" :isShow='1' :iSplus='1' :iScart='1' @myevent="onMyEvent"
  163. @ChangeAttr="ChangeAttr" @ChangeCartNum="ChangeCartNumDuo" @attrVal="attrVal"
  164. @iptCartNum="iptCartNum" @goCat="goCatNum" :is_vip="is_vip" id='product-window'>
  165. </productWindow>
  166. </view>
  167. </template>
  168. <script>
  169. let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  170. import {
  171. vcartList,
  172. getCartCounts,
  173. cartDel
  174. } from '@/api/order.js';
  175. import {
  176. getCategoryList,
  177. getProductslist,
  178. getAttr,
  179. postCartNum
  180. } from '@/api/store.js';
  181. import {
  182. getProducts,
  183. getCustomerList,
  184. getStoreCategory,
  185. getStoreBrand
  186. } from '@/api/new_store.js';
  187. import productWindow from '@/components/productWindow/index';
  188. import goodClass from '@/components/goodClass';
  189. import cartList from '@/components/cartList';
  190. import {
  191. mapState,
  192. mapGetters
  193. } from 'vuex';
  194. import {
  195. goShopDetail
  196. } from '@/libs/order.js';
  197. import {
  198. toLogin
  199. } from '@/libs/login.js';
  200. export default {
  201. computed: {
  202. ...mapState({
  203. cartNum: state => state.indexData.cartNum
  204. }),
  205. ...mapGetters(['isLogin', 'uid', 'cartNum'])
  206. },
  207. components: {
  208. productWindow,
  209. goodClass,
  210. cartList
  211. },
  212. props: {
  213. isFooter: {
  214. type: Boolean,
  215. default: false
  216. },
  217. info: {
  218. type: Object,
  219. default: {}
  220. },
  221. },
  222. data() {
  223. return {
  224. marTop: 0,
  225. switchNum: 2,
  226. sysHeight: sysHeight,
  227. categoryList: [],
  228. navActive: 0,
  229. categoryTitle: '',
  230. categoryErList: [],
  231. tabLeft: 0,
  232. isWidth: 0, //每个导航栏占位
  233. tabClick: 0, //导航栏被点击
  234. iSlong: true,
  235. tempArr: [],
  236. loading: false,
  237. loadend: false,
  238. loadTitle: '加载更多',
  239. page: 1,
  240. limit: 10,
  241. cid: 0, //一级分类
  242. sid: 0, //二级分类
  243. delivery_type: 2, // 配送方式
  244. isAuto: false, //没有授权的不会自动授权
  245. isShowAuth: false, //是否隐藏授权
  246. attr: {
  247. cartAttr: false,
  248. productAttr: [],
  249. productSelect: {}
  250. },
  251. productValue: [],
  252. attrValue: '', //已选属性
  253. storeName: '', //多属性产品名称
  254. id: 0,
  255. cartData: {
  256. cartList: [],
  257. iScart: false
  258. },
  259. totalPrice: 0.00,
  260. lengthCart: 0,
  261. is_vip: 0, //是否是会员
  262. cart_num: 0,
  263. storeInfo: {},
  264. }
  265. },
  266. mounted() {
  267. let that = this;
  268. // 获取设备宽度
  269. uni.getSystemInfo({
  270. success(e) {
  271. that.isWidth = e.windowWidth / 5
  272. }
  273. });
  274. },
  275. methods: {
  276. updateFun(e) {
  277. if (e.cartNum) {
  278. this.tempArr.forEach((item) => {
  279. if (item.id == e.id) {
  280. item.cart_num = e.cartNum
  281. }
  282. })
  283. }
  284. },
  285. // 商品列表
  286. getProducts(flag) {
  287. let that = this;
  288. if (flag === true) {
  289. that.tempArr = []
  290. }
  291. getProducts({
  292. page: that.page,
  293. limit: that.limit,
  294. type: 1,
  295. cid: that.cid,
  296. sid: that.sid,
  297. store_id: that.info.id,
  298. delivery_type: that.delivery_type,
  299. }).then(res => {
  300. console.log(res, 'res')
  301. let list = res.data,
  302. loadend = list.length < that.limit;
  303. that.tempArr = that.$util.SplitArray(list, that.tempArr);
  304. that.$set(that, 'tempArr', that.tempArr);
  305. that.loading = false;
  306. that.loadend = loadend;
  307. that.loadTitle = loadend ? "没有更多内容啦~" : "加载更多";
  308. that.page = that.page + 1;
  309. }).catch(err => {
  310. that.loading = false;
  311. that.loadTitle = '加载更多'
  312. });
  313. },
  314. // 切换自提方式
  315. swithFn(num) {
  316. switch (num) {
  317. case 1:
  318. this.switchNum = 1
  319. this.delivery_type = '3'
  320. this.page = 1
  321. break;
  322. case 2:
  323. this.switchNum = 2
  324. this.delivery_type = '2'
  325. this.page = 1
  326. break;
  327. }
  328. this.getProducts(true)
  329. },
  330. // 跳转到门店列表
  331. goMap() {
  332. uni.navigateTo({
  333. url: "/pages/store/map/index?type=1&storeId=" + this.info.id,
  334. success(res) {
  335. console.log('成功啦', res);
  336. },
  337. fail(err) {
  338. console.log('失败啦', err);
  339. }
  340. })
  341. },
  342. getMarTop() {
  343. // #ifdef MP || APP-PLUS
  344. let that = this;
  345. setTimeout(() => {
  346. // 获取小程序头部高度
  347. let info = uni.createSelectorQuery().in(this).select(".mp-header");
  348. info.boundingClientRect(function(data) {
  349. that.marTop = data.height
  350. }).exec()
  351. }, 100)
  352. // #endif
  353. },
  354. // 生成订单;
  355. subOrder: function() {
  356. let that = this,
  357. delivery_type = 1,
  358. list = that.cartData.cartList,
  359. ids = [];
  360. if (list.length) {
  361. list.forEach(item => {
  362. ids.push(item.id)
  363. delivery_type = item.productInfo.delivery_type[0]
  364. });
  365. uni.navigateTo({
  366. url: '/pages/goods/order_confirm/index?cartId=' + ids.join(',') + '&delivery_type=' +
  367. delivery_type
  368. });
  369. that.cartData.iScart = false;
  370. } else {
  371. return that.$util.Tips({
  372. title: '请选择产品'
  373. });
  374. }
  375. },
  376. // 计算总价;
  377. getTotalPrice: function() {
  378. let that = this,
  379. list = that.cartData.cartList,
  380. totalPrice = 0.00;
  381. list.forEach(item => {
  382. if (item.attrStatus && item.status) {
  383. totalPrice = that.$util.$h.Add(totalPrice, that.$util.$h.Mul(item.cart_num, item
  384. .truePrice));
  385. }
  386. })
  387. that.$set(that, 'totalPrice', totalPrice);
  388. },
  389. ChangeSubDel: function(event) {
  390. let that = this,
  391. list = that.cartData.cartList,
  392. ids = [];
  393. list.forEach(item => {
  394. ids.push(item.id)
  395. });
  396. cartDel(ids.join(",")).then(res => {
  397. that.$set(that.cartData, 'cartList', []);
  398. that.cartData.iScart = false;
  399. that.totalPrice = 0.00;
  400. that.page = 1;
  401. that.loadend = false;
  402. that.tempArr = [];
  403. that.productslist();
  404. that.getCartNum();
  405. })
  406. },
  407. ChangeOneDel: function(id, index) {
  408. let that = this,
  409. list = that.cartData.cartList;
  410. cartDel(id.toString()).then(res => {
  411. list.splice(index, 1);
  412. if (!list.length) {
  413. that.cartData.iScart = false;
  414. that.page = 1;
  415. that.loadend = false;
  416. that.tempArr = [];
  417. that.productslist();
  418. };
  419. that.getCartNum();
  420. })
  421. },
  422. getCartList(iSshow) {
  423. let that = this;
  424. vcartList().then(res => {
  425. that.$set(that.cartData, 'cartList', res.data);
  426. if (res.data.length) {
  427. that.$set(that.cartData, 'iScart', iSshow ? false : !that.cartData.iScart);
  428. } else {
  429. that.$set(that.cartData, 'iScart', false);
  430. }
  431. that.getTotalPrice();
  432. })
  433. },
  434. closeList(e) {
  435. this.$set(this.cartData, 'iScart', e);
  436. // this.page = 1;
  437. // this.loadend = false;
  438. // this.tempArr = [];
  439. // this.productslist();
  440. },
  441. getCartNum: function() {
  442. let that = this;
  443. getCartCounts().then(res => {
  444. this.$store.commit('indexData/setCartNum', res.data.count > 99 ? '..' : res.data.count)
  445. });
  446. },
  447. onMyEvent: function() {
  448. this.$set(this.attr, 'cartAttr', false);
  449. },
  450. /**
  451. * 默认选中属性
  452. *
  453. */
  454. DefaultSelect: function() {
  455. let productAttr = this.attr.productAttr;
  456. let value = [];
  457. for (let key in this.productValue) {
  458. if (this.productValue[key].stock > 0) {
  459. value = this.attr.productAttr.length ? key.split(",") : [];
  460. break;
  461. }
  462. }
  463. for (let i = 0; i < productAttr.length; i++) {
  464. this.$set(productAttr[i], "index", value[i]);
  465. }
  466. //sort();排序函数:数字-英文-汉字;
  467. let productSelect = this.productValue[value.join(",")];
  468. if (productSelect && productAttr.length) {
  469. this.$set(
  470. this.attr.productSelect,
  471. "store_name",
  472. this.storeName
  473. );
  474. this.$set(this.attr.productSelect, "image", productSelect.image);
  475. this.$set(this.attr.productSelect, "price", productSelect.price);
  476. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  477. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  478. this.$set(this.attr.productSelect, "cart_num", 1);
  479. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  480. this.$set(this, "attrValue", value.join(","));
  481. } else if (!productSelect && productAttr.length) {
  482. this.$set(
  483. this.attr.productSelect,
  484. "store_name",
  485. this.storeName
  486. );
  487. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  488. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  489. this.$set(this.attr.productSelect, "stock", 0);
  490. this.$set(this.attr.productSelect, "unique", "");
  491. this.$set(this.attr.productSelect, "cart_num", 0);
  492. this.$set(this, "attrValue", "");
  493. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  494. } else if (!productSelect && !productAttr.length) {
  495. this.$set(
  496. this.attr.productSelect,
  497. "store_name",
  498. this.storeName
  499. );
  500. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  501. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  502. this.$set(this.attr.productSelect, "stock", this.storeInfo.stock);
  503. this.$set(
  504. this.attr.productSelect,
  505. "unique",
  506. this.storeInfo.unique || ""
  507. );
  508. this.$set(this.attr.productSelect, "cart_num", 1);
  509. this.$set(this, "attrValue", "");
  510. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  511. }
  512. },
  513. /**
  514. * 属性变动赋值
  515. *
  516. */
  517. ChangeAttr: function(res) {
  518. let productSelect = this.productValue[res];
  519. if (productSelect && productSelect.stock > 0) {
  520. this.$set(this.attr.productSelect, "image", productSelect.image);
  521. this.$set(this.attr.productSelect, "price", productSelect.price);
  522. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  523. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  524. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  525. this.$set(this.attr.productSelect, "cart_num", 1);
  526. this.$set(this, "attrValue", res);
  527. } else if (productSelect && productSelect.stock == 0) {
  528. this.$set(this.attr.productSelect, "image", productSelect.image);
  529. this.$set(this.attr.productSelect, "price", productSelect.price);
  530. this.$set(this.attr.productSelect, "stock", 0);
  531. this.$set(this.attr.productSelect, "unique", "");
  532. this.$set(this.attr.productSelect, 'vip_price', productSelect.vip_price);
  533. this.$set(this.attr.productSelect, "cart_num", 0);
  534. this.$set(this, "attrValue", "");
  535. } else {
  536. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  537. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  538. this.$set(this.attr.productSelect, "stock", 0);
  539. this.$set(this.attr.productSelect, "unique", "");
  540. this.$set(this.attr.productSelect, 'vip_price', this.storeInfo.vip_price);
  541. this.$set(this.attr.productSelect, "cart_num", 0);
  542. this.$set(this, "attrValue", "");
  543. }
  544. },
  545. attrVal(val) {
  546. this.$set(this.attr.productAttr[val.indexw], 'index', this.attr.productAttr[val.indexw].attr_values[val
  547. .indexn]);
  548. },
  549. /**
  550. * 购物车手动填写
  551. *
  552. */
  553. iptCartNum: function(e) {
  554. this.$set(this.attr.productSelect, 'cart_num', e);
  555. },
  556. onLoadFun() {},
  557. // 产品列表
  558. // 点击默认单属性购物车
  559. goCartDan(item, index) {
  560. if (!this.isLogin) {
  561. this.getIsLogin();
  562. } else {
  563. this.tempArr[index].cart_num = 1;
  564. this.$set(this, 'tempArr', this.tempArr);
  565. this.goCat(0, item.id, 1);
  566. }
  567. },
  568. // 改变单属性购物车
  569. ChangeCartNumDan(changeValue, index, item) {
  570. let num = this.tempArr[index];
  571. let stock = this.tempArr[index].stock;
  572. this.ChangeCartNum(changeValue, num, stock, 0, item.id);
  573. },
  574. // 改变多属性购物车
  575. ChangeCartNumDuo(changeValue) {
  576. //获取当前变动属性
  577. let productSelect = this.productValue[this.attrValue];
  578. //如果没有属性,赋值给商品默认库存
  579. if (productSelect === undefined && !this.attr.productAttr.length)
  580. productSelect = this.attr.productSelect;
  581. //无属性值即库存为0;不存在加减;
  582. if (productSelect === undefined) return;
  583. let stock = productSelect.stock || 0;
  584. let num = this.attr.productSelect;
  585. this.ChangeCartNum(changeValue, num, stock, 1, this.id);
  586. },
  587. // 已经加入购物车时的购物加减;
  588. ChangeCartList(changeValue, index) {
  589. let list = this.cartData.cartList;
  590. let num = list[index];
  591. let stock = list[index].trueStock;
  592. this.ChangeCartNum(changeValue, num, stock, 0, num.product_id, index, 1);
  593. if (!list.length) {
  594. this.cartData.iScart = false;
  595. this.page = 1;
  596. this.loadend = false;
  597. this.tempArr = [];
  598. this.productslist();
  599. }
  600. },
  601. // 购物车加减计算函数
  602. ChangeCartNum(changeValue, num, stock, isDuo, id, index, cart) {
  603. if (changeValue) {
  604. num.cart_num++;
  605. if (num.cart_num > stock) {
  606. if (isDuo) {
  607. this.$set(this.attr.productSelect, "cart_num", stock ? stock : 1);
  608. this.$set(this, "cart_num", stock ? stock : 1);
  609. } else {
  610. num.cart_num = stock ? stock : 0;
  611. this.$set(this, 'tempArr', this.tempArr);
  612. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  613. }
  614. return this.$util.Tips({
  615. title: "该产品没有更多库存了"
  616. });
  617. } else {
  618. if (!isDuo) {
  619. if (cart) {
  620. this.goCat(0, id, 1, 1, num.product_attr_unique);
  621. this.getTotalPrice();
  622. } else {
  623. this.goCat(0, id, 1);
  624. }
  625. }
  626. }
  627. } else {
  628. num.cart_num--;
  629. if (num.cart_num == 0) {
  630. this.cartData.cartList.splice(index, 1);
  631. if (isDuo) {
  632. this.$set(this.attr.productSelect, "cart_num", 1);
  633. this.$set(this, "cart_num", 1);
  634. }
  635. }
  636. if (num.cart_num < 0) {
  637. if (isDuo) {
  638. this.$set(this.attr.productSelect, "cart_num", 1);
  639. this.$set(this, "cart_num", 1);
  640. } else {
  641. num.cart_num = 0;
  642. this.$set(this, 'tempArr', this.tempArr);
  643. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  644. }
  645. } else {
  646. if (!isDuo) {
  647. if (cart) {
  648. this.goCat(0, id, 0, 1, num.product_attr_unique);
  649. this.getTotalPrice();
  650. } else {
  651. this.goCat(0, id, 0);
  652. }
  653. }
  654. }
  655. }
  656. this.tempArr.forEach((item) => {
  657. if (item.id == id) {
  658. item.cart_num = num.cart_num;
  659. }
  660. })
  661. },
  662. // 多规格加入购物车;
  663. goCatNum() {
  664. this.goCat(1, this.id, 1);
  665. },
  666. /*
  667. * 加入购物车
  668. */
  669. goCat: function(duo, id, type, cart, unique) {
  670. let that = this;
  671. if (duo) {
  672. let productSelect = that.productValue[this.attrValue];
  673. //如果有属性,没有选择,提示用户选择
  674. if (
  675. that.attr.productAttr.length &&
  676. productSelect === undefined
  677. )
  678. return that.$util.Tips({
  679. title: "产品库存不足,请选择其它属性"
  680. });
  681. }
  682. let q = {
  683. product_id: id,
  684. num: duo ? that.attr.productSelect.cart_num : 1,
  685. type: type,
  686. unique: duo ? that.attr.productSelect.unique : cart ? unique : ""
  687. };
  688. postCartNum(q)
  689. .then(function(res) {
  690. if (duo) {
  691. that.attr.cartAttr = false;
  692. that.$util.Tips({
  693. title: "添加购物车成功"
  694. });
  695. // that.page = 1;
  696. // that.loadend = false;
  697. that.tempArr.forEach((item, index) => {
  698. if (item.id == that.id) {
  699. let arrtStock = that.attr.productSelect.stock
  700. let objNum = parseInt(item.cart_num) + parseInt(that.attr.productSelect
  701. .cart_num);
  702. item.cart_num = objNum > arrtStock ? arrtStock : objNum
  703. }
  704. })
  705. // that.productslist();
  706. }
  707. that.getCartNum();
  708. if (!cart) {
  709. that.getCartList(1);
  710. }
  711. })
  712. .catch(err => {
  713. return that.$util.Tips({
  714. title: err
  715. });
  716. });
  717. },
  718. goCartDuo(item) {
  719. if (!this.isLogin) {
  720. this.getIsLogin();
  721. } else {
  722. uni.showLoading({
  723. title: '加载中'
  724. });
  725. this.storeName = item.store_name;
  726. this.getAttrs(item.id);
  727. this.$set(this, 'id', item.id);
  728. this.$set(this.attr, 'cartAttr', true);
  729. }
  730. },
  731. getIsLogin() {
  732. toLogin();
  733. },
  734. // 商品详情接口;
  735. getAttrs(id) {
  736. let that = this;
  737. getAttr(id, 0).then(res => {
  738. uni.hideLoading();
  739. that.$set(that.attr, 'productAttr', res.data.productAttr);
  740. that.$set(that, 'productValue', res.data.productValue);
  741. that.$set(that, 'is_vip', res.data.storeInfo.is_vip);
  742. that.$set(that, 'storeInfo', res.data.storeInfo);
  743. that.DefaultSelect();
  744. })
  745. },
  746. // 去详情页
  747. goDetail(item) {
  748. goShopDetail(item, this.uid).then(res => {
  749. uni.navigateTo({
  750. url: `/pages/goods_details/index?id=${item.id}&fromType=1`
  751. });
  752. });
  753. },
  754. openTap() {
  755. this.iSlong = false
  756. },
  757. closeTap() {
  758. this.iSlong = true
  759. },
  760. // 分类数据
  761. getAllCategory: function() {
  762. let that = this;
  763. getStoreCategory().then(res => {
  764. let data = res.data;
  765. data.forEach(item => {
  766. item.children.unshift({
  767. 'id': 0,
  768. 'cate_name': '全部'
  769. })
  770. })
  771. that.categoryTitle = data[0].cate_name;
  772. that.cid = data[0].id;
  773. that.sid = 0;
  774. that.navActive = 0;
  775. that.tabClick = 0;
  776. that.categoryList = data;
  777. that.categoryErList = res.data[0].children ? res.data[0].children : [];
  778. that.page = 1;
  779. that.loadend = false;
  780. that.tempArr = [];
  781. that.getProducts();
  782. })
  783. },
  784. tapNav(index, item) {
  785. uni.pageScrollTo({
  786. duration: 0,
  787. scrollTop: 0
  788. })
  789. let list = this.categoryList[index];
  790. this.navActive = index;
  791. this.categoryTitle = list.cate_name;
  792. this.categoryErList = item.children ? item.children : [];
  793. this.tabClick = 0;
  794. this.tabLeft = 0;
  795. this.cid = list.id;
  796. this.sid = 0;
  797. this.page = 1;
  798. this.loadend = false;
  799. this.tempArr = [];
  800. this.getProducts();
  801. },
  802. // 导航栏点击
  803. longClick(index) {
  804. if (this.categoryErList.length > 3) {
  805. this.tabLeft = (index - 1) * (this.isWidth + 6) //设置下划线位置
  806. };
  807. this.tabClick = index; //设置导航点击了哪一个
  808. this.iSlong = true;
  809. this.sid = this.categoryErList[index].id;
  810. this.page = 1;
  811. this.loadend = false;
  812. this.tempArr = [];
  813. this.getProducts();
  814. },
  815. },
  816. onReachBottom: function() {
  817. this.getProducts();
  818. }
  819. }
  820. </script>
  821. <style lang="scss">
  822. /* #ifdef MP || APP-PLUS */
  823. .mp-header {
  824. z-index: 30;
  825. position: fixed;
  826. left: 0;
  827. top: 0;
  828. width: 100%;
  829. background: #fff;
  830. border-bottom: 1px solid #F0F0F0;
  831. .serch-wrapper {
  832. height: 100%;
  833. /* #ifdef MP */
  834. padding: 0 220rpx 0 53rpx;
  835. /* #endif */
  836. /* #ifdef APP-PLUS */
  837. padding: 0 50rpx 0 40rpx;
  838. /* #endif */
  839. .input {
  840. flex: 1;
  841. height: 55rpx;
  842. padding: 0 0 0 30rpx;
  843. background: #F8F8F8;
  844. color: #ADADAD;
  845. font-size: 26rpx;
  846. /* #ifdef MP */
  847. width: 70%;
  848. /* #endif */
  849. /* #ifdef APP-PLUS */
  850. width: 100%;
  851. /* #endif */
  852. border-radius: 50rpx;
  853. .iconfont {
  854. margin-right: 20rpx;
  855. }
  856. }
  857. }
  858. }
  859. /* #endif */
  860. page {
  861. background-color: #fff;
  862. }
  863. /deep/.product-window.joinCart {
  864. z-index: 999;
  865. }
  866. ::-webkit-scrollbar {
  867. width: 0;
  868. height: 0;
  869. color: transparent;
  870. display: none;
  871. }
  872. .goodCate {
  873. /deep/.mask {
  874. z-index: 99;
  875. }
  876. /deep/.attrProduct {
  877. .mask {
  878. z-index: 100;
  879. }
  880. }
  881. .header {
  882. position: fixed;
  883. height: 128rpx;
  884. background-color: #fff;
  885. top: 0;
  886. left: 0;
  887. width: 100%;
  888. z-index: 99;
  889. border-bottom: 1px solid #eee;
  890. /* #ifdef H5 */
  891. padding-top: 20rpx;
  892. /* #endif */
  893. .pageIndex {
  894. width: 68rpx;
  895. height: 68rpx;
  896. border-radius: 50%;
  897. background-color: #F7F7F7;
  898. .iconfont {
  899. color: #666666;
  900. font-size: 30rpx;
  901. }
  902. // image{
  903. // width: 29rpx;
  904. // height: 30rpx;
  905. // }
  906. }
  907. .search {
  908. width: 690rpx;
  909. height: 68rpx;
  910. border-radius: 36rpx;
  911. background-color: #F7F7F7;
  912. font-size: 26rpx;
  913. color: #cccccc;
  914. padding: 0 30rpx;
  915. box-sizing: border-box;
  916. .iconfont {
  917. font-size: 30rpx;
  918. margin-right: 18rpx;
  919. color: #666666;
  920. }
  921. }
  922. }
  923. .conter {
  924. /* #ifdef H5 */
  925. padding-top: 128rpx;
  926. /* #endif */
  927. height: 100vh;
  928. background-color: #fff;
  929. .aside {
  930. position: fixed;
  931. width: 23%;
  932. left: 0;
  933. bottom: 0;
  934. /* #ifdef H5 */
  935. top: 302rpx;
  936. /* #endif */
  937. /* #ifndef H5 */
  938. top: 316rpx;
  939. /* #endif */
  940. background-color: #F7F7F7;
  941. overflow-y: auto;
  942. overflow-x: hidden;
  943. /* #ifdef H5 */
  944. // margin-top: 128rpx;
  945. /* #endif */
  946. z-index: 99;
  947. padding-bottom: 194rpx;
  948. .item {
  949. height: 100rpx;
  950. width: 100%;
  951. font-size: 26rpx;
  952. color: #333333;
  953. &.on {
  954. background-color: #FFFFFF;
  955. width: 100%;
  956. text-align: center;
  957. color: var(--view-theme);
  958. font-weight: 500;
  959. position: relative;
  960. &::after {
  961. content: "";
  962. position: absolute;
  963. width: 6rpx;
  964. height: 46rpx;
  965. background: var(--view-theme);
  966. border-radius: 0 4rpx 4rpx 0;
  967. left: 0
  968. }
  969. }
  970. }
  971. }
  972. .wrapper {
  973. margin-top: 160rpx;
  974. padding-bottom: 250rpx;
  975. /* #ifdef H5 */
  976. margin-top: 50rpx;
  977. padding-bottom: 200rpx;
  978. /* #endif */
  979. width: 77%;
  980. float: right;
  981. background-color: #FFFFFF;
  982. // padding-bottom: 240rpx;
  983. .bgcolor {
  984. width: 100%;
  985. background-color: #FFFFFF;
  986. }
  987. // .goodsList {
  988. // margin-top: 0 !important;
  989. // }
  990. .mask {
  991. z-index: 9;
  992. }
  993. .longTab {
  994. width: 65%;
  995. position: fixed;
  996. top: 316rpx;
  997. /* #ifdef H5 */
  998. top: 302rpx;
  999. // margin-top: 128rpx;
  1000. /* #endif */
  1001. height: 100rpx;
  1002. z-index: 99;
  1003. background-color: #FFFFFF;
  1004. .longItem {
  1005. height: 44rpx;
  1006. display: inline-block;
  1007. line-height: 44rpx;
  1008. text-align: center;
  1009. font-size: 26rpx;
  1010. overflow: hidden;
  1011. text-overflow: ellipsis;
  1012. white-space: nowrap;
  1013. color: #333333;
  1014. background-color: #F7F7F7;
  1015. border-radius: 22rpx;
  1016. margin-left: 12rpx;
  1017. &.click {
  1018. font-weight: bold;
  1019. background-color: var(--view-theme);
  1020. color: #ffffff;
  1021. }
  1022. }
  1023. .underlineBox {
  1024. height: 3px;
  1025. width: 20%;
  1026. display: flex;
  1027. align-content: center;
  1028. justify-content: center;
  1029. transition: .5s;
  1030. .underline {
  1031. width: 33rpx;
  1032. height: 4rpx;
  1033. background-color: #FFFFFF;
  1034. }
  1035. }
  1036. }
  1037. .openList {
  1038. width: 12%;
  1039. height: 100rpx;
  1040. background-color: #FFFFFF;
  1041. line-height: 100rpx;
  1042. padding-left: 30rpx;
  1043. position: fixed;
  1044. right: 0;
  1045. top: 316rpx;
  1046. /* #ifdef H5 */
  1047. top: 302rpx;
  1048. right: 2rpx;
  1049. /* #endif */
  1050. z-index: 99;
  1051. .iconfont {
  1052. font-size: 22rpx;
  1053. color: #666666;
  1054. }
  1055. }
  1056. .downTab {
  1057. width: 78%;
  1058. position: fixed;
  1059. top: 0rpx;
  1060. /* #ifdef H5 */
  1061. top: 302rpx;
  1062. /* #endif */
  1063. z-index: 102;
  1064. background-color: #FFFFFF;
  1065. .title {
  1066. height: 100rpx;
  1067. font-size: 26rpx;
  1068. color: #999999;
  1069. padding-left: 20rpx;
  1070. .closeList {
  1071. width: 90rpx;
  1072. height: 100%;
  1073. line-height: 100rpx;
  1074. padding-left: 30rpx;
  1075. transform: rotate(180deg);
  1076. .iconfont {
  1077. font-size: 22rpx;
  1078. color: #666666;
  1079. }
  1080. }
  1081. }
  1082. .children {
  1083. max-height: 500rpx;
  1084. overflow-x: hidden;
  1085. overflow-y: auto;
  1086. padding-bottom: 20rpx;
  1087. .item {
  1088. height: 60rpx;
  1089. background-color: #F7F7F7;
  1090. border-radius: 30rpx;
  1091. line-height: 60rpx;
  1092. padding: 0 15rpx;
  1093. margin: 0 0 20rpx 20rpx;
  1094. width: 165rpx;
  1095. text-align: center;
  1096. &.click {
  1097. font-weight: bold;
  1098. background-color: var(--view-theme);
  1099. color: #ffffff;
  1100. }
  1101. }
  1102. }
  1103. }
  1104. .goodsList {
  1105. margin-top: 0rpx;
  1106. padding: 0 30rpx 0 20rpx;
  1107. /* #ifdef H5 */
  1108. margin-top: 228rpx;
  1109. /* #endif */
  1110. /deep/.item {
  1111. margin-bottom: 33rpx !important;
  1112. // .pictrue {
  1113. // height: 216rpx;
  1114. // }
  1115. .text {
  1116. font-size: 26rpx;
  1117. }
  1118. .bottom {
  1119. .sales {
  1120. .money {
  1121. font-size: 34rpx;
  1122. text {
  1123. font-size: 26rpx;
  1124. }
  1125. }
  1126. }
  1127. .cart {
  1128. .pictrue {
  1129. width: 50rpx;
  1130. height: 50rpx;
  1131. }
  1132. }
  1133. }
  1134. }
  1135. }
  1136. }
  1137. }
  1138. .store-address {
  1139. width: 100%;
  1140. margin-top: 15rpx;
  1141. position: relative;
  1142. padding: 0rpx 30rpx 0 30rpx;
  1143. height: 185rpx;
  1144. /* #ifdef H5 */
  1145. height: 200rpx;
  1146. /* #endif */
  1147. background-color: #fff;
  1148. .address {
  1149. font-size: 32rpx;
  1150. font-weight: 500;
  1151. color: #333333;
  1152. .name {
  1153. max-width: 400rpx;
  1154. }
  1155. .icon-xiangyou {
  1156. font-size: 24rpx;
  1157. margin-left: 10rpx;
  1158. }
  1159. }
  1160. .distance {
  1161. margin-top: 24rpx;
  1162. font-size: 24rpx;
  1163. font-weight: 400;
  1164. color: #999999;
  1165. }
  1166. .time {
  1167. margin-top: 24rpx;
  1168. font-size: 24rpx;
  1169. font-weight: 400;
  1170. color: #333333;
  1171. }
  1172. .activeColor {
  1173. position: absolute;
  1174. right: 45px;
  1175. background-color: var(--view-theme) !important;
  1176. color: #fff !important;
  1177. }
  1178. .activeColor2 {
  1179. position: absolute;
  1180. left: 47px;
  1181. /* #ifdef H5 */
  1182. left: 40px;
  1183. /* #endif */
  1184. background-color: var(--view-theme) !important;
  1185. color: #fff !important;
  1186. }
  1187. .rightAdd {
  1188. right: 110rpx !important;
  1189. }
  1190. .switch {
  1191. position: absolute;
  1192. top: 15rpx;
  1193. /* #ifdef H5 */
  1194. top: 20rpx;
  1195. /* #endif */
  1196. right: 30rpx;
  1197. .delivery {
  1198. display: inline-block;
  1199. width: 100rpx;
  1200. height: 50rpx;
  1201. background: #F5F5F5;
  1202. border-radius: 33rpx;
  1203. text-align: center;
  1204. line-height: 50rpx;
  1205. font-size: 26rpx;
  1206. font-weight: 400;
  1207. color: #999999;
  1208. }
  1209. }
  1210. }
  1211. .footer {
  1212. width: 100%;
  1213. position: fixed;
  1214. left: 0;
  1215. background-color: #fff;
  1216. box-shadow: 0px -3px 16px rgba(36, 12, 12, 0.05);
  1217. z-index: 101;
  1218. padding-left: 30rpx;
  1219. box-sizing: border-box;
  1220. height: 100rpx;
  1221. bottom: 98rpx;
  1222. bottom: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  1223. bottom: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  1224. &.on {
  1225. // #ifndef H5
  1226. bottom: 0rpx;
  1227. // #endif
  1228. }
  1229. .cartIcon {
  1230. width: 80rpx;
  1231. height: 80rpx;
  1232. border-radius: 50%;
  1233. position: relative;
  1234. margin-top: -36rpx;
  1235. .iconfont {
  1236. font-size: 94rpx;
  1237. margin-top: 12rpx;
  1238. color: var(--view-theme);
  1239. }
  1240. &.noCart {
  1241. .iconfont {
  1242. color: #CBCBCB;
  1243. }
  1244. }
  1245. .num {
  1246. min-width: 14rpx;
  1247. background-color: #fff;
  1248. color: var(--view-theme);
  1249. border-radius: 15px;
  1250. position: absolute;
  1251. right: -10rpx;
  1252. top: 20rpx;
  1253. font-size: 20rpx;
  1254. padding: 0 10rpx;
  1255. border: 1px solid var(--view-theme);
  1256. }
  1257. }
  1258. .money {
  1259. font-size: 26rpx;
  1260. font-weight: bold;
  1261. color: var(--view-priceColor);
  1262. margin-right: 34rpx;
  1263. .num {
  1264. font-size: 34rpx;
  1265. }
  1266. }
  1267. .bnt {
  1268. width: 192rpx;
  1269. height: 76rpx;
  1270. background-color: var(--view-theme);
  1271. border-radius: 46px;
  1272. line-height: 76rpx;
  1273. text-align: center;
  1274. color: #fff;
  1275. font-size: 28rpx;
  1276. margin-right: 30rpx;
  1277. }
  1278. .noCart {
  1279. .money {
  1280. color: #CBCBCB;
  1281. }
  1282. .bnt {
  1283. background-color: #CBCBCB;
  1284. }
  1285. }
  1286. }
  1287. }
  1288. </style>