东风启辰小程序端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

223 lines
5.7KB

  1. // pages/supplement/supplement.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. agreement: false,
  10. isAgreement: true,//是否同意协议
  11. jobList:[],
  12. jobValue:0,
  13. provinceArr: [],//省
  14. provinceValue: 0,//选中的省下标
  15. storeArr: [],//店铺
  16. storeValue: 0,//选中的店铺下标
  17. realname:"",
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. app.globalData.nowPage = 2;
  24. if (app.globalData.openid) {
  25. this.loadFun();
  26. } else {
  27. app.globalData.openidSuccessFuc = this.loadFun;
  28. }
  29. },
  30. loadFun:function(){
  31. this.getJobList();
  32. this.getUserLocation();
  33. var authenticationStatus = app.globalData.authenticationStatus;
  34. if (authenticationStatus.realName){
  35. this.setData({
  36. realname: authenticationStatus.realName
  37. })
  38. }
  39. },
  40. /**
  41. * 生命周期函数--监听页面初次渲染完成
  42. */
  43. onReady: function () {
  44. },
  45. /**
  46. * 生命周期函数--监听页面显示
  47. */
  48. onShow: function () {
  49. },
  50. /**
  51. * 生命周期函数--监听页面隐藏
  52. */
  53. onHide: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面卸载
  57. */
  58. onUnload: function () {
  59. },
  60. /**
  61. * 页面相关事件处理函数--监听用户下拉动作
  62. */
  63. onPullDownRefresh: function () {
  64. },
  65. /**
  66. * 页面上拉触底事件的处理函数
  67. */
  68. onReachBottom: function () {
  69. },
  70. /**
  71. * 用户点击右上角分享
  72. */
  73. onShareAppMessage: function () {
  74. },
  75. agreementState: function () {//协议
  76. this.setData({
  77. isAgreement: !this.data.isAgreement
  78. })
  79. },
  80. agreementControl: function () {
  81. this.setData({
  82. agreement: !this.data.agreement
  83. })
  84. },
  85. getJobList:function(){
  86. app.wxRequest(app.globalData.urlRoot + "userInfo/getJobList", {}, res => {
  87. if(res.code==200){
  88. this.setData({
  89. jobList:res.data
  90. })
  91. var authenticationStatus = app.globalData.authenticationStatus;
  92. if (authenticationStatus.jobId) {
  93. for(let i=0;i<res.data.length;i++){
  94. if (res.data[i].jobId == authenticationStatus.jobId){
  95. this.setData({
  96. jobValue: i,
  97. jobDetail: res.data[i].jobDetail
  98. })
  99. break;
  100. }
  101. }
  102. }
  103. }
  104. },this)
  105. },
  106. jobChange:function(e){
  107. this.setData({
  108. jobValue:e.detail.value
  109. })
  110. },
  111. getUserLocation: function (e) {
  112. wx.getLocation({
  113. type: 'gcj02', //wgs84
  114. success: (res) => {
  115. this.getDistributorList(res.longitude, res.latitude);
  116. },
  117. fail: (res) => {
  118. this.getDistributorList("", "");
  119. }
  120. })
  121. },
  122. getDistributorList: function (longitude, latitude) {//获取经销商列表
  123. app.wxRequest(app.globalData.urlRoot + "agent/getAgentList", { longitude: longitude, latitude: latitude}, res => {
  124. if (res.code == 200) {
  125. this.setData({
  126. provinceArr: res.data.list,
  127. storeArr: res.data.list[res.data.nearData.provinceIndex].children,
  128. provinceValue: res.data.nearData.provinceIndex,
  129. storeValue: res.data.nearData.cityIndex
  130. })
  131. var authenticationStatus = app.globalData.authenticationStatus;
  132. if (authenticationStatus.city) {
  133. for (let i = 0; i < res.data.list.length; i++) {
  134. if (res.data.list[i].province == authenticationStatus.city){
  135. this.setData({
  136. provinceValue: i,
  137. storeArr: this.data.provinceArr[i].children,
  138. storeValue: 0
  139. })
  140. break;
  141. }
  142. }
  143. }
  144. } else {
  145. wx.showToast({
  146. title: res.msg,
  147. icon: "none"
  148. })
  149. }
  150. }, this);
  151. },
  152. provinceChane: function (e) {//选中省
  153. this.setData({
  154. provinceValue: e.detail.value,
  155. storeArr: this.data.provinceArr[e.detail.value].children,
  156. storeValue: 0
  157. })
  158. },
  159. storeChane: function (e) {//选中店铺
  160. this.setData({
  161. storeValue: e.detail.value,
  162. })
  163. },
  164. getRealname: function (e) {//获取用户输入的姓名
  165. this.data.realname = e.detail.value;
  166. },
  167. submitMsg: function () {
  168. if(!this.data.realname){
  169. wx.showToast({
  170. title: '请输入姓名',
  171. icon:'none'
  172. })
  173. return;
  174. }
  175. if (!this.data.isAgreement) {
  176. wx.showToast({
  177. title: '请同意协议',
  178. icon: 'none'
  179. })
  180. return;
  181. }
  182. var data = {
  183. realName:this.data.realname,
  184. jobId: this.data.jobList[this.data.jobValue].jobId,
  185. jobDetail: this.data.jobList[this.data.jobValue].jobDetail,
  186. agentDetail: this.data.storeArr[this.data.storeValue]['agent_detail'],
  187. agentCode: this.data.storeArr[this.data.storeValue]['agent_code'],
  188. city: this.data.provinceArr[this.data.provinceValue]['province']
  189. }
  190. app.wxRequest(app.globalData.urlRoot + "certificationInfo/submitCertificationInfoData", data,res=>{
  191. if (res.code == 200) {
  192. app.globalData.authenticationStatus.realName = this.data.realname
  193. app.globalData.authenticationStatus.jobId = this.data.jobList[this.data.jobValue].jobId
  194. app.globalData.authenticationStatus.jobDetail = this.data.storeArr[this.data.storeValue]['agent_detail']
  195. app.globalData.authenticationStatus.city = this.data.provinceArr[this.data.provinceValue]['province']
  196. app.globalData.authenticationStatus.agentDetail = this.data.storeArr[this.data.storeValue]['agent_detail']
  197. wx.navigateBack({
  198. delta: 1,
  199. })
  200. }else{
  201. wx.showToast({
  202. title: res.msg,
  203. icon:'none'
  204. })
  205. }
  206. },this,"POST");
  207. }
  208. })