index.vue 18 KB

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