index.vue 17 KB

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