index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. await this.getTemplate();
  192. await this.getEnterpriseInfo();
  193. // #ifdef MP
  194. // 获取小程序分销商参数
  195. if (options.businessmanId) {
  196. this.$store.commit('commit_businessmanId', options.businessmanId);
  197. this.relationshipBusinessman(options.businessmanId);
  198. } else if (options.scene) {
  199. // 扫码进入
  200. const scene = decodeURIComponent(options.scene);
  201. if (scene.indexOf('_') > -1) {
  202. const id = scene.slice(0, scene.length - 1);
  203. console.log('staffId', id);
  204. this.$store.commit('commit_staffId', id);
  205. } else {
  206. this.$store.commit('commit_businessmanId', scene);
  207. this.relationshipBusinessman(scene);
  208. }
  209. }
  210. // #endif
  211. this.show_goods_price = this.isLogin ? 5 : this.baseSet.goodsPrice;
  212. // 实时定位
  213. if (JSON.stringify(this.$store.state.locationObj) !== '{}') {
  214. await this.resetGetLocation();
  215. }
  216. // #ifdef APP-PLUS
  217. // 获取APP版本
  218. await this.getVersion();
  219. // #endif
  220. await this.getBasicField();
  221. await this.getIndexData();
  222. await this.getClassSettingInfo();
  223. // #ifdef MP-WEIXIN
  224. // 小程序的原生菜单中显示分享按钮
  225. uni.showShareMenu({
  226. withShareTicket: false,
  227. menus: ['shareAppMessage', 'shareTimeline']
  228. });
  229. // #endif
  230. },
  231. methods: {
  232. // #ifdef MP
  233. // 添加分销上下级关系 source: 1:首次点击链接 2:首次下单 3:首次付款'
  234. async relationshipBusinessman(businessmanId) {
  235. console.log('上级ID', businessmanId);
  236. if (!this.isLogin) {
  237. // 没有登录不请求接口
  238. return;
  239. }
  240. await this.$u.api.relationshipBusinessman({
  241. businessmanId: businessmanId,
  242. source: 1
  243. });
  244. console.log('上下:', data.data);
  245. },
  246. // #endif
  247. // #ifdef APP-PLUS
  248. // app 升级
  249. downloadApp() {
  250. this.closeUPop();
  251. let url;
  252. if (this.$common.source() === 2) {
  253. this.up_show = true;
  254. url = '';
  255. const downloadTask = uni.downloadFile({
  256. url: url,
  257. success: downloadResult => {
  258. if (downloadResult.statusCode === 200) {
  259. plus.runtime.install(
  260. downloadResult.tempFilePath,
  261. {
  262. force: false
  263. },
  264. function() {
  265. console.log('install success...');
  266. plus.runtime.restart();
  267. },
  268. function(e) {
  269. console.log(e);
  270. // console.error('install fail...');
  271. }
  272. );
  273. }
  274. }
  275. });
  276. downloadTask.onProgressUpdate(res => {
  277. this.up_percent = res.progress;
  278. });
  279. } else {
  280. plus.runtime.openURL(this.downloadUrl);
  281. }
  282. },
  283. // 获取app版本 升级
  284. async getVersion() {
  285. await this.$u.api
  286. .getVersion({
  287. oldVersion: this.oldVersion
  288. })
  289. .then(res => {
  290. uni.setStorageSync('isUpdate', res.data.isUpdate);
  291. if (res.data.isUpdate) {
  292. this.downloadUrl = res.data.downloadUrl;
  293. // App 升级机制,检测安卓
  294. if (this.$common.source() === 2) {
  295. this.upgradePop = true;
  296. } else {
  297. // IOS 审核通过后再打开升级提示
  298. if (this.iosAuditStatus === 5) {
  299. this.upgradePop = true;
  300. }
  301. }
  302. }
  303. });
  304. },
  305. closeUPop() {
  306. this.upgradePop = false;
  307. },
  308. // #endif
  309. resetGetLocation() {
  310. this.amapPlugin.getRegeo({
  311. success: data => {
  312. const proCity = ['北京市', '天津市', '上海市', '重庆市'];
  313. // console.log('获取定位:', data)
  314. const provinceName = data[0].regeocodeData.addressComponent.province;
  315. const cityName = proCity.includes(provinceName) ? provinceName : data[0].regeocodeData.addressComponent.city;
  316. const districtName = data[0].regeocodeData.addressComponent.district;
  317. const address = data[0].desc || data[0].name || data[0].regeocodeData.addressComponent.streetNumber.street || data[0].regeocodeData.addressComponent.township;
  318. const location = {
  319. provinceName: provinceName,
  320. cityName: cityName,
  321. districtName: districtName,
  322. address: address
  323. };
  324. if (location.districtName !== this.$store.state.locationObj.districtName) {
  325. uni.showModal({
  326. title: '提示',
  327. content: '检测到您位置已改变,是否切换到新的位置',
  328. success: res => {
  329. if (res.confirm) {
  330. this.$store.commit('commit_locationObj', {
  331. ...location,
  332. latitude: data[0].latitude,
  333. longitude: data[0].longitude
  334. });
  335. }
  336. }
  337. });
  338. }
  339. },
  340. fail: err => {
  341. console.log('获取位置失败::', err);
  342. }
  343. });
  344. },
  345. openLocation() {
  346. // #ifdef MP-WEIXIN
  347. uni.chooseLocation({
  348. success: res => {
  349. const location = this.$_utils.getArea(res.address);
  350. this.$store.commit('commit_locationObj', {
  351. ...location,
  352. address: location.address || res.name,
  353. latitude: res.latitude,
  354. longitude: res.longitude
  355. });
  356. }
  357. });
  358. // #endif
  359. // #ifdef APP-PLUS || MP-TOUTIAO
  360. uni.navigateTo({
  361. url: '/pages/index/SearchAddress'
  362. });
  363. // #endif
  364. },
  365. async getIndexData() {
  366. if (getToken()) {
  367. await this.getCustomerInfo();
  368. await this.getCartByUserCenterId();
  369. }
  370. },
  371. //首页
  372. async getTemplate() {
  373. await this.$u.api
  374. .homePage({
  375. pageType: 1
  376. })
  377. .then(({ data }) => {
  378. uni.stopPullDownRefresh();
  379. this.is_data = true;
  380. this.model = data.type;
  381. if (data.type === 2) {
  382. this.temData = data.data;
  383. this.topData = data.data[0].modelData;
  384. } else {
  385. const homeObj = {};
  386. for (let i in data.data) {
  387. const item = data.data[i];
  388. homeObj[item.moduleAlias] = item;
  389. }
  390. this.home_data = homeObj;
  391. this.cateOn = this.home_data.goodsCate.moduleData.cateData[0].categoryName;
  392. this.goodsData = this.home_data.goodsCate.moduleData.cateData[0].goodsData;
  393. }
  394. });
  395. },
  396. //获取购物车数据
  397. async getCartByUserCenterId() {
  398. await this.$u.api.getCartByUserCenterId().then(data => {
  399. this.$store.commit('commit_cartNum', data.data.goodsNum);
  400. this.$store.commit('commit_cartPrice', data.data.totalMoney);
  401. });
  402. },
  403. // 获取分类页面模版
  404. async getClassSettingInfo() {
  405. await this.$u.api.getClassSettingInfo().then(data => {
  406. this.$store.commit('commit_cateModel', data.data.value);
  407. });
  408. },
  409. // 获取商城基本设置
  410. async getBasicField() {
  411. // personnelReview,客户审核,
  412. // finishData: 4, 完善资料 4禁用 5启用
  413. // finishDataGo: false, 完善资料登录后立即去完善
  414. // shop,商城名称,
  415. // images,商城LOGO,
  416. // goodsPrice,商品价格是否允许游客查看,
  417. // stockDisplay,库存展示设置,4:不显示库存;5: 显示有/无货;6:显示库存数量
  418. // themeStyle,风格设置
  419. // startUpPage,启动页设置
  420. // startDeliveryPrice,起送价
  421. // freeExpressPrice 满多少元包邮
  422. // isSalesNum,是否显示销量,4:不显示,5:显示
  423. // cancelOrder,5开启:订单在出库前客户可以点击取消订单按钮;4禁用:只有待审核的订单客户才能操作取消订单按钮;
  424. // cancelOrderAudit,取消订单审核状态 5开启 4禁用
  425. await this.$u.api
  426. .getBasicField({
  427. field: [
  428. 'personnelReview',
  429. 'finishData',
  430. 'finishDataGo',
  431. 'shop',
  432. 'images',
  433. 'goodsPrice',
  434. 'stockDisplay',
  435. 'themeStyle',
  436. 'startUpPage',
  437. 'startDeliveryPrice',
  438. 'freeExpressPrice',
  439. 'isSalesNum',
  440. 'phone',
  441. 'cancelOrder',
  442. 'cancelOrderAudit'
  443. ]
  444. })
  445. .then(data => {
  446. this.show_goods_price = this.isLogin ? 5 : data.data.goodsPrice;
  447. this.startUpPage = data.data.startUpPage || {
  448. img: '',
  449. isEnable: false,
  450. time: 5
  451. };
  452. let themeStyle = '';
  453. if (data.data.themeStyle) {
  454. let theme = data.data.themeStyle.theme;
  455. if (!theme) {
  456. switch (data.data.themeStyle.label) {
  457. case '纯净绿':
  458. theme = 'green';
  459. break;
  460. case '热情红':
  461. theme = 'red';
  462. break;
  463. case '活力橙':
  464. theme = 'orange';
  465. break;
  466. case '格调金':
  467. theme = 'gold';
  468. break;
  469. case '雅致粉':
  470. theme = 'pink';
  471. break;
  472. case '商务蓝':
  473. theme = 'blue';
  474. break;
  475. }
  476. }
  477. themeStyle = {
  478. ...data.data.themeStyle,
  479. theme: theme
  480. };
  481. }
  482. this.$store.commit('commit_baseSet', {
  483. ...data.data,
  484. isSalesNum: data.data.isSalesNum || 5,
  485. preSale: data.data.preSale || 4,
  486. startDeliveryPrice: data.data.startDeliveryPrice || 0,
  487. themeStyle: themeStyle || {
  488. label: '热情红',
  489. theme: 'red',
  490. color_t: '#ff3883',
  491. color_o: '#fd463e'
  492. },
  493. startUpPage: data.data.startUpPage || {
  494. img: '',
  495. isEnable: false,
  496. time: 5
  497. }
  498. });
  499. });
  500. },
  501. //先获取个人资料 用来判断审核状态
  502. async getCustomerInfo() {
  503. await this.$u.api.getCustomerInfo().then(({ data }) => {
  504. this.$store.commit('commit_userStatus', data);
  505. if (this.baseSet.finishDataGo && data.status === 0) {
  506. this.tip_model = true;
  507. }
  508. });
  509. },
  510. async getEnterpriseInfo() {
  511. await this.$u.api.getEnterpriseInfo().then(({ data }) => {
  512. this.$store.commit('commit_iosAuditStatus', data.iosAuditStatus);
  513. this.$store.commit('commit_enterpriseInfo', data);
  514. if (new Date().getTime() >= data.expireTime * 1000) {
  515. uni.reLaunch({
  516. url: '/pages/index/FullScreen'
  517. });
  518. }
  519. });
  520. },
  521. // 完善资料提示取消
  522. tipCancel(){
  523. this.tip_model = false;
  524. },
  525. // 跳转完善资料页面
  526. finishCofirm(){
  527. this.goPage('/pagesT/user/editUserInfo');
  528. }
  529. },
  530. // 下拉刷新
  531. onPullDownRefresh() {
  532. this.getTemplate();
  533. this.getIndexData();
  534. this.getBasicField();
  535. this.getClassSettingInfo();
  536. },
  537. onPageScroll(obj) {
  538. this.scrollTop = obj.scrollTop;
  539. }
  540. };
  541. </script>
  542. <style lang="scss" scoped>
  543. .view-wrap {
  544. background-repeat: no-repeat;
  545. background-color: #f7f8fa;
  546. background-size: 750rpx;
  547. // background-position: 0 calc(var(--status-bar-height) + 44px);
  548. }
  549. .upgrade-view {
  550. background-color: #fff;
  551. text-align: center;
  552. width: 600upx;
  553. border-radius: 12upx;
  554. padding: 24upx;
  555. position: relative;
  556. .closePop {
  557. position: absolute;
  558. bottom: -100upx;
  559. width: 50upx;
  560. height: 50upx;
  561. color: #fff;
  562. left: 50%;
  563. transform: translateX(-25upx);
  564. .ibonguanbi {
  565. font-size: 48upx;
  566. }
  567. }
  568. .upgrade-img {
  569. width: 275upx;
  570. height: 275upx;
  571. margin: 30upx auto 0;
  572. display: block;
  573. }
  574. .upgrade-tit {
  575. font-size: 36upx;
  576. }
  577. .upgrade-num {
  578. color: #999;
  579. font-size: 24upx;
  580. padding: 20upx;
  581. }
  582. .upgrade-cont {
  583. font-size: 28upx;
  584. padding-bottom: 30upx;
  585. line-height: 36upx;
  586. }
  587. .upgrade-btn {
  588. width: 516upx;
  589. height: 86upx;
  590. font-size: 32upx;
  591. color: #fff;
  592. border-radius: 8upx;
  593. background-color: #007aff;
  594. line-height: 86upx;
  595. margin: 0 auto;
  596. }
  597. }
  598. </style>