list.vue 14 KB

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