index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <template>
  2. <view>
  3. <view class="nav-header">
  4. <view class="nav-header-left">
  5. <text class="nav-header-left-text">{{orgName}}</text>
  6. <!-- <image class="nav-header-left-icons1" src="../../images/dingwei.png"></image> -->
  7. <!-- <text class="nav-header-left-text" @click="getLocation">{{orgName}}</text> -->
  8. <!-- <image class="nav-header-left-icons2" src="../../images/jiantouxia.png"></image> -->
  9. </view>
  10. <view class="nav-header-right">
  11. <image src="../../images/user.png" @click="goUser"></image>
  12. </view>
  13. </view>
  14. <view class="calendar-box">
  15. <template v-for="(item,index) in date">
  16. <view :key="index" class="calendar-box-list" :class="curDay == item.date?'cur':''" @click="selectDate(item)">
  17. <view class="calendar-box-list-l1">{{item.week}}</view>
  18. <view class="calendar-box-list-l2">{{item.day}}</view>
  19. </view>
  20. </template>
  21. </view>
  22. <view class="subnav-box">
  23. <template v-for="(item,index) in types">
  24. <view class="subnav-box-list" :class="curType == item.id?'cur':''" @click="selectType(item)">{{item.name}}</view>
  25. </template>
  26. </view>
  27. <view class="main">
  28. <view class="main-cate">
  29. <template v-for="(item,index) in cate">
  30. <view :key="index" class="main-cate-list" :class="item.id == curCate?'cur':''" @click="selectCate(item)">
  31. {{item.name}}
  32. </view>
  33. </template>
  34. </view>
  35. <view class="main-goods">
  36. <template v-if="goods.length > 0">
  37. <view class="main-goods-cate">
  38. {{curCateText}}
  39. </view>
  40. <view class="main-goods-list" v-for="(item,index) in goods" :key="index">
  41. <view class="main-goods-img">
  42. <image v-if="item.imageLoad" :src="item.img" @error="onErrorImg(item)" @load="onSuccessImg(item)" mode="aspectFill"></image>
  43. <image v-if="!item.imageLoad" src="../../images/errorbg.png" mode="aspectFill"></image>
  44. </view>
  45. <view class="main-goods-box">
  46. <view class="main-goods-title">
  47. {{item.title}}
  48. </view>
  49. <view class="main-goods-desc">
  50. {{item.description}}
  51. </view>
  52. <view class="main-goods-nums">
  53. <text class="main-goods-price">¥{{item.price}}</text>
  54. <image v-if="item.nums > 0" src="../../images/minu.png" @click="minuGoods(item)"></image>
  55. <text v-if="item.nums > 0">{{item.nums}}</text>
  56. <image src="../../images/plus.png" @click="plusGoods(item)"></image>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <template v-else>
  62. <view class="no-data">
  63. <image src="../../images/no_data.png" mode=""></image>
  64. <view class="no-data-text">
  65. 空空如也~
  66. </view>
  67. </view>
  68. </template>
  69. <view>
  70. <br>
  71. </view>
  72. </view>
  73. </view>
  74. <view class="bottom-box">
  75. <view class="bottom-box-icon">
  76. <image src="../../images/plus.png"></image>
  77. <view v-if="cart > 0" class="bottom-box-count">
  78. {{cart}}
  79. </view>
  80. </view>
  81. <view class="bottom-box-text">
  82. <text v-if="totalPrice > 0">总价:¥{{totalPrice}}元</text>
  83. </view>
  84. <view class="bottom-box-btn" @click="goOrder">
  85. 确认订单
  86. </view>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. var app = getApp();
  92. export default {
  93. data() {
  94. return {
  95. orgId: '',
  96. orgName: '',
  97. date: [],
  98. curDay: '',
  99. cate: [],
  100. curCate: 0,
  101. curCateText: '',
  102. curType: 0,
  103. types: [],
  104. goods: [],
  105. cart: 0,
  106. totalPrice: 0
  107. }
  108. },
  109. onLoad() {
  110. var orgId = this.getUrlCode('orgId');
  111. console.log('sssss1',orgId);
  112. if(orgId){
  113. uni.setStorageSync(app.globalData.storagePre+'orgId',orgId);
  114. app.globalData.userinfo.orgId = orgId;
  115. }else{
  116. orgId = uni.getStorageSync(app.globalData.storagePre+'orgId');
  117. if(orgId){
  118. app.globalData.userinfo.orgId = orgId;
  119. }else{
  120. uni.showToast({
  121. title: '参数错误',
  122. icon: 'none',
  123. duration: 2000
  124. })
  125. }
  126. }
  127. console.log('sssss',orgId);
  128. app.checkLogin();
  129. this.orgId = uni.getStorageSync(app.globalData.storagePre+'orgId');
  130. this.orgName = uni.getStorageSync(app.globalData.storagePre+'orgName');
  131. },
  132. onShow() {
  133. this.cart = 0;
  134. this.totalPrice = 0;
  135. var that = this;
  136. app.ajaxReadyCallback = res => { //各个接口统一回调方法
  137. var apiname = res.data.apiname;
  138. console.log(res);
  139. if(apiname == 'shop'){
  140. that.orgId = res.data.data.orgId;
  141. that.orgName = res.data.data.name;
  142. uni.setStorageSync(app.globalData.storagePre+'orgId',res.data.data.orgId);
  143. uni.setStorageSync(app.globalData.storagePre+'orgName',res.data.data.name);
  144. that.getDate();
  145. } else if (apiname == 'date') {
  146. that.date = res.data.data;
  147. that.curDay = that.date[0].date;
  148. that.getType();
  149. } else if (apiname == 'types') {
  150. that.types = res.data.data;
  151. that.curType = that.types[0].id;
  152. that.getCate();
  153. } else if (apiname == 'cate') {
  154. that.cate = res.data.data;
  155. this.cart = 0;
  156. this.totalPrice = 0;
  157. if(that.cate.length > 0){
  158. that.cate.forEach((item) => {
  159. const info = item;
  160. info.goods.forEach((item2) => {
  161. const info2 = item2;
  162. info2.nums = 0;
  163. info2.imageLoad = true;
  164. })
  165. })
  166. that.curCate = that.cate[0].id;
  167. that.curCateText = that.cate[0].name;
  168. that.goods = that.cate[0].goods;
  169. }
  170. }else if(apiname == 'orgInfo'){
  171. that.orgId = res.data.data.orgId;
  172. that.orgName = res.data.data.name;
  173. uni.setStorageSync(app.globalData.storagePre+'orgName',res.data.name);
  174. that.getDate();
  175. }
  176. }
  177. this.getLocation();
  178. },
  179. methods: {
  180. getUrlCode (name) {
  181. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null
  182. },
  183. goUser(){
  184. uni.navigateTo({
  185. url: '/pages/user/index'
  186. });
  187. },
  188. goOrder(){
  189. const selectGoods = [];
  190. this.cate.forEach((item) => {
  191. item.goods.forEach((item2) => {
  192. if(item2.nums > 0){
  193. selectGoods.push(item2);
  194. }
  195. })
  196. });
  197. try {
  198. const data = {
  199. goods: selectGoods,
  200. type: this.curType,
  201. day: this.curDay
  202. }
  203. if(data.goods.length == 0 || !data.type || !data.day){
  204. uni.showToast({
  205. title: '未选择商品',
  206. icon: 'none',
  207. duration: 2000
  208. });
  209. return;
  210. }
  211. uni.setStorageSync(app.globalData.storagePre+'orderData',JSON.stringify(data));
  212. uni.navigateTo({
  213. url: '/pages/index/order'
  214. });
  215. } catch (e) {
  216. uni.showToast({
  217. title: '操作失败,请重试',
  218. icon: 'none',
  219. duration: 2000
  220. })
  221. }
  222. },
  223. getLocation(){
  224. app.ajax({
  225. url: app.globalData.serverUrl + 'org/info',
  226. type: 'POST',
  227. apiname: 'orgInfo',
  228. });
  229. // this.orgName = "定位中...";
  230. // // let lat = 34.747486;
  231. // // let lng = 113.666841;
  232. // let that = this;
  233. // if (this.$wechat && this.$wechat.isWechat()) {//获取定位经纬度
  234. // this.$wechat.location(function (res) {
  235. // console.log(res)
  236. // let lat = res.latitude; // 纬度,浮点数,范围为90 ~ -90
  237. // let lng = res.longitude; // 经度,浮点数,范围为180 ~ -180。
  238. // that.getShop(lat,lng);
  239. // //根据经纬度,解析区域,提示用户输入
  240. // });
  241. // }
  242. // that.getShop(lat,lng);
  243. },
  244. getOrg(){
  245. app.ajax({
  246. url: app.globalData.serverUrl + 'org/info',
  247. type: 'POST',
  248. apiname: 'orgInfo',
  249. });
  250. },
  251. // getShop(lat,lng){
  252. // app.ajax({
  253. // url: app.globalData.serverUrl + 'org/info',
  254. // type: 'POST',
  255. // apiname: 'shop',
  256. // data: {
  257. // lat: lat,
  258. // lng: lng
  259. // }
  260. // });
  261. // },
  262. getDate(){
  263. app.ajax({
  264. url: app.globalData.serverUrl + 'shopDay/date',
  265. type: 'POST',
  266. apiname: 'date'
  267. });
  268. },
  269. getType(){
  270. app.ajax({
  271. url: app.globalData.serverUrl + 'shopDay/types',
  272. type: 'POST',
  273. apiname: 'types',
  274. data: {
  275. day: this.curDay
  276. }
  277. });
  278. },
  279. getCate(){
  280. app.ajax({
  281. url: app.globalData.serverUrl + 'shopDay/cate',
  282. type: 'POST',
  283. apiname: 'cate',
  284. data: {
  285. type: this.curType
  286. }
  287. });
  288. },
  289. // getGoods(){
  290. // app.ajax({
  291. // url: app.globalData.serverUrl + 'server/shopDay/goods',
  292. // type: 'POST',
  293. // apiname: 'goods',
  294. // data: {
  295. // type: this.curType,
  296. // cate_id: this.curCate
  297. // }
  298. // });
  299. // },
  300. selectDate(item){
  301. this.curDay = item.date;
  302. this.goods = [];
  303. this.cate = [];
  304. this.formatGoods();
  305. this.getType();
  306. },
  307. selectType(item){
  308. this.curType = item.id;
  309. this.goods = [];
  310. this.cate = [];
  311. this.formatGoods();
  312. this.getCate();
  313. },
  314. selectCate(item){
  315. this.curCate = item.id;
  316. this.curCateText = item.name;
  317. this.goods = item.goods;
  318. this.formatGoods();
  319. // this.getGoods();
  320. },
  321. plusGoods(obj){
  322. this.goods.forEach((item) => {
  323. const info = item;
  324. if(info.id == obj.id){
  325. if(info.nums < 200){
  326. info.nums++;
  327. }
  328. }
  329. })
  330. this.formatGoods();
  331. },
  332. minuGoods(obj){
  333. this.goods.forEach((item) => {
  334. const info = item;
  335. if(info.id == obj.id){
  336. if(info.nums > 0){
  337. info.nums--;
  338. }
  339. }
  340. })
  341. this.formatGoods();
  342. },
  343. onErrorImg(item){
  344. this.$set(item, 'imageLoad', false);
  345. this.$forceUpdate();
  346. },
  347. onSuccessImg(item){
  348. this.$set(item, 'imageLoad', true);
  349. this.$forceUpdate();
  350. },
  351. formatGoods(){
  352. this.cart = 0;
  353. this.totalPrice = 0;
  354. this.cate.forEach((item) => {
  355. const info = item;
  356. if(item.id == this.curCate){
  357. info.goods = this.goods;
  358. }
  359. });
  360. this.cate.forEach((item) => {
  361. const info = item;
  362. info.goods.forEach((item2) => {
  363. this.cart += item2.nums;
  364. this.totalPrice += item2.nums*parseFloat(item2.price);
  365. });
  366. });
  367. this.$forceUpdate();
  368. }
  369. }
  370. }
  371. </script>
  372. <style lang="scss" scoped>
  373. page{
  374. background-color: #FFFFFF;
  375. }
  376. .nav-header {
  377. background-color: $theme-color;
  378. height: 44px;
  379. line-height: 44px;
  380. width: 100%;
  381. overflow: hidden;
  382. color: #FFFFFF;
  383. }
  384. .nav-header-left{
  385. display: inline-block;
  386. width: 500rpx;
  387. height: 100%;
  388. float: left;
  389. padding-left: 20rpx;
  390. }
  391. .nav-header-left-icons1{
  392. width: 38rpx;
  393. height: 38rpx;
  394. vertical-align: middle;
  395. }
  396. .nav-header-left-text{
  397. vertical-align: middle;
  398. font-size: 34rpx;
  399. padding: 0 15rpx;
  400. max-width: 450rpx;
  401. }
  402. .nav-header-left-icons2{
  403. width: 24rpx;
  404. height: 14rpx;
  405. vertical-align: middle;
  406. }
  407. .nav-header-right{
  408. display: inline-block;
  409. width: 150rpx;
  410. height: 100%;
  411. float: right;
  412. text-align: right;
  413. padding-right: 20rpx;
  414. }
  415. .nav-header-right image{
  416. width: 38rpx;
  417. height: 38rpx;
  418. vertical-align: middle;
  419. }
  420. .calendar-box{
  421. text-align: center;
  422. overflow: hidden;
  423. font-size: 32rpx;
  424. background-color: #F5FBFF;
  425. }
  426. .calendar-box-list{
  427. width: 107rpx;
  428. height: 114rpx;
  429. float: left;
  430. padding-top: 6rpx;
  431. }
  432. .calendar-box-list .calendar-box-list-l1{
  433. width: 100%;
  434. height: 50rpx;
  435. line-height: 50rpx;
  436. }
  437. .calendar-box-list .calendar-box-list-l2{
  438. display: inline-block;
  439. width: 50rpx;
  440. height: 50rpx;
  441. line-height: 50rpx;
  442. border-radius: 50%;
  443. }
  444. .calendar-box-list.cur .calendar-box-list-l1{
  445. color: $theme-color;
  446. }
  447. .calendar-box-list.cur .calendar-box-list-l2{
  448. color: #FFFFFF;
  449. background-color: $theme-color;
  450. border-radius: 50%;
  451. }
  452. .subnav-box{
  453. color: #333333;
  454. font-size: 32rpx;
  455. text-align: center;
  456. font-weight: 400;
  457. overflow: hidden;
  458. background-color: #FFFFFF;
  459. // border-bottom: 1rpx solid #F3F3F3;
  460. }
  461. .subnav-box .subnav-box-list{
  462. display: inline-block;
  463. width: 120rpx;
  464. height: 80rpx;
  465. line-height: 80rpx;
  466. float: left;
  467. position: relative;
  468. }
  469. .subnav-box .subnav-box-list.cur{
  470. font-weight: bold;
  471. }
  472. .subnav-box .cur::after{
  473. content: '';
  474. position: absolute;
  475. z-index: 10;
  476. width: 30rpx;
  477. height: 4rpx;
  478. bottom: 0;
  479. left: 50%;
  480. margin-left: -15rpx;
  481. background-color: $theme-color;
  482. }
  483. .bottom-box{
  484. width: 100%;
  485. height: 100rpx;
  486. line-height:100rpx;
  487. position: fixed;
  488. bottom: 0;
  489. left: 0;
  490. background-color: #DDDDDD;
  491. overflow: hidden;
  492. z-index: 100;
  493. }
  494. .bottom-box .bottom-box-btn{
  495. display: inline-block;
  496. width: 196rpx;
  497. height: 100%;
  498. background-color: $theme-color;
  499. font-size: 38rpx;
  500. color: #FFFFFF;
  501. float: right;
  502. text-align: center;
  503. }
  504. .bottom-box .bottom-box-icon{
  505. display: inline-block;
  506. width: 140rpx;
  507. height: 100%;
  508. position: relative;
  509. text-align: center;
  510. float: left;
  511. }
  512. .bottom-box .bottom-box-icon image{
  513. width: 64rpx;
  514. height: 64rpx;
  515. border-radius: 50%;
  516. vertical-align: middle;
  517. }
  518. .bottom-box .bottom-box-icon .bottom-box-count{
  519. min-width: 34rpx;
  520. height: 34rpx;
  521. line-height: 34rpx;
  522. background-color: #FF541F;
  523. color: #FFFFFF;
  524. border-radius: 17rpx;
  525. position: absolute;
  526. z-index: 10;
  527. right: 10rpx;
  528. top: 10rpx;
  529. font-size: 24rpx;
  530. padding: 0 5rpx;
  531. }
  532. .bottom-box .bottom-box-text{
  533. width: 410rpx;
  534. height: 100%;
  535. color: #949494;
  536. font-size: 34rpx;
  537. font-weight: 400;
  538. float: left;
  539. }
  540. .main{
  541. position: fixed;
  542. top: 290rpx;
  543. left: 0;
  544. right: 0;
  545. bottom: 100rpx;
  546. z-index: 10;
  547. background-color: #FFFFFF;
  548. }
  549. .main .main-cate{
  550. width: 180rpx;
  551. height: 100%;
  552. background-color: #F3F3F3;
  553. float: left;
  554. text-align: center;
  555. color: #333333;
  556. font-size: 30rpx;
  557. overflow: auto;
  558. }
  559. .main .main-cate .main-cate-list{
  560. height: 90rpx;
  561. line-height: 90rpx;
  562. }
  563. .main .main-cate .main-cate-list.cur{
  564. background-color: #FFFFFF;
  565. }
  566. .main .main-goods{
  567. width: 530rpx;
  568. height: 100%;
  569. background-color: #FFFFFF;
  570. float: right;
  571. // padding-right: 20rpx;
  572. overflow: auto;
  573. // padding-top: 10rpx;
  574. // padding-bottom: 30rpx;
  575. padding: 20rpx;
  576. }
  577. .main-goods-cate{
  578. font-size: 30rpx;
  579. line-height: 40rpx;
  580. color: #333333;
  581. font-weight: bold;
  582. }
  583. .main-goods-list{
  584. width: 530rpx;
  585. height: 150rpx;
  586. margin: 20rpx 0;
  587. }
  588. .main-goods-list .main-goods-img{
  589. width: 150rpx;
  590. height: 150rpx;
  591. float: left;
  592. }
  593. .main-goods-list .main-goods-img image{
  594. width: 100%;
  595. height: 100%;
  596. }
  597. .main-goods-box{
  598. width: 360rpx;
  599. height: 100%;
  600. float: right;
  601. }
  602. .main-goods-title{
  603. display: block;
  604. font-size: 30rpx;
  605. font-weight: bold;
  606. line-height: 50rpx;
  607. color: #333333;
  608. }
  609. .main-goods-desc{
  610. line-height: 30rpx;
  611. height: 60rpx;
  612. font-size: 24rpx;
  613. color: #333333;
  614. }
  615. .main-goods-nums{
  616. height: 40rpx;
  617. line-height: 40rpx;
  618. text-align: right;
  619. }
  620. .main-goods-price{
  621. width: 100rpx;
  622. display: inline-block;
  623. float: left;
  624. font-size: 28rpx;
  625. color: #FF541F;
  626. text-align: left;
  627. padding: 0 !important;
  628. }
  629. .main-goods-nums image{
  630. width: 44rpx;
  631. height: 44rpx;
  632. vertical-align: middle;
  633. }
  634. .main-goods-nums text{
  635. padding: 0 20rpx;
  636. vertical-align: middle;
  637. }
  638. </style>