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.

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