addShipOnwer.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // pages/shipOwnerManage/shipOwnerList/shipOwnerList.js
  2. import {
  3. postApi
  4. } from "../../../apis/api"
  5. import {
  6. uploadImage
  7. } from "../../../utils/uploadImage"
  8. Page({
  9. data: {
  10. step: 1,
  11. userId: 0,
  12. userName: "",
  13. userPhone: "",
  14. idCardNo: '',
  15. idcardFrontFileKey: '',
  16. idcardFrontViewUrl: '',
  17. idcardFrontDownloadUrl: '',
  18. idcardBackFileKey: '',
  19. idcardBackViewUrl: '',
  20. idcardBackDownloadUrl: '',
  21. shipId: 0,
  22. shipName: "",
  23. shipMmsi: "",
  24. shipCerts: []
  25. },
  26. async checkShipOwner() {
  27. if (!this.data.userPhone) {
  28. wx.showToast({
  29. title: '请填写手机号',
  30. icon: "error"
  31. })
  32. return
  33. }
  34. let res = await postApi('/ship/search/shipOwner', {
  35. userPhone: this.data.userPhone
  36. })
  37. console.log(res)
  38. if (res.data.status == 0) {
  39. this.setData({
  40. ...res.data.result,
  41. step: 2
  42. })
  43. } else {
  44. this.setData({
  45. step: 2
  46. })
  47. }
  48. },
  49. step2next() {
  50. if (!this.data.userName) {
  51. wx.showToast({
  52. title: '请填写船东姓名',
  53. icon: "error"
  54. })
  55. return
  56. }
  57. if (!this.data.userPhone) {
  58. wx.showToast({
  59. title: '请填写手机号',
  60. icon: "error"
  61. })
  62. return
  63. }
  64. this.setData({
  65. step: 3
  66. })
  67. },
  68. async uploadId(e) {
  69. let res = await uploadImage(1)
  70. if (res.status == 0) {
  71. if (e.currentTarget.dataset.type == 'head') {
  72. let {
  73. idcardFrontFileKey,
  74. idcardFrontViewUrl,
  75. idcardFrontDownloadUrl,
  76. } = this
  77. idcardFrontFileKey = res.result.key
  78. idcardFrontViewUrl = res.result.viewUrl
  79. idcardFrontDownloadUrl = res.result.downloadUrl
  80. this.setData({
  81. idcardFrontFileKey,
  82. idcardFrontViewUrl,
  83. idcardFrontDownloadUrl,
  84. })
  85. } else {
  86. let {
  87. idcardBackFileKey,
  88. idcardBackViewUrl,
  89. idcardBackDownloadUrl,
  90. } = this
  91. idcardBackFileKey = res.result.key
  92. idcardBackViewUrl = res.result.viewUrl
  93. idcardBackDownloadUrl = res.result.downloadUrl
  94. this.setData({
  95. idcardBackFileKey,
  96. idcardBackViewUrl,
  97. idcardBackDownloadUrl,
  98. })
  99. }
  100. }
  101. },
  102. async uploadShipCerts(e) {
  103. let res = await uploadImage(2)
  104. if (res.status == 0) {
  105. let {
  106. downloadUrl,
  107. key: fileKey,
  108. viewUrl
  109. } = res.result
  110. if (e.currentTarget.dataset.type == 'push') {
  111. this.data.shipCerts.push({
  112. downloadUrl,
  113. fileKey,
  114. viewUrl
  115. })
  116. } else {
  117. this.data.shipCerts[e.currentTarget.dataset.index] = {
  118. downloadUrl,
  119. fileKey,
  120. viewUrl
  121. }
  122. }
  123. this.setData({
  124. shipCerts: this.data.shipCerts
  125. })
  126. }
  127. },
  128. async submit() {
  129. if (!this.data.shipName) {
  130. wx.showToast({
  131. title: '请填写船舶名称',
  132. icon: "error"
  133. })
  134. return
  135. }
  136. if (!this.data.shipMmsi) {
  137. wx.showToast({
  138. title: '请填写MMSI',
  139. icon: "error"
  140. })
  141. return
  142. }
  143. let postData = {
  144. ...this.data,
  145. loginAccountId: wx.getStorageSync('loginAccountId')
  146. }
  147. console.log(postData)
  148. delete postData.__webviewId__
  149. delete postData.step
  150. let res = await postApi('/ship/add', postData)
  151. if (res.data.status == 0) {
  152. wx.switchTab({
  153. url: '/pages/shipOwnerManage/shipOwnerList/shipOwnerList',
  154. })
  155. }
  156. }
  157. })