goods_cate3.vue 31 KB

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