goods_cate2.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209
  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. }).then(res => {
  505. let list = res.data,
  506. loadend = list.length < that.limit;
  507. that.tempArr = that.$util.SplitArray(list, that.tempArr);
  508. that.$set(that, 'tempArr', that.tempArr);
  509. that.loading = false;
  510. that.loadend = loadend;
  511. that.loadTitle = loadend ? "没有更多内容啦~" : "加载更多";
  512. that.page = that.page + 1;
  513. }).catch(err => {
  514. that.loading = false;
  515. that.loadTitle = '加载更多'
  516. });
  517. },
  518. // 点击默认单属性购物车
  519. goCartDan(item, index) {
  520. if (!this.isLogin) {
  521. this.getIsLogin();
  522. } else {
  523. this.tempArr[index].cart_num = 1;
  524. this.$set(this, 'tempArr', this.tempArr);
  525. this.goCat(0, item.id, 1);
  526. }
  527. },
  528. // 改变单属性购物车
  529. ChangeCartNumDan(changeValue, index, item) {
  530. let num = this.tempArr[index];
  531. let stock = this.tempArr[index].stock;
  532. this.ChangeCartNum(changeValue, num, stock, 0, item.id);
  533. },
  534. // 改变多属性购物车
  535. ChangeCartNumDuo(changeValue) {
  536. //获取当前变动属性
  537. let productSelect = this.productValue[this.attrValue];
  538. //如果没有属性,赋值给商品默认库存
  539. if (productSelect === undefined && !this.attr.productAttr.length)
  540. productSelect = this.attr.productSelect;
  541. //无属性值即库存为0;不存在加减;
  542. if (productSelect === undefined) return;
  543. let stock = productSelect.stock || 0;
  544. let num = this.attr.productSelect;
  545. this.ChangeCartNum(changeValue, num, stock, 1);
  546. },
  547. // 已经加入购物车时的购物加减;
  548. ChangeCartList(changeValue, index) {
  549. let list = this.cartData.cartList;
  550. let num = list[index];
  551. let stock = list[index].trueStock;
  552. this.ChangeCartNum(changeValue, num, stock, 0, num.product_id, index, 1);
  553. if (!list.length) {
  554. this.cartData.iScart = false;
  555. this.page = 1;
  556. this.loadend = false;
  557. this.tempArr = [];
  558. this.productslist();
  559. }
  560. },
  561. // 购物车加减计算函数
  562. ChangeCartNum(changeValue, num, stock, isDuo, id, index, cart) {
  563. if (changeValue) {
  564. num.cart_num++;
  565. if (num.cart_num > stock) {
  566. if (isDuo) {
  567. this.$set(this.attr.productSelect, "cart_num", stock ? stock : 1);
  568. this.$set(this, "cart_num", stock ? stock : 1);
  569. } else {
  570. num.cart_num = stock ? stock : 0;
  571. this.$set(this, 'tempArr', this.tempArr);
  572. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  573. }
  574. return this.$util.Tips({
  575. title: "该产品没有更多库存了"
  576. });
  577. } else {
  578. if (!isDuo) {
  579. if (cart) {
  580. this.goCat(0, id, 1, 1, num.product_attr_unique);
  581. this.getTotalPrice();
  582. } else {
  583. this.goCat(0, id, 1);
  584. }
  585. }
  586. }
  587. } else {
  588. num.cart_num--;
  589. if (num.cart_num == 0) {
  590. this.cartData.cartList.splice(index, 1);
  591. }
  592. if (num.cart_num < 0) {
  593. if (isDuo) {
  594. this.$set(this.attr.productSelect, "cart_num", 1);
  595. this.$set(this, "cart_num", 1);
  596. } else {
  597. num.cart_num = 0;
  598. this.$set(this, 'tempArr', this.tempArr);
  599. this.$set(this.cartData, 'cartList', this.cartData.cartList);
  600. }
  601. } else {
  602. if (!isDuo) {
  603. if (cart) {
  604. this.goCat(0, id, 0, 1, num.product_attr_unique);
  605. this.getTotalPrice();
  606. } else {
  607. this.goCat(0, id, 0);
  608. }
  609. }
  610. }
  611. }
  612. this.tempArr.forEach((item)=>{
  613. if(item.id == id){
  614. item.cart_num = num.cart_num;
  615. }
  616. })
  617. },
  618. // 多规格加入购物车;
  619. goCatNum() {
  620. this.goCat(1, this.id, 1);
  621. },
  622. /*
  623. * 加入购物车
  624. */
  625. goCat: function(duo, id, type, cart, unique) {
  626. let that = this;
  627. if (duo) {
  628. let productSelect = that.productValue[this.attrValue];
  629. //如果有属性,没有选择,提示用户选择
  630. if (
  631. that.attr.productAttr.length &&
  632. productSelect === undefined
  633. )
  634. return that.$util.Tips({
  635. title: "产品库存不足,请选择其它属性"
  636. });
  637. }
  638. let q = {
  639. product_id: id,
  640. num: duo ? that.attr.productSelect.cart_num : 1,
  641. type: type,
  642. unique: duo ? that.attr.productSelect.unique : cart ? unique : ""
  643. };
  644. postCartNum(q)
  645. .then(function(res) {
  646. if (duo) {
  647. that.attr.cartAttr = false;
  648. that.$util.Tips({
  649. title: "添加购物车成功"
  650. });
  651. // that.page = 1;
  652. // that.loadend = false;
  653. that.tempArr.forEach((item, index) => {
  654. if (item.id == that.id) {
  655. let arrtStock = that.attr.productSelect.stock
  656. let objNum = parseInt(item.cart_num) + parseInt(that.attr.productSelect.cart_num);
  657. item.cart_num = objNum > arrtStock?arrtStock:objNum
  658. }
  659. })
  660. // that.productslist();
  661. }
  662. that.getCartNum();
  663. if (!cart) {
  664. that.getCartList(1);
  665. }
  666. })
  667. .catch(err => {
  668. return that.$util.Tips({
  669. title: err
  670. });
  671. });
  672. },
  673. goCartDuo(item) {
  674. if (!this.isLogin) {
  675. this.getIsLogin();
  676. } else {
  677. // uni.showLoading({
  678. // title: '加载中'
  679. // });
  680. this.storeName = item.store_name;
  681. this.getAttrs(item.id);
  682. this.$set(this, 'id', item.id);
  683. this.$set(this.attr, 'cartAttr', true);
  684. }
  685. },
  686. getIsLogin() {
  687. //#ifndef MP
  688. toLogin();
  689. //#endif
  690. //#ifdef MP
  691. this.isShowAuth = true;
  692. //#endif
  693. },
  694. // 商品详情接口;
  695. getAttrs(id) {
  696. let that = this;
  697. getAttr(id, 0).then(res => {
  698. // uni.hideLoading();
  699. that.$set(that.attr, 'productAttr', res.data.productAttr);
  700. that.$set(that, 'productValue', res.data.productValue);
  701. that.$set(that, 'is_vip', res.data.storeInfo.is_vip);
  702. that.$set(that, 'storeInfo', res.data.storeInfo);
  703. that.DefaultSelect();
  704. })
  705. },
  706. // 去详情页
  707. goDetail(item) {
  708. goShopDetail(item, this.uid).then(res => {
  709. uni.navigateTo({
  710. url: `/pages/goods_details/index?id=${item.id}&fromType=1`
  711. });
  712. });
  713. },
  714. openTap() {
  715. this.iSlong = false
  716. },
  717. closeTap() {
  718. this.iSlong = true
  719. },
  720. getAllCategory: function() {
  721. let that = this;
  722. getCategoryList().then(res => {
  723. let data = res.data;
  724. data.forEach(item => {
  725. item.children.unshift({
  726. 'id': 0,
  727. 'cate_name': '全部'
  728. })
  729. })
  730. that.categoryTitle = data[0].cate_name;
  731. that.cid = data[0].id;
  732. that.sid = 0;
  733. that.navActive = 0;
  734. that.tabClick = 0;
  735. that.categoryList = data;
  736. that.categoryErList = res.data[0].children ? res.data[0].children : [];
  737. that.page = 1;
  738. that.loadend = false;
  739. that.tempArr = [];
  740. that.productslist();
  741. })
  742. },
  743. tapNav(index, item) {
  744. uni.pageScrollTo({
  745. duration:0,
  746. scrollTop:0
  747. })
  748. let list = this.categoryList[index];
  749. this.navActive = index;
  750. this.categoryTitle = list.cate_name;
  751. this.categoryErList = item.children ? item.children : [];
  752. this.tabClick = 0;
  753. this.tabLeft = 0;
  754. this.cid = list.id;
  755. this.sid = 0;
  756. this.page = 1;
  757. this.loadend = false;
  758. this.tempArr = [];
  759. this.productslist();
  760. },
  761. // 导航栏点击
  762. longClick(index) {
  763. if (this.categoryErList.length > 3) {
  764. this.tabLeft = (index - 1) * (this.isWidth + 6) //设置下划线位置
  765. };
  766. this.tabClick = index; //设置导航点击了哪一个
  767. this.iSlong = true;
  768. this.sid = this.categoryErList[index].id;
  769. this.page = 1;
  770. this.loadend = false;
  771. this.tempArr = [];
  772. this.productslist();
  773. },
  774. }
  775. }
  776. </script>
  777. <style lang="scss">
  778. /* #ifdef MP || APP-PLUS */
  779. .mp-header {
  780. z-index: 30;
  781. position: fixed;
  782. left: 0;
  783. top: 0;
  784. width: 100%;
  785. background: #fff;
  786. border-bottom: 1px solid #F0F0F0;
  787. .serch-wrapper {
  788. height: 100%;
  789. /* #ifdef MP */
  790. padding: 0 220rpx 0 53rpx;
  791. /* #endif */
  792. /* #ifdef APP-PLUS */
  793. padding: 0 50rpx 0 40rpx;
  794. /* #endif */
  795. .input {
  796. flex: 1;
  797. height: 55rpx;
  798. padding: 0 0 0 30rpx;
  799. background: #F8F8F8;
  800. color: #ADADAD;
  801. font-size: 26rpx;
  802. /* #ifdef MP */
  803. width: 70%;
  804. /* #endif */
  805. /* #ifdef APP-PLUS */
  806. width: 100%;
  807. /* #endif */
  808. border-radius: 50rpx;
  809. .iconfont {
  810. margin-right: 20rpx;
  811. }
  812. }
  813. }
  814. }
  815. /* #endif */
  816. .scroll-Y {
  817. height: 100vh;
  818. }
  819. page {
  820. background-color: #fff;
  821. }
  822. /deep/.product-window.joinCart {
  823. z-index: 999;
  824. }
  825. ::-webkit-scrollbar {
  826. width: 0;
  827. height: 0;
  828. color: transparent;
  829. display: none;
  830. }
  831. .goodCate {
  832. .mask {
  833. z-index: 99;
  834. }
  835. /deep/.attrProduct {
  836. .mask {
  837. z-index: 100;
  838. }
  839. }
  840. .header {
  841. position: fixed;
  842. background-color: #fff;
  843. height: 128rpx;
  844. top: 0;
  845. left: 0;
  846. width: 100%;
  847. z-index: 99;
  848. border-bottom: 1px solid #F0F0F0;
  849. .pageIndex {
  850. width: 68rpx;
  851. height: 68rpx;
  852. border-radius: 50%;
  853. background-color: #F8F8F8;
  854. text-align: center;
  855. line-height: 68rpx;
  856. .iconfont {
  857. color: #ADADAD;
  858. font-size: 30rpx;
  859. }
  860. }
  861. .search {
  862. width: 690rpx;
  863. height: 68rpx;
  864. border-radius: 36rpx;
  865. background-color: #F8F8F8;
  866. font-size: 26rpx;
  867. color: #ADADAD;
  868. .iconfont {
  869. font-size: 30rpx;
  870. margin: 4rpx 16rpx 0 0;
  871. }
  872. }
  873. }
  874. .conter {
  875. /* #ifdef H5 */
  876. padding-top: 128rpx;
  877. /* #endif */
  878. height: 100vh;
  879. background-color: #fff;
  880. .aside {
  881. position: fixed;
  882. width: 23%;
  883. left: 0;
  884. bottom: 0;
  885. top: 0;
  886. background-color: #f7f7f7;
  887. overflow-y: auto;
  888. overflow-x: hidden;
  889. /* #ifdef H5 */
  890. margin-top: 128rpx;
  891. /* #endif */
  892. z-index: 99;
  893. padding-bottom: 194rpx;
  894. .item {
  895. height: 100rpx;
  896. width: 100%;
  897. font-size: 26rpx;
  898. color: #424242;
  899. &.on {
  900. background-color: #fff;
  901. width: 100%;
  902. text-align: center;
  903. color: var(--view-theme);
  904. font-weight: 500;
  905. position: relative;
  906. &::after {
  907. content: "";
  908. position: absolute;
  909. width: 6rpx;
  910. height: 46rpx;
  911. background: var(--view-theme);
  912. border-radius: 0 4rpx 4rpx 0;
  913. left: 0
  914. }
  915. }
  916. }
  917. }
  918. .wrapper {
  919. margin-top: 104rpx;
  920. width: 77%;
  921. float: right;
  922. background-color: #fff;
  923. padding-bottom: 240rpx;
  924. .bgcolor {
  925. width: 100%;
  926. background-color: #fff;
  927. }
  928. .goodsList {
  929. margin-top: 0 !important;
  930. }
  931. .mask {
  932. z-index: 9;
  933. }
  934. .longTab {
  935. width: 65%;
  936. position: fixed;
  937. top: 0;
  938. // #ifdef H5
  939. margin-top: 128rpx;
  940. // #endif
  941. height: 100rpx;
  942. z-index: 99;
  943. background-color: #fff;
  944. .longItem {
  945. height: 44rpx;
  946. display: inline-block;
  947. line-height: 44rpx;
  948. text-align: center;
  949. font-size: 26rpx;
  950. overflow: hidden;
  951. text-overflow: ellipsis;
  952. white-space: nowrap;
  953. color: #989898;
  954. background-color: #F7F7F7;
  955. border-radius: 22rpx;
  956. margin-left: 12rpx;
  957. &.click {
  958. font-weight: bold;
  959. background-color: var(--view-minorColorT);
  960. color: var(--view-theme);
  961. }
  962. }
  963. .underlineBox {
  964. height: 3px;
  965. width: 20%;
  966. display: flex;
  967. align-content: center;
  968. justify-content: center;
  969. transition: .5s;
  970. .underline {
  971. width: 33rpx;
  972. height: 4rpx;
  973. background-color: white;
  974. }
  975. }
  976. }
  977. .openList {
  978. width: 12%;
  979. height: 100rpx;
  980. background-color: #fff;
  981. line-height: 100rpx;
  982. padding-left: 30rpx;
  983. position: fixed;
  984. right: 0;
  985. // #ifdef H5
  986. top: 128rpx;
  987. // #endif
  988. z-index: 99;
  989. .iconfont {
  990. font-size: 22rpx;
  991. color: #989898;
  992. }
  993. }
  994. .downTab {
  995. width: 77%;
  996. position: fixed;
  997. top: 0;
  998. // #ifdef H5
  999. margin-top: 128rpx;
  1000. // #endif
  1001. z-index: 99;
  1002. background-color: #fff;
  1003. right: 0;
  1004. .title {
  1005. height: 100rpx;
  1006. font-size: 26rpx;
  1007. color: #ADADAD;
  1008. padding-left: 20rpx;
  1009. .closeList {
  1010. width: 90rpx;
  1011. height: 100%;
  1012. line-height: 100rpx;
  1013. padding-left: 30rpx;
  1014. transform: rotate(180deg);
  1015. .iconfont {
  1016. font-size: 22rpx;
  1017. color: #989898;
  1018. }
  1019. }
  1020. }
  1021. .children {
  1022. max-height: 500rpx;
  1023. overflow-x: hidden;
  1024. overflow-y: auto;
  1025. padding-bottom: 20rpx;
  1026. .item {
  1027. height: 60rpx;
  1028. background-color: #F7F7F7;
  1029. border-radius: 30rpx;
  1030. line-height: 60rpx;
  1031. padding: 0 15rpx;
  1032. margin: 0 0 20rpx 20rpx;
  1033. width: 165rpx;
  1034. text-align: center;
  1035. &.click {
  1036. font-weight: bold;
  1037. background-color: var(--view-minorColorT);
  1038. color: var(--view-theme);
  1039. }
  1040. }
  1041. }
  1042. }
  1043. .goodsList {
  1044. margin-top: 228rpx;
  1045. padding: 0 30rpx 0 20rpx;
  1046. /deep/.item {
  1047. margin-bottom: 33rpx !important;
  1048. .pictrue {
  1049. height: 212rpx;
  1050. }
  1051. .text {
  1052. font-size: 26rpx;
  1053. }
  1054. .bottom {
  1055. .sales {
  1056. .money {
  1057. font-size: 34rpx;
  1058. text {
  1059. font-size: 26rpx;
  1060. }
  1061. }
  1062. }
  1063. .cart {
  1064. .pictrue {
  1065. width: 50rpx;
  1066. height: 50rpx;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. }
  1072. }
  1073. }
  1074. .footer {
  1075. position: fixed;
  1076. left: 0;
  1077. width: 100%;
  1078. background-color: #fff;
  1079. box-shadow: 0px -3rpx 16rpx rgba(36, 12, 12, 0.05);
  1080. z-index: 100;
  1081. padding: 0 30rpx;
  1082. box-sizing: border-box;
  1083. height: 100rpx;
  1084. // #ifdef H5
  1085. bottom: 94rpx;
  1086. bottom: calc(94rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  1087. bottom: calc(94rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  1088. // #endif
  1089. // #ifndef H5
  1090. bottom: 98rpx;
  1091. bottom: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  1092. bottom: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  1093. // #endif
  1094. &.on{
  1095. // #ifndef H5
  1096. bottom: 0rpx;
  1097. // #endif
  1098. }
  1099. .cartIcon {
  1100. width: 80rpx;
  1101. height: 80rpx;
  1102. border-radius: 50%;
  1103. position: relative;
  1104. margin-top: -36rpx;
  1105. .iconfont {
  1106. font-size: 94rpx;
  1107. margin-top: 12rpx;
  1108. color: var(--view-theme);
  1109. }
  1110. &.noCart {
  1111. .iconfont {
  1112. color: #CBCBCB;
  1113. }
  1114. }
  1115. .num {
  1116. min-width: 14rpx;
  1117. background-color: #fff;
  1118. color: var(--view-theme);
  1119. border-radius: 15px;
  1120. position: absolute;
  1121. right: -10rpx;
  1122. top: 20rpx;
  1123. font-size: 20rpx;
  1124. padding: 0 10rpx;
  1125. border: 1px solid var(--view-theme);
  1126. }
  1127. }
  1128. .money {
  1129. color: var(--view-priceColor);
  1130. font-size: 28rpx;
  1131. font-weight: bold;
  1132. .num {
  1133. font-size: 42rpx;
  1134. }
  1135. .bnt {
  1136. width: 192rpx;
  1137. height: 76rpx;
  1138. background: var(--view-theme);
  1139. border-radius: 46rpx;
  1140. line-height: 76rpx;
  1141. text-align: center;
  1142. color: #fff;
  1143. margin-left: 24rpx;
  1144. }
  1145. &.noCart{
  1146. color: #CBCBCB;
  1147. .bnt{
  1148. background-color: #CBCBCB;
  1149. }
  1150. }
  1151. }
  1152. }
  1153. }
  1154. </style>