apply.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. var app = getApp();
  2. var util = require('../../utils/util.js');
  3. Page({
  4. mixins: [require('../../mixin/commonMixin.js')],
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. pickerIndex: 0,
  10. formArr: [],
  11. status: 0
  12. },
  13. canSub: true,
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function(options) {
  18. this.getMemberInfo();
  19. },
  20. /**
  21. * 授权成功回调
  22. */
  23. authSuccess: function() {
  24. let that = this;
  25. this.setData({
  26. needAuth: false
  27. }, () => {
  28. that.getMemberInfo();
  29. })
  30. },
  31. /**
  32. * 生命周期函数--监听页面显示
  33. */
  34. onShow: function() {
  35. let that = this;
  36. util.check_login_new().then((res) => {
  37. if (res) {
  38. that.setData({
  39. needAuth: false
  40. })
  41. } else {
  42. that.setData({
  43. needAuth: true
  44. })
  45. }
  46. })
  47. },
  48. getMemberInfo: function() {
  49. var token = wx.getStorageSync('token');
  50. let that = this;
  51. token && app.util.request({
  52. url: 'entry/wxapp/user',
  53. data: {
  54. controller: 'user.get_user_info',
  55. token: token
  56. },
  57. dataType: 'json',
  58. success: function(res) {
  59. wx.hideLoading();
  60. if (res.data.code == 0) {
  61. let commiss_diy_name = res.data.commiss_diy_name || '分销';
  62. wx.setNavigationBarTitle({
  63. title: `会员${commiss_diy_name}`,
  64. })
  65. //未开启分销
  66. if (res.data.commiss_level == 0) {
  67. wx.navigateTo({
  68. url: '/lionfish_comshop/pages/user/me',
  69. })
  70. return;
  71. }
  72. //状态判断
  73. let userInfo = res.data.data;
  74. let status = 0; //未填写 1 已填写未审核 2 已审核
  75. let { commiss_become_condition, commiss_biaodan_need } = res.data;
  76. if (commiss_biaodan_need==1){
  77. if (userInfo.is_writecommiss_form==1) {
  78. status = 1;
  79. //已填写
  80. if (userInfo.comsiss_flag == 1) {
  81. userInfo.comsiss_state == 0 ? status = 1 : status = 2;
  82. }
  83. } else if (userInfo.comsiss_flag == 1&&userInfo.comsiss_state == 1) {
  84. status = 2;
  85. }
  86. } else {
  87. status = 1
  88. }
  89. let formArr = [];
  90. let commiss_diy_form = res.data.commiss_diy_form;
  91. if (commiss_diy_form && commiss_diy_form.length > 0) {
  92. commiss_diy_form.forEach((item)=>{
  93. let value = '';
  94. if (item.type == 'text' || item.type == 'textarea'){
  95. value = item.value;
  96. } else if(item.type == 'select') {
  97. value = item.value[0].value || '';
  98. }
  99. let formObj = {type: item.type, name: item.title, value, index: 0};
  100. formArr.push(formObj);
  101. })
  102. }
  103. that.setData({
  104. commiss_become_condition,
  105. commiss_diy_form,
  106. userInfo,
  107. status,
  108. formArr,
  109. commiss_diy_name
  110. })
  111. } else {
  112. that.setData({
  113. needAuth: true
  114. })
  115. }
  116. }
  117. })
  118. },
  119. /**
  120. * 输入框获得焦点
  121. */
  122. iptFocus: function(t) {
  123. let name = t.currentTarget.dataset.name;
  124. this.setData({
  125. currentFocus: name
  126. })
  127. },
  128. /**
  129. * 输入框失去焦点
  130. */
  131. iptBlur: function() {
  132. this.setData({
  133. currentFocus: ''
  134. })
  135. },
  136. bindPickerChange(e) {
  137. console.log('picker发送选择改变,携带值为', e.detail.value)
  138. let formArr = this.data.formArr;
  139. let name = e.currentTarget.dataset.name;
  140. let index = e.currentTarget.dataset.idx;
  141. let pickIdx = e.detail.value;
  142. let commiss_diy_form = this.data.commiss_diy_form;
  143. let formObj = { type: 'select', name: commiss_diy_form[index].title, value: commiss_diy_form[index].value[pickIdx].value || '', index: pickIdx };
  144. formArr.splice(index, 1, formObj)
  145. this.setData({ formArr });
  146. },
  147. radioChange(e) {
  148. let formArr = this.data.formArr;
  149. let index = e.currentTarget.dataset.idx;
  150. let value = e.detail.value;
  151. let commiss_diy_form = this.data.commiss_diy_form;
  152. let formObj = { type: 'radio', name: commiss_diy_form[index].title, value };
  153. formArr.splice(index, 1, formObj)
  154. this.setData({ formArr });
  155. console.log('radio发生change事件,携带value值为:', e.detail.value)
  156. },
  157. checkboxChange(e) {
  158. let formArr = this.data.formArr;
  159. let index = e.currentTarget.dataset.idx;
  160. let value = e.detail.value;
  161. let commiss_diy_form = this.data.commiss_diy_form;
  162. let formObj = { type: 'checkbox', name: commiss_diy_form[index].title, value };
  163. formArr.splice(index, 1, formObj)
  164. this.setData({ formArr });
  165. console.log('checkbox发生change事件,携带value值为:', e.detail.value)
  166. },
  167. authModal: function(){
  168. if(this.data.needAuth) {
  169. this.setData({ showAuthModal: !this.data.showAuthModal });
  170. return false;
  171. }
  172. return true;
  173. },
  174. formSubmit: function(e){
  175. if (!this.authModal() || !this.canSub) return;
  176. const params = e.detail.value;
  177. let formArr = this.data.formArr;
  178. let commiss_diy_form = this.data.commiss_diy_form;
  179. Object.keys(params).forEach((item)=>{
  180. let iptArr = item.split('-');
  181. let iptIdx = iptArr[1];
  182. let formObj = { type: commiss_diy_form[iptIdx].type, name: commiss_diy_form[iptIdx].title, value: params[item].replace(/^\s*|\s*$/g, "") }
  183. formArr.splice(iptIdx, 1, formObj)
  184. this.setData({ formArr });
  185. })
  186. console.log(formArr);
  187. for (var i = 0; i < formArr.length; i++) {
  188. let item = formArr[i];
  189. if (item.value == '') {
  190. let tip = '选择';
  191. if (item.type == 'text' || item.type == 'textarea') {
  192. tip = '输入';
  193. }
  194. wx.showToast({
  195. title: '请' + tip + item.name,
  196. icon: 'none'
  197. })
  198. return false;
  199. }
  200. }
  201. // [{ type: input, name: '姓名', value ='123'}]
  202. var token = wx.getStorageSync('token');
  203. this.canSub = false;
  204. wx.showLoading({ title: '提交中' })
  205. let that = this;
  206. app.util.request({
  207. url: 'entry/wxapp/user',
  208. data: {
  209. controller: 'distribution.sub_distribut_form',
  210. token,
  211. data: formArr
  212. },
  213. dataType: 'json',
  214. success: function (res) {
  215. wx.hideLoading();
  216. if (res.data.code == 0) {
  217. let status = 1;
  218. if(that.data.commiss_become_condition==0) status = 3;
  219. that.setData({ status })
  220. } else {
  221. that.canSub = true;
  222. wx.showToast({
  223. title: '提交失败,请重试。',
  224. icon: 'none'
  225. })
  226. }
  227. }
  228. })
  229. },
  230. goLink: function(e) {
  231. let url = e.currentTarget.dataset.url;
  232. let type = '';
  233. if (url.indexOf('lionfish_comshop/pages/user/me') != -1) {
  234. type = 'switch'
  235. }
  236. switch (type) {
  237. case "switch":
  238. wx.switchTab({
  239. url
  240. });
  241. break;
  242. default:
  243. wx.navigateTo({
  244. url
  245. });
  246. }
  247. }
  248. })