userInfo.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. var _request = require('../../../../utils/request.js')
  2. var validator = require('../../../../utils/validator.js')
  3. var _handle = require('../../../../utils/handle.js')
  4. Page({
  5. data: {
  6. address: '请选择',
  7. region: ['北京市', '北京市', '东城区'],
  8. name: '',
  9. tel: 0,
  10. more: '',
  11. countdown: 0,
  12. yzm:'',
  13. remark:'',
  14. userinfo:{},
  15. user:{},
  16. showpage:0,
  17. adimg:'',
  18. applyTotal:0,
  19. imgUrl:null,
  20. imgFile:null,
  21. avatar:'',
  22. nickname:'',
  23. sex:0,
  24. birthday:'',
  25. phone:'',
  26. columns: ["未知", "男", "女"],
  27. },
  28. onLoad: function (options) {
  29. this.getUserInfo();
  30. this.getADimg();
  31. this.getApplyTotal();
  32. },
  33. pickSex: function(e) {
  34. console.log('e.detail.value',e.detail.value);
  35. this.setData({
  36. sex: e.detail.value
  37. });
  38. // console.log("当前选择性别-sex", e.detail.value);
  39. },
  40. getUserInfo(){
  41. var that = this
  42. var url = 'v1/user/info'
  43. var params = {}
  44. var success = function (res) {
  45. console.log(res);
  46. that.setData({
  47. userinfo: res.data.wx_user,
  48. user:res.data.user,
  49. avatar:res.data.user.head,
  50. nickname:res.data.user.nickname,
  51. sex:res.data.user.sex,
  52. birthday:res.data.user.birthday.split('T').length > 1?res.data.user.birthday.split('T')[0]:res.data.user.birthday,
  53. phone:res.data.user.tel
  54. })
  55. }
  56. _request.$get(url, params, success)
  57. },
  58. savebtn(){
  59. var that = this;
  60. if(that.data.imgUrl){
  61. var url = 'v1/user/update/info'
  62. var params = {
  63. nickname:that.data.nickname,
  64. birthday:that.data.birthday,
  65. sex:that.data.sex,
  66. }
  67. var success = function (res) {
  68. console.log(res);
  69. wx.showToast({
  70. title: '更新成功',
  71. icon: 'none',
  72. duration: 2000
  73. })
  74. }
  75. var fail = function (res) {
  76. console.log(res);
  77. }
  78. _request.$uploadFile(url,'head',that.data.imgFile, params, success,fail)
  79. }else{
  80. var url = 'v1/user/update/info'
  81. var params = {
  82. nickname:that.data.nickname,
  83. birthday:that.data.birthday,
  84. sex:that.data.sex,
  85. }
  86. var success = function (res) {
  87. console.log(res);
  88. wx.showToast({
  89. title: '更新成功',
  90. icon: 'none',
  91. duration: 2000
  92. })
  93. }
  94. _request.$post(url, params, success)
  95. }
  96. },
  97. setAvatar(){
  98. var that = this;
  99. wx.chooseImage({
  100. count:1,
  101. sizeType:['original','compressed'],
  102. sourceType:['album','camera'],
  103. success:function(res){
  104. var tempfile = res.tempFilePaths;
  105. that.setData({
  106. imgUrl:tempfile,
  107. imgFile:tempfile[0]
  108. })
  109. }
  110. })
  111. },
  112. getADimg(){
  113. var that = this
  114. var url = 'v1/ad/shop_apply/items'
  115. var params = {}
  116. var success = function (res) {
  117. console.log(res);
  118. if(res.data.length > 0){
  119. that.setData({
  120. adimg: res.data[0].img
  121. })
  122. }
  123. }
  124. _request.$get(url, params, success)
  125. },
  126. getApplyTotal(){
  127. var that = this
  128. var url = 'v1/sys_config/apply_total'
  129. var params = {}
  130. var success = function (res) {
  131. console.log(res);
  132. that.setData({
  133. applyTotal: res.data.total / 100
  134. })
  135. }
  136. _request.$get(url, params, success)
  137. },
  138. getTel (val) {
  139. console.log(val)
  140. if (val.detail.encryptedData) {
  141. this.bindWxTel(val.detail)
  142. }
  143. },
  144. bindWxTel (res) {
  145. var str = JSON.stringify({
  146. encryptedData: res.encryptedData,
  147. iv: res.iv
  148. })
  149. var that = this
  150. var url = 'v1/wxuser/one_click/binding/phonumer'
  151. var params = {
  152. userinfo: str
  153. }
  154. var success = function (res) {
  155. console.log(res);
  156. }
  157. _request.$post(url, params, success)
  158. },
  159. getYzm (e) {
  160. _handle.setFormId(e)
  161. if (validator.telphone(this.data.tel)) {
  162. this.requireYzm()
  163. } else {
  164. wx.showToast({
  165. title: '手机号码格式不正确',
  166. icon: 'none',
  167. duration: 2000
  168. })
  169. }
  170. },
  171. startCountdown: function () {
  172. var smsRequestTime = wx.getStorageSync('sms_request_time')
  173. if (smsRequestTime) {
  174. var count = parseInt((60000 - (new Date() - smsRequestTime)) / 1000)
  175. this.setData({
  176. countdown: count
  177. })
  178. if (this.data.countdown > 0) {
  179. var timer = setInterval(() => {
  180. var countdown = this.data.countdown - 1
  181. this.setData({
  182. countdown: countdown
  183. })
  184. if (this.data.countdown <= 0) {
  185. clearInterval(timer)
  186. }
  187. }, 1000)
  188. // clearInterval(this.interval)
  189. }
  190. } else {
  191. }
  192. },
  193. requireYzm () {
  194. var that = this
  195. var url = 'v1/code/send'
  196. console.log(typeof(this.data.tel))
  197. var params = {
  198. tel: this.data.tel,
  199. valid_type: 'shop_application'
  200. }
  201. var success = function (res) {
  202. wx.setStorageSync('sms_request_time', Date.now())
  203. that.startCountdown()
  204. }
  205. _request.$post(url, params, success)
  206. },
  207. bindNickname(e){
  208. this.setData({
  209. nickname: e.detail.value
  210. })
  211. },
  212. bindBirthday(e){
  213. this.setData({
  214. birthday: e.detail.value
  215. })
  216. },
  217. bindPhone (e) {
  218. this.setData({
  219. tel: e.detail.value
  220. })
  221. },
  222. bindYzm (e) {
  223. this.setData({
  224. yzm: e.detail.value
  225. })
  226. },
  227. bindName: function (e) {
  228. this.setData({
  229. name: e.detail.value
  230. })
  231. },
  232. bindMore: function (e) {
  233. this.setData({
  234. more: e.detail.value
  235. })
  236. },
  237. bindRemark: function (e) {
  238. this.setData({
  239. remark: e.detail.value
  240. })
  241. },
  242. validate () {
  243. var msg
  244. if (!validator.required(this.data.name)) {
  245. msg = '姓名不能为空'
  246. } else if (!validator.required(this.data.tel)) {
  247. msg = '联系电话不能为空'
  248. } else if (!validator.telphone(this.data.tel)) {
  249. msg = '手机号码格式不正确'
  250. } else if (this.data.address === '请选择') {
  251. msg = '请选择所在地区'
  252. } else if (!validator.required(this.data.more)) {
  253. msg = '详细地址不能为空'
  254. }
  255. return { isOk: !msg, msg }
  256. },
  257. save: function (e) {
  258. _handle.setFormId(e)
  259. var { isOk, msg } = this.validate()
  260. if (isOk) {
  261. this.shopApplication()
  262. } else {
  263. wx.showToast({
  264. title: msg,
  265. icon: 'none',
  266. duration: 2000
  267. })
  268. }
  269. },
  270. shopApplication () {
  271. var that = this
  272. var url = 'v1/user/shop_application'
  273. var params = {
  274. name: this.data.name,
  275. mobile: this.data.tel,
  276. code:this.data.yzm,
  277. province: this.data.region[0],
  278. city: this.data.region[1],
  279. district: this.data.region[2],
  280. address: this.data.more,
  281. remark: this.data.remark
  282. }
  283. var success = function (res) {
  284. wx.showToast({
  285. title: '申请成功,我们将尽快处理,请您耐心等待',
  286. icon: 'none',
  287. duration: 2000
  288. })
  289. that.setData({showpage:1})
  290. }
  291. _request.$put(url, params, success)
  292. },
  293. bindRegionChange: function (e) {
  294. console.log(e)
  295. this.setData({
  296. region: e.detail.value,
  297. address: e.detail.value[0] + e.detail.value[1] + e.detail.value[2]
  298. })
  299. },
  300. //onShareAppMessage: function (val) {
  301. // return _request.share({
  302. // sc: 'xcx_user_newaddress'
  303. // })
  304. //}
  305. })