indexShip.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // pages/updateInfo/indexShip.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. loginStatus: wx.getStorageSync('loginStatus') ? wx.getStorageSync('loginStatus') : false,
  9. showModal: false,
  10. isSubmitting:false,
  11. defaultText: '请选择',
  12. userId:'',
  13. name:'',
  14. phone:'',
  15. nickname: '',
  16. fileList:[],
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. ///证书图片
  23. let fileList = []
  24. if(null != wx.getStorageSync('unloadImg') && "" != wx.getStorageSync('unloadImg')){
  25. let unloadImg = wx.getStorageSync('unloadImg');
  26. console.log("unloadImg---" + unloadImg);
  27. let unloadImgArray = unloadImg.split(',');
  28. unloadImgArray.forEach(element => {
  29. fileList.push({
  30. url : app.host.BASEIMG_URL + element,
  31. imgUrl : element
  32. })
  33. });
  34. }
  35. this.setData({
  36. loginStatus : wx.getStorageSync('loginStatus') ? wx.getStorageSync('loginStatus') : false,
  37. userId : wx.getStorageSync('id'),
  38. name : wx.getStorageSync('name'),
  39. phone : wx.getStorageSync('phone'),
  40. nickname : wx.getStorageSync('nickname'),
  41. fileList : fileList,//证书图片
  42. })
  43. },
  44. //图片上传
  45. afterRead:function(event){
  46. const { file } = event.detail;
  47. const { type } = event.currentTarget.dataset
  48. app.request.uploadDIY({
  49. url: app.API.uploadImgMap,
  50. page: this,
  51. filePaths:file.url,
  52. setfiled:'file',
  53. params: {},
  54. //isToken: false,
  55. isLoading: false,
  56. successFun: true
  57. }).then(res => {
  58. const imgArray = this.data[type];
  59. imgArray.push({
  60. ...file,
  61. url: app.host.BASEIMG_URL + JSON.parse(res.data).data.imageFile,
  62. imgUrl: JSON.parse(res.data).data.imageFile
  63. });
  64. this.setData({
  65. [type]: imgArray
  66. });
  67. })
  68. },
  69. // 删除图片
  70. deleteImg: function (event) {
  71. const { type } = event.currentTarget.dataset
  72. let getFileList = this.data[type];
  73. getFileList.splice(event.detail.index, 1)
  74. this.setData({
  75. [type]: getFileList
  76. })
  77. },
  78. //表单提交
  79. formSubmit: function (e) {
  80. let formData = e.detail.value;
  81. let reg = /^1[3-9]\d{9}$/;
  82. var mobile = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/;
  83. var warn = ""; //弹框时提示的内容
  84. if (formData.account == '') {
  85. warn = "请输入账号!";
  86. } else if (formData.name == '') {
  87. warn = "请输入船主姓名!";
  88. } else if (formData.phone == '') {
  89. warn = "请输入船主手机号!";
  90. } else if(!reg.test(formData.phone)){
  91. warn = "请确认手机号格式!";
  92. } else if (formData.nickname == '') {
  93. warn = "请输入船舶号!";
  94. }
  95. /** 图片处理 START **/
  96. let getfileList = this.data.fileList
  97. if(getfileList.length < 1){
  98. warn = "请上传船舶证书图片!";
  99. }
  100. let fileNameList = []
  101. let filePathList = []
  102. let unloadImg = ""
  103. getfileList.forEach((element,index) => {
  104. fileNameList.push('图片'+(index+1)+'.'+element.imgUrl.split('.')[1])
  105. filePathList.push(element.imgUrl)
  106. if(""!=unloadImg){
  107. unloadImg = unloadImg + "," + element.imgUrl
  108. }else{
  109. unloadImg = element.imgUrl
  110. }
  111. });
  112. formData.fileNameList = fileNameList
  113. formData.filePathList = filePathList
  114. /** 图片处理 END **/
  115. if (warn != '') {
  116. app.util.checkForm(warn);
  117. } else {
  118. app.request.POST({
  119. url: app.API.updateUserInfo,
  120. params: formData,
  121. page: this,
  122. isLoadingTxt: '处理中...',
  123. isSubmitting: true,
  124. successFun: true
  125. }).then(res => {
  126. let _this = this
  127. wx.showToast({
  128. title: '修改成功',
  129. icon: 'success',
  130. duration: 1500,
  131. mask:true,
  132. complete: function () {
  133. setTimeout( ()=> {
  134. wx.setStorageSync('name', formData.name); //用户姓名
  135. wx.setStorageSync('nickname', formData.nickname); //车牌号
  136. wx.setStorageSync('unloadImg', unloadImg); //证书图片
  137. wx.navigateBack()
  138. }, 1500) //延迟时间
  139. }
  140. })
  141. })
  142. }
  143. },
  144. /**
  145. * 生命周期函数--监听页面初次渲染完成
  146. */
  147. onReady: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面显示
  151. */
  152. onShow: function () {
  153. },
  154. /**
  155. * 生命周期函数--监听页面隐藏
  156. */
  157. onHide: function () {
  158. },
  159. /**
  160. * 生命周期函数--监听页面卸载
  161. */
  162. onUnload: function () {
  163. },
  164. /**
  165. * 页面相关事件处理函数--监听用户下拉动作
  166. */
  167. onPullDownRefresh: function () {
  168. },
  169. /**
  170. * 页面上拉触底事件的处理函数
  171. */
  172. onReachBottom: function () {
  173. },
  174. /**
  175. * 用户点击右上角分享
  176. */
  177. onShareAppMessage: function () {
  178. }
  179. })