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.

396 line
9.4 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.user.banneColor,
  26. levelBg: bgColor.colorFirst.user.levelBg,
  27. view: bgColor.colorFirst.user.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. },
  64. suerService() {
  65. console.log("打开客服")
  66. wx.openCustomerServiceChat({
  67. extInfo: { url: 'https://work.weixin.qq.com/kfid/kfc7f4a755cbb51fa99' },
  68. corpId: 'wwdc116b631d3ea35f',
  69. success(res) { },
  70. fail(res) {
  71. console.log(res);
  72. }
  73. })
  74. },
  75. checkUserStatus() {
  76. let that = this;
  77. Http.get({
  78. url: config.api.checkPhoneStatus,
  79. data: {}
  80. }).then(res => {
  81. wx.navigateTo({
  82. url: '/pages/edit/edit',
  83. })
  84. }).catch(err => {
  85. wx.navigateTo({
  86. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  87. })
  88. })
  89. },
  90. gotoPhoneInfo() {
  91. /**
  92. * 将值传到用户手机号授权的页面
  93. *
  94. */
  95. wx.navigateTo({
  96. url: `/pages/getphoneInfo/index?path=main`
  97. });
  98. },
  99. //是否授权手机号
  100. ifPhoneInfo() {
  101. let that = this;
  102. Http.get({
  103. url: config.api.checkPhoneStatus,
  104. data: {}
  105. }).then(res => {
  106. return
  107. }).catch(err => {
  108. wx.navigateTo({
  109. url: `/pages/getphoneInfo/index?mineFlag=mine`,
  110. })
  111. })
  112. },
  113. /* 判断是否授权*/
  114. userAuthorization() {
  115. Http.get({
  116. url: config.api.checkUserStatus,
  117. data: {
  118. token: app.globalData.token
  119. }
  120. }).then(res => {
  121. this.ifPhoneInfo()
  122. }).catch(err => {
  123. app.globalData.type = 'uc'
  124. wx.navigateTo({
  125. url: `/pages/getuserinfo/index`,
  126. })
  127. })
  128. },
  129. /**
  130. * 跳转到成长值的页面
  131. */
  132. gotograde: function() {
  133. wx.navigateTo({
  134. url: '/pages/czdetail/czdetail',
  135. })
  136. },
  137. /**
  138. * 跳转到商场信息的页面
  139. */
  140. gomallInfo: function() {
  141. wx.navigateTo({
  142. url: '/pages/mallInfo/mallInfo',
  143. })
  144. },
  145. showVersion: function() {
  146. /**
  147. * 长按显示版本号
  148. */
  149. let that = this;
  150. if (that.data.flag == 'hidden') {
  151. that.setData({
  152. flag: 'show'
  153. });
  154. }
  155. },
  156. gotoedit: function() {
  157. this.checkUserStatus();
  158. },
  159. onLoad() {
  160. this.getLocation();
  161. this.updateScene();
  162. // this.getRoomId();
  163. // this.getRoomList();
  164. console.log(wx.getExtConfigSync())
  165. },
  166. //获取房间列表
  167. getRoomList() {
  168. Http.get({
  169. url: config.api.getRoomList,
  170. data: {
  171. token: app.globalData.token,
  172. appId: config.weapp.AppId
  173. }
  174. }).then(res => {
  175. console.log(res)
  176. })
  177. },
  178. getRoomId() {
  179. let roomId = [3] // 填写具体的房间号,可通过下面【获取直播房间列表】 API 获取
  180. let customParams = encodeURIComponent(JSON.stringify({
  181. path: 'pages/index/index',
  182. pid: 1
  183. })) // 开发者在直播间页面路径上携带自定义参数(如示例中的path和pid参数),后续可以在分享卡片链接和跳转至商详页时获取,详见【获取自定义参数】、【直播间到商详页面携带参数】章节(上限600个字符,超过部分会被截断)
  184. console.log(customParams, 777777777)
  185. this.setData({
  186. roomId,
  187. customParams
  188. })
  189. },
  190. /**
  191. * 获得经纬度
  192. */
  193. getLocation() {
  194. let that = this;
  195. wx.getLocation({
  196. type: "wgs84",
  197. success: function(res) {
  198. console.log(res)
  199. if (res && res.longitude && res.latitude) {
  200. Http.post({
  201. url: config.api.updateLBS,
  202. data: {
  203. latitude: res.latitude,
  204. longitude: res.longitude
  205. }
  206. }).then(res => {
  207. console.log(res)
  208. })
  209. }
  210. },
  211. fail: error => {
  212. console.log(error);
  213. }
  214. })
  215. },
  216. /**
  217. * 用户更新scene
  218. */
  219. updateScene() {
  220. Http.post({
  221. url: config.api.updateScene,
  222. data: {
  223. scene: app.globalData.scene
  224. }
  225. }).then(res => {
  226. console.log(res)
  227. })
  228. },
  229. /**
  230. * 生命周期函数--监听页面显示
  231. */
  232. onShow: function() {
  233. if (businessSwitch){
  234. let openId = wx.getStorageSync("openId")
  235. this.setData({
  236. goUrl: `plugin://auto-points-plugin/index?openid=${openId}&mch_id=${this.data.mch_id}`
  237. })
  238. }
  239. console.log(this.data.goUrl)
  240. let that = this;
  241. that.userAuthorization()
  242. if (typeof that.getTabBar === 'function' &&
  243. that.getTabBar()) {
  244. if (ifStoreApp == 1) {
  245. that.getTabBar().setData({
  246. selected: 1
  247. })
  248. } else if (ifStoreApp == 2) {
  249. that.getTabBar().setData({
  250. selected: 2
  251. })
  252. } else {
  253. that.getTabBar().setData({
  254. selected: 3,
  255. })
  256. }
  257. }
  258. that.setData({
  259. appVersion: extConfig.appVersion,
  260. })
  261. /**
  262. * couponNum
  263. * couponNum2
  264. */
  265. let num = wx.getStorageSync('couponNum');
  266. let num1 = wx.getStorageSync('couponNum2');
  267. // wx.hideTabBarRedDot({
  268. // index: 3
  269. // });
  270. if (num == 'couponNum1') {
  271. wx.setStorage({
  272. key: 'couponNum',
  273. data: "couponNum1",
  274. })
  275. that.setData({
  276. couponNum: "couponNum1"
  277. })
  278. } else if (num == 'couponNum') {
  279. that.setData({
  280. couponNum: "couponNum"
  281. })
  282. };
  283. if (num1 == 'couponNum3') {
  284. wx.setStorage({
  285. key: 'couponNum2',
  286. data: "couponNum3",
  287. })
  288. that.setData({
  289. couponNum2: "couponNum3"
  290. })
  291. } else if (num1 == 'couponNum2') {
  292. that.setData({
  293. couponNum2: "couponNum2"
  294. });
  295. };
  296. Http.get({
  297. url: config.api.getScore,
  298. data: {}
  299. }).then(res => {
  300. if (res.data.address && res.data.name && res.data.sex && res.data.birthdate) {
  301. that.setData({
  302. showEdit: true
  303. })
  304. }
  305. let curPhone = res.data.phone ? res.data.phone : '';
  306. if (curPhone) {
  307. let curPhoneList = curPhone.split('');
  308. let curPhoneList01 = [];
  309. curPhoneList.forEach((item, index) => {
  310. if (index >= 3 && index <= 6) {
  311. item = '*';
  312. }
  313. curPhoneList01.push(item);
  314. })
  315. curPhone = curPhoneList01.join('');
  316. }
  317. that.setData({
  318. score: res.data.score,
  319. credit: res.data.credit,
  320. curPhone: curPhone,
  321. levelName: res.data.levelName,
  322. userId: res.data.userId
  323. })
  324. if (res.data.nickName) {
  325. that.setData({
  326. ismember: true,
  327. memberId: res.data.id
  328. })
  329. var size = this.setCanvasSize();
  330. var initUrl = JSON.stringify({
  331. flagid: res.data.id
  332. });
  333. }
  334. })
  335. .catch(err => {
  336. wx.showModal({
  337. title: '提示',
  338. content: err.errMsg,
  339. showCancel: false
  340. })
  341. })
  342. //暂时注释
  343. // that.getrun();
  344. //查询关于我们
  345. Http.get({
  346. url: config.api.getMallInfo,
  347. data: {}
  348. }).then(res => {
  349. if(res.code==200){
  350. this.setData({
  351. memberName:res.data.name,
  352. memberLogo:res.data.imgUrlH
  353. })
  354. }
  355. if (res.data.businessHours !== '[]') {
  356. that.setData({
  357. aboutShow: true
  358. })
  359. } else {
  360. that.setData({
  361. aboutShow: false
  362. })
  363. }
  364. })
  365. .catch(err => {})
  366. },
  367. //适配不同屏幕大小的canvas
  368. setCanvasSize: function() {
  369. var size = {};
  370. try {
  371. var res = wx.getSystemInfoSync();
  372. var scale = 750 / 500;
  373. //不同屏幕下canvas的适配比例;设计稿是750宽
  374. var width = res.windowWidth / scale;
  375. var height = width;
  376. //canvas画布为正方形
  377. size.w = width;
  378. size.h = height;
  379. } catch (e) {
  380. // Do something when catch error
  381. console.log("获取设备信息失败" + e);
  382. }
  383. return size;
  384. },
  385. });