addShipOnwer.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. let {
  40. userName,
  41. userId,
  42. } = res.data.result
  43. this.setData({
  44. userName,
  45. userId,
  46. step: 2
  47. })
  48. } else {
  49. this.setData({
  50. step: 2
  51. })
  52. }
  53. },
  54. step2next() {
  55. if (!this.data.userName) {
  56. wx.showToast({
  57. title: '请填写船东姓名',
  58. icon: "error"
  59. })
  60. return
  61. }
  62. if (!this.data.userPhone) {
  63. wx.showToast({
  64. title: '请填写手机号',
  65. icon: "error"
  66. })
  67. return
  68. }
  69. this.setData({
  70. step: 3
  71. })
  72. },
  73. async uploadId(e) {
  74. let res = await uploadImage(1)
  75. if (res.status == 0) {
  76. if (e.currentTarget.dataset.type == 'head') {
  77. let {
  78. idcardFrontFileKey,
  79. idcardFrontViewUrl,
  80. idcardFrontDownloadUrl,
  81. } = this
  82. idcardFrontFileKey = res.result.key
  83. idcardFrontViewUrl = res.result.viewUrl
  84. idcardFrontDownloadUrl = res.result.downloadUrl
  85. this.setData({
  86. idcardFrontFileKey,
  87. idcardFrontViewUrl,
  88. idcardFrontDownloadUrl,
  89. })
  90. } else {
  91. let {
  92. idcardBackFileKey,
  93. idcardBackViewUrl,
  94. idcardBackDownloadUrl,
  95. } = this
  96. idcardBackFileKey = res.result.key
  97. idcardBackViewUrl = res.result.viewUrl
  98. idcardBackDownloadUrl = res.result.downloadUrl
  99. this.setData({
  100. idcardBackFileKey,
  101. idcardBackViewUrl,
  102. idcardBackDownloadUrl,
  103. })
  104. }
  105. }
  106. },
  107. async uploadShipCerts(e) {
  108. let res = await uploadImage(2)
  109. if (res.status == 0) {
  110. let {
  111. downloadUrl,
  112. key: fileKey,
  113. viewUrl
  114. } = res.result
  115. if (e.currentTarget.dataset.type == 'push') {
  116. this.data.shipCerts.push({
  117. downloadUrl,
  118. fileKey,
  119. viewUrl
  120. })
  121. } else {
  122. this.data.shipCerts[e.currentTarget.dataset.index] = {
  123. downloadUrl,
  124. fileKey,
  125. viewUrl
  126. }
  127. }
  128. this.setData({
  129. shipCerts: this.data.shipCerts
  130. })
  131. }
  132. },
  133. async submit() {
  134. if (!this.data.shipName) {
  135. wx.showToast({
  136. title: '请填写船舶名称',
  137. icon: "error"
  138. })
  139. return
  140. }
  141. if (!this.data.shipMmsi) {
  142. wx.showToast({
  143. title: '请填写MMSI',
  144. icon: "error"
  145. })
  146. return
  147. }
  148. let postData = {
  149. ...this.data,
  150. loginAccountId: wx.getStorageSync('loginAccountId')
  151. }
  152. console.log(postData)
  153. delete postData.__webviewId__
  154. delete postData.step
  155. let res = await postApi('/ship/add', postData)
  156. console.log(res)
  157. return
  158. if (res.data.status == 0) {
  159. wx.switchTab({
  160. url: '/pages/shipOwnerManage/shipOwnerList/shipOwnerList',
  161. })
  162. }
  163. }
  164. })