apply.js 5.9 KB

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