index.vue 40 KB

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