index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  1. <template>
  2. <view>
  3. <u-sticky>
  4. <view>
  5. <scroll-view class="scroll-view_H_MY" :scroll-x="true" @scroll="scroll">
  6. <view :class="index=== oneTypeActive ? 'scroll-view-item_H_MY-active':''"
  7. @click="oneTypeClick(item,index)" v-for="(item,index) in giftTypeList"
  8. class="scroll-view-item_H_MY">
  9. {{item.giftTypeName}}
  10. </view>
  11. </scroll-view>
  12. </view>
  13. </u-sticky>
  14. <view style="display: flex;flex-flow: row wrap;">
  15. <view style="width: 20%; text-align: center;background-color: #f0f0f0;">
  16. <scroll-view scroll-y scroll-with-animation :scrollTop="scrollLeftTop"
  17. :style="[{height: containerHeight + 'px'}]">
  18. <view :class="index === twoTypeActive ? 'giftTypeItem-active':''" @click="twoTypeClick(item,index)"
  19. v-for="(item,index) in giftTypeList[oneTypeActive].children" class="giftTypeItem">
  20. {{item.giftTypeName}}
  21. </view>
  22. </scroll-view>
  23. </view>
  24. <view style="width: 80%;background-color: #ffffff;text-align:center;">
  25. <scroll-view scroll-y scroll-with-animation :scrollTop="scrollLeftTop" :lower-threshold="110"
  26. @scrolltolower="refreshGift" :style="[{height: containerHeight + 'px'}]">
  27. <view class="foodBody">
  28. <view style="width: 49%;">
  29. <view v-if="index %2 === 0" class="goodsItem" v-for="(item, index) in list" :key="index">
  30. <image @click="toMorePage(item)" class="cuisineImg" width="100%" height="100%"
  31. :src=" baseURL+item.giftPictrue" mode="widthFix" radius="5"></image>
  32. <view @click="toMorePage(item)" class="goodsName">{{item.giftName}}</view>
  33. <view class="goodsPrice" @click="toMorePage(item)">
  34. <u-row>
  35. <u-col span="6">
  36. <u-icon name="integral" :label="item.giftPrice"
  37. labelColor="rgb(10, 185, 156)" color="rgb(10, 185, 156)"
  38. labelSize="12.5"></u-icon>
  39. </u-col>
  40. <u-col span="6" textAlign="right">
  41. <view
  42. :style="{'font-size': '12px','color': item.amount === 0 ? '#ffac29':'rgb(0, 0, 0)'}">
  43. {{'库存:'+item.amount}}
  44. </view>
  45. </u-col>
  46. </u-row>
  47. </view>
  48. <view class="gwxx">
  49. </view>
  50. <view class="gwxx">
  51. <view style="display: flex;flex-wrap: wrap-reverse;padding: 0 20rpx;">
  52. <view style="border: 1rpx solid rgb(10, 185, 156);
  53. color: rgb(10, 185, 156);font-size: 22rpx; padding: 5rpx 15rpx;
  54. border-radius: 10rpx;" @click="addGoods(item)">
  55. 加入购物车
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <view style="width: 49%;">
  62. <view v-if="index %2 !== 0" class="goodsItem" v-for="(item, index) in list" :key="index">
  63. <image @click="toMorePage(item)" class="cuisineImg" width="100%" height="100%"
  64. :src=" baseURL+item.giftPictrue" mode="widthFix" radius="5"></image>
  65. <view @click="toMorePage(item)" class="goodsName">{{item.giftName}}</view>
  66. <view class="goodsPrice" @click="toMorePage(item)">
  67. <u-row>
  68. <u-col span="6">
  69. <u-icon name="integral" :label="item.giftPrice"
  70. labelColor="rgb(10, 185, 156)" color="rgb(10, 185, 156)"
  71. labelSize="12.5"></u-icon>
  72. </u-col>
  73. <u-col span="6" textAlign="right">
  74. <view
  75. :style="{'font-size': '12px','color': item.amount === 0 ? '#ffac29':'rgb(0, 0, 0)'}">
  76. {{'库存:'+item.amount}}
  77. </view>
  78. </u-col>
  79. </u-row>
  80. </view>
  81. <view class="gwxx">
  82. <view style="display: flex;flex-wrap: wrap-reverse;padding: 0 20rpx;">
  83. <view style="border: 1rpx solid rgb(10, 185, 156);
  84. color: rgb(10, 185, 156);font-size: 22rpx; padding: 5rpx 15rpx;
  85. border-radius: 10rpx;" @click="addGoods(item)">
  86. 加入购物车
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. <u-loadmore :status="status" />
  94. </scroll-view>
  95. </view>
  96. </view>
  97. <view v-if="noticeStatus">
  98. <u-notice-bar :text="noticeText"></u-notice-bar>
  99. </view>
  100. <view class="content">
  101. <!-- @touchstart="handleStart" @touchmove="handleMove" @touchend="handleEnd" -->
  102. <view :style="{'transform':'translate3d('+0+'px,'+-80+'px,0)'}" class="touch">
  103. <view @click="confirm1">
  104. <view :style="gwcNum === 0 ? 'background-color:#c5c5c5;':'background-color:#e93c45;'" style="position: absolute;top:-30rpx; right: 0;
  105. color: #ffffff;font-size: 30rpx;border-radius: 50%;width: 55rpx;height: 55rpx;">
  106. {{gwcNum}}
  107. </view>
  108. <u-icon name="shopping-cart" size="50" class="gwc" color="#ffffff">
  109. </u-icon>
  110. </view>
  111. </view>
  112. </view>
  113. <!-- <wp-tabbar pagePath="/pages/integral/index" :type="type"></wp-tabbar> -->
  114. </view>
  115. </template>
  116. <script>
  117. export default {
  118. data() {
  119. return {
  120. containerHeight: 0,
  121. stickyOffsetTop: 20,
  122. scrollLeftTop: 0,
  123. height: 0,
  124. option: {
  125. page: 1,
  126. size: 10,
  127. auto: true
  128. },
  129. noticeText: '',
  130. page: 1,
  131. oneTypeActive: 0,
  132. twoTypeActive: 0,
  133. list: [],
  134. giftTypeList: [],
  135. total: 0,
  136. from: {
  137. consumerType: uni.getStorageSync("userInfo").userType,
  138. jgid: uni.getStorageSync("orgInfo").organizationCode,
  139. organizationCode: uni.getStorageSync("orgInfo").organizationCode,
  140. },
  141. scrollTop: 0,
  142. gwcNum: 0,
  143. xMove: 0,
  144. yMove: -80,
  145. baseURL: this.$BASE_URL,
  146. loading: false,
  147. oName: uni.getStorageSync("orgInfo").organizationName,
  148. gwcNum: 0,
  149. maxNum: 0,
  150. timeStop: 0,
  151. goodsList: [],
  152. menuData: {},
  153. status: 'loadmore',
  154. //兑换物品下拉列表锁 避免多次下拉导致出错
  155. loadingLock: 0,
  156. noticeStatus: false
  157. }
  158. },
  159. mounted() {
  160. // this.load(this.option)
  161. this.getNoticeStatus()
  162. this.getSCN()
  163. this.giftType()
  164. this.getNotice()
  165. uni.getSystemInfo({
  166. success: res => {
  167. console.log(res)
  168. const height = this.height
  169. const windowHeight = res.windowHeight // 可使用窗口高度
  170. if (height) {
  171. // 限制containerHeight的值,避免传入的height值过大而出现滚动条
  172. const remainHeight = windowHeight - this.stickyOffsetTop // 因设置了offsetTop后剩余的height值
  173. if (height > remainHeight) {
  174. this.containerHeight = remainHeight
  175. } else {
  176. this.containerHeight = height
  177. }
  178. } else {
  179. this.containerHeight = windowHeight
  180. }
  181. }
  182. })
  183. },
  184. onShow() {
  185. uni.reLaunch({
  186. url: '/pages/tabbar/wpTabbar'
  187. })
  188. },
  189. onPullDownRefresh() {},
  190. onReachBottom() {},
  191. methods: {
  192. imgLoad(img, callback) {
  193. var timer = setInterval(function() {
  194. if (img.complete) {
  195. callback(img)
  196. clearInterval(timer)
  197. }
  198. }, 50)
  199. },
  200. refreshGift() {
  201. if (this.total === this.list.length) {
  202. this.status = 'nomore'
  203. return
  204. }
  205. if (this.loadingLock === 0) {
  206. ++this.option.page
  207. this.taskList(this.option)
  208. }
  209. },
  210. oneTypeClick(type, index) {
  211. this.list = []
  212. this.oneTypeActive = index
  213. this.twoTypeActive = index
  214. this.option.page = 1
  215. this.option.size = 10
  216. this.option.giftType = 2
  217. this.option.giftTypeCode = type.children[0].id
  218. this.taskList(this.option)
  219. },
  220. twoTypeClick(type, index) {
  221. this.list = []
  222. this.twoTypeActive = index
  223. this.option.page = 1
  224. this.option.size = 10
  225. this.option.giftType = 2
  226. this.option.giftTypeCode = type.id
  227. this.taskList(this.option)
  228. },
  229. myIsNaN(value) {
  230. return typeof value === 'number' && !isNaN(value)
  231. },
  232. changeNum(value) {
  233. this.setGwcNum()
  234. },
  235. toMorePage(item) {
  236. uni.setStorageSync("giftContent", item.giftContent)
  237. uni.navigateTo({
  238. url: "../../pages/integral/more"
  239. })
  240. },
  241. async giftType() {
  242. // 发送请求
  243. const {
  244. data: res
  245. } = await this.$httpRequest({
  246. url: '/app/giftType',
  247. method: 'get',
  248. urlType: this.$getUrlType()
  249. });
  250. if (res.code === 200) {
  251. this.giftTypeList = res.data;
  252. this.option.page = 1
  253. this.option.size = 10
  254. this.option.giftType = 2
  255. this.option.giftTypeCode = res.data[0].children[0].id
  256. this.taskList(this.option)
  257. }
  258. },
  259. async getNoticeStatus() {
  260. // 发送请求
  261. const {
  262. data: res
  263. } = await this.$httpRequest({
  264. url: '/app/getNoticeStatus',
  265. method: 'get',
  266. urlType: this.$getUrlType()
  267. });
  268. if (res.code === 200) {
  269. this.noticeStatus = res.msg !== "false"
  270. if (this.noticeStatus) {
  271. this.containerHeight -= (uni.getStorageSync('mydomHeight') + 80)
  272. } else {
  273. this.containerHeight -= (uni.getStorageSync('mydomHeight') + 50)
  274. }
  275. }
  276. },
  277. async addGoods(data) {
  278. let form = {
  279. amount: data.amount,
  280. giftId: data.giftId,
  281. giftName: data.giftName,
  282. giftNumber: data.giftNumber,
  283. giftPictrue: data.giftPictrue,
  284. giftPrice: data.giftPrice,
  285. num: data.num,
  286. plusOrMinus: 0
  287. }
  288. // 发送请求
  289. const {
  290. data: res
  291. } = await this.$httpRequest({
  292. url: '/app/addShopCar',
  293. method: 'post',
  294. data: form,
  295. urlType: this.$getUrlType()
  296. });
  297. if (res.code === 200) {
  298. uni.showToast({
  299. duration: 1500,
  300. title: '添加成功'
  301. })
  302. this.getSCN()
  303. } else {
  304. this.$showModal(res.msg)
  305. }
  306. },
  307. async getNotice() {
  308. // 发送请求
  309. const {
  310. data: res
  311. } = await this.$httpRequest({
  312. url: '/app/getNotice',
  313. method: 'get',
  314. urlType: this.$getUrlType()
  315. });
  316. if (res.code === 200) {
  317. this.noticeText = res.msg
  318. }
  319. },
  320. async getSCN() {
  321. // 发送请求
  322. const {
  323. data: res
  324. } = await this.$httpRequest({
  325. url: '/app/getSCN',
  326. method: 'get',
  327. urlType: this.$getUrlType()
  328. });
  329. if (res.code === 200) {
  330. this.gwcNum = res.data
  331. }
  332. },
  333. async taskList(paging) {
  334. this.getSCN()
  335. this.loadingLock = 1
  336. this.status = 'loading'
  337. this.from.giftType = paging.giftType
  338. this.from.giftTypeCode = paging.giftTypeCode
  339. // 发送请求
  340. const {
  341. data: res
  342. } = await this.$httpRequest({
  343. url: '/app/getGift?pageNum=' + paging.page + '&pageSize=' + paging.size,
  344. method: 'post',
  345. data: this.from,
  346. isNotErrorMsg: true,
  347. urlType: this.$getUrlType()
  348. });
  349. if (res.code === 200) {
  350. if (paging.page === 1) {
  351. this.total = res.total
  352. this.list = res.rows
  353. this.list.forEach(item => {
  354. item.num = 0
  355. })
  356. } else if (paging.page > 1) {
  357. for (var i = 0; i < res.rows.length; i++) {
  358. res.rows[i].num = 0
  359. this.list.push(res.rows[i])
  360. }
  361. }
  362. this.loadingLock = 0
  363. this.status = 'loadmore'
  364. }
  365. },
  366. setGwcNum() {
  367. console.log("setGwcNum")
  368. let count = 0
  369. const goodsListInfo = this.list;
  370. for (var i = 0; i < goodsListInfo.length; i++) {
  371. if (goodsListInfo[i].num) {
  372. let num = parseInt(goodsListInfo[i].num)
  373. let amount = parseInt(goodsListInfo[i].amount)
  374. if (amount < num) {
  375. goodsListInfo[i].num = amount
  376. num = amount
  377. }
  378. count += num
  379. }
  380. }
  381. this.gwcNum = count
  382. },
  383. toShopListPage() {
  384. if (0 === this.gwcNum) {
  385. this.showToast({
  386. duration: 1500,
  387. message: "请选择商品"
  388. });
  389. return;
  390. }
  391. this.show1 = true;
  392. },
  393. addToCart(type, gift) {
  394. if (type === 0 && gift.num === 0) {
  395. return
  396. }
  397. if (gift.amount === 0) {
  398. this.showToast({
  399. duration: 500,
  400. message: "库存不足"
  401. });
  402. return
  403. }
  404. if (type === 1) {
  405. if (gift.num) {
  406. if (gift.amount <= gift.num) {
  407. this.showToast({
  408. duration: 500,
  409. message: "库存已达最大数量"
  410. });
  411. return
  412. }
  413. gift.num += 1
  414. } else {
  415. gift.num = 1
  416. }
  417. } else {
  418. gift.num -= 1
  419. }
  420. let that = this
  421. setTimeout(() => {
  422. that.setGwcNum()
  423. }, 100)
  424. },
  425. scroll: function(e) {
  426. console.log(e)
  427. this.old.scrollTop = e.detail.scrollTop
  428. },
  429. confirm1(e) {
  430. console.log(1)
  431. wx.pageScrollTo({
  432. scrollTop: 0,
  433. success() {
  434. }
  435. })
  436. this.$goto('../../pages/integral/shopcar')
  437. },
  438. showToast(params) {
  439. this.$refs.uToast.show({
  440. ...params,
  441. complete() {}
  442. })
  443. },
  444. handleStart(ev) {
  445. // console.log('start',ev);
  446. // 记录一开始手指按下的坐标
  447. var touch = ev.changedTouches[0];
  448. startPoint.x = touch.pageX;
  449. startPoint.y = touch.pageY;
  450. },
  451. handleMove(ev) {
  452. // console.log('move',ev);
  453. // 防止页面高度很大,出现滚动条,不能移动-默认拖动滚动条事件
  454. ev.preventDefault();
  455. isTouchMove = true;
  456. var touch = ev.changedTouches[0];
  457. var diffPonit = {}; // 存放差值
  458. var movePonit = {
  459. // 记录移动的距离
  460. x: 0,
  461. y: 0
  462. };
  463. diffPonit.x = touch.pageX - startPoint.x;
  464. diffPonit.y = touch.pageY - startPoint.y;
  465. // 移动的距离 = 差值 + 当前坐标点
  466. movePonit.x = diffPonit.x + curPoint.x;
  467. movePonit.y = diffPonit.y + curPoint.y;
  468. this.move(movePonit.x, movePonit.y);
  469. },
  470. handleEnd(ev) {
  471. // console.log('end', ev);
  472. if (!isTouchMove) return;
  473. // 更新坐标原点
  474. var touch = ev.changedTouches[0];
  475. curPoint.x += touch.pageX - startPoint.x;
  476. curPoint.y += touch.pageY - startPoint.y;
  477. // 重置
  478. isTouchMove = false;
  479. },
  480. move(x, y) {
  481. x = x || 0; // 没有传就是0
  482. y = y || 0;
  483. this.xMove = x;
  484. this.yMove = y;
  485. // translate3d (tx,ty,tz) 在X轴偏移tx,在Y轴偏移ty,在Z轴偏移tz,单位px
  486. },
  487. // 刷新刷剧
  488. refresh() {
  489. this.option.page = 1
  490. this.option.size = 10
  491. this.option.giftType = 1
  492. this.taskList(this.option)
  493. },
  494. scrolltolower(e) {},
  495. load(paging) {
  496. this.taskList(paging)
  497. },
  498. loadSuccess(list) {
  499. this.list = list
  500. }
  501. }
  502. }
  503. </script>
  504. <style lang="scss" scoped>
  505. .foodBody {
  506. padding-top: 10rpx;
  507. padding-left: 10rpx;
  508. display: flex;
  509. flex-flow: row wrap;
  510. justify-content: center;
  511. border-radius: 30rpx;
  512. }
  513. .gwxx {
  514. padding-top: 10rpx;
  515. }
  516. .scroll-view_H_MY {
  517. white-space: nowrap;
  518. width: 100%;
  519. letter-spacing: 10rpx;
  520. // padding: 20rpx;
  521. background-color: rgb(255, 255, 255);
  522. // background: linear-gradient(to bottom right, rgb(47, 203, 198), rgb(127, 241, 209));
  523. }
  524. .scroll-view-item_H_MY {
  525. color: #8c8c8c;
  526. height: 35px;
  527. width: 33.4%;
  528. font-size: 30rpx;
  529. display: inline-flex; // item的外层定义成行内元素才可进行滚动 inline-block / inline-flex 均可
  530. flex-direction: column;
  531. align-items: center;
  532. border-right: 1rpx #f3f3f3 solid;
  533. }
  534. .scroll-view-item_H_MY-active {
  535. // background-color: rgb(153, 241, 224);
  536. border-bottom: 5rpx rgb(96, 182, 158) solid;
  537. }
  538. .giftTypeItem {
  539. color: #8c8c8c;
  540. padding: 20rpx 10rpx;
  541. font-size: 25rpx;
  542. letter-spacing: 5rpx;
  543. background-color: #f0f0f0;
  544. border-bottom: 1rpx #f3f3f3 solid;
  545. }
  546. .giftTypeItem-active {
  547. background-color: #ffffff;
  548. }
  549. .isNumNull {
  550. color: #FF0000;
  551. }
  552. .content {
  553. display: flex;
  554. flex-direction: column;
  555. align-items: center;
  556. justify-content: center;
  557. }
  558. .addGwc:active {
  559. color: #ffffff;
  560. }
  561. .touch {
  562. position: fixed;
  563. right: 40rpx;
  564. bottom: 60rpx;
  565. width: 95rpx;
  566. height: 95rpx;
  567. /* 知识点
  568. line-height是行高,针对的对象是文字,height针对的是容器,
  569. 也就是高度,当height和line-height值相同时会居中,
  570. 当line-height值小于height时文字向上移动,反之向下移动。
  571. */
  572. line-height: 95rpx;
  573. /* 文字垂直居中 */
  574. text-align: center;
  575. /* 水平居中 */
  576. background-color: rgba(0, 0, 0, 0.6);
  577. border-radius: 50%;
  578. color: #fff;
  579. font-size: 60rpx;
  580. /* 去除标签点击事件高亮效果 */
  581. -webkit-tap-highlight-color: transparent;
  582. /* 使用transform: translate3d 处理性能高 GUP */
  583. }
  584. #button_div {
  585. position: fixed;
  586. bottom: var(--window-bottom);
  587. }
  588. .mybackColor {
  589. background-color: #8c8c8c;
  590. }
  591. .shopHand {
  592. font-weight: bold;
  593. font-size: 20px;
  594. height: 20%;
  595. padding: 10% 0 10px 10px;
  596. margin-bottom: 5px;
  597. //background: linear-gradient(to bottom right, #85c1bf, #f1fef9);
  598. //background: rgb(55,186,189);
  599. background: #9ED6CF;
  600. }
  601. .cuisineImg {
  602. border-radius: 10px;
  603. max-height: 600rpx;
  604. height: auto;
  605. width: auto;
  606. padding: 0rpx 5rpx 2rpx;
  607. }
  608. .doFoodConfigView {
  609. width: 93%;
  610. margin: 0 auto;
  611. margin-top: 5px;
  612. padding: 2% 5px;
  613. background-color: #ffffff;
  614. border-radius: 10px;
  615. border: 1px solid #d3d3d3;
  616. }
  617. .gwcNum {
  618. width: 15px;
  619. top: 17px;
  620. left: 21px;
  621. position: relative;
  622. }
  623. /* 商品列表 */
  624. .goodsContent {
  625. width: 100%;
  626. margin: 0 auto;
  627. flex-direction: column;
  628. background: #f3f3f3;
  629. display: flex;
  630. justify-content: center;
  631. }
  632. .goodsItem {
  633. width: 280rpx;
  634. background: #FFFFFF;
  635. // border-radius: 10px;
  636. padding: 10rpx 0;
  637. // margin: 5rpx;
  638. // border: 1px solid #ebebeb;
  639. }
  640. .goodsName {
  641. font-size: 24rpx;
  642. color: #2e2e2e;
  643. padding: 10rpx 20rpx;
  644. overflow: hidden;
  645. text-overflow: ellipsis;
  646. display: -webkit-box;
  647. -webkit-line-clamp: 2;
  648. -webkit-box-orient: vertical;
  649. }
  650. .goodsPrice {
  651. color: #ffac29;
  652. font-size: 24rpx;
  653. padding: 0 15rpx;
  654. }
  655. .addFood {
  656. margin-left: 20rpx;
  657. color: #8c8c8c;
  658. }
  659. .minus {
  660. width: 26px;
  661. height: 26px;
  662. background-color: #efefef;
  663. border-width: 1px;
  664. border-color: #c6c6c6;
  665. border-top-left-radius: 100px;
  666. border-top-right-radius: 100px;
  667. border-bottom-left-radius: 100px;
  668. border-bottom-right-radius: 100px;
  669. @include flex;
  670. justify-content: center;
  671. align-items: center;
  672. }
  673. .input {
  674. padding: 0;
  675. }
  676. .plus {
  677. width: 20px;
  678. height: 20px;
  679. background-color: #FF0000;
  680. border-radius: 50%;
  681. /* #ifndef APP-NVUE */
  682. display: flex;
  683. /* #endif */
  684. justify-content: center;
  685. align-items: center;
  686. }
  687. </style>