index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <view class="one_1" v-if="barActive=='0'">
  6. <view class="first">
  7. <image class="image" :src="info.logo&&info.logo.length>0?info.logo[0].url:''" mode=""></image>
  8. </view>
  9. <view class="second">
  10. <scroll-view scroll-y="true" class="scroll-view">
  11. <view class="list-scroll-view">
  12. <view class="list" v-for="(item,index) in shoplist" :key="index">
  13. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode=""></image>
  14. <view class="name">
  15. {{item.name}}
  16. </view>
  17. <view class="other">
  18. <view class="money">
  19. <text>¥</text>
  20. <text>{{item.sell_money}}</text>
  21. </view>
  22. <view class="btn">
  23. <button type="default" size="mini" @click="toBuy(item)">购买</button>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </scroll-view>
  29. </view>
  30. </view>
  31. <view class="one_3" v-else-if="barActive=='1'">
  32. <view class="first">
  33. <input type="text" v-model="searchInfo.name" @blur="toInput" placeholder="搜索商品">
  34. </view>
  35. <view class="second">
  36. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage">
  37. <view class="list-scroll-view">
  38. <view class="second_1">
  39. <view :class="['list',condActive==index?'activeList':'']" v-for="(item,index) in condList" :key="index" @tap="toCond(index,item)">
  40. <view class="name">
  41. {{item.name}}
  42. </view>
  43. <view class="icon">
  44. <view class="icon_1">
  45. <text :class="['iconfont',item.shangActive]" v-if="condActive==index&&shang=='1'"></text>
  46. <text :class="['iconfont',item.shang]" v-else></text>
  47. </view>
  48. <view class="icon_1">
  49. <text :class="['iconfont', item.xiaActive]" v-if="condActive==index&&xia=='-1'"></text>
  50. <text :class="['iconfont', item.xia]" v-else></text>
  51. </view>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="second_2">
  56. <view class="list" v-for="(item,index) in list" :key="index">
  57. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode=""></image>
  58. <view class="sale" v-if="item.is_sale==true">
  59. <text>已售尽</text>
  60. </view>
  61. <view class="name">
  62. {{item.name}}
  63. </view>
  64. <view class="other">
  65. <view class="money">
  66. <text>¥</text>
  67. <text>{{item.sell_money}}</text>
  68. </view>
  69. <view class="btn">
  70. <button type="default" size="mini" @click="toBuy(item)">购买</button>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. </view>
  76. </scroll-view>
  77. </view>
  78. </view>
  79. <view class="one_4" v-else-if="barActive=='2'">
  80. <view class="first">
  81. <image class="image" :src="info.logo&&info.logo.length>0?info.logo[0].url:''" mode=""></image>
  82. <view class="name">{{info.name}}</view>
  83. </view>
  84. <view class="second">
  85. <view class="second_1">
  86. <view class="grade">
  87. <view>{{info.goods_score||0}}</view>
  88. 商品
  89. </view>
  90. <view class="grade">
  91. <view>{{info.send_score||0}}</view>
  92. 发货
  93. </view>
  94. <view class="grade">
  95. <view>{{info.service_score||0}}</view>
  96. 服务
  97. </view>
  98. </view>
  99. <view class="second_2">
  100. <view class="second_2_bor">
  101. <image class="image" :src="info.qrcode&&info.qrcode.length>0?info.qrcode[0].url:''" mode=""></image>
  102. </view>
  103. <view class="txt">
  104. 店铺二维码
  105. </view>
  106. </view>
  107. </view>
  108. <view class="collect">
  109. <text v-if="!collection" @click="toCollect" class="iconfont icon-yduishoucangkongxin"></text>
  110. <text v-else @click="toCollect" class="iconfont icon-yduishoucangshixin"></text>
  111. </view>
  112. </view>
  113. </view>
  114. <view class="two">
  115. <view class="list" v-for="(item,index) in barList" :key="index" @tap="barChange(index,item)">
  116. <view class="icon">
  117. <text :class="['iconfont',barActive==index?item.acticon:item.icon]"></text>
  118. </view>
  119. <view :class="['name',barActive==index?'activename':'']">
  120. {{item.name}}
  121. </view>
  122. </view>
  123. </view>
  124. </view>
  125. </mobile-frame>
  126. </template>
  127. <script>
  128. export default {
  129. data() {
  130. return {
  131. user: {},
  132. id: '',
  133. barActive: '0',
  134. barList: [ //底部菜单
  135. {
  136. icon: 'icon-shangdian',
  137. acticon: "icon-shangdian-copy",
  138. name: '微店首页'
  139. },
  140. {
  141. icon: 'icon-shangpinfenlei',
  142. acticon: "icon-shangpinfenlei-copy",
  143. name: '全部商品'
  144. },
  145. {
  146. icon: 'icon-qiyejianjie',
  147. acticon: "icon-qiyejianjie-copy",
  148. name: '店铺简介'
  149. }
  150. ],
  151. // 店铺信息
  152. info: {},
  153. // 店铺部分商品
  154. shoplist: [],
  155. // 收藏
  156. collection: false,
  157. // 全部商品
  158. searchInfo: {},
  159. list: [],
  160. total: 0,
  161. page: 0,
  162. skip: 0,
  163. limit: 5,
  164. condActive: 0,
  165. shang: '',
  166. xia: '',
  167. condList: [ // 筛选
  168. {
  169. name: '默认',
  170. },
  171. {
  172. name: '销量',
  173. shang: 'icon-shangjiantou',
  174. shangActive: 'icon-shangjiantou-copy',
  175. xia: 'icon-xiajiantou',
  176. xiaActive: 'icon-xiajiantou-copy'
  177. },
  178. {
  179. name: '价格',
  180. shang: 'icon-shangjiantou',
  181. shangActive: 'icon-shangjiantou-copy',
  182. xia: 'icon-xiajiantou',
  183. xiaActive: 'icon-xiajiantou-copy'
  184. },
  185. {
  186. name: '浏览量',
  187. shang: 'icon-shangjiantou',
  188. shangActive: 'icon-shangjiantou-copy',
  189. xia: 'icon-xiajiantou',
  190. xiaActive: 'icon-xiajiantou-copy'
  191. }
  192. ]
  193. };
  194. },
  195. onLoad: async function(e) {
  196. const that = this;
  197. that.$set(that, `id`, e.id || '');
  198. await that.watchLogin();
  199. await that.search();
  200. await that.searchOther();
  201. },
  202. onShow: function() {},
  203. methods: {
  204. // 监听用户是否登录
  205. watchLogin() {
  206. const that = this;
  207. uni.getStorage({
  208. key: 'token',
  209. success: function(res) {
  210. let user = that.$jwt(res.data);
  211. that.$set(that, `user`, user);
  212. },
  213. fail: function(err) {}
  214. })
  215. },
  216. // 查询信息
  217. async search() {
  218. const that = this;
  219. if (that.id) {
  220. // 查询店铺信息
  221. const res = await that.$api(`/shop/${that.id}`, 'GET');
  222. if (res.errcode == '0') that.$set(that, `info`, res.data);
  223. let arr = await that.$api(`/storeShop/check`, `GET`, {
  224. customer: that.user._id,
  225. shop: that.id
  226. });
  227. if (arr.errcode == '0') {
  228. that.$set(that, `collection`, arr.data)
  229. }
  230. // 查询店铺商品
  231. that.searchShopMarket();
  232. // 查询全部商品
  233. that.searchAll();
  234. }
  235. },
  236. // 查询店铺商品
  237. async searchShopMarket() {
  238. const that = this;
  239. const res = await that.$api(`/viewGoods/indexGoodsList`, 'GET', {
  240. shop: that.id,
  241. skip: 0,
  242. limit: 20
  243. })
  244. if (res.errcode == '0') that.$set(that, `shoplist`, res.data);
  245. },
  246. // 查询全部产品
  247. async searchAll() {
  248. const that = this;
  249. let info = {
  250. shop: that.id,
  251. skip: that.skip,
  252. limit: that.limit
  253. }
  254. const res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
  255. ...info,
  256. ...that.searchInfo
  257. })
  258. if (res.errcode == '0') {
  259. let list = [...that.list, ...res.data];
  260. that.$set(that, `list`, list)
  261. that.$set(that, `total`, res.total)
  262. } else {
  263. uni.showToast({
  264. title: res.errmsg,
  265. });
  266. }
  267. },
  268. // 购买
  269. toBuy(item) {
  270. if (item && item._id) {
  271. uni.navigateTo({
  272. url: `/pagesHome/order/detail?id=${item._id}`
  273. })
  274. }
  275. },
  276. // 全部产品-分页
  277. async toPage() {
  278. const that = this;
  279. let list = that.list;
  280. let limit = that.limit;
  281. if (that.total > list.length) {
  282. uni.showLoading({
  283. title: '加载中',
  284. mask: true
  285. })
  286. let page = that.page + 1;
  287. that.$set(that, `page`, page)
  288. let skip = page * limit;
  289. that.$set(that, `skip`, skip)
  290. that.searchAll();
  291. uni.hideLoading();
  292. } else uni.showToast({
  293. title: '没有更多数据了'
  294. });
  295. },
  296. // 输入框
  297. toInput(e) {
  298. const that = this;
  299. that.$set(that.searchInfo, `name`, e.detail.value);
  300. that.clearPage();
  301. that.searchAll();
  302. },
  303. // 筛选
  304. toCond(index, e) {
  305. const that = this;
  306. let condActive = that.condActive;
  307. that.$set(that, `condActive`, index);
  308. if (condActive != index && that.xia == '') {
  309. that.$set(that, `shang`, '0');
  310. that.$set(that, `xia`, '-1');
  311. } else if (condActive == index && that.xia == '-1') {
  312. that.$set(that, `shang`, '1');
  313. that.$set(that, `xia`, '0');
  314. } else if (condActive == index && that.shang == '1') {
  315. that.$set(that, `shang`, '0');
  316. that.$set(that, `xia`, '-1');
  317. } else if (condActive = index && that.shang == '1') {
  318. that.$set(that, `shang`, '0');
  319. that.$set(that, `xia`, '-1');
  320. }
  321. let key = '';
  322. let value;
  323. if (index != 0) {
  324. value = that.shang == '0' ? that.xia : that.shang;
  325. }
  326. if (index == 1) {
  327. key = 'sell_num';
  328. } else if (index == 2) {
  329. key = 'sell_money';
  330. } else if (index == 3) {
  331. key = 'view_num';
  332. }
  333. that.$set(that.searchInfo, `key`, key);
  334. that.$set(that.searchInfo, `value`, value);
  335. that.clearPage();
  336. that.searchAll();
  337. },
  338. // 查询其他信息
  339. async searchOther() {
  340. const that = this;
  341. let user = that.user;
  342. let shop = that.info;
  343. if (user && user._id && shop && shop._id) {
  344. // 商铺是否收藏
  345. let arr = await that.$api(`/storeShop/check`, `GET`, {
  346. customer: user._id,
  347. shop: shop._id
  348. });
  349. if (arr.errcode == '0') {
  350. that.$set(that, `collection`, arr.data)
  351. }
  352. }
  353. },
  354. // 收藏
  355. async toCollect() {
  356. const that = this;
  357. let user = that.user;
  358. let shop = that.info;
  359. if (user && user._id && shop && shop._id) {
  360. let res = await that.$api(`/storeShop`, `POST`, {
  361. customer: user._id,
  362. shop: shop._id
  363. });
  364. if (res.errcode == '0') {
  365. uni.showToast({
  366. title: res.data.msg,
  367. icon: 'none'
  368. })
  369. that.$set(that, `collection`, res.data.result)
  370. }
  371. } else {
  372. uni.showToast({
  373. title: '缺少必要信息,无法收藏',
  374. icon: 'none'
  375. })
  376. }
  377. },
  378. // 选择底部菜单
  379. barChange(index, item) {
  380. const that = this;
  381. that.$set(that, `barActive`, index);
  382. uni.setNavigationBarTitle({
  383. title: item.name
  384. });
  385. },
  386. // 清空列表
  387. clearPage() {
  388. const that = this;
  389. that.$set(that, `list`, [])
  390. that.$set(that, `skip`, 0)
  391. that.$set(that, `limit`, 5)
  392. that.$set(that, `page`, 0)
  393. }
  394. }
  395. }
  396. </script>
  397. <style lang="scss">
  398. .main {
  399. display: flex;
  400. flex-direction: column;
  401. width: 100vw;
  402. height: 100vh;
  403. .one {
  404. position: relative;
  405. flex-grow: 1;
  406. .one_1 {
  407. display: flex;
  408. flex-direction: column;
  409. width: 96vw;
  410. height: 90vh;
  411. padding: 2vw;
  412. background-color: var(--fFB1Color);
  413. .first {
  414. margin: 0 0 2vw 0;
  415. .image {
  416. width: 100%;
  417. height: 50vw;
  418. }
  419. }
  420. .second {
  421. position: relative;
  422. flex-grow: 1;
  423. .list {
  424. margin: 0 2vw 2vw 0;
  425. background-color: var(--fffColor);
  426. padding: 2vw;
  427. width: 43vw;
  428. border-radius: 5px;
  429. .image {
  430. width: 100%;
  431. height: 49vw;
  432. margin: 0 0 1vw 0;
  433. }
  434. .name {
  435. font-size: var(--font15Size);
  436. margin: 0 0 2vw 0;
  437. }
  438. .other {
  439. display: flex;
  440. flex-direction: row;
  441. justify-content: space-between;
  442. .money {
  443. color: var(--ff0Color);
  444. text:nth-child(1) {
  445. font-size: var(--font12Size);
  446. }
  447. }
  448. .btn {
  449. button {
  450. border-radius: 25px;
  451. color: var(--fffColor);
  452. background-color: var(--ff0Color);
  453. font-size: var(--font12Size);
  454. }
  455. }
  456. }
  457. }
  458. .list:nth-child(2n) {
  459. margin: 0 0 2vw 0;
  460. }
  461. }
  462. }
  463. .one_2 {
  464. height: 91vh;
  465. display: flex;
  466. flex-direction: row;
  467. padding: 2vw;
  468. .first_1 {
  469. position: relative;
  470. width: 25vw;
  471. background-color: #fafafa;
  472. display: flex;
  473. flex-direction: column;
  474. .list {
  475. text-align: center;
  476. padding: 2.5vw 0;
  477. border-bottom: 1px solid var(--f1Color);
  478. text {
  479. font-size: var(--font14Size);
  480. }
  481. }
  482. .listActive {
  483. background-color: var(--fffColor);
  484. }
  485. }
  486. .first_2 {
  487. padding: 2vw;
  488. flex-grow: 1;
  489. position: relative;
  490. display: flex;
  491. flex-direction: column;
  492. .list {
  493. margin: 0 0 2vw 0;
  494. padding: 2vw;
  495. .title {
  496. font-size: var(--font16Size);
  497. margin: 0 0 2vw 0;
  498. }
  499. .market {
  500. display: flex;
  501. flex-direction: row;
  502. flex-wrap: wrap;
  503. .marketList {
  504. text-align: center;
  505. margin: 0 2vw 2vw 0;
  506. width: 22vw;
  507. .image {
  508. width: 100%;
  509. height: 15vw;
  510. }
  511. .name {
  512. font-size: var(--font14Size);
  513. }
  514. }
  515. .marketList:nth-child(3n) {
  516. margin: 0 0 2vw 0;
  517. }
  518. }
  519. }
  520. }
  521. }
  522. .one_3 {
  523. display: flex;
  524. flex-direction: column;
  525. width: 100vw;
  526. height: 90vh;
  527. .first {
  528. border-bottom: 1px solid var(--f85Color);
  529. padding: 2vw;
  530. input {
  531. padding: 2vw;
  532. background-color: var(--f1Color);
  533. font-size: var(--font14Size);
  534. border-radius: 5px;
  535. }
  536. }
  537. .second {
  538. position: relative;
  539. flex-grow: 1;
  540. .second_1 {
  541. width: 96vw;
  542. background-color: var(--fffColor);
  543. padding: 2vw;
  544. display: flex;
  545. flex-direction: row;
  546. justify-content: space-around;
  547. .list {
  548. display: flex;
  549. flex-direction: row;
  550. .icon {
  551. position: relative;
  552. top: -5px;
  553. left: 2px;
  554. .icon_1 {
  555. height: 10px;
  556. .iconfont {
  557. font-size: 12px;
  558. }
  559. }
  560. }
  561. }
  562. .activeList {
  563. .name {
  564. color: #ff0000;
  565. }
  566. }
  567. }
  568. .second_2 {
  569. display: flex;
  570. flex-direction: row;
  571. flex-wrap: wrap;
  572. padding: 2vw 2vw 0 2vw;
  573. background-color: var(--f1Color);
  574. .list {
  575. position: relative;
  576. width: 43vw;
  577. margin: 0 2vw 2vw 0;
  578. padding: 2vw;
  579. border-radius: 9px;
  580. background-color: var(--fffColor);
  581. .image {
  582. width: 100%;
  583. height: 40vw;
  584. }
  585. .sale {
  586. position: absolute;
  587. top: 18vw;
  588. text-align: center;
  589. width: 43vw;
  590. text {
  591. background-color: #0000005f;
  592. border-radius: 90px;
  593. display: inline-block;
  594. width: 15vw;
  595. height: 15vw;
  596. color: var(--fffColor);
  597. text-align: center;
  598. line-height: 15vw;
  599. }
  600. }
  601. .name {
  602. font-size: var(--font16Size);
  603. margin: 0 0 1vw 0;
  604. }
  605. .other {
  606. display: flex;
  607. flex-direction: row;
  608. justify-content: space-between;
  609. .money {
  610. font-size: var(--font14Size);
  611. color: var(--ff0Color);
  612. text:nth-child(1) {
  613. font-size: var(--font12Size);
  614. }
  615. }
  616. .other_1 {
  617. flex-grow: 1;
  618. margin: 0 0 0 2vw;
  619. font-size: var(--font12Size);
  620. color: var(--f85Color);
  621. }
  622. .btn {
  623. button {
  624. border-radius: 25px;
  625. color: var(--fffColor);
  626. background-color: var(--ff0Color);
  627. font-size: var(--font12Size);
  628. }
  629. }
  630. }
  631. }
  632. .list:nth-child(2n) {
  633. margin: 0 0 2vw 0;
  634. }
  635. }
  636. }
  637. }
  638. .one_4 {
  639. .first {
  640. display: flex;
  641. flex-direction: column;
  642. align-items: center;
  643. background-color: var(--fFB1Color);
  644. border-bottom-right-radius: 10vw;
  645. border-bottom-left-radius: 10vw;
  646. .image {
  647. width: 20vw;
  648. height: 20vw;
  649. border-radius: 20vw;
  650. }
  651. .name {
  652. margin: 2vw 0;
  653. font-size: var(--font16Szie);
  654. font-weight: bold;
  655. color: var(--mainColor);
  656. }
  657. }
  658. .second {
  659. margin: 2vw 0;
  660. .second_1 {
  661. display: flex;
  662. justify-content: space-evenly;
  663. .grade {
  664. display: flex;
  665. flex-direction: column;
  666. align-items: center;
  667. color: var(--f85Color);
  668. font-size: var(--font13Size);
  669. view {
  670. margin: 1vw 0 0 0;
  671. color: var(--ff0Color);
  672. }
  673. }
  674. }
  675. .second_2 {
  676. display: flex;
  677. justify-content: center;
  678. flex-direction: column;
  679. margin: 15vw 25vw 0 25vw;
  680. text-align: center;
  681. background: #b2b2b2;
  682. padding: 2vw;
  683. border-radius: 5px;
  684. .second_2_bor {
  685. .image {
  686. width: 100%;
  687. height: 40vw;
  688. }
  689. }
  690. .txt {
  691. color: #fff;
  692. font-size: 14px;
  693. margin: 2vw 0;
  694. }
  695. }
  696. }
  697. }
  698. .collect {
  699. position: fixed;
  700. top: 0;
  701. right: 2vw;
  702. .iconfont {
  703. font-size: 25px;
  704. }
  705. }
  706. }
  707. .two {
  708. display: flex;
  709. flex-direction: row;
  710. justify-content: space-around;
  711. border-top: 1px solid #f1f1f1;
  712. .list {
  713. padding: 1vw 0;
  714. text-align: center;
  715. .icon {}
  716. .name {
  717. font-size: 12px;
  718. }
  719. .activename {
  720. color: var(--fFB1Color);
  721. }
  722. }
  723. }
  724. }
  725. .scroll-view {
  726. position: absolute;
  727. top: 0;
  728. left: 0;
  729. right: 0;
  730. bottom: 0;
  731. .list-scroll-view {
  732. display: flex;
  733. flex-direction: row;
  734. flex-wrap: wrap;
  735. }
  736. }
  737. </style>