goods_cate3.vue 30 KB

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