goods_cate2.vue 30 KB

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