index.vue 18 KB

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