index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <template>
  2. <view :style="{ minHeight: sys.windowHeight + 'px' }" :class="[$tm.vx.state().tmVuetify.black ? 'black' : ' ']">
  3. <tm-menubars title="" :shadow="0" :showback="false"></tm-menubars>
  4. <view class="C1b1b1b pb-40">
  5. <view class="sousuo">
  6. <tm-pickersCity level="city" class="dingwei fl" btn-color="bg-gradient-blue-accent" @confirm="okCity"
  7. :default-value="addr">
  8. <view>
  9. <text class="text-size-n">{{addr[1]}}</text>
  10. <tm-icons :size="24" color="white" name="icon-angle-down"></tm-icons>
  11. </view>
  12. </tm-pickersCity>
  13. <tm-search disabled="true" v-model="soso" class="fr shuruk" color="white" confirm-text="" @click="sosoFun"></tm-search>
  14. </view>
  15. <view style="clear: both;"></view>
  16. </view>
  17. <view class="lunbo">
  18. <tm-swiper :previmage="false" @change="lunboFun" :list="list" :height="400" :current="current"></tm-swiper>
  19. <tm-translate class="anniu1 fl" :auto="true" ref="a_1" :duration="80" animation-name="zoomIn">
  20. <image v-if="current!=0" @click="xia()" class="qiehuan" src="/static/img/68.png" mode="widthFix">
  21. </image>
  22. </tm-translate>
  23. <tm-translate class="anniu2 fr" :auto="true" ref="a_5" :duration="80" animation-name="zoomIn">
  24. <image v-if="current<(list.length-1)" @click="shang()" class="qiehuan" src="/static/img/67.png"
  25. mode="widthFix"></image>
  26. </tm-translate>
  27. </view>
  28. <view class="zhuti">
  29. <tm-sheet :shadow="24" class="jiaoxi">
  30. <tm-grid @change="zhonglei" class="mt-20 mb-20" :grid="5" :list="list3" :icon-size="120"
  31. font-color="white"></tm-grid>
  32. </tm-sheet>
  33. <!-- <tm-sheet :shadow="24" class="jiaoxi xiao">
  34. <view class="yifu1 fl">
  35. <image src="/static/img/78.png" mode="widthFix"></image>
  36. </view>
  37. <view class="yifu2 fr">
  38. <image class="yifu21" src="/static/img/77.png" mode="widthFix"></image>
  39. <view>
  40. <image style="width:50%;" src="/static/img/75.png" mode="widthFix"></image>
  41. <image style="width:50%;" class="yifu21" src="/static/img/76.png" mode="widthFix"></image>
  42. </view>
  43. </view>
  44. <view style="clear: both;"></view>
  45. </tm-sheet> -->
  46. <tm-sheet :shadow="24" class="jiaoxi xiao">
  47. <tm-tabs align="center" class="qiehuan1" v-model="activeIndex" :list="list2" range-key="title"
  48. @change="changeTab(activeIndex)"></tm-tabs>
  49. </tm-sheet>
  50. <tm-sheet :shadow="24" class="jiaoxi xiao" style="height:160px;">
  51. <tm-dragGrid :list="list1" :col="3" disabled="false" class="mt-40 mb-40 remen" :icon-size="160"
  52. v-if="list1.length!=0">
  53. <template v-slot:default="{item}">
  54. <view class="flex-center flex-col" @click="tiaozhuan(item)">
  55. <tm-icons class="divcont" :size="160" :name="item.icon" :color="item.color"></tm-icons>
  56. <text class="text-size-m text-white pt-10">{{item.text}}</text>
  57. <text class="text-size-m text-white pt-10">{{item.jie}}</text>
  58. </view>
  59. </template>
  60. </tm-dragGrid>
  61. </tm-sheet>
  62. </view>
  63. <view class="guanggao" @click="xiangqing">
  64. <image style="width:100%;" src="/static/img/82.png" mode="widthFix"></image>
  65. <view class="wenzi">
  66. <view class="mt-10">额外打九折</view>
  67. <view>高达75%的折扣!</view>
  68. </view>
  69. </view>
  70. <view style="height:160px;" class="mt-40 jiage pt-40">
  71. <tm-dragGrid :list="list4" :col="3" disabled="false" class="remen" :icon-size="160" v-if="list4.length!=0">
  72. <template v-slot:default="{item}">
  73. <view class="flex-center flex-col" @click.stop="goXiangQing(item)">
  74. <tm-icons :size="200" :name="item.icon" :color="item.color"></tm-icons>
  75. <text class="text-size-m text-white pt-10">{{item.text}}</text>
  76. <text class="text-size-m text-white pt-10">{{item.jie}}</text>
  77. </view>
  78. </template>
  79. </tm-dragGrid>
  80. </view>
  81. <tm-sheet :shadow="24" class="jiaoxi xiao">
  82. <tm-tabs align="center" class="qiehuan1" v-model="activeIndex" :list="list5" range-key="title"></tm-tabs>
  83. </tm-sheet>
  84. <!-- 单品 -->
  85. <view class="zhuti shangpin">
  86. <tm-sheet :padding="[0, 0]" class="jiaoxi xiao">
  87. <tm-cartCellListFood v-on:jiaruFun="jiarufuFun" v-on:goXiangQing="goXiangQing(item)"
  88. v-for="item in test" :typeclick="typeclick" :mdata="item" :cart-num.sync="item.buy">
  89. </tm-cartCellListFood>
  90. </tm-sheet>
  91. </view>
  92. <view v-if="gouwuche.length!=0" class="fudong" @click="qugowuche">
  93. <image src="../../static/img/87.png" mode="widthFix"></image>
  94. <view class="shuzigwc">{{gouwuche.length}}</view>
  95. </view>
  96. <view class="" v-if="isBottom" style="width: 100%;display: flex;justify-content: center;align-items: center;">
  97. 没有更多了~
  98. </view>
  99. <view style="width:100%;height:60px;"></view>
  100. <!-- 弹出层消息 -->
  101. <tm-message ref="toast"></tm-message>
  102. </view>
  103. </template>
  104. <script>
  105. import {
  106. myRequest
  107. } from '@/api/request.js'
  108. import qqmapsdk from '../../js_sdk/qqmap-wx-jssdk.js'
  109. const QQMapWX = new qqmapsdk({
  110. key: 'KNABZ-OAVCJ-O5IFJ-KBNST-SVIIZ-2EB3G'
  111. });
  112. export default {
  113. data() {
  114. return {
  115. isBottom: false,
  116. current: 0,
  117. activeIndex: 0,
  118. soso: '',
  119. addr: ['江苏省', '南京市', '栖霞区'],
  120. value: '',
  121. list: [],
  122. list1: [],
  123. list2: ['热门', '折扣'],
  124. list3: [],
  125. list4: [],
  126. list5: ['推荐单品'],
  127. test: [],
  128. typeclick: 1, //1加入购物车,2购物车
  129. gouwuche: [],
  130. page: 1,
  131. total: 0
  132. };
  133. },
  134. onLoad() {
  135. },
  136. onShow() {
  137. this.getGwc()
  138. },
  139. created() {
  140. this.sys = uni.getSystemInfoSync();
  141. this.getSort()
  142. this.getBanner()
  143. this.changeTab(1);
  144. this.getHot();
  145. this.getRecommend()
  146. this.getGwc()
  147. this.getCity()
  148. },
  149. onReachBottom() {
  150. this.loadMore()
  151. },
  152. methods: {
  153. getCity() {
  154. var that = this;
  155. uni.getLocation({
  156. type: 'wgs84',
  157. geocode: true,
  158. success: (res) => {
  159. console.log("获取经纬度成功");
  160. this.latitude = res.latitude;
  161. this.longitude = res.longitude;
  162. },
  163. fail: () => {
  164. console.log("获取经纬度失败");
  165. },
  166. complete: () => {
  167. // 解析地址
  168. QQMapWX.reverseGeocoder({
  169. location: {
  170. latitude: this.latitude,
  171. longitude: this.longitude
  172. },
  173. success: function(res) {
  174. console.log("解析地址成功");
  175. console.log(res);
  176. // 省
  177. let province = res.result.ad_info.province;
  178. // 市
  179. let city = res.result.ad_info.city;
  180. //区
  181. let district = res.result.ad_info.district;
  182. that.addr = [province, city, district];
  183. console.log(province);
  184. console.log(city);
  185. console.log(district);
  186. },
  187. fail: function(res) {
  188. // uni.showToast({
  189. // title: '定位失败',
  190. // duration: 2000,
  191. // icon: "none"
  192. // })
  193. console.log(res);
  194. },
  195. complete: function(res) {
  196. console.log(res);
  197. }
  198. })
  199. }
  200. })
  201. },
  202. getGwc() {
  203. let that = this;
  204. myRequest({
  205. url: "/api/ShopCart/shopCartList",
  206. method: 'get',
  207. data: that.reqData
  208. }).then(res => {
  209. if (res.data.code == 200) {
  210. that.gouwuche = res.data.data;
  211. } else {
  212. that.gouwuche = []
  213. }
  214. })
  215. },
  216. getBanner() {
  217. let that = this;
  218. myRequest({
  219. url: "/api/Banner/bannerList",
  220. method: 'get',
  221. data: that.reqData
  222. }).then(res => {
  223. if (res.data.code == 200) {
  224. res.data.data.forEach(item => {
  225. that.list.push({
  226. src: item.image,
  227. })
  228. })
  229. } else {
  230. that.$refs.toast.show({
  231. model: 'error',
  232. label: res.data.msg
  233. })
  234. }
  235. })
  236. },
  237. //获取分类
  238. getSort() {
  239. let that = this;
  240. myRequest({
  241. url: "/api/ShopGoods/getMallClassification",
  242. method: 'get',
  243. data: that.reqData
  244. }).then(res => {
  245. if (res.data.code == 200) {
  246. res.data.data.forEach(item => {
  247. that.list3.push({
  248. icon: item.image,
  249. text: item.category_name,
  250. id:item.id
  251. })
  252. })
  253. } else {
  254. that.$refs.toast.show({
  255. model: 'error',
  256. label: res.data.msg
  257. })
  258. }
  259. })
  260. },
  261. // 热门、折扣
  262. changeTab(activeIndex) {
  263. let that = this;
  264. myRequest({
  265. url: "/api/ShopGoods/thenBuckle",
  266. method: 'post',
  267. data: {
  268. 'type': that.activeIndex + 1
  269. }
  270. }).then(res => {
  271. if (res.data.code == 200) {
  272. that.list1 = [];
  273. res.data.data.forEach(item => {
  274. that.list1.push({
  275. icon: item.image,
  276. text: item.category_name,
  277. pid:item.pid
  278. })
  279. })
  280. } else {
  281. that.$refs.toast.show({
  282. model: 'error',
  283. label: res.data.msg
  284. })
  285. }
  286. })
  287. },
  288. // 获取热门下商品
  289. getHot() {
  290. let that = this;
  291. myRequest({
  292. url: "/api/ShopGoods/popularGoods",
  293. method: 'get',
  294. }).then(res => {
  295. if (res.data.code == 200) {
  296. res.data.data.forEach(item => {
  297. that.list4.push({
  298. icon: item.image,
  299. text: item.goods_name,
  300. id: item.id,
  301. category_id: item.category_id,
  302. jie: item.sale_price,
  303. sale_num: item.sale_num,
  304. stock_num: item.stock_num
  305. })
  306. })
  307. that.list4 = that.list4.slice(0, 3);
  308. } else {
  309. that.$refs.toast.show({
  310. model: 'error',
  311. label: res.data.msg
  312. })
  313. }
  314. })
  315. },
  316. // 获取推荐单品列表
  317. getRecommend() {
  318. // this.page = 1;
  319. let that = this;
  320. // that.test = [];
  321. myRequest({
  322. url: "/api/ShopGoods/recommend",
  323. method: 'get',
  324. data: {
  325. page: that.page
  326. }
  327. }).then(res => {
  328. console.log(res.data.data);
  329. if (res.data.code == 200) {
  330. res.data.data.list.forEach(item => {
  331. that.test.push({
  332. img: item.image,
  333. title: item.goods_name,
  334. price: item.sale_price,
  335. id: item.id,
  336. category_id: item.category_id,
  337. sale_num: item.sale_num,
  338. stock_num: item.stock_num,
  339. is_recommend: item.is_recommend,
  340. })
  341. })
  342. that.total = res.data.data.count;
  343. } else {
  344. that.$refs.toast.show({
  345. model: 'error',
  346. label: res.data.msg
  347. })
  348. }
  349. })
  350. },
  351. // 加载更多
  352. loadMore() {
  353. if (this.test.length < this.total) {
  354. this.isBottom = false;
  355. this.page++;
  356. this.getRecommend()
  357. } else {
  358. this.isBottom = true;
  359. }
  360. },
  361. tiaozhuan(e) {
  362. for(let i=0;i<this.list3.length;i++){
  363. if(this.list3[i].id==e.pid){
  364. uni.navigateTo({
  365. url: "/pages/gengduo/index?index="+i,
  366. })
  367. }
  368. }
  369. },
  370. // 广告详情
  371. xiangqing() {
  372. // uni.navigateTo({
  373. // url: "/pages/shopdetail/index",
  374. // })
  375. },
  376. // 去商品详情页
  377. goXiangQing(data) {
  378. console.log(data);
  379. uni.navigateTo({
  380. url: "/pages/shopdetail/index?cartId=" + data.id + '&classId=' + data.category_id,
  381. })
  382. },
  383. lunboFun(e) {
  384. this.current = e;
  385. },
  386. okCity(e) {
  387. console.log(e);
  388. this.addr = e;
  389. },
  390. qugowuche() {
  391. uni.navigateTo({
  392. url: "/pages/gouwuche/index",
  393. })
  394. },
  395. sosoFun() {
  396. uni.navigateTo({
  397. url: "/pages/shopsoso/index",
  398. })
  399. },
  400. shang() {
  401. this.$refs.a_5.play()
  402. this.current = this.current + 1;
  403. },
  404. xia() {
  405. this.$refs.a_1.play()
  406. this.current = this.current - 1;
  407. },
  408. // 加入购物车
  409. jiarufuFun(data) {
  410. var that = this;
  411. console.log(data)
  412. if (data.type == 2) {
  413. myRequest({
  414. url: "/api/ShopCart/addShopCart",
  415. method: 'post',
  416. data: {
  417. goods_id: data.data.id,
  418. // goods_name: data.data.title,
  419. // goods_image: data.data.img,
  420. // goods_price: data.data.price,
  421. goods_num: 1
  422. }
  423. }).then(res => {
  424. if (res.data.code == 200) {
  425. that.$refs.toast.show({
  426. model: 'success',
  427. label: res.data.msg
  428. })
  429. that.getGwc()
  430. } else {
  431. that.$refs.toast.show({
  432. model: 'error',
  433. label: res.data.msg
  434. })
  435. }
  436. })
  437. }
  438. // else {
  439. // uni.navigateTo({
  440. // url: "/pages/shopdetail/index",
  441. // })
  442. // }
  443. },
  444. zhonglei(e) {
  445. console.log(e)
  446. uni.navigateTo({
  447. url: "/pages/gengduo/index?index="+e.index,
  448. })
  449. }
  450. },
  451. }
  452. </script>
  453. <style lang="scss">
  454. /deep/ .tm-menubars .body {
  455. background-color: #1b1b1b !important;
  456. }
  457. /deep/ .icon-search {
  458. font-size: 23px !important;
  459. color: #8E8E93 !important;
  460. }
  461. /deep/ .tm-search {
  462. width: 80%;
  463. background-color: #414141 !important;
  464. border-radius: 10px;
  465. }
  466. /deep/ .tm-search .grey-darken-5 {
  467. background-color: #414141 !important;
  468. }
  469. .dingwei {
  470. width: 21%;
  471. margin-top: 3%;
  472. }
  473. .shuruk {
  474. width: 77%;
  475. }
  476. .sousuo {
  477. width: 94%;
  478. margin: 0 auto;
  479. }
  480. .qiehuan {
  481. width: 40px;
  482. height: 40px;
  483. }
  484. .lunbo {
  485. position: relative;
  486. }
  487. .anniu1 {
  488. position: absolute;
  489. top: 0px;
  490. z-index: 9999;
  491. top: 43%;
  492. left: 0;
  493. }
  494. .anniu2 {
  495. position: absolute;
  496. top: 0px;
  497. z-index: 9999;
  498. top: 43%;
  499. right: 0;
  500. }
  501. /deep/ .jiaoxi {
  502. margin: 0 !important;
  503. padding: 8px !important;
  504. }
  505. /deep/ .tm-col {
  506. width: 20% !important;
  507. }
  508. .yifu1 {
  509. width: 40%;
  510. }
  511. .yifu2 {
  512. width: 58%;
  513. }
  514. .yifu1 image,
  515. .yifu21 {
  516. width: 100%;
  517. }
  518. .xiao {
  519. margin-top: 15px !important;
  520. }
  521. /deep/ .qiehuan1 .text-primary {
  522. color: white !important;
  523. }
  524. .guanggao {
  525. position: relative;
  526. }
  527. .wenzi {
  528. position: absolute;
  529. bottom: 1px;
  530. right: 0px;
  531. background: #000000;
  532. width: 140px;
  533. height: 55px;
  534. font-size: 14px;
  535. text-align: center;
  536. }
  537. /deep/ .jiage {
  538. background: #1b1b1b;
  539. }
  540. /deep/ .shangpin .white.bk {
  541. background-color: #1b1b1b !important;
  542. }
  543. /deep/ .shangpin .tm-cartCellListFood {
  544. padding: 0px 0px 15px 0px !important;
  545. margin-top: 5px !important;
  546. margin-bottom: 20px !important;
  547. border-bottom: 1px solid #303030;
  548. }
  549. /deep/ .shangpin .border-t-1.bk {
  550. border-top: 1px solid #1b1b1b !important;
  551. }
  552. /deep/ .shangpin .round-3 {
  553. width: 90px !important;
  554. height: 90px !important;
  555. }
  556. /deep/ .shangpin .tm-cartCellListFood-img {
  557. width: 90px !important;
  558. height: 90px !important;
  559. }
  560. .fudong {
  561. position: fixed;
  562. right: 30px;
  563. bottom: 80px;
  564. background: #0DABF2;
  565. width: 60px;
  566. height: 60px;
  567. border-radius: 30px;
  568. text-align: center;
  569. }
  570. .fudong image {
  571. width: 40px;
  572. margin-top: 6px;
  573. }
  574. .shuzigwc {
  575. color: white;
  576. font-weight: 700;
  577. position: absolute;
  578. right: 5px;
  579. background: red;
  580. padding: 2px;
  581. border-radius: 30px;
  582. top: 2px;
  583. width: 15px;
  584. height: 15px;
  585. font-size: 12px;
  586. }
  587. /deep/ .shangpin .title {
  588. color: white !important;
  589. }
  590. /deep/ .shangpin .text-red {
  591. color: white !important;
  592. }
  593. .divcont{
  594. border-radius: 50px;
  595. overflow: hidden;
  596. }
  597. </style>