store_cate1.vue 39 KB

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