index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  1. <template>
  2. <view>
  3. <u-loading-page :loading="loading"></u-loading-page>
  4. <u-toast ref="uToast"></u-toast>
  5. <u-sticky style="background-color: #f3f3f3;margin-top: 10px;" offset-top="5" customNavHeight="0">
  6. <view class="doFoodConfigView">
  7. <u-row>
  8. <u-col span="6">
  9. <view style="padding-left: 15px;" @click="isShowMenuName">
  10. <u-picker id="button_div" keyName="value" :show="show" :columns="menuName" :immediateChange="true"
  11. @confirm="confirm" @cancel="cancel" confirmColor="rgb(55,186,189)">
  12. </u-picker>
  13. <u-text size="15" :bold="true" suffixIcon="arrow-down-fill" iconStyle="font-size: 18px"
  14. :text="cuisineName"></u-text>
  15. </view>
  16. </u-col>
  17. <u-col span="6">
  18. <view style="margin-left: 30rpx;">
  19. <u-row>
  20. <u-col span="3">
  21. <view style="position: relative;">
  22. <view class="gwcNum">
  23. <u-badge v-if="gwcNum !== 0" :showZero="true" shape="horn" bgColor="#FF0000"
  24. :max="9" :value="gwcNum">
  25. </u-badge>
  26. </view>
  27. <view>
  28. <u-icon name="shopping-cart" size="50" class="gwc">
  29. </u-icon>
  30. </view>
  31. </view>
  32. </u-col>
  33. <u-col span="9">
  34. <view>
  35. <u-button style="width:85px;" color="rgb(55,186,189)" @click="toShopListPage">
  36. 确认下单
  37. </u-button>
  38. <u-picker keyName="placeName" :show="show1" :columns="menuName1"
  39. @confirm="confirm1" @cancel="cancel" confirmColor="#53a591">
  40. </u-picker>
  41. </view>
  42. </u-col>
  43. </u-row>
  44. </view>
  45. </u-col>
  46. </u-row>
  47. </view>
  48. </u-sticky>
  49. <view>
  50. <view style="margin-top: 20rpx;">
  51. <view v-if="goodsList.length === 0" style="margin-top: 170px;padding: 0 50px;">
  52. <img style="margin: 0 auto; width: 100%;" src="../../static/img/page/empty_view.png">
  53. </img>
  54. </view>
  55. <view class="goodsContent">
  56. <view class="goodsLeftList">
  57. <view class="goodsItem" v-for="item in goodsLeftList">
  58. <img v-if="item.cuisinePicture" class="cuisineImg" width="100%" height="100%"
  59. :src="baseURL+item.cuisinePicture" mode="widthFix" radius="5"></img>
  60. <img v-else class="cuisineImg" width="100%" height="100%"
  61. src="http://114.115.142.166:8087/down/O1FKVNmmA1up"></img>
  62. <view class="goodsName">{{item.cuisineName}}</view>
  63. <view class="goodsPrice">
  64. <u-icon name="rmb" :label="item.price"></u-icon>
  65. </view>
  66. <view class="gwxx">
  67. <u-row>
  68. <u-col span="4">
  69. <view>
  70. <u-button icon="minus" size="mini" color="#e93c45"
  71. @click="addToCart(0,item)">
  72. </u-button>
  73. </view>
  74. </u-col>
  75. <u-col span="4">
  76. <!-- <u-input v-model="item.amount" type="number"
  77. :disabled="item.maximum === item.amount">
  78. </u-input> -->
  79. <!-- <view style="text-align: center;" v-else>0</view> -->
  80. <view style="text-align: center;">
  81. {{item.amount}}
  82. </view>
  83. </u-col>
  84. <u-col span="4">
  85. <view>
  86. <u-button icon="plus" size="mini" color="rgb(10, 185, 156)"
  87. @click="addToCart(1,item)">
  88. </u-button>
  89. </view>
  90. </u-col>
  91. </u-row>
  92. </view>
  93. </view>
  94. </view>
  95. <view class="goodsRightList">
  96. <view class="goodsItem" v-for="item in goodsRightList">
  97. <img v-if="item.cuisinePicture" class="cuisineImg" width="100%" height="100%"
  98. :src=" baseURL+item.cuisinePicture" mode="widthFix" radius="5"></img>
  99. <img v-else class="cuisineImg" width="100%" height="100%"
  100. src="http://114.115.142.166:8087/down/O1FKVNmmA1up"></img>
  101. <view class="goodsName">{{item.cuisineName}}</view>
  102. <view class="goodsPrice">
  103. <u-icon name="rmb" :label="item.price"></u-icon>
  104. </view>
  105. <view class="gwxx">
  106. <u-row>
  107. <u-col span="4">
  108. <view>
  109. <u-button icon="minus" size="mini" color="#e93c45"
  110. @click="addToCart(0,item)">
  111. </u-button>
  112. </view>
  113. </u-col>
  114. <u-col span="4">
  115. <view style="text-align: center;">
  116. {{item.amount}}
  117. </view>
  118. </u-col>
  119. <u-col span="4">
  120. <view>
  121. <u-button icon="plus" size="mini" color="rgb(10, 185, 156)"
  122. @click="addToCart(1,item)">
  123. </u-button>
  124. </view>
  125. </u-col>
  126. </u-row>
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. </view>
  132. <view
  133. style="padding: 5rpx 7rpx;text-align: center;font-size: 19rpx;color: #868686;position: absolute;bottom: 0;">
  134. 预定声明:预定食品及物品的配送&品质&结算由梅陇社区全权负责 </view>
  135. </view>
  136. <!-- <wp-tabbar pagePath="/pages/orderFood/index" :type="type"></wp-tabbar> -->
  137. </view>
  138. </template>
  139. <script>
  140. export default {
  141. data() {
  142. return {
  143. type: undefined,
  144. isImg: 0,
  145. baseURL: this.$BASE_URL,
  146. loading: false,
  147. cuisineName: '当前时间无内容',
  148. oName: '',
  149. gwcNum: 0,
  150. maxNum: 0,
  151. timeStop: 0,
  152. goodsList: [],
  153. menuData: {},
  154. goodsListCount: 0, //加载第i张图片
  155. // 左侧商品列表
  156. goodsLeftList: [],
  157. goodsLeftListHeight: 0,
  158. // 右侧商品列表
  159. goodsRightList: [],
  160. goodsRightListHeight: 0,
  161. show: false,
  162. from: {
  163. consumerType: uni.getStorageSync("userInfo").userType,
  164. jgid: uni.getStorageSync("orgInfo").organizationCode,
  165. organizationCode: uni.getStorageSync("orgInfo").organizationCode,
  166. },
  167. patternId: '',
  168. menuName: [
  169. []
  170. ],
  171. menuName1: [
  172. []
  173. ],
  174. show: false, //true,
  175. show1: false
  176. }
  177. },
  178. mounted() {
  179. if (this.$getUrlType() === 3) {
  180. this.getCuisinesList();
  181. this.getJcd();
  182. }
  183. uni.setNavigationBarTitle({
  184. title: uni.getStorageSync("orgInfo").organizationName
  185. })
  186. this.type = uni.getStorageSync("tabType")
  187. if (this.$getUrlType() === 3) {
  188. this.getJcd();
  189. if (uni.getStorageSync("isRefresh") === 1) {
  190. this.getCuisinesList();
  191. uni.setStorageSync("isRefresh", 0)
  192. }
  193. uni.setNavigationBarTitle({
  194. title: uni.getStorageSync("orgInfo").organizationName
  195. })
  196. } else {
  197. this.menuData = []
  198. this.goodsList = []
  199. this.goodsLeftList = []
  200. this.goodsRightList = []
  201. this.maxNum = 0
  202. this.gwcNum = 0
  203. this.cuisineName = '当前时间无内容'
  204. }
  205. },
  206. onShow() {
  207. uni.reLaunch({
  208. url: '/pages/tabbar/wpTabbar'
  209. })
  210. uni.setNavigationBarTitle({
  211. title: uni.getStorageSync("orgInfo").organizationName
  212. })
  213. this.type = uni.getStorageSync("tabType")
  214. if (this.$getUrlType() === 3) {
  215. this.getJcd();
  216. if (uni.getStorageSync("isRefresh") === 1) {
  217. this.getCuisinesList();
  218. uni.setStorageSync("isRefresh", 0)
  219. }
  220. uni.setNavigationBarTitle({
  221. title: uni.getStorageSync("orgInfo").organizationName
  222. })
  223. } else {
  224. this.menuData = []
  225. this.goodsList = []
  226. this.goodsLeftList = []
  227. this.goodsRightList = []
  228. this.maxNum = 0
  229. this.gwcNum = 0
  230. this.cuisineName = '当前时间无内容'
  231. }
  232. },
  233. // onPullDownRefresh() {
  234. // this.getCuisinesList();
  235. // this.gwcNum = 0
  236. // },
  237. methods: {
  238. isImgReturn() {
  239. this.isImg = 1;
  240. },
  241. async getJcd() {
  242. this.menuName1[0] = []
  243. this.from = {
  244. consumerType: uni.getStorageSync("userInfo").userType,
  245. jgid: uni.getStorageSync("orgInfo").organizationCode,
  246. organizationCode: uni.getStorageSync("orgInfo").organizationCode,
  247. }
  248. // 发送请求
  249. const {
  250. data: res
  251. } = await this.$httpRequest({
  252. url: '/app/getPlace',
  253. method: 'post',
  254. data: this.from,
  255. isNotErrorMsg: true
  256. });
  257. if (res.code === 200) {
  258. var data = res.data;
  259. this.menuName1 = [
  260. []
  261. ]
  262. for (var i = 0; i < data.length; i++) {
  263. this.menuName1[0].push(data[i])
  264. }
  265. }
  266. },
  267. async getCuisinesList() {
  268. this.menuData = []
  269. this.oName = uni.getStorageSync("orgInfo").organizationName
  270. this.goodsLeftList.length = 0
  271. this.goodsRightList.length = 0
  272. this.from.consumerType = uni.getStorageSync("userInfo").userType
  273. this.from.jgid = uni.getStorageSync("orgInfo").organizationCode
  274. // 发送请求
  275. const {
  276. data: res
  277. } = await this.$httpRequest({
  278. url: '/app/getCuisines',
  279. method: 'post',
  280. data: this.from,
  281. isNotErrorMsg: true
  282. });
  283. if (res.code === 200) {
  284. this.menuData = res.data
  285. uni.setStorageSync("cuisinesData", this.menuData[0])
  286. this.cuisineName = this.menuData[0].menuName
  287. this.maxNum = this.menuData[0].maxCount
  288. this.goodsList = this.menuData[0].registers;
  289. this.goodsList.forEach(item => {
  290. item.amount = 0
  291. })
  292. //给左右列表分配数据
  293. this.toLeftAndRight()
  294. //清空
  295. this.menuName = [
  296. []
  297. ]
  298. for (var i = 0; i < this.menuData.length; i++) {
  299. this.menuName[0].push({
  300. id: i,
  301. value: this.menuData[i].menuName
  302. })
  303. }
  304. } else {
  305. this.cuisineName = res.msg
  306. }
  307. uni.stopPullDownRefresh()
  308. },
  309. setGwcNum() {
  310. this.gwcNum = 0
  311. const goodsListInfo = this.goodsList;
  312. for (var i = 0; i < goodsListInfo.length; i++) {
  313. if (this.goodsList[i].amount) {
  314. this.gwcNum += goodsListInfo[i].amount
  315. }
  316. }
  317. },
  318. toShopListPage() {
  319. if (0 === this.gwcNum) {
  320. this.showToast({
  321. duration: 1500,
  322. message: "还未点菜"
  323. });
  324. return;
  325. }
  326. let that = this
  327. uni.requestSubscribeMessage({
  328. tmplIds: ['76FWJYEGNoYT0XzGycTh-s6dJ7ETsK3-_r1xcvPWvaI'],
  329. success(res) {
  330. that.show1 = true;
  331. }
  332. })
  333. },
  334. addToCart(type, item) {
  335. if (!item.amount) {
  336. item.amount = 0
  337. }
  338. for (var i = 0; i < this.goodsList.length; i++) {
  339. if (item.cuisineNumber === this.goodsList[i].cuisineNumber) {
  340. if (type === 1) {
  341. if (this.gwcNum < this.maxNum) {
  342. if (this.goodsList[i].amount < this.goodsList[i].maximum) {
  343. this.goodsList[i].amount += 1
  344. this.showToast({
  345. duration: 500,
  346. message: "[ " + item.cuisineName + " * " + item.amount + " ]加入购物车"
  347. });
  348. this.gwcNum = this.gwcNum + 1
  349. return
  350. } else {
  351. this.showToast({
  352. duration: 500,
  353. message: "该菜品数量已封顶,无法添加"
  354. });
  355. }
  356. } else {
  357. this.showToast({
  358. duration: 500,
  359. message: "本次订单已封顶,无法添加"
  360. });
  361. }
  362. } else {
  363. if (this.goodsList[i].amount !== 0) {
  364. this.goodsList[i].amount -= 1
  365. this.gwcNum = this.gwcNum - 1
  366. return
  367. }
  368. }
  369. }
  370. }
  371. this.toLeftAndRight()
  372. },
  373. confirm(e) {
  374. //console.log('confirm', e)
  375. const index = e.value[0].id;
  376. uni.setStorageSync("cuisinesData", this.menuData[index])
  377. this.maxNum = this.menuData[0].maxCount
  378. this.cuisineName = this.menuData[index].menuName;
  379. this.goodsList = this.menuData[index].registers;
  380. //给左右列表分配数据
  381. this.toLeftAndRight()
  382. this.show = false;
  383. },
  384. confirm1(e) {
  385. //console.log('confirm', e)
  386. const index = e.value[0].placeNumber;
  387. uni.setStorageSync("jcd", e.value[0].placeName)
  388. uni.setStorageSync("placeNumber", index)
  389. uni.setStorageSync('shopData', this.goodsList);
  390. this.show1 = false;
  391. this.$goto('../../pages/orderFood/list')
  392. },
  393. cancel() {
  394. this.show = false
  395. this.show1 = false
  396. },
  397. isShowMenuName() {
  398. if (!this.menuData.length) {
  399. return;
  400. }
  401. this.show = true
  402. },
  403. showToast(params) {
  404. this.$refs.uToast.show({
  405. ...params,
  406. complete() {}
  407. })
  408. },
  409. toLeftAndRight() {
  410. //保留其他属性清空数组
  411. this.goodsLeftList.length = 0
  412. this.goodsRightList.length = 0
  413. const goodsList = this.goodsList
  414. for (var i = 0; i < goodsList.length; i++) {
  415. if (i % 2 === 0) {
  416. this.goodsLeftList.push(goodsList[i])
  417. } else {
  418. this.goodsRightList.push(goodsList[i])
  419. }
  420. }
  421. },
  422. // 向商品列表添加第一张图片
  423. async waterfallImage() {},
  424. // 图片绑定事件,通过比较左右列表高度,实现瀑布流展示
  425. onImageLoad: function(e) {
  426. let divWidth = 295; //显示的单栏宽度,我设为295rpx
  427. let oImgW = e.detail.width; //图片原始宽度
  428. let oImgH = e.detail.height; //图片原始高度
  429. let rImgH = divWidth * oImgH / oImgW; //根据宽高比计算当前载入的图片的高度
  430. if (rImgH > 600) {
  431. rImgH = 600; //限制图片最高600rpx,可在css中添加 max-height:600rpx;
  432. }
  433. if (this.goodsListCount == 0) {
  434. this.goodsLeftListHeight += rImgH; //第一张图片高度加到goodsLeftListHeight
  435. this.goodsListCount++; //图片索引加1
  436. //添加第二张图片到goodsRightList数组,因为第一张已经初始化到左侧列表中
  437. } else {
  438. this.goodsListCount++; //图片索引加1
  439. if (this.goodsLeftListHeight > this.goodsRightListHeight) { //把图片的高度加到目前高度更低的栏中
  440. this.goodsRightListHeight += rImgH; //第二张图片高度加到goodsRightListHeight
  441. } else {
  442. this.goodsLeftListHeight += rImgH;
  443. }
  444. if (this.goodsListCount < this.goodsList.length) { //根据目前的栏高,把下一张图片,push到低的那栏
  445. if (this.goodsLeftListHeight > this.goodsRightListHeight) {
  446. this.goodsRightList.push(this.goodsList[this.goodsListCount]);
  447. } else {
  448. this.goodsLeftList.push(this.goodsList[this.goodsListCount]);
  449. }
  450. }
  451. }
  452. },
  453. }
  454. }
  455. </script>
  456. <style lang="scss" scoped>
  457. #button_div {
  458. position: fixed;
  459. bottom: var(--window-bottom);
  460. }
  461. .mybackColor {
  462. background-color: #8c8c8c;
  463. }
  464. .shopHand {
  465. font-weight: bold;
  466. font-size: 20px;
  467. height: 20%;
  468. padding: 10% 0 10px 10px;
  469. margin-bottom: 5px;
  470. //background: linear-gradient(to bottom right, #85c1bf, #f1fef9);
  471. //background: rgb(55,186,189);
  472. background: #9ED6CF;
  473. }
  474. .cuisineImg {
  475. border-radius: 10px;
  476. max-height: 300rpx;
  477. width: 295rpx;
  478. padding: 15rpx 15rpx 5rpx;
  479. }
  480. .doFoodConfigView {
  481. width: 93%;
  482. margin: 0 auto;
  483. padding: 2% 5px;
  484. background-color: #ffffff;
  485. border-radius: 10px;
  486. border: 1px solid #d3d3d3;
  487. }
  488. .gwxx {
  489. padding-top: 20rpx;
  490. }
  491. .gwcNum {
  492. width: 20px;
  493. left: 40rpx;
  494. top: -5rpx;
  495. position: absolute;
  496. }
  497. /* 商品列表 */
  498. .goodsContent {
  499. width: 100%;
  500. margin-top: 10rpx;
  501. display: flex;
  502. flex-direction: row;
  503. justify-content: center;
  504. }
  505. .goodsLeftList {
  506. margin: 0 15rpx 0 30rpx;
  507. width: 325rpx;
  508. }
  509. .goodsRightList {
  510. margin: 0 47rpx 0 15rpx;
  511. width: 325rpx;
  512. }
  513. .goodsItem {
  514. background: #FFFFFF;
  515. border: 1rpx solid #eeeeee;
  516. width: 325rpx;
  517. border-radius: 10px;
  518. padding: 5px 4px;
  519. margin-bottom: 15rpx;
  520. }
  521. .goodsName {
  522. font-size: 28rpx;
  523. color: #2e2e2e;
  524. padding: 10rpx 20rpx;
  525. overflow: hidden;
  526. text-overflow: ellipsis;
  527. display: -webkit-box;
  528. -webkit-line-clamp: 2;
  529. -webkit-box-orient: vertical;
  530. }
  531. .goodsPrice {
  532. color: #ffac29;
  533. font-size: 24rpx;
  534. padding: 0 15rpx;
  535. }
  536. .addFood {
  537. margin-left: 150rpx;
  538. }
  539. .minus {
  540. width: 26px;
  541. height: 26px;
  542. background-color: #efefef;
  543. border-width: 1px;
  544. border-color: #c6c6c6;
  545. border-top-left-radius: 100px;
  546. border-top-right-radius: 100px;
  547. border-bottom-left-radius: 100px;
  548. border-bottom-right-radius: 100px;
  549. @include flex;
  550. justify-content: center;
  551. align-items: center;
  552. }
  553. .input {
  554. padding: 0 10px;
  555. }
  556. .plus {
  557. margin: 3px;
  558. width: 26px;
  559. height: 26px;
  560. background-color: #FF0000;
  561. border-radius: 50%;
  562. /* #ifndef APP-NVUE */
  563. display: flex;
  564. /* #endif */
  565. justify-content: center;
  566. align-items: center;
  567. }
  568. </style>