index.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. <template>
  2. <view :style="[mainStyle]">
  3. <view :class="'top' + (isScroll ? ' top-background' : '')" :style="'height:' + systems.barHeight + 'rpx;'">
  4. <!-- #ifdef MP-WEIXIN -->
  5. <view class="top-nav ddflex"
  6. :style="'height:' + systems.navigationHeight + 'rpx;top:' + systems.ktxStatusHeight + 'rpx;'">
  7. <view class="search ddflex" @click="jumpUrl('/pages/search/search')">
  8. <image src="../../static/pages/images/ssico.png"></image>
  9. <view>请输入商品名称搜索</view>
  10. </view>
  11. </view>
  12. <!-- #endif -->
  13. <!-- #ifndef MP-WEIXIN -->
  14. <view class="top-navc ddflex"
  15. :style="'height:' + systems.navigationHeight + 'rpx;top:' + systems.ktxStatusHeight + 'rpx;'">
  16. <view class="searchc ddflex" @click="jumpUrl('/pages/search/search')">
  17. <image src="../../static/pages/images/ssico.png"></image>
  18. <view>请输入商品名称搜索</view>
  19. </view>
  20. </view>
  21. <!-- #endif -->
  22. </view>
  23. <view class="top-con">
  24. <view class="top-bg">
  25. <image :src="picUrlss+'lvluo/service_img.png'"></image>
  26. </view>
  27. <view class="shop">
  28. <view class="shop-info ddflex">
  29. <view class="fflex">
  30. <view class="shop-name ddflex">
  31. <view class="tover">{{ merchant.title }}</view>
  32. <image src="../../static/pages/images/daohang.png" class="daohang" @click="goNavigation()">
  33. </image>
  34. </view>
  35. <view class="shop-datas ddflex">
  36. <!-- <image :src="picUrlss+'lvluo/service_dz.png'"></image> -->
  37. <view class="expre ddflex">预约到店</view>
  38. <!-- <view class="shop-addr"><view class="tover">{{merchant.address}}</view></view> -->
  39. </view>
  40. <view class="shop-infos ddflex">
  41. <view style="margin-right: 15rpx;">
  42. {{ merchant.range ? (merchant.mDistance < 1000 ? merchant.mDistance + 'm ·' : merchant.range + 'km ·') : ''}}
  43. </view>
  44. <!-- <view class="expre ddflex">预约到店</view> -->
  45. <view>服务时间:{{merchant.businessTime}}</view>
  46. <!-- <view class="expre ddflex"><image :src="picUrlss+'lvluo/service_kd.png'"></image><view class="fflex">快递发货</view></view>
  47. <view>预计1-3日达·月售9999+</view> -->
  48. </view>
  49. </view>
  50. <view class="shop-pic">
  51. <image :src="merchant.logo" mode="aspectFit" class="shop-logo"></image>
  52. </view>
  53. </view>
  54. <!-- <view class="m-tag ddflex">
  55. <view class="li ddflex"><image :src="picUrlss+'lvluo/service_dp.png'" style="width: 31rpx;"></image>支持自取</view>
  56. <view class="li ddflex"><image :src="picUrlss+'lvluo/service_fp.png'" style="width: 26rpx;"></image>开发票</view>
  57. <view class="li ddflex"><image :src="picUrlss+'lvluo/service_yd.png'" style="width: 28rpx;"></image>支持预定</view>
  58. </view> -->
  59. <view class="shop-bot" v-if="couponList.length>0">
  60. <view class="coupons-list fflex">
  61. <scroll-view scroll-x="true" class="coupons-s">
  62. <view class="li" v-for="(item,index) in couponList" :key="index"
  63. @click="recieveCoupon(item,index)">
  64. <view class="ddflex">
  65. <view class="coupon-money"><text>¥</text>{{item.couponAmount}}</view>
  66. <view class="coupons-tit">{{item.couponTitle}}</view>
  67. <text
  68. class="coupon-ling">{{item.userCount >= item.userReceive&&item.userCount!=0&&item.userReceive!=-1 ? '已领' : '领'}}</text>
  69. </view>
  70. </view>
  71. </scroll-view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. <block v-if="sort">
  77. <!-- #ifndef H5 -->
  78. <scroll-view scroll-y="true" class="sort-left" :style="'bottom:' + (bottomBlankHeignt + 115) + 'rpx;'">
  79. <block v-for="(item, index) in sortCategorys" :key="index">
  80. <view :class="'li ' + (selectTab == index ? 'active' : '')" :data-index="index" @tap="toScrollView"
  81. :data-id="item.id">{{ item.title }}</view>
  82. </block>
  83. </scroll-view>
  84. <!-- #endif -->
  85. <!-- #ifdef H5 -->
  86. <scroll-view scroll-y="true" class="sort-left"
  87. :style="'bottom:' + (bottomBlankHeignt + 115) + 'rpx;' + 'top: 43px'">
  88. <block v-for="(item, index) in sortCategorys" :key="index">
  89. <view :class="'li ' + (selectTab == index ? 'active' : '')" :data-index="index" @tap="toScrollView"
  90. :data-id="item.id">{{ item.title }}</view>
  91. </block>
  92. </scroll-view>
  93. <!-- #endif -->
  94. <scroll-view scroll-y="true" class="sort-right" :style="'height:' + scrollHeight + 'px;'"
  95. :scroll-into-view="toView" scroll-top="0" @scroll="scrollTo" scroll-with-animation="true">
  96. <view class="rcon">
  97. <view v-for="(cats, idx) in sortCategorys" :key="idx" :id="'position' + idx">
  98. <view class="tit" @tap="goUrl" :data-id="cats.id" :data-title="cats.title">{{ cats.title }}
  99. </view>
  100. <view class="list dflex">
  101. <view v-for="(item, index) in cats.nodes" :key="index" class="li" @tap="goUrl"
  102. :data-id="item.id" :data-title="item.title">
  103. <image :src="item.icon" v-if="item.icon" lazy-load="true"></image>
  104. <view class="litext" :data-key="key" :style="'background-color:' + item.colors" v-else>
  105. {{ item.first }}
  106. </view>
  107. {{ item.title }}
  108. </view>
  109. </view>
  110. </view>
  111. </view>
  112. </scroll-view>
  113. </block>
  114. <view class="ddflex" style="align-items: flex-start;margin-top: 30rpx;position: relative;" v-else>
  115. <scroll-view scroll-y="true" :class="'left savepadding' + (isFixed ? ' left-position' : '')"
  116. :style="'top:' + leftTop + 'rpx;min-height:'+((systems.windowHeight - topHeight)*systems.pxToRpxScale - 131)+'rpx;'">
  117. <view :class="'li ddflex ' + (current == -1 ? 'active' : '')" :data-current="-1" @tap="cateTab">全部服务
  118. </view>
  119. <view :class="'li ddflex ' + (current == -2 ? 'active' : '')" :data-current="-2" @tap="cateTab">爆品推荐
  120. </view>
  121. <view :class="'li ddflex ' + (current == -3 ? 'active' : '')" :data-current="-3" @tap="cateTab"
  122. v-if="config.is_show_group_btn == 1">团购套餐</view>
  123. <block v-for="(item, index) in categorys" :key="index">
  124. <view :class="'li ddflex ' + (current == index ? 'active' : '')" :data-current="index"
  125. :data-id="item.id" @tap="cateTab">
  126. {{ item.title }}
  127. </view>
  128. </block>
  129. </scroll-view>
  130. <view :class="'right' + (isFixed ? ' right-position' : '')">
  131. <view class="savepadding">
  132. <scroll-view scroll-X="true" :class="'tab' + (isFixed ? ' tab-position' : '')"
  133. :style="'top:' + systems.barHeight + 'rpx;'" v-if="cates.length > 0">
  134. <view :class="'li ' + (currents == -1 ? 'active' : '')" @tap="all">全部</view>
  135. <block v-for="(item, index) in cates" :key="index" v-if="!merchantId">
  136. <view :class="'li ' + (currents == index ? 'active' : '')" @tap="cateTabs"
  137. :data-currents="index" :data-id="item.id">
  138. {{ item.title }}{{ merchantId }}
  139. </view>
  140. </block>
  141. </scroll-view>
  142. <view class="sort">
  143. <block v-for="(item, index) in pageList" :key="index">
  144. <view class="li dflex">
  145. <view class="proimgs" @tap="toDetail" :data-id="item.id">
  146. <image :src="item.pic + '?x-oss-process=style/w160'" mode="aspectFit" class="proimg"
  147. lazy-load="true"></image>
  148. <image :src="picUrlss + 'shouqing.png'" class="shouqing" v-if="item.stock < 1">
  149. </image>
  150. </view>
  151. <view class="flex">
  152. <view class="proname" @tap="toDetail" :data-id="item.id">{{ item.title }}</view>
  153. <!-- <view :class="[item.brandName ? '' : 'nopronames', 'pronames']">{{ item.brandName ? item.brandName : '' }}</view> -->
  154. <view class="operate dflex">
  155. <view class="price">
  156. <text>{{ item.salePrice }}</text>
  157. <!-- <text class="vip" v-if="show_membership_price==1&&item.actualPrice < item.salePrice"><text class="sale">VIP</text><text class="members">{{item.actualPrice}}</text></text>
  158. <text class="vip"
  159. v-if="show_membership_price==1&&item.membersPrice<item.salePrice"><text
  160. class="sale">VIP</text><text
  161. class="members">{{item.membersPrice}}</text></text> -->
  162. <text class="del">
  163. <block
  164. v-if="item.marketPrice != 0 && item.marketPrice > item.salePrice">
  165. ¥{{ item.marketPrice }}</block>
  166. </text>
  167. </view>
  168. </view>
  169. <view class="optt ddflex" style="justify-content: space-between;">
  170. <view>
  171. <view class="vip-news ddflex"
  172. v-if="show_membership_price == 1 && item.actualPrice < item.salePrice">
  173. <text class="vip-sale">会员价</text>
  174. <text class="vip-members">¥{{ item.actualPrice }}</text>
  175. </view>
  176. <view class="vip-news ddflex"
  177. v-if="show_membership_price == 1 && item.membersPrice < item.salePrice">
  178. <text class="vip-sale">会员价</text>
  179. <text class="vip-members">¥{{ item.membersPrice }}</text>
  180. </view>
  181. </view>
  182. <view class="add-cart">
  183. <!-- addShopCart -->
  184. <image src="/static/pages/images/jia2.png" @tap="toDetail"
  185. :data-id="item.id" :data-skuid="item.skuId" :data-index="index"
  186. :data-state="item.state"></image>
  187. </view>
  188. </view>
  189. </view>
  190. </view>
  191. </block>
  192. <view class="nodata nosp bgfff" v-if="show">
  193. <image :src="picUrlss + 'empty_sp.png'"></image>
  194. <text>暂无商品</text>
  195. </view>
  196. </view>
  197. </view>
  198. </view>
  199. </view>
  200. <cart :isUpdate="isUpdate"></cart>
  201. <foot channel="service" :isUpdate="isUpdate"></foot>
  202. </view>
  203. </template>
  204. <script>
  205. // pages/sort/sort.js
  206. //获取应用实例
  207. const app = getApp();
  208. const req = require('../../utils/request.js');
  209. const util = require('../../utils/util.js');
  210. let scrollDdirection = 0; // 用来计算滚动的方向
  211. import foot from '../../components/nav-bar/index';
  212. import cart from '../../components/shopping-cart/index';
  213. export default {
  214. data() {
  215. return {
  216. mainStyle: app.globalData.mainStyle,
  217. isUpdate: false,
  218. picUrlss: req.public.picUrls,
  219. systems: {},
  220. topHeight: 0,
  221. isFixed: false,
  222. isScroll: false,
  223. bottomBlankHeignt: app.globalData.isIPhoneX ? 68 : 0,
  224. categorys: [],
  225. //产品一级分类列表
  226. cates: [],
  227. //产品二级分类列表
  228. current: -1,
  229. currents: -1,
  230. page: 1,
  231. sort: false,
  232. sortCategorys: [],
  233. //产品一级分类列表
  234. selectTab: 0,
  235. scrollTop: 0,
  236. scrollHeight: 0,
  237. // 滚动视图的高度
  238. toView: 'position0',
  239. // 滚动视图跳转的位置
  240. scrollInfo: [],
  241. isload: true,
  242. // 自定义自己喜欢的颜色
  243. colorArr: ['#e83fa0', '#0cd4c5', '#b146f4', '#18c88b', '#227bfe', '#e8a52f', '#f78d58'],
  244. // 存储随机颜色
  245. randomColorArr: [],
  246. isUpdate: false, // 是否更新消息
  247. merchantId: '',
  248. id: '',
  249. show_membership_price: 0,
  250. Is_Store_Price_Stock: 0,
  251. pageList: [],
  252. _key: '',
  253. show: Boolean,
  254. cateid: '',
  255. merchant: {},
  256. label: [],
  257. couponList: [],
  258. config: {},
  259. leftTop: 0,
  260. };
  261. },
  262. components: {
  263. foot,
  264. cart
  265. },
  266. props: {},
  267. onLoad: async function(options) {
  268. // 如果是tab页面不往下执行跳转tab缓存页面
  269. await this.getConfig().then(async res => {
  270. if (req.isTabPage('service', this.config.solution_name)) {
  271. req.toTabBar('service', options)
  272. return false
  273. } else {
  274. this.onLoadPage(options)
  275. }
  276. });
  277. },
  278. async onShow() {
  279. // 如果是tab页面不往下执行跳转tab缓存页面
  280. await this.getConfig().then(async res => {
  281. if (req.isTabPage('service', this.config.solution_name)) {
  282. return false
  283. } else {
  284. this.onShowPage()
  285. }
  286. });
  287. },
  288. onReachBottom() {
  289. this.onReachBottomPage()
  290. },
  291. methods: {
  292. async onLoadPage(options) {
  293. // console.log(options);
  294. this.setData({
  295. current: options.current ? options.current : -1,
  296. merchantId: options.merchantId,
  297. id: options.id
  298. });
  299. await this.getConfig();
  300. uni.getSystemInfo({
  301. success: res => {
  302. this.setData({
  303. scrollHeight: res.windowHeight - (136 * res.windowWidth) / 750
  304. });
  305. }
  306. });
  307. if (this.sort) await this.sortCategory();
  308. else await this.category('0', 'categorys', options.id);
  309. console.log('this.topHeight?????', this.topHeight);
  310. },
  311. onShowPage() {
  312. this.setData({
  313. isUpdate: !this.isUpdate
  314. });
  315. this.merchant = req.getStorage('MERCHANT') ? req.getStorage('MERCHANT') : req.getStorage(
  316. 'defaultMerchant');
  317. if (this.merchant.label) {
  318. this.label = this.merchant.label.split(',');
  319. }
  320. this.getCoupon();
  321. },
  322. onReachBottomPage() {
  323. this.page++;
  324. if (this.currents > -1) {
  325. this.getList(this.cateid);
  326. } else {
  327. if (this.current == -1) {
  328. this.getList();
  329. } else if (this.current == -2) {
  330. this.getList('', 'Recommend')
  331. } else {
  332. this.getList(this.id);
  333. }
  334. }
  335. },
  336. onPageScrollPage(e) {
  337. console.log('onPageScrollPage')
  338. const systemInfo = uni.getSystemInfoSync();
  339. let height = systemInfo.statusBarHeight + 44;
  340. if (e.scrollTop > height) {
  341. this.isScroll = true;
  342. } else {
  343. this.isScroll = false;
  344. }
  345. if (e.scrollTop > this.topHeight) {
  346. this.isFixed = true;
  347. this.leftTop = this.systems.barHeight;
  348. } else {
  349. this.isFixed = false;
  350. this.leftTop = 0;
  351. }
  352. },
  353. recieveCoupon(item, index) {
  354. if (item.userReceive > -1 && item.userCount >= item.userReceive) {
  355. return req.msg('超出优惠券领取限制,无法领取');
  356. }
  357. req.postRequest('/api/coupon/receive', {
  358. id: item.id
  359. }, res => {
  360. item.userCount++;
  361. req.msg('领取成功');
  362. });
  363. },
  364. goNavigation() {
  365. // #ifdef MP-WEIXIN
  366. let plugin = requirePlugin('routePlan');
  367. let key = req.public.mapLBSKEY; //使用在腾讯位置服务申请的key
  368. let referer = this.config.CONFIG_PROJECT_TITLE; //调用插件的app的名称
  369. // console.log("名称====" + referer);
  370. let endPoint = JSON.stringify({
  371. //终点
  372. 'name': this.merchant.title,
  373. 'latitude': this.merchant.lat,
  374. 'longitude': this.merchant.lng
  375. });
  376. var url = 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint;
  377. uni.navigateTo({
  378. url: url
  379. });
  380. // #endif
  381. // #ifdef H5
  382. util.openMapNavigation(this.merchant.lat, this.merchant.lng, this.merchant.title, '');
  383. // #endif
  384. },
  385. getCoupon() {
  386. let form = {
  387. page: 1,
  388. limit: 5
  389. }
  390. req.getRequest('/api/coupon/list', form, data => {
  391. this.couponList = data;
  392. })
  393. },
  394. getConfig() {
  395. var _this = this;
  396. return new Promise((resolve, reject) => {
  397. req.getRequest('/api/config', {}, function(res) {
  398. this.config = res;
  399. if (res && res.Product_Sort_ico == 1)
  400. _this.setData({
  401. sort: true
  402. });
  403. if (res && res.show_membership_price == 1) {
  404. _this.setData({
  405. show_membership_price: 1
  406. });
  407. }
  408. if (res && res.Is_Store_Price_Stock == 1) {
  409. _this.setData({
  410. Is_Store_Price_Stock: 1
  411. });
  412. }
  413. resolve(res);
  414. });
  415. });
  416. },
  417. category(id, dataName, listId) {
  418. //产品分类
  419. let that = this;
  420. // console.log(id, dataName, listId);
  421. let from = {
  422. page: 1,
  423. size: 1000,
  424. pid: id
  425. };
  426. if (this.Is_Store_Price_Stock == 1) {
  427. if (req.getStorage('smallShop')) {
  428. from.merchantId = req.getStorage('smallShop').merchantDTO.id;
  429. } else if (req.getStorage('MERCHANT')) {
  430. from.merchantId = req.getStorage('MERCHANT').id;
  431. }
  432. }
  433. return new Promise((resolve, reject) => {
  434. req.getRequest('/api/category/list', from, res => {
  435. // console.log(res);
  436. let data = {};
  437. data[dataName] = res;
  438. if (id == 0) {
  439. if (listId) {
  440. this.getList(listId); // this.initCate(listId, 'cates');
  441. } else {
  442. this.getList();
  443. // this.initCate(res[0].id, 'cates');
  444. // that.setData({
  445. // id: res[0].id
  446. // });
  447. }
  448. }
  449. that.setData(data);
  450. // console.log(data);
  451. resolve();
  452. });
  453. })
  454. },
  455. async initCate(id, dataName) {
  456. await this.category(id, dataName); // if(this.data.merchantId){
  457. // return false
  458. // }
  459. this.getList(id);
  460. },
  461. cateTab(e) {
  462. let current = e.currentTarget.dataset.current;
  463. let id = e.currentTarget.dataset.id;
  464. this.isload = true;
  465. if (current == -1) {
  466. this.cates = [];
  467. this.current = current;
  468. this.page = 1;
  469. this.pageList = [];
  470. this.getList();
  471. } else if (current == -2) {
  472. this.cates = [];
  473. this.current = current;
  474. this.page = 1;
  475. this.pageList = [];
  476. this.getList('', 'Recommend');
  477. } else if (current == -3) {
  478. uni.navigateTo({
  479. url: '/group/list/index'
  480. })
  481. } else {
  482. this.current = current;
  483. this.page = 1;
  484. this.pageList = [];
  485. this.categoryId = id;
  486. this.id = id;
  487. this.currents = -1;
  488. this.initCate(id, 'cates');
  489. }
  490. },
  491. getList(id, attr) {
  492. if (!this.isload) return false;
  493. this.isload = false;
  494. // console.log("====================")
  495. //产品列表
  496. let that = this;
  497. var startTime = new Date().getTime();
  498. // console.log(id);
  499. let from = {
  500. page: that.page,
  501. limit: 6,
  502. };
  503. if (id) from.categoryId = id;
  504. if (attr) from.attr = attr;
  505. if (this.Is_Store_Price_Stock == 1) {
  506. if (req.getStorage('MERCHANT')) {
  507. if (req.getStorage('MERCHANT').isDefault != 1) {
  508. from.merchantId = req.getStorage('MERCHANT').id;
  509. } else {
  510. delete from.merchantId;
  511. }
  512. }
  513. }
  514. if (from.page == 1) {
  515. uni.showLoading()
  516. }
  517. return new Promise((resolve, reject) => {
  518. req.getRequest('/api/product/list', from, res => {
  519. // console.log(new Date().getTime() - startTime);
  520. if (res && res.length >= from.limit) that.isload = true;
  521. if (that.page > 1) res = that.pageList.concat(res);
  522. if (res.length <= 0) {
  523. that.setData({
  524. show: true
  525. });
  526. } else {
  527. that.setData({
  528. show: false
  529. });
  530. }
  531. that.setData({
  532. pageList: res
  533. });
  534. uni.hideLoading();
  535. resolve();
  536. });
  537. })
  538. },
  539. cateTabs(e) {
  540. let current = e.currentTarget.dataset.currents;
  541. let id = e.currentTarget.dataset.id;
  542. this.setData({
  543. currents: current,
  544. page: 1,
  545. pageList: [],
  546. cateid: id
  547. });
  548. this.isload = true;
  549. this.page = 1;
  550. this.getList(id);
  551. },
  552. all() {
  553. // console.log(this.id); // this.getList(this.data.id)
  554. this.setData({
  555. currents: -1
  556. });
  557. this.initCate(this.id, 'cates');
  558. },
  559. toDetail(e) {
  560. let id = e.currentTarget.dataset.id; // let merchant = e.currentTarget.dataset.merchant
  561. // let shopId = e.currentTarget.dataset.shopid
  562. if (this.Is_Store_Price_Stock == 1) {
  563. if (req.getStorage('smallShop')) {
  564. var merchantId = req.getStorage('smallShop').merchantDTO.id;
  565. var shopId = req.getStorage('smallShop').id;
  566. app.globalData.openPage('product/detail/detail?id=' + id + '&merchantId=' + merchantId +
  567. '&shopId=' + shopId);
  568. } else if (req.getStorage('MERCHANT')) {
  569. if (req.getStorage('MERCHANT').isDefault != 1) {
  570. merchantId = req.getStorage('MERCHANT').id;
  571. app.globalData.openPage('product/detail/detail?id=' + id + '&merchantId=' + merchantId);
  572. } else {
  573. app.globalData.openPage('product/detail/detail?id=' + id);
  574. }
  575. }
  576. } else {
  577. app.globalData.openPage('product/detail/detail?id=' + id);
  578. } // if (!shopId) {
  579. // app.openPage("product/detail/detail?id=" + id + "&merchantId=" + merchantId)
  580. // } else {
  581. // app.openPage("product/detail/detail?id=" + id + "&merchantId=" + merchantId + "&shopId=" + shopId)
  582. // }
  583. // app.openPage("product/detail/detail?id=" + id)
  584. },
  585. addShopCart(e) {
  586. let that = this;
  587. let skuId = e.currentTarget.dataset.skuid;
  588. let id = e.currentTarget.dataset.id;
  589. let index = e.currentTarget.dataset.index;
  590. let pageList = that.pageList;
  591. let state = e.currentTarget.dataset.state; // let merchant = req.getStorage('MERCHANT');
  592. req.isLogin().then(success => {
  593. if (success) {
  594. let params = {
  595. skuId: skuId,
  596. quantity: 1,
  597. productId: id
  598. };
  599. if (req.getStorage('smallShop')) {
  600. params.merchantId = req.getStorage('smallShop').merchantDTO.id;
  601. params.shopId = req.getStorage('smallShop').id;
  602. } else if (req.getStorage('MERCHANT')) {
  603. params.merchantId = req.getStorage('MERCHANT').id;
  604. } // if(state!=1){
  605. // return req.msg('您来晚了,商品已经下架')
  606. // }
  607. req.postRequest('/api/purchase/cart', params, res => {
  608. that.setData({
  609. isUpdate: !that.isUpdate
  610. });
  611. req.msg('加入购物车成功');
  612. });
  613. }
  614. });
  615. },
  616. sortCategory() {
  617. //产品分类
  618. let that = this;
  619. let params = {
  620. page: 1,
  621. size: 1000
  622. };
  623. if (this.Is_Store_Price_Stock == 1) {
  624. if (req.getStorage('smallShop')) {
  625. params.merchantId = req.getStorage('smallShop').merchantDTO
  626. .id; // params.shopId= req.getStorage('smallShop').id
  627. } else if (req.getStorage('MERCHANT')) {
  628. if (req.getStorage('MERCHANT').isDefault != 1) {
  629. params.merchantId = req.getStorage('MERCHANT').id;
  630. }
  631. }
  632. }
  633. return new Promise((resolve, reject) => {
  634. req.getRequest('/api/category/list', params, res => {
  635. if (res) {
  636. let array = res
  637. .filter(it => it.pid == 0)
  638. .map(item => {
  639. item.nodes = res
  640. .filter(ite => ite.pid == item.id)
  641. .map(mp => {
  642. mp.first = mp.title.substr(0, 1);
  643. let random = that.colorArr[Math.floor(Math.random() *
  644. that.colorArr.length)];
  645. mp.colors = random;
  646. return mp;
  647. });
  648. return item;
  649. });
  650. that.setData({
  651. sortCategorys: array
  652. });
  653. setTimeout(() => {
  654. that.lisenerScroll();
  655. }, 100);
  656. }
  657. resolve();
  658. });
  659. })
  660. },
  661. goUrl(e) {
  662. let id = e.currentTarget.dataset.id;
  663. let title = e.currentTarget.dataset.title;
  664. if (this.Is_Store_Price_Stock == 1) {
  665. if (req.getStorage('smallShop')) {
  666. var merchantId = req.getStorage('smallShop').merchantDTO.id;
  667. app.globalData.openPage('product/list/list?id=' + id + '&smallShop=true' + '&title=' + title);
  668. } else if (req.getStorage('MERCHANT')) {
  669. if (req.getStorage('MERCHANT').isDefault != 1) {
  670. merchantId = req.getStorage('MERCHANT').id;
  671. app.globalData.openPage('product/list/list?id=' + id + '&merchantId=' + merchantId +
  672. '&title=' + title);
  673. } else {
  674. app.globalData.openPage('product/list/list?id=' + id + '&title=' + title);
  675. }
  676. }
  677. } else {
  678. app.globalData.openPage('product/list/list?id=' + id + '&title=' + title);
  679. } // app.openPage(e.currentTarget.dataset.url)
  680. },
  681. toScrollView(e) {
  682. const {
  683. index
  684. } = e.currentTarget.dataset;
  685. this.setData({
  686. selectTab: index,
  687. toView: `position${index}`
  688. });
  689. },
  690. /**
  691. * 获取右边每个分类的头部偏移量
  692. */
  693. lisenerScroll() {
  694. // var _ts=this;
  695. /* setTimeout(() => {
  696. _ts.setHeight(0);
  697. }, 10000);*/
  698. // 获取各分类容器距离顶部的距离
  699. new Promise(resolve => {
  700. let query = uni.createSelectorQuery();
  701. var clength = this.sortCategorys.length;
  702. for (var k = 0; k < clength; k++) {
  703. query.select(`#position${k}`).boundingClientRect();
  704. }
  705. query.exec(function(res) {
  706. resolve(res);
  707. });
  708. }).then(res => {
  709. var categorys = this.sortCategorys;
  710. if (res.length == categorys.length) {
  711. categorys.forEach((item, index) => {
  712. item.offsetTop = res[index].top;
  713. });
  714. this.setData({
  715. scrollInfo: res,
  716. sortCategorys: categorys
  717. });
  718. }
  719. });
  720. },
  721. setHeight(k) {
  722. var _ts = this;
  723. if (_ts.isload) {
  724. return;
  725. }
  726. _ts.isload = false;
  727. let query = uni.createSelectorQuery();
  728. query.select(`#position${k}`).boundingClientRect();
  729. query.exec(function(res) {
  730. var _key = 'categorys[' + k + '].offsetTop';
  731. _ts.setData({
  732. [_key]: res[0].top
  733. });
  734. _ts.isload = true;
  735. });
  736. },
  737. /**
  738. * 监听滚动条滚动事件
  739. */
  740. scrollTo(e) {
  741. const scrollTop = e.detail.scrollTop; //滚动的Y轴
  742. const {
  743. selectTab,
  744. sortCategorys
  745. } = this;
  746. if (scrollDdirection < scrollTop) {
  747. // 向上滑动
  748. scrollDdirection = scrollTop; // 计算偏移位置
  749. // console.log(current, scrollTop,categorys[current + 1].offsetTop);
  750. if (selectTab < sortCategorys.length - 1 && scrollTop >= sortCategorys[selectTab + 1].offsetTop) {
  751. // console.log("chua");
  752. this.setData({
  753. selectTab: selectTab + 1
  754. });
  755. }
  756. } else {
  757. // 向下滑动
  758. scrollDdirection = scrollTop; // 计算偏移位置
  759. if (selectTab > 0 && scrollTop < sortCategorys[selectTab].offsetTop && scrollTop > 0) {
  760. this.setData({
  761. selectTab: selectTab - 1
  762. });
  763. }
  764. }
  765. },
  766. jumpUrl(url) {
  767. uni.navigateTo({
  768. url: url
  769. })
  770. },
  771. closeUpdate() {
  772. this.isShowUpdate = false;
  773. },
  774. updateInfo(e) {
  775. this.isUpdateInfo = e;
  776. },
  777. updateMobile(e) {
  778. this.isUpdateMobile = e;
  779. }
  780. },
  781. created() {
  782. const systemInfo = uni.getSystemInfoSync();
  783. console.log('systemInfo==', systemInfo)
  784. // px转换到rpx的比例
  785. let pxToRpxScale = 750 / systemInfo.windowWidth;
  786. let systems = {
  787. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  788. navigationHeight: 44 * pxToRpxScale, // 导航栏的高度
  789. windowHeight: systemInfo.windowHeight,
  790. pxToRpxScale: pxToRpxScale
  791. };
  792. console.log('windowHeight==', systems.windowHeight)
  793. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  794. this.systems = systems;
  795. },
  796. mounted: function(e) {
  797. this.$nextTick(() => {
  798. let that = this;
  799. const query = wx.createSelectorQuery().in(this);
  800. query
  801. .select('.top-con')
  802. .boundingClientRect(function(res) {
  803. console.log('top-con==', res);
  804. that.topHeight = res.height;
  805. console.log('that.topHeight==', that.topHeight);
  806. })
  807. .exec();
  808. })
  809. },
  810. onPageScroll(e) {
  811. this.onPageScrollPage(e)
  812. }
  813. };
  814. </script>
  815. <style scoped>
  816. @import './index.css';
  817. </style>