addShipOnwer.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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("/cos/upload", {
  70. type: 1
  71. })
  72. if (res.status == 0) {
  73. if (e.currentTarget.dataset.type == 'head') {
  74. let {
  75. idcardFrontFileKey,
  76. idcardFrontViewUrl,
  77. idcardFrontDownloadUrl,
  78. } = this
  79. idcardFrontFileKey = res.result.key
  80. idcardFrontViewUrl = res.result.viewUrl
  81. idcardFrontDownloadUrl = res.result.downloadUrl
  82. this.setData({
  83. idcardFrontFileKey,
  84. idcardFrontViewUrl,
  85. idcardFrontDownloadUrl,
  86. })
  87. } else {
  88. let {
  89. idcardBackFileKey,
  90. idcardBackViewUrl,
  91. idcardBackDownloadUrl,
  92. } = this
  93. idcardBackFileKey = res.result.key
  94. idcardBackViewUrl = res.result.viewUrl
  95. idcardBackDownloadUrl = res.result.downloadUrl
  96. this.setData({
  97. idcardBackFileKey,
  98. idcardBackViewUrl,
  99. idcardBackDownloadUrl,
  100. })
  101. }
  102. }
  103. },
  104. async uploadShipCerts(e) {
  105. let res = await uploadImage("/cos/upload", {
  106. type: 2
  107. })
  108. if (res.status == 0) {
  109. let {
  110. downloadUrl,
  111. key: fileKey,
  112. viewUrl
  113. } = res.result
  114. if (e.currentTarget.dataset.type == 'push') {
  115. this.data.shipCerts.push({
  116. downloadUrl,
  117. fileKey,
  118. viewUrl
  119. })
  120. } else {
  121. this.data.shipCerts[e.currentTarget.dataset.index] = {
  122. downloadUrl,
  123. fileKey,
  124. viewUrl
  125. }
  126. }
  127. this.setData({
  128. shipCerts: this.data.shipCerts
  129. })
  130. }
  131. },
  132. async submit() {
  133. if (!this.data.shipName) {
  134. wx.showToast({
  135. title: '请填写船舶名称',
  136. icon: "error"
  137. })
  138. return
  139. }
  140. if (!this.data.shipMmsi) {
  141. wx.showToast({
  142. title: '请填写MMSI',
  143. icon: "error"
  144. })
  145. return
  146. }
  147. let postData = {
  148. ...this.data,
  149. loginAccountId: wx.getStorageSync('loginAccountId')
  150. }
  151. console.log(postData)
  152. delete postData.__webviewId__
  153. delete postData.step
  154. let res = await postApi('/ship/add', postData)
  155. wx.setStorageSync('apiStatus', 'success')
  156. if (res.data.status == 0) {
  157. wx.switchTab({
  158. url: '/pages/shipOwnerManage/shipOwnerList/shipOwnerList',
  159. })
  160. } else {
  161. wx.showToast({
  162. title: res.data.msg,
  163. icon: "error"
  164. })
  165. }
  166. }
  167. })