personaldata.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. const app = getApp();
  2. Page({
  3. data: {
  4. information: '', //个人信息
  5. optioninfo:'', //择偶信息
  6. houselunbo:'', //轮播图
  7. // uploadImages: '', //轮播图放大
  8. adopticon:'', //认证信息
  9. headurl: [], //个人头像
  10. },
  11. onShow: function (options) {
  12. var that = this;
  13. // 个人信息
  14. let information_url = 'my/personaldata/personal';
  15. let information_data = {
  16. };
  17. app.postRequest(information_url, information_data, function (res) {
  18. if (res.code == 201) {
  19. // console.log(res.data);
  20. that.setData({
  21. information: res.data
  22. })
  23. }
  24. })
  25. // 择偶信息
  26. let optioninfo_url = 'my/personaloption/optioninfo';
  27. let optioninfo_data = {
  28. };
  29. app.postRequest(optioninfo_url, optioninfo_data, function (res) {
  30. // console.log(res.data);
  31. if (res.code == 201) {
  32. that.setData({
  33. optioninfo: res.data,
  34. optioninfocode:res,
  35. })
  36. }
  37. })
  38. // 轮播图片
  39. // let img_url = 'my/images/albumchange';
  40. // let img_data = {
  41. // };
  42. // app.postRequest(img_url, img_data, function (res) {
  43. // if (res.code == 201) {
  44. // // console.log(res.data);
  45. // that.setData({
  46. // houselunbo: res.data
  47. // })
  48. // // 对象转数组
  49. // var itemList = res.data;
  50. // //声明一个空的数组
  51. // var items = [];
  52. // //遍历数据
  53. // for (let i in itemList) {
  54. // //push到空数组里
  55. // items.push(itemList[i].img);
  56. // }
  57. // // console.log(items);
  58. // //传输数据到页面
  59. // that.setData({
  60. // uploadImages: items,
  61. // })
  62. // }
  63. // })
  64. // 认证信息
  65. let adopticon_url = 'my/authentication/adopticon';
  66. let adopticon_data = {
  67. };
  68. app.postRequest(adopticon_url, adopticon_data, function (res) {
  69. console.log(res.data);
  70. // console.log(res);
  71. if (res.code == 201) {
  72. that.setData({
  73. adopticon: res.data,
  74. adopticoncode: res,
  75. })
  76. }
  77. })
  78. // 个人头像
  79. let headurl_url = 'my/images/headurl';
  80. let headurl_data = {
  81. };
  82. app.postRequest(headurl_url, headurl_data, function (res) {
  83. if (res.code == 201) {
  84. // console.log(res.data);
  85. that.setData({
  86. headurl: res.data
  87. })
  88. }
  89. })
  90. },
  91. // 上传图片
  92. chooseImageTap: function (e) {
  93. var _this = this;
  94. wx.showActionSheet({
  95. itemList: ['预览图片', '上传头像'],
  96. success(res) {
  97. // console.log(res.tapIndex)
  98. if (res.tapIndex == 0) { //预览所选图片
  99. // console.log(that.data.uploadImages);
  100. // console.log(e.currentTarget.dataset.src);
  101. wx.previewImage({
  102. urls: [e.currentTarget.dataset.src],
  103. current: e.currentTarget.dataset.src
  104. })
  105. }
  106. if (res.tapIndex == 1) {
  107. wx.chooseImage({
  108. count: 1,
  109. sizeType: ['original', 'compressed'],
  110. sourceType: ['album', 'camera'],
  111. success(res) {
  112. let tempFilesSize = res.tempFiles[0].size;
  113. if (tempFilesSize > 1024 * 1024 * 3) {
  114. wx.showModal({
  115. title: '提示',
  116. content: '图片不得超过3MB',
  117. showCancel: false,
  118. })
  119. return;
  120. }
  121. var Headportrait = res.tempFilePaths[0];
  122. // console.log(res.tempFilePaths[0]);
  123. //上传图片
  124. wx.uploadFile({
  125. url: app.globalData.url + 'my/images/headimg',
  126. filePath: Headportrait,
  127. name: 'photo',
  128. formData: {
  129. key: wx.getStorageSync('access_key'),
  130. token: wx.getStorageSync('access_token')
  131. },
  132. success: function (res) {
  133. var data = JSON.parse(res.data);
  134. console.log(data);
  135. if (data.code == 201) {
  136. var _qrcode = '上传成功'
  137. getApp().Tips(_qrcode);
  138. _this.onShow();
  139. return;
  140. }
  141. var _qrcode2 = data.msg;
  142. getApp().Tips(_qrcode2);
  143. }, fail: function (d) {
  144. }
  145. })
  146. }
  147. })
  148. }
  149. },
  150. fail(res) {
  151. console.log(res.errMsg)
  152. }
  153. })
  154. },
  155. })