index.js 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. // index.js
  2. // 获取应用实例
  3. const app = getApp()
  4. const link = app.globalData.url
  5. Page({
  6. data: {
  7. grids1: [{
  8. image: 'order',
  9. text: '我的订单'
  10. }, {
  11. image: 'user',
  12. text: '好友列表'
  13. }, {
  14. image: 'help',
  15. text: '帮助中心'
  16. }, {
  17. image: 'add',
  18. text: '邀请好友'
  19. }, {
  20. image: 'to-top',
  21. text: '手动同步订单'
  22. }, {
  23. image: 'customer-service',
  24. text: '联系客服'
  25. }, {
  26. image: 'setting',
  27. text: '设置'
  28. },
  29. {
  30. image: 'success',
  31. text: '提现'
  32. },
  33. //{
  34. // image: 'eye',
  35. // text: '我的足迹'
  36. // }, {
  37. // image: 'scan',
  38. // text: '扫一扫'
  39. // },
  40. ],
  41. grids2: [{
  42. image: 'order',
  43. text: '我的订单'
  44. }, {
  45. image: 'user',
  46. text: '好友列表'
  47. }, {
  48. image: 'help',
  49. text: '帮助中心'
  50. }, {
  51. image: 'add',
  52. text: '邀请好友'
  53. }, {
  54. image: 'to-top',
  55. text: '手动同步订单'
  56. }, {
  57. image: 'customer-service',
  58. text: '联系客服'
  59. }, {
  60. image: 'setting',
  61. text: '设置'
  62. },
  63. {
  64. image: 'success',
  65. text: '提现'
  66. },
  67. {
  68. image: 'phone',
  69. text: '管理员'
  70. },
  71. //{
  72. // image: 'scan',
  73. // text: '扫一扫'
  74. // },
  75. ],
  76. // grids2: [{
  77. // image: 'cart',
  78. // text: '我的购物车'
  79. // }, {
  80. // image: 'help',
  81. // text: '帮助中心'
  82. // }, {
  83. // image: 'address',
  84. // text: '地址管理'
  85. // }, {
  86. // image: 'order',
  87. // text: '我的订单'
  88. // }, {
  89. // image: 'customer-service',
  90. // text: '联系客服'
  91. // }, ],
  92. motto: 'Hello World',
  93. userInfo: {},
  94. hasUserInfo: false,
  95. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  96. canIUseGetUserProfile: false,
  97. canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
  98. },
  99. // 事件处理函数
  100. bindViewTap() {
  101. wx.navigateTo({
  102. url: '../logs/logs'
  103. })
  104. },
  105. onLoad() {
  106. // var that = this
  107. // var opneId = wx.getStorageSync('openId')
  108. // var nickName = wx.getStorageSync('nickName')
  109. // //var admin = wx.getStorageSync('admin')
  110. // if (wx.getUserProfile) {
  111. // this.setData({
  112. // canIUseGetUserProfile: true
  113. // })
  114. // }
  115. // //获取金额
  116. // wx.request( {
  117. // url: link + "/v1/forward/lhf",
  118. // header: {
  119. // "Content-Type": "application/json",
  120. // "function":"/v1/user/wallet/get"
  121. // },
  122. // method: "POST",
  123. // data: { openId: opneId },
  124. // success (res) {
  125. // console.log(res)
  126. // that.setData({
  127. // wallet: res.data.data.wallet
  128. // })
  129. // }
  130. // })
  131. // console.log(nickName)
  132. // // if (nickName == '' ){
  133. // wx.request( {
  134. // url: link + "/v1/forward/lhf",
  135. // header: {
  136. // "Content-Type": "application/json",
  137. // "function":"/v1/user/open.id/get"
  138. // },
  139. // method: "POST",
  140. // data: { openId: opneId },
  141. // success (res) {
  142. // console.log(res)
  143. // var admin = false
  144. // wx.setStorageSync('nickName', res.data.data.user.nickName)
  145. // wx.setStorageSync('userId', res.data.data.user.id)
  146. // if (res.data.data.user.admin == 1){
  147. // admin = true
  148. // }
  149. // that.setData({
  150. // userId: res.data.data.user.id,
  151. // admin:admin
  152. // })
  153. // }
  154. // })
  155. // // } else{
  156. // // var userId = wx.getStorageSync('userId')
  157. // // console.log(userId)
  158. // // that.setData({
  159. // // userId: userId
  160. // // })
  161. // // }
  162. },
  163. clickGrid(e) {
  164. var that = this
  165. console.log(e)
  166. if (e.detail.cell.text == "我的订单"){
  167. wx.navigateTo({
  168. url:"/pages/order/order"
  169. })
  170. } else if (e.detail.cell.text == "联系客服"){
  171. wx.showModal({
  172. title: '客服微信',
  173. content: '客服微信:tao1024_com,点击复制按钮,直接复制客服微信号,粘贴到微信中搜索添加客服.',
  174. showCancel: true,//是否显示取消按钮
  175. cancelText:"取消",//默认是“取消”
  176. //cancelColor:'skyblue',//取消文字的颜色
  177. confirmText:"复制",//默认是“确定”
  178. //confirmColor: 'skyblue',//确定文字的颜色
  179. success: function (res) {
  180. if (res.cancel) {
  181. //点击取消,默认隐藏弹框
  182. } else {
  183. wx.setClipboardData({
  184. data: 'tao1024_com',
  185. success (res) {
  186. //点击确定
  187. wx.showToast({
  188. title: '复制成功',//提示文字
  189. duration:2000,//显示时长
  190. mask:true,//是否显示透明蒙层,防止触摸穿透,默认:false
  191. icon:'success', //图标,支持"success"、"loading"
  192. success:function(){ },//接口调用成功
  193. fail: function () { }, //接口调用失败的回调函数
  194. complete: function () { } //接口调用结束的回调函数
  195. })
  196. }
  197. })
  198. }
  199. },
  200. fail: function (res) { },//接口调用失败的回调函数
  201. complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  202. })
  203. }
  204. else if (e.detail.cell.text == "提现") {
  205. // wx.showToast({
  206. // title: "结算金额:0元",
  207. // icon: 'none'
  208. // });
  209. wx.navigateTo({
  210. url:"/pages/trans/trans"
  211. })
  212. } else if (e.detail.cell.text == "邀请好友"){
  213. console.log('邀请好友')
  214. wx.navigateTo({
  215. url:"/pages/friends/friends"
  216. })
  217. } else if (e.detail.cell.text == "好友列表"){
  218. wx.navigateTo({
  219. url:"/pages/friends-list/friends-list"
  220. })
  221. } else if (e.detail.cell.text == "管理员"){
  222. wx.navigateTo({
  223. url:"/pages/admin/admin"
  224. })
  225. }
  226. else {
  227. wx.showToast({
  228. title: "功能开发中...",
  229. icon: 'none'
  230. });
  231. }
  232. },
  233. getUserProfile(e) {
  234. var that = this
  235. var openId = wx.getStorageSync('openId')
  236. var nickName = wx.getStorageSync('nickName')
  237. console.log("'"+nickName+"'")
  238. console.log(openId)
  239. if (nickName == ''){
  240. wx.getUserProfile({
  241. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  242. success: (res) => {
  243. console.log(res)
  244. //更新user
  245. wx.request( {
  246. url: link + "/v1/forward/lhf",
  247. header: {
  248. "Content-Type": "application/json",
  249. "function":"/v1/user/update/name"
  250. },
  251. method: "POST",
  252. data: { openId: openId ,nickName:res.userInfo.nickName,avatarUrl:res.userInfo.avatarUrl},
  253. success (ress) {
  254. console.log(ress)
  255. wx.setStorageSync('nickName', res.userInfo.nickName)
  256. }
  257. })
  258. that.clickGrid(e)
  259. }
  260. })
  261. } else{
  262. that.clickGrid(e)
  263. }
  264. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  265. },
  266. getUserInfo(e) {
  267. // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
  268. console.log(e)
  269. this.setData({
  270. userInfo: e.detail.userInfo,
  271. hasUserInfo: true
  272. })
  273. },
  274. onShow:function (e) {
  275. var that = this
  276. var opneId = wx.getStorageSync('openId')
  277. var nickName = wx.getStorageSync('nickName')
  278. //var admin = wx.getStorageSync('admin')
  279. if (wx.getUserProfile) {
  280. this.setData({
  281. canIUseGetUserProfile: true
  282. })
  283. }
  284. //获取金额
  285. wx.request( {
  286. url: link + "/v1/forward/lhf",
  287. header: {
  288. "Content-Type": "application/json",
  289. "function":"/v1/user/wallet/get"
  290. },
  291. method: "POST",
  292. data: { openId: opneId },
  293. success (res) {
  294. console.log(res)
  295. that.setData({
  296. wallet: res.data.data.wallet
  297. })
  298. }
  299. })
  300. console.log(nickName)
  301. // if (nickName == '' ){
  302. wx.request( {
  303. url: link + "/v1/forward/lhf",
  304. header: {
  305. "Content-Type": "application/json",
  306. "function":"/v1/user/open.id/get"
  307. },
  308. method: "POST",
  309. data: { openId: opneId },
  310. success (res) {
  311. console.log(res)
  312. var admin = false
  313. wx.setStorageSync('nickName', res.data.data.user.nickName)
  314. wx.setStorageSync('userId', res.data.data.user.id)
  315. if (res.data.data.user.admin >= 1){
  316. admin = true
  317. }
  318. that.setData({
  319. userId: res.data.data.user.id,
  320. admin:admin
  321. })
  322. }
  323. })
  324. }
  325. /**
  326. * 用户点击右上角分享
  327. */
  328. // onShareAppMessage: function () {
  329. // var openId = wx.getStorageSync('openId')
  330. // return {
  331. // title: '优惠券小程序',
  332. // desc: '电商内部优惠券',
  333. // path: 'pages/boutique/outique?openId=' + openId // 路径,传递参数到指定页面。
  334. // }
  335. // }
  336. })