index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. <template>
  2. <view :class="['qn-page-' + theme]" class="view-wrap" :style="pageStyle">
  3. <NavigationBar v-if="is_data" :scrollTop="scrollTop" :modelData="topData" @openLocation="openLocation" />
  4. <view style="position: relative; z-index: 2;">
  5. <block v-if="is_data"><PageDesign :temData="temData" :showGoodsPrice="showGoodsPrice" :selAddress="now_sel_address"></PageDesign></block>
  6. <!-- 骨架 -->
  7. <Skeleton v-else :imgTitle="true" :loading="true" :showAvatar="false"></Skeleton>
  8. <!-- #ifdef APP-PLUS -->
  9. <u-popup v-model="upgradePop" mode="center" :border-radius="12">
  10. <view class="upgrade-view">
  11. <image class="upgrade-img" src="https://onlineimg.qianniao.vip/shengji.jpg" mode="aspectFit"></image>
  12. <view class="upgrade-tit">发现新版本</view>
  13. <view class="upgrade-num">{{ newVersion }}</view>
  14. <view class="upgrade-cont">
  15. 为了您更好的体验,
  16. <br />
  17. 请您去升级到新版本哦!
  18. </view>
  19. <view @click="downloadApp" class="upgrade-btn">立即升级</view>
  20. <view class="closePop" @click="closeUPop"><text class="ibonfont ibonguanbi"></text></view>
  21. </view>
  22. </u-popup>
  23. <u-popup :mask-close-able="false" v-model="up_show" mode="center" :border-radius="12">
  24. <view class="upgrade-view">
  25. <image class="upgrade-img" src="https://onlineimg.qianniao.vip/shengji.jpg" mode="aspectFit"></image>
  26. <view class="upgrade-tit">新版本更新中</view>
  27. <view class="upgrade-cont"><u-line-progress :striped="true" :percent="up_percent" :striped-active="true"></u-line-progress></view>
  28. </view>
  29. </u-popup>
  30. <!-- #endif -->
  31. <u-modal v-model="tip_model" @confirm="finishCofirm" @cancel="tipCancel" :show-cancel-button="true" content="请先完善资料,再进行购物" confirm-text="去完善" cancel-text="逛逛商城"></u-modal>
  32. <!-- 底部tabbar -->
  33. <Tabbar v-model="current"></Tabbar>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import permision from '@/access/wa-permission/permission.js';
  39. import PageDesign from '@/components/PageDesign/PageDesign.vue';
  40. import { getToken, getUserInfo } from '@/access/common.js';
  41. import NavigationBar from '@/components/PageDesign/components/NavigationBar.vue';
  42. import Skeleton from '@/components/J-skeleton.vue';
  43. export default {
  44. components: {
  45. PageDesign,
  46. Skeleton,
  47. NavigationBar
  48. },
  49. data() {
  50. return {
  51. tip_model: false, // 完善资料提示
  52. up_percent: 0,
  53. up_show: false,
  54. current: 0,
  55. upgradePop: false,
  56. newVersion: '',
  57. oldVersion: 'v1.0.6',
  58. model: 0,
  59. now_sel_address: {},
  60. home_data: {},
  61. temData: {},
  62. is_data: false,
  63. show_goods_price: 4,
  64. userCenterId: '',
  65. topData: {
  66. name: '',
  67. topBgColor: '#ffffff',
  68. textColor: '#000000',
  69. pageBgColor: '#f7f8fa',
  70. bgImage: ''
  71. },
  72. startUpPage: {
  73. img: '',
  74. isEnable: false,
  75. time: 5
  76. },
  77. scrollTop: 0
  78. };
  79. },
  80. computed: {
  81. enterprice() {
  82. return this.$store.state.enterpriseInfo;
  83. },
  84. isUpdate() {
  85. return this.$store.state.isUpdate;
  86. },
  87. pageTit() {
  88. if (this.temData.length) {
  89. const obj = this.temData[0].modelData;
  90. return obj.name;
  91. } else {
  92. return this.baseSet.shop || '首页';
  93. }
  94. },
  95. baseSet() {
  96. return this.$store.state.baseSet;
  97. },
  98. pageStyle() {
  99. if (this.temData.length) {
  100. const obj = this.temData[0].modelData;
  101. return `background-color:${obj.pageBgColor};background-image:url(${obj.bgImage});backgroundPosition: ${
  102. obj.topBgColor ? '0 ' + (this.barHeight + 44) + 'px' : '0 0'
  103. }`;
  104. } else {
  105. return '';
  106. }
  107. },
  108. isLogin() {
  109. return this.$store.state.hasLogin;
  110. },
  111. showGoodsPrice() {
  112. if (this.baseSet.goodsPrice === 5 && this.isLogin) {
  113. return '';
  114. } else if (!this.isLogin && this.baseSet.goodsPrice === 4) {
  115. return '请登录';
  116. } else if (this.$store.state.userStatus.enableStatus === 4 && this.baseSet.goodsPrice === 4) {
  117. return '已禁用';
  118. } else if (this.$store.state.userStatus.status !== 2 && this.baseSet.goodsPrice === 4) {
  119. if (this.$store.state.userStatus.status === 0) {
  120. return '待审核';
  121. } else if (this.$store.state.userStatus.status === 1) {
  122. return '审核中';
  123. } else if (this.$store.state.userStatus.status === 3) {
  124. return '已驳回';
  125. }
  126. } else {
  127. return '';
  128. }
  129. },
  130. // #ifdef APP-PLUS
  131. iosAuditStatus() {
  132. return this.$store.state.iosAuditStatus;
  133. }
  134. // #endif
  135. },
  136. watch: {
  137. '$store.state.locationObj'(val) {
  138. if (JSON.stringify(val) === '{}') {
  139. console.log(333);
  140. this.getAuthorizeInfo();
  141. return;
  142. }
  143. uni.hideToast();
  144. this.getTemplate();
  145. },
  146. isLogin(val) {
  147. this.getTemplate();
  148. this.getIndexData();
  149. }
  150. },
  151. async onShow() {
  152. // #ifdef APP-PLUS
  153. if (JSON.stringify(this.$store.state.locationObj || {}) === '{}') {
  154. if (plus.os.name == 'iOS') {
  155. let result = permision.judgeIosPermission('location');
  156. if (result) {
  157. await this.resetGetLocation();
  158. }
  159. } else {
  160. let result = await permision.requestAndroidPermission('android.permission.ACCESS_FINE_LOCATION');
  161. if (result == 1) {
  162. await this.resetGetLocation();
  163. }
  164. }
  165. }
  166. // #endif
  167. // #ifdef MP-WEIXIN || MP-TOUTIAO || H5
  168. if (JSON.stringify(this.$store.state.locationObj || {}) === '{}') {
  169. await this.getAuthorizeInfo();
  170. return;
  171. }
  172. // #endif
  173. },
  174. // 发送给朋友
  175. onShareAppMessage() {
  176. return {
  177. title: this.baseSet.shop,
  178. path: '/pages/index/index?businessmanId=' + (this.$store.state.userStatus.id || ''),
  179. success: res => {
  180. console.log(res);
  181. }
  182. };
  183. },
  184. // #ifdef MP-WEIXIN
  185. // 分享到朋友圈
  186. onShareTimeline(obj) {},
  187. // 收藏小程序
  188. onAddToFavorites() {},
  189. // #endif
  190. async onLoad(options) {
  191. console.log('h获取模板');
  192. try{
  193. await this.getTemplate();
  194. console.log('h获取模板11');
  195. await this.getEnterpriseInfo();
  196. // #ifdef MP
  197. // 获取小程序分销商参数
  198. console.log("xxxxxxx")
  199. console.log(options.businessmanId)
  200. if (options.businessmanId) {
  201. this.$store.commit('commit_businessmanId', options.businessmanId);
  202. this.relationshipBusinessman(options.businessmanId);
  203. } else if (options.scene) {
  204. // 扫码进入
  205. const scene = decodeURIComponent(options.scene);
  206. if (scene.indexOf('_') > -1) {
  207. const id = scene.slice(0, scene.length - 1);
  208. console.log('staffId', id);
  209. this.$store.commit('commit_staffId', id);
  210. } else {
  211. this.$store.commit('commit_businessmanId', scene);
  212. this.relationshipBusinessman(scene);
  213. }
  214. }
  215. // #endif
  216. this.show_goods_price = this.isLogin ? 5 : this.baseSet.goodsPrice;
  217. // 实时定位
  218. if (JSON.stringify(this.$store.state.locationObj) !== '{}') {
  219. await this.resetGetLocation();
  220. }
  221. // #ifdef APP-PLUS
  222. // 获取APP版本
  223. await this.getVersion();
  224. // #endif
  225. await this.getBasicField();
  226. await this.getIndexData();
  227. await this.getClassSettingInfo();
  228. // #ifdef MP-WEIXIN
  229. // 小程序的原生菜单中显示分享按钮
  230. uni.showShareMenu({
  231. withShareTicket: false,
  232. menus: ['shareAppMessage', 'shareTimeline']
  233. });
  234. // #endif
  235. }catch(e){
  236. console.log(e,'错误');
  237. //TODO handle the exception
  238. }
  239. },
  240. methods: {
  241. // #ifdef MP
  242. // 添加分销上下级关系 source: 1:首次点击链接 2:首次下单 3:首次付款'
  243. async relationshipBusinessman(businessmanId) {
  244. console.log('上级ID', businessmanId);
  245. if (!this.isLogin) {
  246. // 没有登录不请求接口
  247. return;
  248. }
  249. await this.$u.api.relationshipBusinessman({
  250. businessmanId: businessmanId,
  251. source: 1
  252. });
  253. console.log('上下:', data.data);
  254. },
  255. // #endif
  256. // #ifdef APP-PLUS
  257. // app 升级
  258. downloadApp() {
  259. this.closeUPop();
  260. let url;
  261. if (this.$common.source() === 2) {
  262. this.up_show = true;
  263. url = '';
  264. const downloadTask = uni.downloadFile({
  265. url: url,
  266. success: downloadResult => {
  267. if (downloadResult.statusCode === 200) {
  268. plus.runtime.install(
  269. downloadResult.tempFilePath,
  270. {
  271. force: false
  272. },
  273. function() {
  274. console.log('install success...');
  275. plus.runtime.restart();
  276. },
  277. function(e) {
  278. console.log(e);
  279. // console.error('install fail...');
  280. }
  281. );
  282. }
  283. }
  284. });
  285. downloadTask.onProgressUpdate(res => {
  286. this.up_percent = res.progress;
  287. });
  288. } else {
  289. plus.runtime.openURL(this.downloadUrl);
  290. }
  291. },
  292. // 获取app版本 升级
  293. async getVersion() {
  294. await this.$u.api
  295. .getVersion({
  296. oldVersion: this.oldVersion
  297. })
  298. .then(res => {
  299. uni.setStorageSync('isUpdate', res.data.isUpdate);
  300. if (res.data.isUpdate) {
  301. this.downloadUrl = res.data.downloadUrl;
  302. // App 升级机制,检测安卓
  303. if (this.$common.source() === 2) {
  304. this.upgradePop = true;
  305. } else {
  306. // IOS 审核通过后再打开升级提示
  307. if (this.iosAuditStatus === 5) {
  308. this.upgradePop = true;
  309. }
  310. }
  311. }
  312. });
  313. },
  314. closeUPop() {
  315. this.upgradePop = false;
  316. },
  317. // #endif
  318. resetGetLocation() {
  319. this.amapPlugin.getRegeo({
  320. success: data => {
  321. const proCity = ['北京市', '天津市', '上海市', '重庆市'];
  322. // console.log('获取定位:', data)
  323. const provinceName = data[0].regeocodeData.addressComponent.province;
  324. const cityName = proCity.includes(provinceName) ? provinceName : data[0].regeocodeData.addressComponent.city;
  325. const districtName = data[0].regeocodeData.addressComponent.district;
  326. const address = data[0].desc || data[0].name || data[0].regeocodeData.addressComponent.streetNumber.street || data[0].regeocodeData.addressComponent.township;
  327. const location = {
  328. provinceName: provinceName,
  329. cityName: cityName,
  330. districtName: districtName,
  331. address: address
  332. };
  333. if (location.districtName !== this.$store.state.locationObj.districtName) {
  334. uni.showModal({
  335. title: '提示',
  336. content: '检测到您位置已改变,是否切换到新的位置',
  337. success: res => {
  338. if (res.confirm) {
  339. this.$store.commit('commit_locationObj', {
  340. ...location,
  341. latitude: data[0].latitude,
  342. longitude: data[0].longitude
  343. });
  344. }
  345. }
  346. });
  347. }
  348. },
  349. fail: err => {
  350. console.log('获取位置失败::', err);
  351. }
  352. });
  353. },
  354. openLocation() {
  355. // #ifdef MP-WEIXIN
  356. uni.chooseLocation({
  357. success: res => {
  358. const location = this.$_utils.getArea(res.address);
  359. this.$store.commit('commit_locationObj', {
  360. ...location,
  361. address: location.address || res.name,
  362. latitude: res.latitude,
  363. longitude: res.longitude
  364. });
  365. }
  366. });
  367. // #endif
  368. // #ifdef APP-PLUS || MP-TOUTIAO
  369. uni.navigateTo({
  370. url: '/pages/index/SearchAddress'
  371. });
  372. // #endif
  373. },
  374. async getIndexData() {
  375. if (getToken()) {
  376. await this.getCustomerInfo();
  377. await this.getCartByUserCenterId();
  378. }
  379. },
  380. //首页
  381. async getTemplate() {
  382. console.log('请求模板');
  383. await this.$u.api
  384. .homePage({
  385. pageType: 1
  386. })
  387. .then(({ data }) => {
  388. console.log('模板返回',data);
  389. uni.stopPullDownRefresh();
  390. this.is_data = true;
  391. this.model = data.type;
  392. if (data.type === 2) {
  393. this.temData = data.data;
  394. console.log('版面信息',this.temData)
  395. this.topData = data.data[0].modelData;
  396. } else {
  397. const homeObj = {};
  398. for (let i in data.data) {
  399. const item = data.data[i];
  400. homeObj[item.moduleAlias] = item;
  401. }
  402. this.home_data = homeObj;
  403. this.cateOn = this.home_data.goodsCate.moduleData.cateData[0].categoryName;
  404. this.goodsData = this.home_data.goodsCate.moduleData.cateData[0].goodsData;
  405. }
  406. }).catch((e)=>{
  407. console.log(e,'末班错误');
  408. });
  409. },
  410. //获取购物车数据
  411. async getCartByUserCenterId() {
  412. await this.$u.api.getCartByUserCenterId().then(data => {
  413. this.$store.commit('commit_cartNum', data.data.goodsNum);
  414. this.$store.commit('commit_cartPrice', data.data.totalMoney);
  415. });
  416. },
  417. // 获取分类页面模版
  418. async getClassSettingInfo() {
  419. await this.$u.api.getClassSettingInfo().then(data => {
  420. this.$store.commit('commit_cateModel', data.data.value);
  421. });
  422. },
  423. // 获取商城基本设置
  424. async getBasicField() {
  425. // personnelReview,客户审核,
  426. // finishData: 4, 完善资料 4禁用 5启用
  427. // finishDataGo: false, 完善资料登录后立即去完善
  428. // shop,商城名称,
  429. // images,商城LOGO,
  430. // goodsPrice,商品价格是否允许游客查看,
  431. // stockDisplay,库存展示设置,4:不显示库存;5: 显示有/无货;6:显示库存数量
  432. // themeStyle,风格设置
  433. // startUpPage,启动页设置
  434. // startDeliveryPrice,起送价
  435. // freeExpressPrice 满多少元包邮
  436. // isSalesNum,是否显示销量,4:不显示,5:显示
  437. // cancelOrder,5开启:订单在出库前客户可以点击取消订单按钮;4禁用:只有待审核的订单客户才能操作取消订单按钮;
  438. // cancelOrderAudit,取消订单审核状态 5开启 4禁用
  439. await this.$u.api
  440. .getBasicField({
  441. field: [
  442. 'personnelReview',
  443. 'finishData',
  444. 'finishDataGo',
  445. 'shop',
  446. 'images',
  447. 'goodsPrice',
  448. 'stockDisplay',
  449. 'themeStyle',
  450. 'startUpPage',
  451. 'startDeliveryPrice',
  452. 'freeExpressPrice',
  453. 'isSalesNum',
  454. 'phone',
  455. 'cancelOrder',
  456. 'cancelOrderAudit'
  457. ]
  458. })
  459. .then(data => {
  460. this.show_goods_price = this.isLogin ? 5 : data.data.goodsPrice;
  461. this.startUpPage = data.data.startUpPage || {
  462. img: '',
  463. isEnable: false,
  464. time: 5
  465. };
  466. let themeStyle = '';
  467. if (data.data.themeStyle) {
  468. let theme = data.data.themeStyle.theme;
  469. if (!theme) {
  470. switch (data.data.themeStyle.label) {
  471. case '纯净绿':
  472. theme = 'green';
  473. break;
  474. case '热情红':
  475. theme = 'red';
  476. break;
  477. case '活力橙':
  478. theme = 'orange';
  479. break;
  480. case '格调金':
  481. theme = 'gold';
  482. break;
  483. case '雅致粉':
  484. theme = 'pink';
  485. break;
  486. case '商务蓝':
  487. theme = 'blue';
  488. break;
  489. }
  490. }
  491. themeStyle = {
  492. ...data.data.themeStyle,
  493. theme: theme
  494. };
  495. }
  496. this.$store.commit('commit_baseSet', {
  497. ...data.data,
  498. isSalesNum: data.data.isSalesNum || 5,
  499. preSale: data.data.preSale || 4,
  500. startDeliveryPrice: data.data.startDeliveryPrice || 0,
  501. themeStyle: themeStyle || {
  502. label: '热情红',
  503. theme: 'red',
  504. color_t: '#ff3883',
  505. color_o: '#fd463e'
  506. },
  507. startUpPage: data.data.startUpPage || {
  508. img: '',
  509. isEnable: false,
  510. time: 5
  511. }
  512. });
  513. });
  514. },
  515. //先获取个人资料 用来判断审核状态
  516. async getCustomerInfo() {
  517. await this.$u.api.getCustomerInfo().then(({ data }) => {
  518. this.$store.commit('commit_userStatus', data);
  519. if (this.baseSet.finishDataGo && data.status === 0) {
  520. this.tip_model = true;
  521. }
  522. });
  523. },
  524. async getEnterpriseInfo() {
  525. await this.$u.api.getEnterpriseInfo().then(({ data }) => {
  526. this.$store.commit('commit_iosAuditStatus', data.iosAuditStatus);
  527. this.$store.commit('commit_enterpriseInfo', data);
  528. if (new Date().getTime() >= data.expireTime * 1000) {
  529. uni.reLaunch({
  530. url: '/pages/index/FullScreen'
  531. });
  532. }
  533. });
  534. },
  535. // 完善资料提示取消
  536. tipCancel(){
  537. this.tip_model = false;
  538. },
  539. // 跳转完善资料页面
  540. finishCofirm(){
  541. this.goPage('/pagesT/user/editUserInfo');
  542. }
  543. },
  544. // 下拉刷新
  545. onPullDownRefresh() {
  546. this.getTemplate();
  547. this.getIndexData();
  548. this.getBasicField();
  549. this.getClassSettingInfo();
  550. },
  551. onPageScroll(obj) {
  552. this.scrollTop = obj.scrollTop;
  553. }
  554. };
  555. </script>
  556. <style lang="scss" scoped>
  557. .view-wrap {
  558. background-repeat: no-repeat;
  559. background-color: #f7f8fa;
  560. background-size: 750rpx;
  561. // background-position: 0 calc(var(--status-bar-height) + 44px);
  562. }
  563. .upgrade-view {
  564. background-color: #fff;
  565. text-align: center;
  566. width: 600upx;
  567. border-radius: 12upx;
  568. padding: 24upx;
  569. position: relative;
  570. .closePop {
  571. position: absolute;
  572. bottom: -100upx;
  573. width: 50upx;
  574. height: 50upx;
  575. color: #fff;
  576. left: 50%;
  577. transform: translateX(-25upx);
  578. .ibonguanbi {
  579. font-size: 48upx;
  580. }
  581. }
  582. .upgrade-img {
  583. width: 275upx;
  584. height: 275upx;
  585. margin: 30upx auto 0;
  586. display: block;
  587. }
  588. .upgrade-tit {
  589. font-size: 36upx;
  590. }
  591. .upgrade-num {
  592. color: #999;
  593. font-size: 24upx;
  594. padding: 20upx;
  595. }
  596. .upgrade-cont {
  597. font-size: 28upx;
  598. padding-bottom: 30upx;
  599. line-height: 36upx;
  600. }
  601. .upgrade-btn {
  602. width: 516upx;
  603. height: 86upx;
  604. font-size: 32upx;
  605. color: #fff;
  606. border-radius: 8upx;
  607. background-color: #007aff;
  608. line-height: 86upx;
  609. margin: 0 auto;
  610. }
  611. }
  612. </style>