store_cate1.vue 39 KB

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