info.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. define(['core', 'tpl'], function(core, tpl) {
  2. var modal = {};
  3. modal.init = function(params) {
  4. params = $.extend({
  5. returnurl: '',
  6. template_flag: 0,
  7. new_area: 0
  8. }, params || {});
  9. if (typeof(window.memberData) !== 'undefined') {
  10. if (memberData.avatar) {
  11. $(".avatar").attr('src', memberData.avatar)
  12. }
  13. if (memberData.nickname) {
  14. $(".nickname").text(memberData.nickname)
  15. }
  16. }
  17. var reqParams = ['foxui.picker'];
  18. if (params.new_area) {
  19. reqParams = ['foxui.picker', 'foxui.citydatanew']
  20. }
  21. require(reqParams, function() {
  22. $('#city').cityPicker({
  23. new_area: params.new_area,
  24. showArea: false
  25. });
  26. $('#birthday').datePicker()
  27. });
  28. $('#btn-submit').click(function() {
  29. var postdata = {};
  30. if (params.template_flag == 0) {
  31. if ($('#realname').val() == '') {
  32. FoxUI.toast.show('请填写姓名');
  33. return
  34. }
  35. if ($('#mobile').val() == '') {
  36. FoxUI.toast.show('请填写手机号');
  37. return
  38. }
  39. if (!$('#mobile').isMobile() && !params.wapopen) {
  40. FoxUI.toast.show('请填写正确手机号码');
  41. return
  42. }
  43. if ($(this).attr('submit')) {
  44. return
  45. }
  46. var birthday = $('#birthday').val().split('-');
  47. var citys = $('#city').val().split(' ');
  48. $(this).html('处理中...').attr('submit', 1);
  49. postdata = {
  50. 'memberdata': {
  51. 'realname': $('#realname').val(),
  52. 'weixin': $('#weixin').val(),
  53. 'gender': $('#sex').val(),
  54. 'birthyear': $('#birthday').val().length > 0 ? birthday[0] : 0,
  55. 'birthmonth': $('#birthday').val().length > 0 ? birthday[1] : 0,
  56. 'birthday': $('#birthday').val().length > 0 ? birthday[2] : 0,
  57. 'province': $('#city').val().length > 0 ? citys[0] : '',
  58. 'city': $('#city').val().length > 0 ? citys[1] : '',
  59. 'datavalue': $('#city').attr('data-value'),
  60. 'nickname': $('#nickname').val().length > 0 ? $('#nickname').val() : '',
  61. 'avatar': $("#avatar").data('filename') != '' ? $('#avatar').data('filename') : ''
  62. },
  63. 'mcdata': {
  64. 'realname': $('#realname').val(),
  65. 'gender': $('#sex').val(),
  66. 'birthyear': $('#birthday').val().length > 0 ? birthday[0] : 0,
  67. 'birthmonth': $('#birthday').val().length > 0 ? birthday[1] : 0,
  68. 'birthday': $('#birthday').val().length > 0 ? birthday[2] : 0,
  69. 'resideprovince': $('#city').val().length > 0 ? citys[0] : '',
  70. 'residecity': $('#city').val().length > 0 ? citys[1] : ''
  71. }
  72. };
  73. if (!params.wapopen) {
  74. postdata.memberdata.mobile = $('#mobile').val();
  75. postdata.mcdata.mobile = $('#mobile').val()
  76. }
  77. core.json('member/info/submit', postdata, function(json) {
  78. modal.complete(params, json)
  79. }, true, true)
  80. } else {
  81. FoxUI.loader.show('mini');
  82. $(this).html('处理中...').attr('submit', 1);
  83. require(['biz/plugin/diyform'], function(diyform) {
  84. postdata = diyform.getData('.diyform-container');
  85. FoxUI.loader.hide();
  86. if (postdata) {
  87. core.json('member/info/submit', {
  88. memberdata: postdata
  89. }, function(json) {
  90. modal.complete(params, json)
  91. }, true, true)
  92. } else {
  93. $('#btn-submit').html('确认修改').removeAttr('submit')
  94. }
  95. })
  96. }
  97. })
  98. };
  99. modal.complete = function(params, json) {
  100. FoxUI.loader.hide();
  101. if (json.status == 1) {
  102. FoxUI.toast.show('保存成功');
  103. if (params.returnurl) {
  104. location.href = params.returnurl
  105. } else {
  106. history.back()
  107. }
  108. } else {
  109. $('#btn-submit').html('确认修改').removeAttr('submit');
  110. FoxUI.toast.showshow('保存失败!')
  111. }
  112. };
  113. modal.initFace = function() {
  114. $("#btn-getinfo").unbind('click').click(function() {
  115. FoxUI.confirm("确认使用微信昵称、头像吗?<br>使用微信资料保存后才生效", function() {
  116. var nickname = $.trim($("#nickname").data('wechat'));
  117. var avatar = $.trim($("#avatar").data('wechat'));
  118. $("#nickname").val(nickname);
  119. $("#avatar").attr('src', avatar).data('filename', avatar)
  120. })
  121. });
  122. $("#file-avatar").change(function() {
  123. var fileid = $(this).attr('id');
  124. FoxUI.loader.show('mini');
  125. $.ajaxFileUpload({
  126. url: core.getUrl('util/uploader'),
  127. data: {
  128. file: fileid
  129. },
  130. secureuri: false,
  131. fileElementId: fileid,
  132. dataType: 'json',
  133. success: function(res) {
  134. if (res.error == 0) {
  135. $("#avatar").attr('src', res.url).data('filename', res.filename)
  136. } else {
  137. FoxUI.toast.show("上传失败请重试")
  138. }
  139. FoxUI.loader.hide();
  140. return
  141. }
  142. })
  143. })
  144. };
  145. return modal
  146. });