C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

641 line
15 KiB

  1. var app = getApp();
  2. const navigationBarHeight = (getApp().statusBarHeight + 44) + 'px'
  3. const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
  4. let businessSwitch = extConfig.attr.businessSwitch
  5. let mch_id = extConfig.attr.mchId
  6. let ifStoreApp = extConfig.attr.ifStoreApp;
  7. const Http = require("../utils/HttpBasics");
  8. const imgurl = require("../utils/imgurl");
  9. var config = require("../config/config.js");
  10. const bgColor = require("../utils/bgColor.js")
  11. Page({
  12. /**
  13. * 页面的初始数据
  14. */
  15. data: {
  16. mch_id: mch_id,
  17. businessSwitch: businessSwitch,
  18. goUrl: "",
  19. templateId: [],
  20. aboutShow: false,
  21. navigationBarHeight,
  22. ifStoreApp: ifStoreApp,
  23. aboutUs: imgurl.aboutUs.url,
  24. rqCode: imgurl.barcode.url,
  25. banneColor: bgColor.colorFirst.user2.banneColor,
  26. levelBg: bgColor.colorFirst.user.levelBg,
  27. view: bgColor.colorFirst.user2.view,
  28. fenxiang: imgurl.fenxiang1.url,
  29. redirectUrl: imgurl.redirect.url,
  30. editUrl: imgurl.edit.url,
  31. activeUrl: imgurl.active.url,
  32. dingUrl: imgurl.ding.url,
  33. duihuan: imgurl.duihuan.url,
  34. shoppingAtlas: imgurl.shoppingAtlas.url,
  35. quansUrl: imgurl.quans.url,
  36. wmintegral: imgurl.wmintegral.url,
  37. cardiconUrl: imgurl.cardicon.url,
  38. myactivitygift: imgurl.myactivitygift.url,
  39. myactivity: imgurl.myactivity.url,
  40. cheUrl: imgurl.che.url,
  41. giftUrl: imgurl.gift.url,
  42. wmbarginicon: imgurl.wmbarginicon.url,
  43. wmspellgroup: imgurl.wmspellgroup.url,
  44. canIUse: wx.canIUse('official-account'),
  45. mineFlag: "",
  46. flag: 'hidden',
  47. score: '0',
  48. credit: '0',
  49. userId: "",
  50. memberName: "",
  51. memberLogo: "",
  52. curPhone: '',
  53. name: "",
  54. birthdate: "",
  55. sex: "",
  56. showEdit: false,
  57. ismember: false,
  58. canvasHidden: false,
  59. maskHidden: true,
  60. imagePath: '',
  61. appVersion: "",
  62. placeholder: '',
  63. userAvatarUrl: "",
  64. userName: "",
  65. ifSetUserInfo: false
  66. },
  67. suerService() {
  68. console.log("打开客服")
  69. wx.openCustomerServiceChat({
  70. extInfo: { url: 'https://work.weixin.qq.com/kfid/kfc7f4a755cbb51fa99' },
  71. corpId: 'wwdc116b631d3ea35f',
  72. success(res) { },
  73. fail(res) {
  74. console.log(res);
  75. }
  76. })
  77. },
  78. checkUserStatus() {
  79. let that = this;
  80. Http.get({
  81. url: config.api.checkPhoneStatus,
  82. data: {}
  83. }).then(res => {
  84. wx.navigateTo({
  85. url: '/pages/edit/edit',
  86. })
  87. }).catch(err => {
  88. wx.navigateTo({
  89. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  90. })
  91. })
  92. },
  93. gotoPhoneInfo() {
  94. /**
  95. * 将值传到用户手机号授权的页面
  96. *
  97. */
  98. wx.navigateTo({
  99. url: `/pages/getphoneInfo/index?path=main`
  100. });
  101. },
  102. //是否授权手机号
  103. ifPhoneInfo() {
  104. Http.get({
  105. url: config.api.checkPhoneStatus,
  106. data: {}
  107. }).then(res => {
  108. console.log(res, 'res');
  109. that.setData({
  110. ifSetUserInfo: true
  111. })
  112. // 手机号未授权
  113. const ifSetUserInfo = wx.getStorageSync('ifSetUserInfo')
  114. if (ifSetUserInfo == 1) {
  115. if (!that.data.ifSetUserInfo) return
  116. wx.showModal({
  117. title: '完善个人信息',
  118. content: '请继续完成个人信息哦',
  119. showCancel: true,
  120. cancelText: "以后再说",
  121. cancelColor: '',
  122. confirmText: "去完善",
  123. confirmColor: '#FD832D',
  124. complete: (res) => {
  125. if (res.cancel) {
  126. console.log('cancel');
  127. }
  128. if (res.confirm) {
  129. wx.navigateTo({
  130. url: '/pages3/setUserInfo/index',
  131. })
  132. }
  133. // 已完成手机号授权
  134. wx.setStorageSync('ifSetUserInfo', 2)
  135. }
  136. })
  137. }
  138. return
  139. }).catch(err => {
  140. console.log(err, 'err');
  141. that.setData({
  142. ifSetUserInfo: false
  143. })
  144. const ifSetUserInfo = wx.getStorageSync('ifSetUserInfo')
  145. if (ifSetUserInfo != 2) {
  146. wx.setStorageSync('ifSetUserInfo', 1) //手机号未授权
  147. }
  148. // wx.navigateTo({
  149. // url: `/pages/getphoneInfo/index?mineFlag=mine`,
  150. // })
  151. })
  152. },
  153. /* 判断是否授权*/
  154. userAuthorization() {
  155. Http.get({
  156. url: config.api.checkUserStatus,
  157. data: {
  158. token: app.globalData.token
  159. }
  160. }).then(res => {
  161. this.ifPhoneInfo()
  162. }).catch(err => {
  163. app.globalData.type = 'uc'
  164. wx.navigateTo({
  165. url: `/pages/getuserinfo/index`,
  166. })
  167. })
  168. },
  169. /**
  170. * 跳转到成长值的页面
  171. */
  172. gotograde: function () {
  173. if (this.data.ifSetUserInfo) {
  174. wx.navigateTo({
  175. url: '/pages/czdetail/czdetail',
  176. })
  177. } else {
  178. wx.navigateTo({
  179. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  180. })
  181. }
  182. },
  183. gotointegralmall: function () {
  184. if (this.data.ifSetUserInfo) {
  185. wx.navigateTo({
  186. url: '/pages/integralmall/integraHistory/index',
  187. })
  188. } else {
  189. wx.navigateTo({
  190. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  191. })
  192. }
  193. },
  194. goToOrder() {
  195. if (this.data.ifSetUserInfo) {
  196. wx.navigateTo({
  197. url: '/pages/order/index/index?id=all',
  198. })
  199. } else {
  200. wx.navigateTo({
  201. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  202. })
  203. }
  204. },
  205. goToCouponorder() {
  206. if (this.data.ifSetUserInfo) {
  207. wx.navigateTo({
  208. url: '/pages/couponorder/index/index',
  209. })
  210. } else {
  211. wx.navigateTo({
  212. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  213. })
  214. }
  215. },
  216. goToCardorder() {
  217. if (this.data.ifSetUserInfo) {
  218. wx.navigateTo({
  219. url: '/pages/cardorder/index/index',
  220. })
  221. } else {
  222. wx.navigateTo({
  223. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  224. })
  225. }
  226. },
  227. goToIntegralmall() {
  228. if (this.data.ifSetUserInfo) {
  229. wx.navigateTo({
  230. url: '/pages/integralmall/index',
  231. })
  232. } else {
  233. wx.navigateTo({
  234. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  235. })
  236. }
  237. },
  238. goToBargain() {
  239. if (this.data.ifSetUserInfo) {
  240. wx.navigateTo({
  241. url: '/pages/bargain/bargain?from=myhtml',
  242. })
  243. } else {
  244. wx.navigateTo({
  245. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  246. })
  247. }
  248. },
  249. goToSpellGroup() {
  250. if (this.data.ifSetUserInfo) {
  251. wx.navigateTo({
  252. url: '/pages/spellGroup/spellGroup?from=myhtml',
  253. })
  254. } else {
  255. wx.navigateTo({
  256. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  257. })
  258. }
  259. },
  260. goToMyactivity() {
  261. if (this.data.ifSetUserInfo) {
  262. wx.navigateTo({
  263. url: '/pages/user/myactivity/index',
  264. })
  265. } else {
  266. wx.navigateTo({
  267. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  268. })
  269. }
  270. },
  271. goToSetUserInfo() {
  272. if (this.data.ifSetUserInfo) {
  273. wx.navigateTo({
  274. url: '/pages3/setUserInfo/index',
  275. })
  276. } else {
  277. wx.navigateTo({
  278. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  279. })
  280. }
  281. },
  282. goToSpecialcourtesy() {
  283. if (this.data.ifSetUserInfo) {
  284. wx.navigateTo({
  285. url: '/pages/specialcourtesy/specialcourtesy',
  286. })
  287. } else {
  288. wx.navigateTo({
  289. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  290. })
  291. }
  292. },
  293. goToExchangeCard() {
  294. if (this.data.ifSetUserInfo) {
  295. wx.navigateTo({
  296. url: '/pages/exchangeCard/exchangeCard',
  297. })
  298. } else {
  299. wx.navigateTo({
  300. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  301. })
  302. }
  303. },
  304. goToQuestionnaire() {
  305. if (this.data.ifSetUserInfo) {
  306. wx.navigateTo({
  307. url: '/pages/questionnaire/questionnaireLsit/questionnaireLsit',
  308. })
  309. } else {
  310. wx.navigateTo({
  311. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  312. })
  313. }
  314. },
  315. goToComplaint() {
  316. if (this.data.ifSetUserInfo) {
  317. wx.navigateTo({
  318. url: '/pages/complaint/complaint',
  319. })
  320. } else {
  321. wx.navigateTo({
  322. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  323. })
  324. }
  325. },
  326. goToQuestionnaire() {
  327. if (this.data.ifSetUserInfo) {
  328. wx.navigateTo({
  329. url: '/pages/questionnaire/questionnaireLsit/questionnaireLsit',
  330. })
  331. } else {
  332. wx.navigateTo({
  333. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  334. })
  335. }
  336. },
  337. goToBusinessSwitch() {
  338. if (this.data.ifSetUserInfo) {
  339. wx.navigateTo({
  340. url: this.data.goUrl,
  341. })
  342. } else {
  343. wx.navigateTo({
  344. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  345. })
  346. }
  347. },
  348. share() {
  349. if (this.data.ifSetUserInfo) {
  350. wx.navigateTo({
  351. url: '/pages/shareFriend/shareFriend',
  352. })
  353. } else {
  354. wx.navigateTo({
  355. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  356. })
  357. }
  358. },
  359. /**
  360. * 跳转到商场信息的页面
  361. */
  362. gomallInfo: function () {
  363. wx.navigateTo({
  364. url: '/pages/mallInfo/mallInfo',
  365. })
  366. },
  367. showVersion: function () {
  368. /**
  369. * 长按显示版本号
  370. */
  371. let that = this;
  372. if (that.data.flag == 'hidden') {
  373. that.setData({
  374. flag: 'show'
  375. });
  376. }
  377. },
  378. gotoedit: function () {
  379. // this.checkUserStatus();
  380. console.log('goSetAvatar');
  381. wx.navigateTo({
  382. url: '/pages3/setUserInfo/index'
  383. })
  384. },
  385. onLoad(options) {
  386. // this.getLocation();
  387. this.updateScene();
  388. // this.getRoomId();
  389. // this.getRoomList();
  390. console.log(wx.getExtConfigSync())
  391. },
  392. //获取房间列表
  393. getRoomList() {
  394. Http.get({
  395. url: config.api.getRoomList,
  396. data: {
  397. token: app.globalData.token,
  398. appId: config.weapp.AppId
  399. }
  400. }).then(res => {
  401. console.log(res)
  402. })
  403. },
  404. getRoomId() {
  405. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  406. let customParams = encodeURIComponent(JSON.stringify({
  407. path: 'pages/index/index',
  408. pid: 1
  409. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  410. console.log(customParams, 777777777)
  411. this.setData({
  412. roomId,
  413. customParams
  414. })
  415. },
  416. /**
  417. * 获得经纬度
  418. */
  419. // getLocation() {
  420. // let that = this;
  421. // wx.getLocation({
  422. // type: "wgs84",
  423. // success: function(res) {
  424. // console.log(res)
  425. // if (res && res.longitude && res.latitude) {
  426. // Http.post({
  427. // url: config.api.updateLBS,
  428. // data: {
  429. // latitude: res.latitude,
  430. // longitude: res.longitude
  431. // }
  432. // }).then(res => {
  433. // console.log(res)
  434. // })
  435. // }
  436. // },
  437. // fail: error => {
  438. // console.log(error);
  439. // }
  440. // })
  441. // },
  442. /**
  443. * 用户更新scene
  444. */
  445. updateScene() {
  446. Http.post({
  447. url: config.api.updateScene,
  448. data: {
  449. scene: app.globalData.scene
  450. }
  451. }).then(res => {
  452. console.log(res)
  453. })
  454. },
  455. /**
  456. * 生命周期函数--监听页面显示
  457. */
  458. onShow: function () {
  459. this.ifPhoneInfo()
  460. if (businessSwitch) {
  461. let openId = wx.getStorageSync("openId")
  462. this.setData({
  463. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  464. })
  465. }
  466. console.log(this.data.goUrl)
  467. let that = this;
  468. that.userAuthorization()
  469. if (typeof that.getTabBar === 'function' &&
  470. that.getTabBar()) {
  471. if (ifStoreApp == 1) {
  472. that.getTabBar().setData({
  473. selected: 1
  474. })
  475. } else if (ifStoreApp == 2) {
  476. that.getTabBar().setData({
  477. selected: 2
  478. })
  479. } else {
  480. that.getTabBar().setData({
  481. selected: 3,
  482. })
  483. }
  484. }
  485. that.setData({
  486. appVersion: extConfig.appVersion,
  487. })
  488. /**
  489. * couponNum
  490. * couponNum2
  491. */
  492. let num = wx.getStorageSync('couponNum');
  493. let num1 = wx.getStorageSync('couponNum2');
  494. // wx.hideTabBarRedDot({
  495. // index: 3
  496. // });
  497. if (num == 'couponNum1') {
  498. wx.setStorage({
  499. key: 'couponNum',
  500. data: "couponNum1",
  501. })
  502. that.setData({
  503. couponNum: "couponNum1"
  504. })
  505. } else if (num == 'couponNum') {
  506. that.setData({
  507. couponNum: "couponNum"
  508. })
  509. };
  510. if (num1 == 'couponNum3') {
  511. wx.setStorage({
  512. key: 'couponNum2',
  513. data: "couponNum3",
  514. })
  515. that.setData({
  516. couponNum2: "couponNum3"
  517. })
  518. } else if (num1 == 'couponNum2') {
  519. that.setData({
  520. couponNum2: "couponNum2"
  521. });
  522. };
  523. Http.get({
  524. url: config.api.getScore,
  525. data: {}
  526. }).then(res => {
  527. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  528. that.setData({
  529. showEdit: true
  530. })
  531. }
  532. let curPhone = res.data.phone ? res.data.phone : '';
  533. if (curPhone) {
  534. let curPhoneList = curPhone.split('');
  535. let curPhoneList01 = [];
  536. curPhoneList.forEach((item, index) => {
  537. if (index >= 3 && index <= 6) {
  538. item = '*';
  539. }
  540. curPhoneList01.push(item);
  541. })
  542. curPhone = curPhoneList01.join('');
  543. }
  544. that.setData({
  545. score: res.data.score,
  546. credit: res.data.credit,
  547. curPhone: curPhone,
  548. levelName: res.data.levelName,
  549. userId: res.data.userId,
  550. userAvatarUrl: res.data.avatarUrl,
  551. userName: res.data.nickName
  552. })
  553. if (res.data.nickName) {
  554. that.setData({
  555. ismember: true,
  556. memberId: res.data.id
  557. })
  558. var size = this.setCanvasSize();
  559. var initUrl = JSON.stringify({
  560. flagid: res.data.id
  561. });
  562. }
  563. })
  564. .catch(err => {
  565. wx.showModal({
  566. title: '提示',
  567. content: err.errMsg,
  568. showCancel: false
  569. })
  570. })
  571. //暂时注释
  572. // that.getrun();
  573. //查询关于我们
  574. Http.get({
  575. url: config.api.getMallInfo,
  576. data: {}
  577. }).then(res => {
  578. if (res.code == 200) {
  579. this.setData({
  580. memberName: res.data.name,
  581. memberLogo: res.data.imgUrlH
  582. })
  583. }
  584. if (res.data.businessHours !== '[]') {
  585. that.setData({
  586. aboutShow: true
  587. })
  588. } else {
  589. that.setData({
  590. aboutShow: false
  591. })
  592. }
  593. })
  594. .catch(err => { })
  595. },
  596. //适配不同屏幕大小的canvas
  597. setCanvasSize: function () {
  598. var size = {};
  599. try {
  600. var res = wx.getSystemInfoSync();
  601. var scale = 750 / 500;
  602. //不同屏幕下canvas的适配比例;设计稿是750宽
  603. var width = res.windowWidth / scale;
  604. var height = width;
  605. //canvas画布为正方形
  606. size.w = width;
  607. size.h = height;
  608. } catch (e) {
  609. // Do something when catch error
  610. console.log("获取设备信息失败" + e);
  611. }
  612. return size;
  613. }
  614. });