apply.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // lionfish_comshop/pages/supply/apply.js
  2. var util = require('../../utils/util.js');
  3. var app = getApp();
  4. var status = require('../../utils/index.js');
  5. Page({
  6. mixins: [require('../../mixin/globalMixin.js')],
  7. data: {
  8. image_thumb: '',
  9. image_o_full: '',
  10. orign_image: '',
  11. shopname: '',
  12. name: '',
  13. mobile: '',
  14. product: '',
  15. state: null
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. status.setNavBgColor();
  22. this.getData();
  23. },
  24. /**
  25. * 授权成功回调
  26. */
  27. authSuccess: function () {
  28. let that = this;
  29. this.setData({
  30. needAuth: false
  31. }, () => {
  32. that.getData();
  33. })
  34. },
  35. authModal: function () {
  36. if (this.data.needAuth) {
  37. this.setData({ showAuthModal: !this.data.showAuthModal });
  38. return false;
  39. }
  40. return true;
  41. },
  42. /**
  43. * 生命周期函数--监听页面显示
  44. */
  45. onShow: function () {
  46. util.check_login_new().then((res) => {
  47. if (res) {
  48. this.setData({ needAuth: false });
  49. } else {
  50. this.setData({ needAuth: true });
  51. }
  52. })
  53. },
  54. getData: function(){
  55. wx.showLoading();
  56. var token = wx.getStorageSync('token');
  57. let that = this;
  58. app.util.request({
  59. url: 'entry/wxapp/index',
  60. data: {
  61. controller: 'supply.apply_info',
  62. token: token
  63. },
  64. dataType: 'json',
  65. method: 'POST',
  66. success: function (res) {
  67. wx.hideLoading();
  68. let code = res.data.code;
  69. let supply_diy_name = res.data.supply_diy_name || '供应商';
  70. wx.setNavigationBarTitle({
  71. title: `申请成为${supply_diy_name}`,
  72. })
  73. if (code == 0) {
  74. that.setData({
  75. state: res.data.data.state || 0,
  76. supply_diy_name
  77. })
  78. } else if(code == 1) {
  79. that.setData({ supply_diy_name })
  80. //needAuth
  81. console.log('needAuth');
  82. }
  83. }
  84. })
  85. },
  86. inputShopName: function (e) {
  87. this.setData({
  88. shopname: e.detail.value
  89. })
  90. },
  91. inputName: function (e) {
  92. this.setData({
  93. name: e.detail.value
  94. })
  95. },
  96. inputMobile: function (e) {
  97. this.setData({
  98. mobile: e.detail.value
  99. })
  100. },
  101. inputAdvantage: function (e) {
  102. this.setData({
  103. product: e.detail.value
  104. })
  105. },
  106. addImg: function () {
  107. var that = this;
  108. wx.chooseImage({
  109. count: 1,
  110. success: function (res) {
  111. var tempFilePaths = res.tempFilePaths;
  112. var new_thumb_img = that.data.thumb_img;
  113. wx.showLoading({ title: '上传中' });
  114. wx.uploadFile({
  115. url: app.util.url('entry/wxapp/index', {
  116. 'm': 'lionfish_comshop',
  117. 'controller': 'goods.doPageUpload'
  118. }),
  119. filePath: tempFilePaths[0],
  120. name: 'upfile',
  121. formData: {
  122. 'name': tempFilePaths[0]
  123. },
  124. header: {
  125. 'content-type': 'multipart/form-data'
  126. },
  127. success: function (res) {
  128. wx.hideLoading();
  129. var data = JSON.parse(res.data);
  130. var image_thumb = data.image_thumb;
  131. var image_o_full = data.image_o_full;
  132. var orign_image = data.image_o;
  133. that.setData({
  134. image_thumb: image_thumb,
  135. image_o_full: image_o_full,
  136. orign_image: orign_image
  137. })
  138. }
  139. })
  140. }
  141. });
  142. },
  143. submit: function () {
  144. if (!this.authModal()) return;
  145. var token = wx.getStorageSync('token');
  146. var shopname = this.data.shopname;
  147. var mobile = this.data.mobile;
  148. var name = this.data.name;
  149. var product = this.data.product;
  150. var that = this;
  151. if (shopname == '') {
  152. wx.showToast({
  153. title: '请填供应商名称',
  154. icon: 'none',
  155. })
  156. return false;
  157. }
  158. if (name == '') {
  159. wx.showToast({
  160. title: '请填写供应商联系人',
  161. icon: 'none',
  162. })
  163. return false;
  164. }
  165. if (mobile == '' || !(/^1(3|4|5|6|7|8|9)\d{9}$/.test(mobile))) {
  166. wx.showToast({
  167. title: '手机号码有误',
  168. icon: 'none',
  169. })
  170. return false;
  171. }
  172. var s_data = {
  173. shopname, name, mobile, product, controller: 'user.supply_apply', 'token': token
  174. };
  175. app.util.request({
  176. 'url': 'entry/wxapp/user',
  177. 'data': s_data,
  178. method: 'post',
  179. dataType: 'json',
  180. success: function (res) {
  181. if (res.data.code == 0) {
  182. wx.showToast({
  183. title: '提交成功,等待审核',
  184. icon: 'none',
  185. duration: 2000,
  186. success: function(){
  187. setTimeout(()=>{
  188. wx.switchTab({
  189. url: '/lionfish_comshop/pages/user/me',
  190. })
  191. }, 2000)
  192. }
  193. })
  194. } else {
  195. wx.showModal({
  196. title: '提示',
  197. content: res.data.msg,
  198. showCancel: false
  199. })
  200. }
  201. }
  202. })
  203. }
  204. })