index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842
  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||5}}</view>
  88. 商品
  89. </view>
  90. <view class="grade">
  91. <view>{{info.send_score||5}}</view>
  92. 发货
  93. </view>
  94. <view class="grade">
  95. <view>{{info.service_score||5}}</view>
  96. 服务
  97. </view>
  98. </view>
  99. <view class="qrcode_1">
  100. <view class="qrcode_1_1">
  101. <uqrcode ref="uqrcode" canvas-id="qrcode" :value="uqrcodeInfo" :options="{ margin:10 }"></uqrcode>
  102. <view class="txt">
  103. 店铺二维码
  104. </view>
  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. uqrcodeInfo: ''
  195. };
  196. },
  197. onLoad: async function(e) {
  198. const that = this;
  199. let id = '6333d71d32c5f69745f9bd32';
  200. if (e && e.id) id = e.id;
  201. else id = decodeURIComponent(e.q).split('id=')[1];
  202. that.$set(that, `id`, id);
  203. await that.watchLogin();
  204. await that.search();
  205. await that.searchOther();
  206. },
  207. onShow: function() {},
  208. onReady: function() {
  209. // const that = this;
  210. // that.createQrcode();
  211. },
  212. methods: {
  213. // 监听用户是否登录
  214. watchLogin() {
  215. const that = this;
  216. uni.getStorage({
  217. key: 'token',
  218. success: function(res) {
  219. let user = that.$jwt(res.data);
  220. that.$set(that, `user`, user);
  221. },
  222. fail: function(err) {}
  223. })
  224. },
  225. // 查询信息
  226. async search() {
  227. const that = this;
  228. if (that.id) {
  229. // 查询店铺信息
  230. const res = await that.$api(`/shop/${that.id}`, 'GET');
  231. if (res.errcode == '0') that.$set(that, `info`, res.data);
  232. let arr = await that.$api(`/storeShop/check`, `GET`, {
  233. customer: that.user._id,
  234. shop: that.id
  235. });
  236. if (arr.errcode == '0') {
  237. that.$set(that, `collection`, arr.data)
  238. }
  239. // 查询店铺商品
  240. that.searchShopMarket();
  241. // 查询全部商品
  242. that.searchAll();
  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() {
  279. const that = this;
  280. if (that.id) {
  281. const url = `${that.$config.serverUrl}/shopinfo?id=${that.id}`;
  282. that.$set(that, `uqrcodeInfo`, url);
  283. that.$refs.uqrcode.make({
  284. enableDelay: true
  285. })
  286. .then(res => {
  287. console.log(res);
  288. })
  289. .finally(() => {
  290. console.log('2');
  291. })
  292. }
  293. },
  294. // 购买
  295. toBuy(item) {
  296. if (item && item._id) {
  297. uni.navigateTo({
  298. url: `/pagesHome/order/detail?id=${item._id}`
  299. })
  300. }
  301. },
  302. // 全部产品-分页
  303. async toPage() {
  304. const that = this;
  305. let list = that.list;
  306. let limit = that.limit;
  307. if (that.total > list.length) {
  308. uni.showLoading({
  309. title: '加载中',
  310. mask: true
  311. })
  312. let page = that.page + 1;
  313. that.$set(that, `page`, page)
  314. let skip = page * limit;
  315. that.$set(that, `skip`, skip)
  316. that.searchAll();
  317. uni.hideLoading();
  318. } else uni.showToast({
  319. title: '没有更多数据了'
  320. });
  321. },
  322. // 输入框
  323. toInput(e) {
  324. const that = this;
  325. that.$set(that.searchInfo, `name`, e.detail.value);
  326. that.clearPage();
  327. that.searchAll();
  328. },
  329. // 筛选
  330. toCond(index, e) {
  331. const that = this;
  332. let condActive = that.condActive;
  333. that.$set(that, `condActive`, index);
  334. if (condActive != index && that.xia == '') {
  335. that.$set(that, `shang`, '0');
  336. that.$set(that, `xia`, '-1');
  337. } else if (condActive == index && that.xia == '-1') {
  338. that.$set(that, `shang`, '1');
  339. that.$set(that, `xia`, '0');
  340. } else if (condActive == index && that.shang == '1') {
  341. that.$set(that, `shang`, '0');
  342. that.$set(that, `xia`, '-1');
  343. } else if (condActive = index && that.shang == '1') {
  344. that.$set(that, `shang`, '0');
  345. that.$set(that, `xia`, '-1');
  346. }
  347. let key = '';
  348. let value;
  349. if (index != 0) {
  350. value = that.shang == '0' ? that.xia : that.shang;
  351. }
  352. if (index == 1) {
  353. key = 'sell_num';
  354. } else if (index == 2) {
  355. key = 'sell_money';
  356. } else if (index == 3) {
  357. key = 'view_num';
  358. }
  359. that.$set(that.searchInfo, `key`, key);
  360. that.$set(that.searchInfo, `value`, value);
  361. that.clearPage();
  362. that.searchAll();
  363. },
  364. // 查询其他信息
  365. async searchOther() {
  366. const that = this;
  367. let user = that.user;
  368. let shop = that.info;
  369. if (user && user._id && shop && shop._id) {
  370. // 商铺是否收藏
  371. let arr = await that.$api(`/storeShop/check`, `GET`, {
  372. customer: user._id,
  373. shop: shop._id
  374. });
  375. if (arr.errcode == '0') {
  376. that.$set(that, `collection`, arr.data)
  377. }
  378. }
  379. },
  380. // 收藏
  381. async toCollect() {
  382. const that = this;
  383. let user = that.user;
  384. let shop = that.info;
  385. if (user && user._id && shop && shop._id) {
  386. let res = await that.$api(`/storeShop`, `POST`, {
  387. customer: user._id,
  388. shop: shop._id
  389. });
  390. if (res.errcode == '0') {
  391. uni.showToast({
  392. title: res.data.msg,
  393. icon: 'none'
  394. })
  395. that.$set(that, `collection`, res.data.result)
  396. }
  397. } else {
  398. uni.showToast({
  399. title: '缺少必要信息,无法收藏',
  400. icon: 'none'
  401. })
  402. }
  403. },
  404. // 选择底部菜单
  405. barChange(index, item) {
  406. const that = this;
  407. that.$set(that, `barActive`, index);
  408. uni.setNavigationBarTitle({
  409. title: item.name
  410. });
  411. // 店铺简介时,绘制二维码
  412. if (index == '2') that.createQrcode();
  413. },
  414. // 清空列表
  415. clearPage() {
  416. const that = this;
  417. that.$set(that, `list`, [])
  418. that.$set(that, `skip`, 0)
  419. that.$set(that, `limit`, 5)
  420. that.$set(that, `page`, 0)
  421. }
  422. }
  423. }
  424. </script>
  425. <style lang="scss">
  426. .main {
  427. display: flex;
  428. flex-direction: column;
  429. width: 100vw;
  430. height: 100vh;
  431. .one {
  432. position: relative;
  433. flex-grow: 1;
  434. .one_1 {
  435. display: flex;
  436. flex-direction: column;
  437. width: 96vw;
  438. height: 90vh;
  439. padding: 2vw;
  440. background-color: var(--fFB1Color);
  441. .first {
  442. margin: 0 0 2vw 0;
  443. .image {
  444. width: 100%;
  445. height: 50vw;
  446. }
  447. }
  448. .second {
  449. position: relative;
  450. flex-grow: 1;
  451. .list {
  452. margin: 0 2vw 2vw 0;
  453. background-color: var(--fffColor);
  454. padding: 2vw;
  455. width: 43vw;
  456. border-radius: 5px;
  457. .image {
  458. width: 100%;
  459. height: 49vw;
  460. margin: 0 0 1vw 0;
  461. }
  462. .name {
  463. font-size: var(--font15Size);
  464. margin: 0 0 2vw 0;
  465. }
  466. .other {
  467. display: flex;
  468. flex-direction: row;
  469. justify-content: space-between;
  470. .money {
  471. color: var(--ff0Color);
  472. text:nth-child(1) {
  473. font-size: var(--font12Size);
  474. }
  475. }
  476. .btn {
  477. button {
  478. border-radius: 25px;
  479. color: var(--fffColor);
  480. background-color: var(--ff0Color);
  481. font-size: var(--font12Size);
  482. }
  483. }
  484. }
  485. }
  486. .list:nth-child(2n) {
  487. margin: 0 0 2vw 0;
  488. }
  489. }
  490. }
  491. .one_2 {
  492. height: 91vh;
  493. display: flex;
  494. flex-direction: row;
  495. padding: 2vw;
  496. .first_1 {
  497. position: relative;
  498. width: 25vw;
  499. background-color: #fafafa;
  500. display: flex;
  501. flex-direction: column;
  502. .list {
  503. text-align: center;
  504. padding: 2.5vw 0;
  505. border-bottom: 1px solid var(--f1Color);
  506. text {
  507. font-size: var(--font14Size);
  508. }
  509. }
  510. .listActive {
  511. background-color: var(--fffColor);
  512. }
  513. }
  514. .first_2 {
  515. padding: 2vw;
  516. flex-grow: 1;
  517. position: relative;
  518. display: flex;
  519. flex-direction: column;
  520. .list {
  521. margin: 0 0 2vw 0;
  522. padding: 2vw;
  523. .title {
  524. font-size: var(--font16Size);
  525. margin: 0 0 2vw 0;
  526. }
  527. .market {
  528. display: flex;
  529. flex-direction: row;
  530. flex-wrap: wrap;
  531. .marketList {
  532. text-align: center;
  533. margin: 0 2vw 2vw 0;
  534. width: 22vw;
  535. .image {
  536. width: 100%;
  537. height: 15vw;
  538. }
  539. .name {
  540. font-size: var(--font14Size);
  541. }
  542. }
  543. .marketList:nth-child(3n) {
  544. margin: 0 0 2vw 0;
  545. }
  546. }
  547. }
  548. }
  549. }
  550. .one_3 {
  551. display: flex;
  552. flex-direction: column;
  553. width: 100vw;
  554. height: 90vh;
  555. .first {
  556. border-bottom: 1px solid var(--f85Color);
  557. padding: 2vw;
  558. input {
  559. padding: 2vw;
  560. background-color: var(--f1Color);
  561. font-size: var(--font14Size);
  562. border-radius: 5px;
  563. }
  564. }
  565. .second {
  566. position: relative;
  567. flex-grow: 1;
  568. .second_1 {
  569. width: 96vw;
  570. background-color: var(--fffColor);
  571. padding: 2vw;
  572. display: flex;
  573. flex-direction: row;
  574. justify-content: space-around;
  575. .list {
  576. display: flex;
  577. flex-direction: row;
  578. .icon {
  579. position: relative;
  580. top: -5px;
  581. left: 2px;
  582. .icon_1 {
  583. height: 10px;
  584. .iconfont {
  585. font-size: 12px;
  586. }
  587. }
  588. }
  589. }
  590. .activeList {
  591. .name {
  592. color: #ff0000;
  593. }
  594. }
  595. }
  596. .second_2 {
  597. display: flex;
  598. flex-direction: row;
  599. flex-wrap: wrap;
  600. padding: 2vw 2vw 0 2vw;
  601. background-color: var(--f1Color);
  602. .list {
  603. position: relative;
  604. width: 43vw;
  605. margin: 0 2vw 2vw 0;
  606. padding: 2vw;
  607. border-radius: 9px;
  608. background-color: var(--fffColor);
  609. .image {
  610. width: 100%;
  611. height: 40vw;
  612. }
  613. .sale {
  614. position: absolute;
  615. top: 18vw;
  616. text-align: center;
  617. width: 43vw;
  618. text {
  619. background-color: #0000005f;
  620. border-radius: 90px;
  621. display: inline-block;
  622. width: 15vw;
  623. height: 15vw;
  624. color: var(--fffColor);
  625. text-align: center;
  626. line-height: 15vw;
  627. }
  628. }
  629. .name {
  630. font-size: var(--font16Size);
  631. margin: 0 0 1vw 0;
  632. }
  633. .other {
  634. display: flex;
  635. flex-direction: row;
  636. justify-content: space-between;
  637. .money {
  638. font-size: var(--font14Size);
  639. color: var(--ff0Color);
  640. text:nth-child(1) {
  641. font-size: var(--font12Size);
  642. }
  643. }
  644. .other_1 {
  645. flex-grow: 1;
  646. margin: 0 0 0 2vw;
  647. font-size: var(--font12Size);
  648. color: var(--f85Color);
  649. }
  650. .btn {
  651. button {
  652. border-radius: 25px;
  653. color: var(--fffColor);
  654. background-color: var(--ff0Color);
  655. font-size: var(--font12Size);
  656. }
  657. }
  658. }
  659. }
  660. .list:nth-child(2n) {
  661. margin: 0 0 2vw 0;
  662. }
  663. }
  664. }
  665. }
  666. .one_4 {
  667. .first {
  668. display: flex;
  669. flex-direction: column;
  670. align-items: center;
  671. background-color: var(--fFB1Color);
  672. border-bottom-right-radius: 10vw;
  673. border-bottom-left-radius: 10vw;
  674. .image {
  675. width: 20vw;
  676. height: 20vw;
  677. border-radius: 20vw;
  678. }
  679. .name {
  680. margin: 2vw 0;
  681. font-size: var(--font16Szie);
  682. font-weight: bold;
  683. color: var(--mainColor);
  684. }
  685. }
  686. .second {
  687. margin: 2vw 0;
  688. .second_1 {
  689. display: flex;
  690. justify-content: space-evenly;
  691. .grade {
  692. display: flex;
  693. flex-direction: column;
  694. align-items: center;
  695. color: var(--f85Color);
  696. font-size: var(--font13Size);
  697. view {
  698. margin: 1vw 0 0 0;
  699. color: var(--ff0Color);
  700. }
  701. }
  702. }
  703. .qrcode_1 {
  704. display: flex;
  705. justify-content: center;
  706. text-align: center;
  707. margin: 5vw 0;
  708. .qrcode_1_1 {
  709. padding: 2vw;
  710. background: red;
  711. .uqrcode {
  712. width: 216px !important;
  713. height: 216px !important;
  714. }
  715. // canvas {
  716. // width: 180px !important;
  717. // height: 180px !important;
  718. // }
  719. .txt {
  720. margin: 2vw 0 0 0;
  721. }
  722. }
  723. }
  724. }
  725. }
  726. .collect {
  727. position: fixed;
  728. top: 0;
  729. right: 2vw;
  730. .iconfont {
  731. font-size: 25px;
  732. }
  733. }
  734. }
  735. .two {
  736. display: flex;
  737. flex-direction: row;
  738. justify-content: space-around;
  739. border-top: 1px solid #f1f1f1;
  740. .list {
  741. padding: 1vw 0;
  742. text-align: center;
  743. .icon {}
  744. .name {
  745. font-size: 12px;
  746. }
  747. .activename {
  748. color: var(--fFB1Color);
  749. }
  750. }
  751. }
  752. }
  753. .scroll-view {
  754. position: absolute;
  755. top: 0;
  756. left: 0;
  757. right: 0;
  758. bottom: 0;
  759. .list-scroll-view {
  760. display: flex;
  761. flex-direction: row;
  762. flex-wrap: wrap;
  763. }
  764. }
  765. </style>