index.vue 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415
  1. <template>
  2. <view class="container">
  3. <view class="utop"></view>
  4. <uni-nav-bar :fixed="true" class="unibar" title="Coffunity"
  5. left-icon="home" backgroundColor="white" :border="false" height="60px" @clickLeft="onHome"/>
  6. <view class="loading" :style="{height:(windowHeight-statusBarHeight-50-height)+'px'}" v-if="isloading">
  7. <image src="https://business.coffunity.cn/upload/loading4.gif" style="width:20px;height:20px"></image>
  8. </view>
  9. <block v-else>
  10. <!-- <view class="head-bg" :style="{background:setColor}"></view> -->
  11. <view class="head-block">
  12. <view class="page-title-block flex flex-nowarp box-pack-between">
  13. <view class="flex-grow-1 flex-y-center">
  14. <!-- <block v-if="teen_index==2 && systemInfo.is_waimai==1">
  15. <i class="iconfont icon-dizhi icon-1" style="color:#999;margin-right:0 ;"></i>
  16. <view class="page-title text-nowarp" @click="getWechatAddress" data-index="1">
  17. {{address.address||'请选择地址'}}
  18. </view>
  19. </block> -->
  20. <!-- <block v-if="(teen_index==1 || teen_index==3) && (systemInfo.is_hall ==1 || systemInfo.is_ziti==1)"> -->
  21. <!-- <i class="iconfont icon-canyin icon-1" :style="{color:setColor}"></i> -->
  22. <navigator url="../../menber/shop" class="page-title text-nowarp store-title">
  23. {{storeInfo.title || ''}} <uni-icons type="right" size="3"></uni-icons>
  24. </navigator>
  25. <!-- </block> -->
  26. </view>
  27. <view class="flex-grow-1 flex-y-center" style="justify-content: flex-end; align-items: center;">
  28. <view @click="onMyOrder" style="margin-right:10px;font-size:12px;font-weight:bold;">我的订单</view>
  29. </view>
  30. <!--is_ziti 自提 is_waimai 外卖 is_hall 堂食 -->
  31. <!-- <view class="por flex-grow-0"
  32. v-if="(systemInfo.is_hall==1||systemInfo.is_ziti==1) && systemInfo.is_waimai==1">
  33. <view class="item-off flex">
  34. <view class="flex-grow-1 flex-center" @click="bindCheck" :data-index="item.teenIndex"
  35. v-for="(item,index) of teen" :key="index"
  36. :class="item.teenIndex==teen_index||item.teenIndexTwo==teen_index?'act':''"
  37. :style="[item.teenIndex==teen_index||item.teenIndexTwo==teen_index?{'background-color':setColor}:'']">
  38. {{item.name}}
  39. </view>
  40. </view>
  41. </view> -->
  42. </view>
  43. <!-- <view @click="showNotice" hover-class="nav-hover" class="notice-block flex flex-y-center arr-r">
  44. <view class="content text-nowarp">公告:{{systemInfo.announcement || ''}}</view>
  45. </view> -->
  46. </view>
  47. <view :class="['main-block','flex','flex-nowarp','flex-x-between']"
  48. >
  49. <scroll-view scroll-y class="left-bar" :scroll-into-view="menuScrollIntoView" scroll-with-animation>
  50. <view v-for="(item,index) in goodsList" :id="`menu-${item.id}`" :key="index"
  51. :class="['item',currentCateId == item.id?'active':'']" @click="handleMenuTap(index,item.id)">
  52. <view class="name" >{{item.title}}</view>
  53. <view class="num" v-if="item.num>0">{{item.num}}</view>
  54. <!-- <view class="rund" :style="[currentCateId == item.id?{'background-color':setColor}:'']"></view> -->
  55. </view>
  56. </scroll-view>
  57. <view class="right-bar">
  58. <!-- <view class="top flex flex-nowarp flex-x-between flex-y-center"> -->
  59. <!-- <view class="active-cat flex flex-nowarp flex-y-center text-nowarp">
  60. <text class="name">{{goodsList[catActive].title}}</text>
  61. <text class="desc text-nowarp"
  62. v-if="goodsList[catActive].desc">({{goodsList[catActive].desc}})</text>
  63. </view> -->
  64. <!-- <navigator :url="`/pages/search/search?store_id=${store_id}&table_id=${table_id}`"
  65. class="search-btn flex flex-x-center flex-y-center flex-nowarp">
  66. <image src="../../static/icon_4.png" mode="aspectFit" class="icon-4"></image>
  67. <view class="btn-name">搜索</view>
  68. </navigator> -->
  69. <!-- </view> -->
  70. <scroll-view scroll-y :scroll-into-view="cateGoods" class="content" @scroll="handleGoodsScroll">
  71. <view :id="`cate-${item.id}`" :class="['item','goods-cat-item',index == 0?'first':'']"
  72. v-for="(item,index) in goodsList" :key="index">
  73. <view class="cat-block flex flex-nowarp flex-y-center text-nowarp">
  74. <text class="name">{{item.title}}</text>
  75. <text class="desc text-nowarp" v-if="item.desc">({{item.desc}})</text>
  76. </view>
  77. <view class="goods-list">
  78. <view class="goods-item flex flex-y-center flex-nowarp"
  79. v-for="(item2,index2) in item.goods_list" :key="index2">
  80. <image :src="URL+item2.thumb" mode="aspectFill" class="img"
  81. @click="shopDetails(item2.id)" lazy-load="true"></image>
  82. <view class="goods-info flex flex-column flex-x-between">
  83. <view class="name">{{item2.name}}</view>
  84. <view class="price flex-y-bottom">
  85. <block v-if="item2.is_rebate==1">
  86. <view>¥{{item2.first_price}}</view>
  87. <view class="textDecoration">¥{{item2.price}}</view>
  88. </block>
  89. <block v-else>
  90. <view>¥{{item2.price}}</view>
  91. </block>
  92. </view>
  93. <view class="price" v-if="item2.is_rebate==1 && item2.rebate">
  94. <view class="rebate-border">
  95. {{item2.rebate}}
  96. </view>
  97. </view>
  98. <view class="flex flex-x-end flex-y-center">
  99. <view class="spec-btn"
  100. v-if="item2.is_gg == 2" @click="showSpec(item2.id)">
  101. <!-- <view class="spec-num" v-if="item2.num>0">{{item2.num}}</view> -->
  102. <view class="circle" >选规格</view>
  103. <view class="spec-num-gg" v-if="item2.num !== 0">{{item2.num}}</view>
  104. </view>
  105. <view class="goods-num-block flex flex-x-end flex-y-center" v-else
  106. :style="{color:setColor}">
  107. <!-- <block v-if="systemInfo.set.is_pocket==1">
  108. <view class="num-btn num-btn-2 iconfont icon-jia1 gdsf"
  109. @click="changeNumShopping(item.id,item2.id,2,'goods','',item2.price,item2.many_rebate,item2.is_rebate)">
  110. </view>
  111. </block>
  112. -->
  113. <block>
  114. <view class="num-btn num-btn-1 iconfont icon-jian1"
  115. @click="changeNum(item.id,item2.id,1,'goods','',item2.price,item2.many_rebate,item2.is_rebate)"
  116. v-if="item2.num>0"></view>
  117. <view class="num" v-if="item2.num>0">{{item2.num}}</view>
  118. <view class="num-btn num-btn-2 iconfont icon-jia1 gdsf"
  119. @click="changeNum(item.id,item2.id,2,'goods','',item2.price,item2.many_rebate,item2.is_rebate)">
  120. </view>
  121. </block>
  122. </view>
  123. </view>
  124. <view class="ft24 many_rebate" v-if="item2.many_rebate>0 && item2.is_rebate==1">
  125. {{item2.many_rebate}}{{item2.unit}}起购
  126. </view>
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. </scroll-view>
  132. </view>
  133. </view>
  134. <shopping-car v-on:catActive="bindCatActive" :carNum="carNum" :isDistance="is_distance"
  135. :deliveryPrice="delivery_price" :carTotal="carTotal" :carGoods="carGoods" :userInfo="userInfo"
  136. :eat_people="choosepeoples" @choosebag="choosebag" :checked="pocket"/>
  137. <view class="mask flex flex-column flex-nowarp flex-x-center flex-y-center" v-show="maskPop">
  138. <!-- 详情弹窗 -->
  139. <!-- 公告弹窗 -->
  140. <view class="pop-block notice-pop" v-show="noticePop">
  141. <view class="title">门店公告</view>
  142. <scroll-view scroll-y="true" class="content-block">
  143. <view class="content">{{systemInfo.announcement || ''}}</view>
  144. </scroll-view>
  145. <view class="sub-btn" :style="{color:setColor}" @click="showNotice">我已知晓</view>
  146. </view>
  147. <!-- 规格弹窗 -->
  148. <block v-if="specPop">
  149. <view class="pop-block spec-pop">
  150. <view class="title">{{goodsDetail.name}}</view>
  151. <scroll-view scroll-y="true" class="content-block">
  152. <view class="content">
  153. <block v-for="(item,index) in goodsDetail.edit_value" :key="index">
  154. <view class="spec-cat-title">
  155. <text>{{item.spec_name}}</text>
  156. <text style="font-size:24rpx;color:#aaa">(仅单选)</text>
  157. </view>
  158. <view class="spec-list flex">
  159. <view v-for="(spec,specIndex) in item.spec" :key="specIndex"
  160. @click="chooseSpec(index,specIndex)"
  161. :class="['spec-item',spec.active?'active':'']"
  162. :style="[spec.active?{'background-color':setColor,'border-color':setColor}:'']">
  163. {{spec.name}}
  164. <block v-if="spec.price">¥{{spec.price}}</block>
  165. </view>
  166. </view>
  167. </block>
  168. </view>
  169. </scroll-view>
  170. <view class="btm-block flex flex-y-baseline flex-nowarp">
  171. <view class="flex flex-nowarp flex-y-baseline">
  172. <view class="price">¥{{goodsDetail.spec_price}}</view>
  173. <view class="unit">/{{goodsDetail.unit}}</view>
  174. </view>
  175. <view class="choose-spec-list text-3" v-if="goodsDetail.specName">
  176. ({{goodsDetail.specName}})</view>
  177. <block>
  178. <view class="add-car-btn" :style="{'background-color':setColor}"
  179. v-if="goodsDetail.num == 0"
  180. @click="changeNum(goodsDetail.category_id,goodsDetail.id,2,'spec',goodsDetail.many_rebate,goodsDetail.is_rebate)">
  181. 加入购物车</view>
  182. <view class="goods-num-block flex flex-x-end flex-y-center" v-else
  183. :style="{color:setColor}">
  184. <view class="num-btn num-btn-1 iconfont icon-jian1"
  185. @click="changeNum(goodsDetail.category_id,goodsDetail.id,1,'spec',goodsDetail.many_rebate,goodsDetail.is_rebate)">
  186. </view>
  187. <view class="num">{{goodsDetail.num}}</view>
  188. <view class="num-btn num-btn-2 iconfont icon-jia1"
  189. @click="changeNum(goodsDetail.category_id,goodsDetail.id,2,'spec',goodsDetail.many_rebate,goodsDetail.is_rebate)">
  190. </view>
  191. </view>
  192. </block>
  193. </view>
  194. </view>
  195. <image src="/static/icon_5.png" mode="aspectFit" class="spec-close-btn" @click="showSpec">
  196. </image>
  197. </block>
  198. </view>
  199. </block>
  200. <float-modal v-if="shopId" :shopId="shopId" @modalStatusBack="handleModalBack"></float-modal>
  201. <!-- 2021041200077000000019093688 -->
  202. <page-btm-bar :active="3" />
  203. <!-- <uni-popup ref="popup" type="center">
  204. <view class="shopping">
  205. <form @submit="Shoppingbag">
  206. <view class="shopping_title flex-center">
  207. 购物口袋
  208. </view>
  209. <view class="shopping_number flex-center">
  210. <input type="number" name="pocket" placeholder-class="shopping_placeholder"
  211. placeholder="口袋:1(单个数字)" />
  212. </view>
  213. <view class="flex-y-center shopping_btn">
  214. <view class="flex-grow-1 flex-center">
  215. 取消
  216. </view>
  217. <view class="shopping_line">
  218. </view>
  219. <button form-type="submit" class="flex-grow-1 flex-center" style="font-size:32rpx">
  220. 确定
  221. </button>
  222. </view>
  223. </form>
  224. </view>
  225. </uni-popup> -->
  226. </view>
  227. </template>
  228. <script>
  229. import {
  230. mapState,
  231. mapGetters,
  232. mapMutations
  233. } from 'vuex'
  234. const app = getApp();
  235. const _timer = "";
  236. let hideLoading = true;
  237. import mpHtml from '@/uni_modules/mp-html/components/mp-html/mp-html'
  238. import shoppingCar from '@/components/shoppingCar.vue';
  239. export default {
  240. components: {
  241. shoppingCar
  242. },
  243. data() {
  244. return {
  245. user_xcx_info: {}, // 记录普通用户信息
  246. maskPop: false, //弹窗一层判断
  247. getPhonePop: false, //获取手机号码弹窗
  248. detailPop: false, //详情弹窗
  249. noticePop: false, //通知弹窗
  250. specPop: false, //规格弹窗
  251. carGoodsPop: false, //购物车弹窗
  252. carGoods: [], //购物车商品
  253. carNum: 0, //购物车数量
  254. carTotal: 0, //购物车价格
  255. specActive: [0, 0], //选中规格
  256. goodsList: [], //商品列表
  257. goodsDetail: {}, //商品详情
  258. teen: [],
  259. delivery_price: '0.00', //配送费
  260. is_distance: 1, //是否超过距离
  261. loading: false,
  262. //加载页
  263. cateScrollTop: 0,
  264. sizeCalcState: false,
  265. currentCateId: null, //选中分类id
  266. currentCateDId: null, //选中分类id
  267. catActive: 0, //选中分类
  268. catActive_act: null,
  269. menuScrollIntoView: 'menu-0',
  270. cateGoods: "",
  271. isState: true,
  272. scrollEndTimer: null,
  273. statusBarHeight: 0,
  274. windowHeight: 650,
  275. safeAreaInsetsBottom: 0,
  276. height: 0,
  277. heightPx: 0,
  278. URL: getApp().globalData.URL,
  279. isloading: true,
  280. SocketOpen: false,
  281. number: 0,
  282. lockReconnect: false,
  283. limit: 0,
  284. choosepeoples: 0, //选择的人数
  285. new_goodsList: [],
  286. scrollTop: 0,
  287. shopId: '',
  288. shoppingObj: {},
  289. pocket: 1,
  290. is_checkeds:1,
  291. storeInfo:null,
  292. }
  293. },
  294. computed: {
  295. ...mapState(['systemInfo', 'setColor', 'store_id', 'table_id', 'userInfo', 'teen_index', 'address',
  296. 'descFood'
  297. ]),
  298. dateRange() {
  299. const {
  300. store_id,
  301. userInfo
  302. } = this;
  303. return {
  304. store_id,
  305. userInfo
  306. }
  307. },
  308. dataTask() {
  309. const {
  310. store_id,
  311. table_id,
  312. systemInfo
  313. } = this;
  314. return {
  315. store_id,
  316. table_id,
  317. systemInfo
  318. }
  319. },
  320. },
  321. watch: {
  322. systemInfo(nVal) {
  323. if (!this.$store.state.is_Refresh) {
  324. return
  325. }
  326. },
  327. descFood(nVal) {
  328. this.teen = [{
  329. name: nVal.food1,
  330. teenIndex: 1,
  331. teenIndexTwo: 3,
  332. },
  333. {
  334. name: nVal.food2,
  335. teenIndex: 2,
  336. },
  337. ]
  338. },
  339. setColor(nVal) {
  340. uni.setNavigationBarColor({
  341. frontColor: '#ffffff',
  342. backgroundColor: nVal,
  343. })
  344. },
  345. teen_index(val) {
  346. console.log('----teen_index')
  347. // console.log("切换数据更新")
  348. this.getIndexInfo();
  349. },
  350. dateRange(val) {
  351. console.log('----dateRange')
  352. if (val.store_id && val.userInfo.id) {
  353. this.getIndexInfo();
  354. this.setCopy();
  355. this.isovertime();
  356. }
  357. },
  358. is_creatOrder(val) {
  359. this.getCarList();
  360. },
  361. dataTask(val) {
  362. if (val.store_id && val.table_id && val.systemInfo) {
  363. if (val.systemInfo.shopid) {
  364. this.shopId = val.systemInfo.shopid;
  365. }
  366. if (val.systemInfo.is_qian_many == 1) {
  367. this.Socket();
  368. }
  369. }
  370. },
  371. address(val) {
  372. if (val.id) {
  373. this.getDeliveryPrice();
  374. }
  375. },
  376. },
  377. onLoad(options) {
  378. // this.teen_index == 2 ? this.getDeliveryPrice() : '';
  379. uni.setStorageSync("lastChoose", false) //默认没有选择就餐人数
  380. this.BarHeight();
  381. uni.hideTabBar();
  382. this.userInfo = uni.getStorageSync('userInfo');
  383. if (this.systemInfo) {
  384. this.shopId = this.systemInfo.shopid;
  385. }
  386. if (this.store_id) {
  387. this.getIndexInfo()
  388. this.setCopy();
  389. this.teen = [{
  390. name: this.descFood.food1,
  391. teenIndex: 1,
  392. teenIndexTwo: 3,
  393. },
  394. {
  395. name: this.descFood.food2,
  396. teenIndex: 2,
  397. },
  398. ];
  399. }else{
  400. uni.navigateTo({
  401. url:'/shop/index/index'
  402. })
  403. }
  404. },
  405. onHide() {
  406. clearInterval(this._timer)
  407. },
  408. onReady() {},
  409. onShow() {
  410. if (this.goodsList.length) {
  411. this.getCarList()
  412. }
  413. this.teen_index == 2 ? this.MyDefaultAddress() : '';
  414. // diy跳转分类
  415. let cate_id = this.$store.state.cate_id;
  416. if (cate_id && this.goodsList.length) {
  417. var obj = this.goodsList.find((v, i) => v.id == cate_id);
  418. var index = this.goodsList.findIndex(item => item.id === cate_id);
  419. if (obj.id) {
  420. this.$nextTick(() => {
  421. this.currentCateId = obj.id; //选中分类id
  422. this.currentCateDId = obj.id; //选中分类id
  423. this.catActive = index; //选中分类
  424. this.cateGoods = `cate-${obj.id}`
  425. })
  426. }
  427. }
  428. if (this.store_id && this.table_id && this.systemInfo) {
  429. if (this.systemInfo.is_qian_many == 1) {
  430. this.Socket();
  431. }
  432. }
  433. this.SocketClose();
  434. if (this.store_id && this.userInfo.id) {
  435. this.teen_index == 1 ? this.isovertime() : ''; //距离上一次是否超时 是否选择人数
  436. }
  437. },
  438. onPullDownRefresh() {
  439. if (this.store_id) {
  440. this.getIndexInfo()
  441. } else {
  442. uni.stopPullDownRefresh();
  443. }
  444. },
  445. onShareAppMessage(e) {
  446. return {}
  447. },
  448. onShareTimeline() {
  449. return {
  450. title: this.systemInfo.title,
  451. imageUrl: this.URL + this.systemInfo.thumb,
  452. }
  453. },
  454. methods: {
  455. ...mapMutations(['SET_ADDRESS', 'SET_TEEN_INDEX']),
  456. onMyOrder(e){
  457. uni.navigateTo({
  458. url:"/pages/myOrderList/myOrderList"
  459. })
  460. },
  461. handleModalBack(res) {
  462. console.log(res, '-----123')
  463. },
  464. onHome(e){
  465. uni.switchTab({
  466. url:'/pages/home/home'
  467. })
  468. },
  469. choosebag(index) {
  470. this.pocket = index;
  471. },
  472. openVideo() {
  473. let goods = this.goodsDetail;
  474. if (goods.feedid && goods.finder) {
  475. wx.openChannelsActivity({
  476. finderUserName: goods.finder,
  477. feedId: goods.feedid,
  478. success: () => {
  479. console.log("打开成功")
  480. }
  481. })
  482. } else {
  483. wx.openChannelsUserProfile({
  484. finderUserName: goods.finder,
  485. success: () => {
  486. console.log("打开成功")
  487. }
  488. })
  489. }
  490. },
  491. closeSocket() {
  492. uni.closeSocket();
  493. },
  494. Socket() {
  495. if (this.systemInfo.is_qian_many == 1) {
  496. app.globalData.callback = (r) => {
  497. let res = JSON.parse(r.data);
  498. if (res.type == 'clear_list') {
  499. if (this.goodsList.length > 0) {
  500. this.carGoods = []
  501. this.carNum = 0
  502. this.carTotal = 0
  503. this.maskPop = false
  504. this.carGoodsPop = false
  505. let goodsList = this.goodsList
  506. for (let i in goodsList) {
  507. goodsList[i].num = 0
  508. for (let j in goodsList[i].goods_list) {
  509. goodsList[i].goods_list[j].num = 0
  510. }
  511. }
  512. this.goodsList = goodsList
  513. }
  514. } else if (res.type == 'ping') {
  515. return
  516. } else if (res.type == 'init_list' || res.type == 'add_cart_list') {
  517. this.isloading = false
  518. if (res.list.length == 0) {
  519. this.maskPop = false
  520. this.carGoodsPop = false
  521. }
  522. this.computGoodsNum(res.list, res.total_price, this.number)
  523. }
  524. }
  525. setTimeout(() => {
  526. this.socktopentInit()
  527. }, 1000)
  528. }
  529. },
  530. // 初始化
  531. socktopentInit() {
  532. var datas = {
  533. group: this.table_id,
  534. type: 'init',
  535. store_id: this.store_id,
  536. table_id: this.table_id,
  537. }
  538. app.sendSocketMessage(JSON.stringify(datas)).then(res => {
  539. console.log('初始化!');
  540. })
  541. },
  542. // 重新链接
  543. SocketClose() {
  544. app.globalData.closeCallback = (r) => {
  545. console.log(r, "我已断开")
  546. if (this.systemInfo.is_qian_many == 1) {
  547. this.reconnect();
  548. }
  549. }
  550. },
  551. // 断开重新链接30次之后更新
  552. reconnect() {
  553. if (this.lockReconnect) return;
  554. this.lockReconnect = true;
  555. clearTimeout(this.timer)
  556. if (this.limit < 30) {
  557. this.timer = setTimeout(() => {
  558. app.initSocket();
  559. app.globalData.onSocketOpen = (r) => {
  560. this.socktopentInit()
  561. }
  562. this.lockReconnect = false;
  563. }, 5000);
  564. this.limit = this.limit + 1;
  565. }
  566. },
  567. // 获取高度
  568. BarHeight() {
  569. var _this = this;
  570. uni.getSystemInfo({
  571. success: function(e) {
  572. // console.log(e,"getSystemInfo")
  573. // #ifdef MP-WEIXIN
  574. var custom = uni.getMenuButtonBoundingClientRect();
  575. _this.height = custom.height + 3 * (custom.top - e.statusBarHeight);
  576. // #endif
  577. // 导航栏高度=状态栏高度+标题栏高度,标题栏高度=胶囊按钮高度+3*(胶囊按钮Top-状态栏高度)
  578. // #ifdef MP-ALIPAY
  579. var custom = e.titleBarHeight;
  580. // 48
  581. _this.height = custom;
  582. // #endif
  583. // console.log(e, "getSystemInfo")
  584. // 36
  585. _this.statusBarHeight = e.statusBarHeight;
  586. _this.windowHeight = e.windowHeight;
  587. // #ifdef MP-ALIPAY
  588. _this.heightPx = 350 / 750 * e.windowWidth;
  589. // #endif
  590. // #ifdef MP-WEIXIN
  591. _this.heightPx = 370 / 750 * e.windowWidth;
  592. // #endif
  593. // #ifdef MP-WEIXIN
  594. _this.safeAreaInsetsBottom = e.screenHeight - e.safeArea.bottom;
  595. // #endif
  596. // #ifdef MP-ALIPAY
  597. let model = e.model,
  598. hg = 0;
  599. let iphoneArr = new Set(['iPhone X', 'iPhone 11', 'iPhone 11 Pro Max', 'iPhone XR',
  600. 'iPhone 12', 'iPhone 13'
  601. ]); //机型
  602. if (iphoneArr.has(model)) hg = 36;
  603. _this.safeAreaInsetsBottom = hg;
  604. // #endif
  605. }
  606. })
  607. },
  608. getShop(e) {
  609. uni.navigateTo({
  610. url: "../../shop/index/index"
  611. })
  612. },
  613. // 赋能
  614. setCopy() {
  615. if (getApp().globalData.isApp) {
  616. this.$http.request('xcx/funeng', {
  617. store_id: this.store_id,
  618. }, "", "", hideLoading).then(res => {
  619. getApp().globalData.isApp = false
  620. let way_power = res.data.way_power;
  621. if (!way_power) {
  622. return
  623. }
  624. let content = way_power.replace(/<br\s*\/?\s*>/ig, "\n");
  625. uni.setClipboardData({
  626. data: content,
  627. success: function(r) {
  628. console.log('success', r);
  629. }
  630. });
  631. })
  632. }
  633. },
  634. bindCatActive(e) {
  635. this.currentCateDId = e;
  636. this.currentCateId = e;
  637. this.cateGoods = `cate-${e}`
  638. },
  639. // 选择外卖地址
  640. bindCheck(e) {
  641. let index = e.currentTarget.dataset.index;
  642. index = index == 1 ? (this.systemInfo.is_hall == 1 ? index : this.systemInfo.is_ziti == 1 ? 3 : index) :
  643. index;
  644. this.SET_TEEN_INDEX(index);
  645. // 从默认地址获取配送费
  646. if (index == 2) {
  647. this.getDeliveryPrice();
  648. }
  649. //判断如果切换到点餐且没有选就调走
  650. if (this.teen_index == 1) {
  651. this.isovertime(); //距离上一次是否超时
  652. }
  653. },
  654. // 获取默认地址
  655. MyDefaultAddress() {
  656. if (this.address.id) {
  657. this.getDeliveryPrice();
  658. } else {
  659. this.$http.request('xcx/MyDefaultAddress', {
  660. user_id: this.userInfo.id,
  661. }, "", "", hideLoading).then(res => {
  662. this.SET_ADDRESS(res.data)
  663. // console.log("getDeliveryPrice")
  664. this.getDeliveryPrice();
  665. }).catch(err => {})
  666. }
  667. },
  668. // 获取配送费
  669. getDeliveryPrice() {
  670. this.$http.request('xcx/getDeliveryPrice', {
  671. lat: this.address.lat || '',
  672. lng: this.address.lng || '',
  673. store_id: this.store_id,
  674. }, "", "", hideLoading).then(res => {
  675. let distance = Number(res.data.distance);
  676. if (distance) {
  677. if (!distance) {
  678. this.is_distance = 2;
  679. return
  680. }
  681. this.delivery_price = Number(res.data.delivery_price);
  682. if (!this.systemInfo.set.number || !distance) {
  683. this.is_distance = 1;
  684. return
  685. }
  686. // 如果大于商家距离is_distance = 2 提出超出距离
  687. if (distance > this.systemInfo.set.number) {
  688. this.is_distance = 2;
  689. } else {
  690. this.is_distance = 1;
  691. }
  692. } else {
  693. this.is_distance = 3;
  694. }
  695. }).catch(err => {})
  696. },
  697. // 选择外卖地址
  698. getWechatAddress: function(e) {
  699. uni.navigateTo({
  700. url: '../address/address?teen_index=1'
  701. })
  702. },
  703. //获取首页分类 商品列表
  704. getIndexInfo() {
  705. // console.log("门店数据更新")
  706. this.$http.request('xcx/system', {
  707. store_id: uni.getStorageSync('store_id'),
  708. table_id: uni.getStorageSync('table_id'),
  709. }).then(res => {
  710. this.sizeCalcState = false;
  711. let is_rebate = 2
  712. this.storeInfo=res.data;
  713. try {
  714. is_rebate = res.data.set.is_rebate
  715. } catch (err) {
  716. console.log(err)
  717. }
  718. console.log('res',res);
  719. if (is_rebate == 1) {
  720. this.getCategoryList()
  721. return false
  722. }
  723. this.$http.request('xcx/index', {
  724. store_id: this.store_id,
  725. state: Number(this.teen_index),
  726. }, "", "", hideLoading).then(res => {
  727. uni.stopPullDownRefresh();
  728. let list = res.data;
  729. this.goodsList = list;
  730. // diy跳转分类
  731. let cate_id = this.$store.state.cate_id;
  732. if (cate_id) {
  733. var obj = list.find((v, i) => v.id == cate_id);
  734. var index = list.findIndex(item => item.id === cate_id);
  735. if (obj.id) {
  736. this.currentCateId = obj.id; //选中分类id
  737. this.currentCateDId = obj.id; //选中分类id
  738. this.catActive = index; //选中分类
  739. this.cateGoods = `cate-${obj.id}`
  740. }
  741. }else{
  742. if(list.length>0){
  743. var obj=list[0];
  744. this.currentCateId = obj.id; //选中分类id
  745. this.currentCateDId = obj.id; //选中分类id
  746. this.catActive = index; //选中分类
  747. this.cateGoods = `cate-${obj.id}`
  748. }
  749. }
  750. this.getCarList();
  751. }).catch(err => {
  752. uni.stopPullDownRefresh()
  753. })
  754. })
  755. },
  756. //获取购物车数据
  757. getCarList() {
  758. var url = 'xcx/cart_list',
  759. datas;
  760. console.log(this.systemInfo);
  761. if (this.systemInfo.is_qian_many == 1) {
  762. return
  763. }
  764. datas = {
  765. user_id: this.userInfo.id,
  766. store_id: this.store_id,
  767. }
  768. if (this.userInfo.id && this.store_id) {
  769. this.$http.request(url, datas, "", "", hideLoading).then(res => {
  770. if(res.data.list<=0){
  771. this.pocket = 1
  772. }
  773. let arr = this.$utils.removal(res.data.list)
  774. this.new_list = res.data.new_list;
  775. this.computGoodsNum(arr, res.data.total_price, 0, res.data.new_list)
  776. this.isloading = false
  777. }).catch(err => {})
  778. }
  779. },
  780. //根据购物车列表计算购物车数据
  781. computGoodsNum(list, total_price, spec_num, new_list = []) {
  782. if (this.goodsList.length <= 0) {
  783. return
  784. }
  785. let num = 0
  786. //计算商品数量
  787. let goodsList = this.goodsList;
  788. for (let i in goodsList) {
  789. goodsList[i].num = 0
  790. for (let j in goodsList[i].goods_list) {
  791. goodsList[i].goods_list[j].num = 0
  792. }
  793. }
  794. for (let i in list) {
  795. num += list[i].num
  796. for (let j in goodsList) {
  797. if (list[i].category_id == goodsList[j].id) {
  798. for (let n in goodsList[j].goods_list) {
  799. if (list[i].goods_id == goodsList[j].goods_list[n].id) {
  800. goodsList[j].num += list[i].num
  801. goodsList[j].goods_list[n].num += list[i].num
  802. break
  803. }
  804. }
  805. break;
  806. }
  807. }
  808. }
  809. this.goodsList = goodsList
  810. this.carNum = num
  811. this.carGoods = new_list
  812. this.$store.commit('SET_CARGOODS', new_list) //监听购物车是否有变化
  813. this.carTotal = total_price
  814. if (this.detailPop || this.specPop) {
  815. this.goodsDetail.num = spec_num
  816. }
  817. },
  818. /**
  819. * 改变商品数量
  820. * @category_id:分类id
  821. * @goods_id:商品id
  822. * @type:1减少 2增加
  823. * @data_from 购物车列表传 'car' 规格弹窗传 'spec' 无规格传 'goods' 否则不传
  824. * @car_index 购物车下标 data_form = 'car'传
  825. * @goods_price 商品价格 data_from = 'goods' 传
  826. * @many_rebate 起购数量 is_rebate=1/2 是/否起购
  827. * */
  828. changeNum(category_id, goods_id, type, data_from, car_index, goods_price, many_rebate = '', is_rebate = '',
  829. idx = '') {
  830. /* pocket 购物口袋
  831. goodsList 数据列表
  832. idx 如果是有从购物车加入 */
  833. let money = 0,
  834. pocket = this.pocket,
  835. carGoods,
  836. num = 0,
  837. spec = '',
  838. new_list = this.new_list,
  839. carItem = false;
  840. carGoods = this.carGoods;
  841. pocket = idx === '' ? pocket : idx;
  842. if (type == 2) {
  843. for (let i of new_list) {
  844. if (i.pocket == pocket) {
  845. carGoods = i.list;
  846. }
  847. }
  848. }
  849. if (type == 1) {
  850. function getData(new_list,pocket,goods_id) {
  851. let as = false
  852. for (let i of new_list) {
  853. for(let j of i.list){
  854. if (i.pocket == pocket && j.goods_id == goods_id) {
  855. as = true
  856. }
  857. }
  858. }
  859. return as
  860. }
  861. // 判断当前选中的购物口袋是否选中并且还有产品
  862. let isAllStudentType = getData(new_list,pocket,goods_id)
  863. if (isAllStudentType) {
  864. for (let i of new_list) {
  865. if (i.pocket == pocket) {
  866. carGoods = i.list;
  867. }
  868. }
  869. } else {
  870. for (let i of new_list) {
  871. for (let j of i.list) {
  872. if (j.goods_id == goods_id) {
  873. pocket = i.pocket
  874. carGoods = i.list
  875. }
  876. }
  877. }
  878. }
  879. }
  880. if (data_from == 'car') {
  881. //购物车规格
  882. carItem = carGoods[car_index]
  883. spec = carItem.spec || ''
  884. money = carItem.price
  885. } else if (data_from == 'spec') {
  886. let specArr = []
  887. let specList = this.goodsDetail.edit_value
  888. for (let i in specList) {
  889. for (let j in specList[i].spec)
  890. if (specList[i].spec[j].active) {
  891. specArr.push(specList[i].spec_name + ':' + specList[i].spec[j].name)
  892. break
  893. }
  894. }
  895. if (specArr.length != specList.length) {
  896. uni.showToast({
  897. title: "请选择规格",
  898. icon: 'none'
  899. })
  900. return false
  901. } else {
  902. spec = specArr.join(',')
  903. money = this.goodsDetail.spec_price
  904. // 调用 showSpec 方法
  905. this.showSpec(goods_id);
  906. }
  907. } else if (data_from == 'goods') {
  908. //无规格商品
  909. spec = ''
  910. money = goods_price
  911. }
  912. if (data_from != 'car') {
  913. for (let i in carGoods) {
  914. if (carGoods[i].goods_id == goods_id && carGoods[i].spec == spec) {
  915. carItem = carGoods[i]
  916. break
  917. }
  918. }
  919. }
  920. num = carItem ? carItem.num : 0
  921. if (type == 1) {
  922. if (num > 0) {
  923. // 起购
  924. if (many_rebate > 0 && is_rebate == 1) {
  925. if (many_rebate >= num) {
  926. num = num - many_rebate;
  927. } else {
  928. num--;
  929. }
  930. } else {
  931. num--
  932. }
  933. } else {
  934. return false
  935. }
  936. } else if (type == 2) {
  937. // 起购
  938. if (many_rebate > 0 && is_rebate == 1) {
  939. if (many_rebate <= num) {
  940. num++
  941. } else {
  942. num = num + many_rebate;
  943. }
  944. } else {
  945. num++
  946. }
  947. } else {
  948. return false
  949. }
  950. let datas = {
  951. user_id: this.userInfo.id,
  952. category_id: category_id, //分类id
  953. goods_id: goods_id, //是 string 商品id
  954. num: num <= 0 ? 0 : num, //是 string 购买数量
  955. table_id: this.table_id, //是 string 桌号
  956. spec: spec, //是 string 规格(json),有的传
  957. money: money,
  958. group: this.table_id,
  959. type: 'add_cart',
  960. store_id: this.store_id,
  961. pocket: pocket
  962. }
  963. if (this.systemInfo.is_qian_many == 1 && app.globalData.readyReset == 1) {
  964. app.sendSocketMessage(JSON.stringify(datas)).then(res => {
  965. this.number = num;
  966. })
  967. } else {
  968. this.$http.request('xcx/add_cart', datas, 'POST', false, true).then(res => {
  969. if (res.data.list.length == 0 && data_from == 'car') {
  970. this.pocket = 1
  971. this.maskPop = false
  972. this.carGoodsPop = false
  973. }
  974. let arr = this.$utils.removal(res.data.list)
  975. this.new_list = res.data.new_list;
  976. this.computGoodsNum(arr, res.data.total_price, num, res.data.new_list)
  977. }).catch(err => {})
  978. }
  979. },
  980. //清空购物车
  981. clearCar() {
  982. // console.log("ggg")
  983. this.pocket = 1
  984. this.new_list = []
  985. this.carGoods = []
  986. this.$store.commit('SET_CARGOODS', []) //监听购物车是否有变化
  987. this.carNum = 0
  988. this.carTotal = 0
  989. this.maskPop = false
  990. this.carGoodsPop = false
  991. let goodsList = this.goodsList
  992. for (let i in goodsList) {
  993. goodsList[i].num = 0
  994. for (let j in goodsList[i].goods_list) {
  995. goodsList[i].goods_list[j].num = 0
  996. }
  997. }
  998. this.goodsList = goodsList
  999. // 多人点餐开启
  1000. if (this.systemInfo.is_qian_many == 1 && app.globalData.readyReset == 1) {
  1001. let datas = {
  1002. group: this.table_id,
  1003. type: "clear",
  1004. store_id: this.store_id,
  1005. table_id: this.table_id,
  1006. }
  1007. app.sendSocketMessage(JSON.stringify(datas)).then(res => {
  1008. // console.log('发送成功!');
  1009. })
  1010. }
  1011. },
  1012. //拼接图片全路径
  1013. getImgSrc(src) {
  1014. if (src) {
  1015. return this.$utils.getImgSrc(src)
  1016. }
  1017. },
  1018. //新增跳转详情
  1019. shopDetails(e) {
  1020. uni.navigateTo({
  1021. url: '/menber/goods_detail?id=' + e
  1022. })
  1023. },
  1024. //显示商品详情弹窗
  1025. showGoodsDetail(index, index2) {
  1026. if (this.detailPop) {
  1027. this.maskPop = false
  1028. this.detailPop = false
  1029. return false
  1030. }
  1031. this.goodsDetail = JSON.parse(JSON.stringify(this.goodsList[index].goods_list[index2]))
  1032. this.goodsDetail.description = this.goodsList[index].goods_list[index2].description.replace(/\<img/gi,
  1033. '<img style="max-width:100%;height:auto" ')
  1034. this.goodsDetail.category_id = this.goodsList[index].id
  1035. this.maskPop = true
  1036. this.detailPop = true
  1037. },
  1038. //显示公告详情
  1039. showNotice() {
  1040. this.maskPop = !this.maskPop
  1041. this.noticePop = !this.noticePop
  1042. },
  1043. //显示规格弹窗
  1044. showSpec(goods_id) {
  1045. if (this.specPop) {
  1046. this.maskPop = false
  1047. this.specPop = false
  1048. return false
  1049. }
  1050. this.$http.request('xcx/goodinfo', {
  1051. goods_id: goods_id
  1052. }, "", "", hideLoading).then(res => {
  1053. let info = res.data.goods
  1054. let edit_value = info.edit_value
  1055. for (let i in edit_value) {
  1056. for (let j in edit_value[i].spec) {
  1057. edit_value[i].spec[j] = {
  1058. 'name': edit_value[i].spec[j],
  1059. active: false
  1060. }
  1061. }
  1062. }
  1063. info.edit_value = edit_value
  1064. info.spec_price = info.price
  1065. info.num = 0
  1066. info.specName = ""
  1067. this.goodsDetail = info
  1068. this.maskPop = true
  1069. this.specPop = true
  1070. this.detailPop = false
  1071. }).catch(err => {})
  1072. },
  1073. //选择规格
  1074. chooseSpec(index, specIndex) {
  1075. let spec = this.goodsDetail.edit_value[index].spec
  1076. for (let i in spec) {
  1077. if (i == specIndex) {
  1078. spec[i].active = true
  1079. } else {
  1080. spec[i].active = false
  1081. }
  1082. }
  1083. this.goodsDetail.edit_value[index].spec = spec
  1084. this.goodsDetail.num = 0
  1085. this.computSpecPrice()
  1086. },
  1087. //计算规格价格
  1088. computSpecPrice() {
  1089. let edit_value = this.goodsDetail.edit_value
  1090. let specNameArr = [],
  1091. carSpecArr = []
  1092. for (let i in edit_value) {
  1093. for (let j in edit_value[i].spec) {
  1094. if (edit_value[i].spec[j].active) {
  1095. specNameArr.push(edit_value[i].spec[j].name)
  1096. carSpecArr.push(edit_value[i].spec_name + ':' + edit_value[i].spec[j].name)
  1097. break
  1098. }
  1099. }
  1100. }
  1101. let specName = specNameArr.join(":")
  1102. this.goodsDetail.specName = specNameArr.join(',')
  1103. let spec = this.goodsDetail.spec
  1104. for (let i in spec) {
  1105. if (spec[i].spec == specName) {
  1106. this.goodsDetail.spec_price = this.userInfo.is_vip == 1 ? spec[i].growth : spec[i].growth
  1107. break
  1108. }
  1109. }
  1110. let carGoods = this.carGoods
  1111. carSpecArr = carSpecArr.join(",")
  1112. for (let i in carGoods) {
  1113. if (this.goodsDetail.id == carGoods[i].goods_id && carSpecArr == carGoods[i].spec) {
  1114. this.goodsDetail.num = carGoods[i].num
  1115. break
  1116. }
  1117. }
  1118. },
  1119. //选择分类
  1120. handleMenuTap(index, id) {
  1121. // console.log(index, id)
  1122. if (!this.sizeCalcState) {
  1123. this.calcSize()
  1124. }
  1125. this.catActive = index;
  1126. this.catActive_act = index;
  1127. this.currentCateId = id;
  1128. this.currentCateDId = id;
  1129. this.cateGoods = `cate-${id}`
  1130. },
  1131. // 商品滚动
  1132. async handleGoodsScroll({
  1133. detail
  1134. }) {
  1135. // console.log('商品滚动',detail)
  1136. if (!this.sizeCalcState) {
  1137. this.calcSize()
  1138. }
  1139. var {
  1140. scrollTop
  1141. } = await detail;
  1142. if (this.scrollEndTimer) {
  1143. clearTimeout(this.scrollEndTimer);
  1144. this.scrollEndTimer = null;
  1145. }
  1146. this.scrollEndTimer = setTimeout(() => {
  1147. let deltaY = this.scrollTop - scrollTop;
  1148. this.scrollTop = scrollTop;
  1149. // console.log(this.goodsList[this.catActive].top,scrollTop,deltaY,"scrollTop")
  1150. // scrollfx<0 下滚动 ,下滚动同时分类的top 大于滚动条时候,说明滚动下面商品不够,退出自动切换分类。
  1151. if (deltaY < 0 && this.goodsList[this.catActive].top >= scrollTop) {
  1152. return
  1153. }
  1154. let tabs = this.goodsList.filter(item => item.top <= Math.floor(scrollTop + 10)).reverse();
  1155. // console.log(tabs)
  1156. if (tabs.length > 0) {
  1157. this.currentCateId = tabs[0].id;
  1158. this.currentCateDId = tabs[0].id;
  1159. this.catActive = tabs[0].catActive;
  1160. this.menuScrollIntoView = `menu-${tabs[0].id}`;
  1161. this.catActive_act = null;
  1162. }
  1163. }, 300);
  1164. },
  1165. calcSize() {
  1166. let h = 10;
  1167. this.goodsList.forEach((item, index) => {
  1168. let view = uni.createSelectorQuery().select(`#cate-${item.id}`)
  1169. view.fields({
  1170. size: true
  1171. }, data => {
  1172. item.top = Math.floor(h);
  1173. h += data.height
  1174. item.bottom = h
  1175. item.catActive = index
  1176. }).exec()
  1177. })
  1178. this.sizeCalcState = true
  1179. },
  1180. //是否超时
  1181. isovertime() {
  1182. let lastpageChoose = uni.getStorageSync("lastChoose"); //上个页面是否选择了
  1183. let teenIndexs = this.teen_index; //等于1是点餐 2是外卖
  1184. //选择的人数
  1185. // console.log(this.choosepeoples, "this.choosepeoples")
  1186. this.$http.request('xcx/eat_people_time', {
  1187. store_id: this.store_id,
  1188. user_id: this.userInfo.id,
  1189. }).then(res => {
  1190. if (res.code == "200") {
  1191. //先判断是否开启
  1192. // console.error(res.data)
  1193. if (res.data.eat_open == 1 && this.teen_index == 1) {
  1194. //首先判断是否开启选择人数就餐且是点餐的情况
  1195. if (res.data.eat_open_time == 1) { //判断时间开关是否开启1开启 0关闭
  1196. if (res.data.on_time == 1 && !lastpageChoose) { //on_time 1超过 2没超过
  1197. uni.navigateTo({
  1198. url: '../../menber/choose_people'
  1199. })
  1200. }
  1201. if (res.data.on_time == 2) {
  1202. console.log(this.choosepeoples, "this.choosepeoples")
  1203. this.choosepeoples = 0;
  1204. }
  1205. } else { //关闭时间开关需重新选择
  1206. if (!lastpageChoose) {
  1207. uni.navigateTo({
  1208. url: '../../menber/choose_people'
  1209. })
  1210. }
  1211. }
  1212. }
  1213. }
  1214. }).catch((res) => {
  1215. uni.showToast({
  1216. title: res.message,
  1217. icon: 'none'
  1218. })
  1219. });
  1220. },
  1221. // 获取商品分类
  1222. getCategoryList() {
  1223. this.$http.request('yy/xcx_index', {
  1224. store_id: this.store_id,
  1225. state: Number(this.teen_index),
  1226. }).then(res => {
  1227. // console.log("商品分类", res)
  1228. this.goodsList = res.data
  1229. if (res.data.length > 0) {
  1230. this.currentCateId = res.data[0].id
  1231. this.getCategoryGoods(res.data[0].id, 0, res.data.length)
  1232. }
  1233. }).catch(err => {
  1234. })
  1235. },
  1236. // 获取指定分类商品
  1237. getCategoryGoods(category_id, index, len) {
  1238. // console.log('获取指定分类商品', category_id)
  1239. //如果已经请求过商品不再重复请求
  1240. if (this.goodsList[index].goods_list) {
  1241. return false
  1242. }
  1243. this.$http.request('yy/xcx_detail', {
  1244. store_id: this.store_id,
  1245. state: Number(this.teen_index),
  1246. category_id,
  1247. }).then(res => {
  1248. // console.log("分类商品")
  1249. uni.stopPullDownRefresh();
  1250. this.goodsList[index].goods_list = res.data
  1251. if (len - index > 1) {
  1252. this.getCategoryGoods(this.goodsList[index + 1].id, index + 1, len)
  1253. } else if (len - index == 1) {
  1254. // console.log('123456')
  1255. // diy跳转分类
  1256. let cate_id = this.$store.state.cate_id;
  1257. if (cate_id) {
  1258. var obj = this.goodsList.find((v, i) => v.id == cate_id);
  1259. var activeIndex = this.goodsList.findIndex(item => item.id === cate_id);
  1260. if (obj.id) {
  1261. this.currentCateId = obj.id; //选中分类id
  1262. this.currentCateDId = obj.id; //选中分类id
  1263. this.catActive = activeIndex; //选中分类
  1264. }
  1265. }
  1266. this.getCarList();
  1267. }
  1268. }).catch(err => {
  1269. uni.stopPullDownRefresh();
  1270. })
  1271. },
  1272. }
  1273. }
  1274. // function removal(arr) {
  1275. // var newArr=[];
  1276. // arr.forEach(item => {
  1277. // var dataItem = item;
  1278. // if(newArr.length>0) {
  1279. // var filterValue = newArr.filter(v => {
  1280. // return v.goods_id == dataItem.goods_id
  1281. // })
  1282. // if(filterValue.length>0){
  1283. // newArr.forEach(n => {
  1284. // if( n.goods_id == filterValue[0].goods_id){
  1285. // n.num = filterValue[0].num + dataItem.num
  1286. // }
  1287. // })
  1288. // }else{
  1289. // newArr.push(dataItem)
  1290. // }
  1291. // }else{
  1292. // newArr.push(dataItem)
  1293. // }
  1294. // })
  1295. // return newArr
  1296. // }
  1297. </script>
  1298. <style lang="scss">
  1299. @import url("./index.css");
  1300. </style>