memberCenter.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. // pages/memberCenter/memberCenter.js
  2. const api = require('../../api/index')
  3. const pay = require('../../utils/pay')
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userinfo:{},
  10. equity:[
  11. {
  12. icon:'/static/svg/会员下载.svg',
  13. label:'权益一'
  14. },
  15. {
  16. icon:'/static/svg/会员权益 (1).svg',
  17. label:'权益二'
  18. },
  19. {
  20. icon:'/static/svg/会员权益.svg',
  21. label:'权益三'
  22. },
  23. {
  24. icon:'/static/svg/会员级别处理.svg',
  25. label:'权益四'
  26. },
  27. ],
  28. grades:[
  29. {
  30. background_icon:'/static/svg/B级会员背景图标.svg',
  31. background_color:'#3f395c',
  32. grade:'B级会员',
  33. money:'365'
  34. },
  35. {
  36. background_icon:'/static/svg/A级会员背景图标.svg',
  37. background_color:'#ff0101',
  38. grade:'A级会员',
  39. money:'520'
  40. },
  41. {
  42. background_icon:'/static/svg/S级会员背景图标.svg',
  43. background_color:'#000000',
  44. grade:'S级会员',
  45. money:'888'
  46. },
  47. ],
  48. choseVip:null,
  49. tableData:[],//会员权益
  50. tableHead:[]
  51. },
  52. /**
  53. * 生命周期函数--监听页面加载
  54. */
  55. onLoad(options) {
  56. this.getUserinfo()
  57. // var thead= [
  58. // { key: 'orderNum', name: '订单编号' },
  59. // { key: 'machNum', name: '机器编号' },
  60. // { key: 'planeNum', name: '计划生产数量' },
  61. // { key: 'planeEndTime', name: '计划结束时间' },
  62. // { key: 'productName', name: '产品名称' }
  63. // ]
  64. // var data= [
  65. // { orderNum: '01234dsnfbujhcdsvfkudshcvjbsdkcbsdjkchbsdjkhb', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  66. // { orderNum: '31234', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  67. // { orderNum: '13455', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  68. // { orderNum: '47867', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  69. // { orderNum: '34565', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  70. // { orderNum: '76809', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' },
  71. // { orderNum: '01034', machNum: '23', planeNum: '20', planeEndTime: '2022-08-08', productName: '8W0 864 733-B9_PA' }
  72. // ]
  73. // this.setData(
  74. // {
  75. // tableHead:thead,
  76. // tableData:data
  77. // }
  78. // )
  79. this.queryAllVip()
  80. },
  81. /**
  82. * 生命周期函数--监听页面初次渲染完成
  83. */
  84. onReady() {
  85. },
  86. /**
  87. * 生命周期函数--监听页面显示
  88. */
  89. onShow() {
  90. },
  91. /**
  92. * 页面功能
  93. */
  94. //获取所有会员
  95. queryAllVip(){
  96. var that = this
  97. api.queryAllVip().then(res=>{
  98. if(res.code == 200){
  99. console.log(res)
  100. var data = res.data.data
  101. var grades = []
  102. var tableHead = [
  103. {
  104. key:"functionName",
  105. name:''
  106. }
  107. ]
  108. data.forEach(item => {
  109. var config = JSON.parse(item.configParameter)
  110. var obj = {
  111. background_icon:config.background_icon,
  112. background_color:config.background_color,
  113. grade:item.name,
  114. money:item.price,
  115. vipUuid:item.vipUuid
  116. }
  117. tableHead.push(
  118. {
  119. key:item.vipUuid,
  120. name:item.name
  121. }
  122. )
  123. grades.push(obj)
  124. })
  125. that.setData(
  126. {
  127. grades:grades,
  128. tableHead:tableHead,
  129. choseVip:null
  130. }
  131. )
  132. that.getVipRights()
  133. console.log(that.data.grades)
  134. }
  135. })
  136. },
  137. //获取会员权益
  138. getVipRights(){
  139. var that = this
  140. api.getVipRights().then(res=>{
  141. if(res.code == 200){
  142. var data = res.data.data
  143. var tableData = []
  144. for(var i = 0;i<data.length;i++){
  145. var obj = {
  146. functionName:data[i].functionName
  147. }
  148. var right = data[i].vipRightsVOList
  149. for(var j = 0;j<that.data.tableHead.length;j++){
  150. var head = that.data.tableHead[j]
  151. if(head.key == 'functionName'){
  152. continue
  153. }
  154. var obj2 = right.find(item=>{
  155. return item.vipUuid == head.key
  156. })
  157. if(obj2){
  158. obj[head.key] = obj2.description
  159. }else{
  160. obj[head.key] = ''
  161. }
  162. }
  163. tableData.push(obj)
  164. }
  165. that.setData(
  166. {
  167. tableData:tableData
  168. }
  169. )
  170. console.log(that.data.tableHead,that.data.tableData)
  171. }
  172. })
  173. },
  174. //获取用户信息
  175. getUserinfo(){
  176. api.selectPerson().then(res=>{
  177. if(res.code == 200){
  178. this.setData(
  179. {
  180. userinfo:res.data
  181. }
  182. )
  183. }
  184. })
  185. },
  186. //选择开通会员类型
  187. chooseVip(e){
  188. var {item} = e.currentTarget.dataset
  189. this.setData(
  190. {
  191. choseVip:item
  192. }
  193. )
  194. },
  195. //开通会员
  196. openVip(){
  197. if(!this.data.choseVip){
  198. api.notify(
  199. {
  200. type:'warning',
  201. message:'请先选择需要开通会员的类型',
  202. top:wx.getStorageSync('height')
  203. }
  204. )
  205. }
  206. var params = {
  207. goodType:1,
  208. goodUuid:this.data.choseVip.vipUuid
  209. }
  210. wx.showLoading({
  211. title: '加载中',
  212. })
  213. pay.payMoney(params).then(res=>{
  214. console.log(res)
  215. if(res.errMsg == 'requestPayment:ok'){
  216. api.notify(
  217. {
  218. type:'success',
  219. message:'开通会员成功',
  220. top:wx.getStorageSync('height')
  221. }
  222. )
  223. this.getUserinfo()
  224. }
  225. }).catch(error=>{
  226. })
  227. },
  228. /**
  229. * 生命周期函数--监听页面隐藏
  230. */
  231. onHide() {
  232. },
  233. /**
  234. * 生命周期函数--监听页面卸载
  235. */
  236. onUnload() {
  237. },
  238. /**
  239. * 页面相关事件处理函数--监听用户下拉动作
  240. */
  241. onPullDownRefresh() {
  242. },
  243. /**
  244. * 页面上拉触底事件的处理函数
  245. */
  246. onReachBottom() {
  247. },
  248. /**
  249. * 用户点击右上角分享
  250. */
  251. onShareAppMessage() {
  252. }
  253. })