indexShip.js 4.9 KB

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