list.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <template>
  2. <view :style="[mainStyle]">
  3. <!--product/list/list.wxml-->
  4. <view class="ssbox bgfff">
  5. <view class="search dflex" @tap="search">
  6. <image src="/static/pages/images/ssico.png"></image>
  7. <view>{{searchTitle ? searchTitle : '搜索你想要的商品'}}</view>
  8. </view>
  9. </view>
  10. <view class="filter dflex bgfff">
  11. <view :class="'li ' + (sort=='default'?'active':'')" @tap="ss" data-v="default">默认</view>
  12. <view :class="'li ' + (sort=='stock'?'active':'')" @tap="ss" data-v="stock">销量</view>
  13. <view v-if="sort=='default'||sort=='stock'" class="li" @tap="ss" data-v="ltPrice">价格<image
  14. src="/static/pages/images/jiage.png" class="updown"></image>
  15. </view>
  16. <view v-if="sort=='ltPrice'" class="li active" @tap="ss" data-v="gtPrice">价格<image
  17. src="/static/pages/images/up.png" class="updown"></image>
  18. </view>
  19. <view v-if="sort=='gtPrice'" class="li active" @tap="ss" data-v="ltPrice">价格<image
  20. src="/static/pages/images/down.png" class="updown"></image>
  21. </view>
  22. <view class="shaixuan li dflex" v-if="showview" @tap="translateshow">筛选<image
  23. src="/static/pages/images/shaixuan.png">
  24. </image>
  25. </view>
  26. </view>
  27. <view class="tabcon dflex" v-if="pageList.length > 0">
  28. <view v-for="(item, index) in pageList" :key="index" class="li">
  29. <view class="jsdimgs" @tap="toDetail" :data-id="item.id">
  30. <image :src="item.pic + '?x-oss-process=style/w375'" mode="aspectFit" class="jsdpro"
  31. lazy-load="true"></image>
  32. <image src="/static/pages/images/jishida.png" v-if="item.isJs" class="jsdimg"></image>
  33. <image :src="picUrlss + 'shouqing.png'" class="shouqin" v-if="item.stock<1"></image>
  34. </view>
  35. <view class="jsdinfo">
  36. <view class="proname" @tap="toDetail" :data-id="item.id">{{item.title}}</view>
  37. <view class="xiaol dflex">
  38. <block v-if="item.isOtc != 5 && about.is_open_shop == 1 && (isDistriUser == 2 || ascription)">
  39. <view class="zhuan dflex" v-if="item.commission>0">
  40. <block>
  41. <text>赚</text>
  42. <view class="dflex">¥{{item.commission }}</view>
  43. </block>
  44. </view>
  45. </block>
  46. <view class="yishou">{{item.sellStock}}件已售</view>
  47. </view>
  48. <view class="operate dflex">
  49. <view class="price">
  50. ¥<text>{{item.salePrice}}</text>
  51. <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>
  52. <text class="vip"
  53. v-if="show_membership_price==1&&item.membersPrice<item.salePrice"><text
  54. class="sale">VIP</text><text
  55. class="members">{{item.membersPrice}}</text></text>
  56. <text class="del" v-if="show_membership_price!=1">
  57. <block v-if="item.marketPrice!=0&&item.marketPrice>item.salePrice">
  58. ¥{{item.marketPrice}}
  59. </block>
  60. </text>
  61. </view>
  62. <view class="add-cart">
  63. <view class="dot" :animation="ani" :hidden="!showdot">+1</view><!-- addShopCart -->
  64. <image src="/static/pages/images/jia.png" @tap="toDetail" :data-id="item.id"
  65. :data-skuid="item.skuId" :data-index="index" :data-state="item.state"></image>
  66. <!-- <block v-else>v-if="item.stock>0"
  67. <text class="color999">已售罄</text>
  68. </block> -->
  69. <!-- <view class="nums dflex">
  70. <image src="/pages/images/jian.png"></image>
  71. <view class="num">1</view>
  72. <image src="/pages/images/jia1.png"></image>
  73. </view> -->
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <view class="nodata" v-if="ishow">
  80. <image :src="picUrlss+'empty_sp.png'"></image>
  81. <text>暂无商品</text>
  82. </view>
  83. <block v-else>
  84. <view class="nomore dflex" v-if="!isLoad&&hasmore">亲,没有更多了</view>
  85. <block v-else>
  86. <view class="nomore dflex" v-if="!isShowLoading">加载中···</view>
  87. </block>
  88. </block>
  89. <!-- <view class="contact_index1" id="contact_index1" bindtap="goshopCar">
  90. <image src="/pages/images/cart.png"></image>
  91. <text class="dots" wx:if="{{count > 0}}">{{count}}</text>
  92. </view> -->
  93. <cart :isUpdate="isUpdate"></cart>
  94. <!-- 筛选 -->
  95. <view :class="isRuleTrue?'isRuleShow':'isRuleHide'">
  96. <view class="mask" @tap="cancel"></view>
  97. <view class="shai" :animation="animationData">
  98. <view class="shai-box">
  99. <!-- <view class="shai-tit">分类<view class="quanbu dflex">全部<image src="/pages/images/bico.png"></image></view></view> -->
  100. <view class="shai-tit">分类</view>
  101. <view class="shai-lis dflex" v-if="categoryList.length>0">
  102. <view v-for="(item, index) in categoryList" :key="index"
  103. :class="'li ' + (showId == item.id ? 'active' : '')" :data-id="item.id"
  104. @tap="childCategory">{{item.title}}</view>
  105. </view>
  106. </view>
  107. <view class="shai-bot dflex">
  108. <!-- <view class="reset">重置</view> -->
  109. <!-- <view class="confirm" bindtap="success">确定<text>(124件商品)</text></view> -->
  110. <view class="confirm" @tap="success">确定</view>
  111. </view>
  112. </view>
  113. </view>
  114. </view>
  115. </template>
  116. <script>
  117. // product/list/list.js
  118. const app = getApp();
  119. const req = require("../../utils/request.js");
  120. import cart from "../../components/shopping-cart/index";
  121. export default {
  122. data() {
  123. return {
  124. mainStyle: app.globalData.mainStyle,
  125. picUrlss: req.public.picUrls,
  126. page: 1,
  127. pageList: [],
  128. pid: '',
  129. showId: 0,
  130. showview: true,
  131. isLoad: true,
  132. hasmore: false,
  133. categoryId: '',
  134. categoryList: [],
  135. searchTitle: '',
  136. sort: 'default',
  137. //stock 库存 ltPrice 价格升序 gtPrice 价格降序
  138. attr: '',
  139. //属性 boutique 精品, news 新品,sell_well 爆款,Recommend 推荐,
  140. isUpdate: false,
  141. //是否更新消息
  142. isRuleTrue: false,
  143. //筛选是否显示
  144. ishow: false,
  145. isShowLoading: true, // //购物车x坐标
  146. // animationx: 0,
  147. // //购物车y坐标
  148. // animationy: 0,
  149. // //是否显示飞行物,默认不显示
  150. showdot: false,
  151. // //动画对象
  152. ani: {},
  153. merchantId: "",
  154. shopId: "",
  155. merchant: "",
  156. show_membership_price: 0,
  157. hasemore: false,
  158. animation: "",
  159. animationData: {},
  160. about: {},
  161. isDistriUser: 0, // 判断用户是否是分销员 2为分销员
  162. ascription: false,//是否开启小店
  163. };
  164. },
  165. components: {
  166. cart
  167. },
  168. props: {},
  169. onLoad: function(options) {
  170. // console.log(options);
  171. this.query = options;
  172. let merchant;
  173. if (req.getStorage('smallShop')) {
  174. merchant = req.getStorage('smallShop');
  175. } else {
  176. merchant = req.getStorage('MERCHANT');
  177. }
  178. if (options.merchantId) {
  179. this.setData({
  180. merchantId: options.merchantId
  181. });
  182. }
  183. if (options.shopId) {
  184. this.shopId = options.shopId
  185. }
  186. this.setData({
  187. showId: options.categoryId,
  188. merchant: merchant,
  189. pid: options.id
  190. }); // let attr = ''
  191. // this.setData({
  192. // pid: options.id
  193. // })
  194. // if (options.title) {
  195. // switch (options.title) {
  196. // case "精选榜单":
  197. // attr = "boutique";
  198. // break;
  199. // case "店长推荐":
  200. // attr = "Recommend";
  201. // break;
  202. // }
  203. // }
  204. this.attr = options.attr;
  205. uni.setNavigationBarTitle({
  206. title: options.title ? options.title : '产品'
  207. });
  208. if (options.searchTitle) {
  209. this.setData({
  210. searchTitle: options.searchTitle
  211. });
  212. }
  213. this.categoryId = options.id;
  214. this.getList();
  215. },
  216. // onReady() {
  217. // //页面渲染完后获取购物车在页面中的坐标
  218. // const query = wx.createSelectorQuery()
  219. // query.select('#contact_index1').boundingClientRect()
  220. // query.selectViewport().scrollOffset()
  221. // query.exec(function(res) {
  222. // console.log(res)
  223. // let point = res[0]
  224. // //坐标修正,让飞行物可以正好落在购物车正中心,20是飞行物宽度一半然后转化成px
  225. // var xtemp = (point.left + point.right) / 2 - 20 / 750 * wx.getSystemInfoSync().windowWidth
  226. // var ytemp = (point.top + point.bottom) / 2 - 20 / 750 * wx.getSystemInfoSync().windowWidth
  227. // console.log('xtemp : ' + xtemp + ' ytemp : ' + ytemp)
  228. // that.setData({
  229. // //获取修正后坐标
  230. // animationx: xtemp,
  231. // animationy: ytemp
  232. // })
  233. // })
  234. // },
  235. onShow() {
  236. this.getConfig();
  237. this.getMy();
  238. },
  239. onReachBottom() {
  240. this.page++;
  241. this.getList();
  242. },
  243. onReady: function() {
  244. this.animation = uni.createAnimation();
  245. },
  246. methods: {
  247. getMy() {
  248. let that = this;
  249. let userInfo = req.getStorage('userInfo');
  250. if(!userInfo || userInfo == null) return false;
  251. req.getRequest('/api/user/my', {}, data => {
  252. that.isDistriUser = data.isDistriUser;
  253. if (data && data.listShopBase && data.listShopBase != null && data.listShopBase.length >0) {
  254. if (data.listShopBase[0].merchant_id == that.merchant.id && that.merchant.type != 5) {
  255. that.ascription = true;
  256. }
  257. }
  258. });
  259. },
  260. getConfig() {
  261. var _this = this;
  262. return new Promise((resolve, reject) => {
  263. req.getRequest('/api/config', {}, function(res) {
  264. _this.about = res;
  265. if (res && res.show_membership_price == 1) {
  266. _this.setData({
  267. show_membership_price: 1
  268. });
  269. }
  270. resolve();
  271. });
  272. });
  273. },
  274. ss(e) {
  275. var dt = e.currentTarget.dataset;
  276. // console.log(dt)
  277. this.isLoad = true;
  278. this.refresh(dt.v);
  279. },
  280. refresh(s, t) {
  281. this.setData({
  282. hasemore: true,
  283. sort: s
  284. });
  285. this.page = 1;
  286. this.getList();
  287. },
  288. search() {
  289. // app.openPage('pages/search/search?searchTitle=' + this.data.searchTitle)
  290. let supplier = '';
  291. if (this.query.supplier) {
  292. supplier = '&supplier=' + this.query.supplier;
  293. }
  294. if (this.query.merchantId) {
  295. if (this.query.shopId) {
  296. app.globalData.redirectTab('pages/search/search?searchTitle=' + this.searchTitle + "&merchantId=" +
  297. this.query.merchantId + '&shopId=' + this.query.shopId + supplier);
  298. } else {
  299. app.globalData.redirectTab('pages/search/search?searchTitle=' + this.searchTitle + '&merchantId=' +
  300. this.merchantId +
  301. supplier);
  302. }
  303. } else {
  304. app.globalData.redirectTab('pages/search/search?searchTitle=' + this.searchTitle + supplier);
  305. }
  306. },
  307. getList() {
  308. let isShowLoading = false;
  309. if (this.page == 1 && !isShowLoading) {
  310. req.loadIng('加载中');
  311. isShowLoading = true;
  312. }
  313. let that = this;
  314. // console.log(that.isLoad);
  315. if (!that.isLoad) {
  316. this.setData({
  317. isLoad: false
  318. });
  319. return false;
  320. }
  321. that.isLoad = false;
  322. that.translate(1);
  323. let form = {
  324. page: that.page,
  325. limit: 10,
  326. sort: that.sort,
  327. attr: that.attr,
  328. categoryId: that.categoryId,
  329. merchantId: that.query.merchantId
  330. }; // if(that.data.merchant.isDefault!=1){
  331. // form.merchantId=that.data.merchant.id
  332. // }
  333. if (this.query.supplier) {
  334. form.supplier = this.query.supplier;
  335. }
  336. if(this.query.productForm) form.productForm = this.query.productForm
  337. if(that.searchTitle) form.searchTitle= that.searchTitle
  338. if (this.query.shopId&&that.query.searchTitle) {
  339. form.sid = this.query.shopId
  340. form.merchantId = this.query.merchantId
  341. delete form.searchTitle;
  342. if(that.searchTitle) form.title = that.searchTitle;
  343. form.type = 1;
  344. req.getRequest('/api/shopProduct/list', form, data => {
  345. // console.log(form);
  346. if (data && data.length >= 10) {
  347. that.isLoad = true;
  348. } else {
  349. that.setData({
  350. hasmore: true,
  351. isLoad: false
  352. });
  353. }
  354. ;
  355. if (that.page > 1) data = that.pageList.concat(data);
  356. data = data.map(it => {
  357. if (it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1) it.isJs =
  358. true;
  359. return it;
  360. });
  361. that.setData({
  362. pageList: data
  363. });
  364. // console.log(data);
  365. if (data.length <= 0) {
  366. that.setData({
  367. ishow: true
  368. });
  369. } else {
  370. that.setData({
  371. ishow: false
  372. });
  373. }
  374. if (isShowLoading) {
  375. uni.hideLoading();
  376. this.setData({
  377. isShowLoading: false
  378. });
  379. isShowLoading = false;
  380. }
  381. });
  382. } else {
  383. req.getRequest('/api/product/list', form, data => {
  384. // console.log(form);
  385. if (data && data.length >= 10) {
  386. that.isLoad = true;
  387. } else {
  388. that.setData({
  389. hasmore: true,
  390. isLoad: false
  391. });
  392. }
  393. ;
  394. if (that.page > 1) data = that.pageList.concat(data);
  395. data = data.map(it => {
  396. if (it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1) it.isJs =
  397. true;
  398. return it;
  399. });
  400. that.setData({
  401. pageList: data
  402. });
  403. // console.log(data);
  404. if (data.length <= 0) {
  405. that.setData({
  406. ishow: true,
  407. });
  408. } else {
  409. that.setData({
  410. ishow: false
  411. });
  412. }
  413. if (isShowLoading) {
  414. uni.hideLoading();
  415. this.setData({
  416. isShowLoading: false
  417. });
  418. isShowLoading = false;
  419. }
  420. });
  421. }
  422. },
  423. toDetail(e) {
  424. let id = e.currentTarget.dataset.id;
  425. if (this.query.shopId) {
  426. app.globalData.openPage("product/detail/detail?id=" + id + "&merchantId=" + this.query.merchantId +
  427. '&shopId=' + this.query.shopId);
  428. }
  429. if (this.query.merchantId && !this.query.shopId) {
  430. app.globalData.openPage("product/detail/detail?id=" + id + "&merchantId=" + this.query.merchantId);
  431. }
  432. if (!this.merchantId) {
  433. app.globalData.openPage("product/detail/detail?id=" + id);
  434. }
  435. },
  436. addShopCart(e) {
  437. let that = this;
  438. let state = e.currentTarget.dataset.state;
  439. let skuId = e.currentTarget.dataset.skuid;
  440. let id = e.currentTarget.dataset.id;
  441. let index = e.currentTarget.dataset.index;
  442. let pageList = that.pageList;
  443. let params = {
  444. skuId: skuId,
  445. quantity: 1,
  446. productId: id
  447. }; // if(state!=1){
  448. // return req.msg('您来晚了,商品已经下架')
  449. // }
  450. if (this.query.shopId) {
  451. params.shopId = this.query.shopId, params.merchantId = this.query.merchantId;
  452. } else {
  453. params.merchantId = this.query.merchantId;
  454. }
  455. // console.log(pageList);
  456. req.postRequest('/api/purchase/cart', params, res => {
  457. that.setData({
  458. isUpdate: !that.isUpdate
  459. });
  460. req.msg('加入购物车成功');
  461. }); // if(that.data.showdot == true){
  462. // return
  463. // }
  464. // //获取点击点坐标
  465. // var touches = e.touches[0]
  466. // //坐标修正,同上,这么做是为了让飞行点落到点击的中心
  467. // let toptemp = touches.clientY - 20 / 750 * wx.getSystemInfoSync().windowWidth
  468. // let lefttemp = touches.clientX - 20 / 750 * wx.getSystemInfoSync().windowWidth
  469. // console.log('toptemp : ' + toptemp + ' lefttemp : ' + lefttemp)
  470. // var animation1 = wx.createAnimation({
  471. // duration: 1,
  472. // timingFunction: 'ease'
  473. // })
  474. // //通过极短的时间让飞行点移动到手指点击位置,同时让飞行点显示出来
  475. // animation1.left(lefttemp).top(toptemp).step()
  476. // that.setData({
  477. // ani: animation1.export(),
  478. // showdot: true
  479. // })
  480. // //然后让飞行点飞行到购物车坐标处,形成添加效果
  481. // setTimeout(function(){
  482. // const animation = wx.createAnimation({
  483. // duration: 1500,
  484. // timingFunction: 'ease'
  485. // })
  486. // //通过Animation的left和top这两个API,将飞行点移动到购物车坐标处
  487. // animation.left(that.data.animationx).top(that.data.animationy).step()
  488. // that.setData({
  489. // ani: animation.export()
  490. // })
  491. // setTimeout(function () {
  492. // var counttemp = that.data.count + 1
  493. // that.setData({
  494. // showdot: false,
  495. // ani: null,
  496. // count: counttemp
  497. // })
  498. // }.bind(this), 1520)//这里也是要稍微延后,后隐藏飞行点,然后清除动画,增加购物计数器
  499. // },5)//注意这里要稍微延后,保证前面移动到手指点击处的动画完成
  500. },
  501. childCategory: function(e) {
  502. var id = e.currentTarget.dataset.id;
  503. // console.log(id);
  504. this.setData({
  505. showId: id
  506. });
  507. },
  508. translateshow() {
  509. // console.log(this.showId);
  510. this.setData({
  511. isRuleTrue: true
  512. });
  513. this.animation.translate(-310, 0).step();
  514. this.animationData = this.animation.export()
  515. },
  516. translate: function(type) {
  517. var that = this;
  518. req.getRequest('/api/category/list', {
  519. pid: that.pid
  520. }, data => {
  521. // console.log(data);
  522. if (data) {
  523. that.setData({
  524. categoryList: data
  525. });
  526. if (data.length > 0) {
  527. this.setData({ // showId: data[0].id,
  528. // ishow: false
  529. });
  530. } else {
  531. this.setData({
  532. showview: false // ishow: true
  533. });
  534. }
  535. }
  536. });
  537. if (type != 1) {
  538. this.setData({
  539. isRuleTrue: true
  540. });
  541. this.animation.translate(-310, 0).step();
  542. this.animationData = this.animation.export()
  543. }
  544. },
  545. success: function() {
  546. this.setData({
  547. isRuleTrue: false
  548. });
  549. var that = this;
  550. that.page = 1;
  551. var categoryId = that.showId;
  552. this.animation.translate(0, 0).step();
  553. this.animationData = this.animation.export()
  554. if (categoryId != null && categoryId != "") {
  555. this.setData({
  556. categoryId: categoryId,
  557. isLoad: true
  558. });
  559. that.getList();
  560. }
  561. },
  562. cancel() {
  563. this.setData({
  564. isRuleTrue: false
  565. });
  566. this.animation.translate(0, 0).step();
  567. this.animationData = this.animation.export()
  568. }
  569. }
  570. };
  571. </script>
  572. <style>
  573. @import "./list.css";
  574. </style>