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.

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