goods_cate2.vue 29 KB

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