index.vue 16 KB

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