edit.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. // pages/car/edit.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. showModal: false,
  9. defaultText: '请选择',
  10. isSubmitting: false,
  11. shipTypeArray: [], //船型
  12. shipTypeIndex: null,
  13. shipArray:[], //船主
  14. shipIndex:null,
  15. certificatePathList:[], //船舶证书
  16. contractPathList:[], //安全环保合同
  17. statusFlag:'true', //是否启用状态 1:启用 2:关闭
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. if (wx.getStorageSync('loginStatus')) {
  24. //船型
  25. let treeData = app.globalData.treeArr
  26. for (const element of treeData) {
  27. let arrStr;
  28. switch (element.dictValue) {
  29. case 'ship_type':
  30. arrStr = "shipTypeArray";
  31. break;
  32. }
  33. this.setData({
  34. [arrStr]: element.children
  35. })
  36. }
  37. //获取详情
  38. var pages = getCurrentPages();
  39. var prevPage = pages[pages.length - 2];
  40. let getInfo = prevPage.data.resData[options.index]
  41. //船舶证书 certificatePathList
  42. let certificatePathList = []
  43. if(getInfo.shipCertificatePath){
  44. let unloadImgArr = getInfo.shipCertificatePath.split(',')
  45. unloadImgArr.forEach(element => {
  46. certificatePathList.push({
  47. url : app.host.BASEIMG_URL+element,
  48. imgUrl : element,
  49. isImage : true
  50. })
  51. });
  52. }
  53. //安全环保合同 contractPathList
  54. let contractPathList = []
  55. if(getInfo.contractPath){
  56. let unloadImgArr = getInfo.contractPath.split(',')
  57. unloadImgArr.forEach(element => {
  58. contractPathList.push({
  59. url : app.host.BASEIMG_URL+element,
  60. imgUrl : element,
  61. isImage : true
  62. })
  63. });
  64. }
  65. this.setData({
  66. info : getInfo,
  67. shipId : getInfo.shipId ? getInfo.shipId : wx.getStorageSync('id'),
  68. shipType : getInfo.shipType,
  69. certificatePathList : certificatePathList,
  70. contractPathList : contractPathList
  71. })
  72. //获取船主下拉列表
  73. this.loadUserData()
  74. } else {
  75. wx.switchTab({
  76. url: '/pages/center/index',
  77. })
  78. }
  79. },
  80. //船主
  81. loadUserData:function(){
  82. app.request.GET({
  83. url: app.API.roleUser,
  84. params: {
  85. roleName : '船主',
  86. },
  87. page: this,
  88. successFun: true
  89. }).then(res => {
  90. this.setData({
  91. shipArray : res.data.data,
  92. shipIndex : app.util.getDicIndex(res.data.data, this.data.shipId, 'id')
  93. })
  94. if(this.data.shipId){
  95. this.setData({
  96. shipMobile : this.data.shipArray[this.data.shipIndex].phone,
  97. })
  98. }
  99. })
  100. },
  101. //下拉选择
  102. bindPickerChange: function (e) {
  103. let { pickername } = e.target.dataset
  104. let getIndex = pickername + 'Index'
  105. app.util.getPickerIndex(this, getIndex, e);
  106. switch (pickername) {
  107. case 'ship': //选择船主
  108. this.setData({
  109. shipMobile : this.data.shipArray[this.data.shipIndex].phone,
  110. })
  111. break;
  112. }
  113. },
  114. // 单选
  115. dangerStatusChange: function (e) {
  116. this.setData({
  117. [e.currentTarget.dataset.radiotype]: e.detail.value
  118. })
  119. },
  120. //多选
  121. checkboxChange: function (e) {
  122. this.setData({
  123. [e.currentTarget.dataset.checkboxtype]: e.detail
  124. })
  125. },
  126. //图片上传
  127. afterRead:function(event){
  128. const { file } = event.detail;
  129. const { type } = event.currentTarget.dataset
  130. app.request.uploadDIY({
  131. url: app.API.uploadImgMap,
  132. page: this,
  133. filePaths:file.url,
  134. setfiled:'file',
  135. params: {},
  136. //isToken: false,
  137. isLoading: false,
  138. successFun: true
  139. }).then(res => {
  140. const imgArray = this.data[type];
  141. imgArray.push({
  142. ...file,
  143. url: app.host.BASEIMG_URL + JSON.parse(res.data).data.imageFile,
  144. imgUrl: JSON.parse(res.data).data.imageFile
  145. });
  146. this.setData({
  147. [type]: imgArray
  148. });
  149. })
  150. },
  151. // 删除图片
  152. deleteImg: function (event) {
  153. const { type } = event.currentTarget.dataset
  154. let getFileList = this.data[type];
  155. getFileList.splice(event.detail.index, 1)
  156. this.setData({
  157. [type]: getFileList
  158. })
  159. },
  160. //开关
  161. onChange(e) {
  162. let { switchType } = e.currentTarget.dataset
  163. let number = 0
  164. if(e.detail=='1'){
  165. if(this.data.blackSwitch=='1'){
  166. number = number+1
  167. }
  168. if(this.data.whiteSwitch=='1'){
  169. number = number+1
  170. }
  171. if(this.data.internal=='1'){
  172. number = number+1
  173. }
  174. if(number<1){
  175. // 需要手动对 checked 状态进行更新
  176. this.setData({
  177. [switchType]: e.detail
  178. });
  179. }else{
  180. app.util.checkForm('黑白名单及内部车辆最多只能开启一项');
  181. }
  182. }else{
  183. this.setData({
  184. [switchType]: e.detail
  185. });
  186. }
  187. },
  188. //提交事件
  189. formSubmit: function ({detail:{value}}) {
  190. var warn = ""; //弹框时提示的内容
  191. /** 船舶证书 certificatePathList (必传) 图片处理 START **/
  192. let getcertificatePathList = this.data.certificatePathList
  193. if(getcertificatePathList.length < 1){
  194. warn = "请上传船舶证书图片!";
  195. }
  196. let certificateNameList = []
  197. let certificatePathList = []
  198. getcertificatePathList.forEach((element,index) => {
  199. certificateNameList.push('图片'+(index+1)+'.'+element.imgUrl.split('.')[1])
  200. certificatePathList.push(element.imgUrl)
  201. });
  202. value.certificateNameList = certificateNameList
  203. value.certificatePathList = certificatePathList
  204. /** 图片处理 END **/
  205. /** 安全环保合同 contractPathList (非必传) 图片处理 START **/
  206. let getcontractPathList = this.data.contractPathList
  207. if(getcontractPathList.length < 1){
  208. // warn = "请上传安全环保合同!";
  209. }else{
  210. // 上传了安保合同才处理
  211. let contractNameList = []
  212. let contractPathList = []
  213. getcontractPathList.forEach((element,index) => {
  214. contractNameList.push('图片'+(index+1)+'.'+element.imgUrl.split('.')[1])
  215. contractPathList.push(element.imgUrl)
  216. });
  217. value.contractNameList = contractNameList
  218. value.contractPathList = contractPathList
  219. }
  220. /** 图片处理 END **/
  221. if (value.shipNumber == '') {
  222. warn = "请输入船舶号";
  223. } else if (value.shipType == '') {
  224. warn = "请输入船型";
  225. } else if (value.shipId == '') {
  226. warn = "请选择船主";
  227. } else if (value.statusFlag == '') {
  228. warn = "请选择是否启用";
  229. }
  230. value.status = value.statusFlag=='true'?'1':'2'
  231. if (warn != '') {
  232. app.util.checkForm(warn);
  233. } else {
  234. app.request.POST({
  235. url: app.API.shipEdit,
  236. params: value,
  237. page: this,
  238. isLoadingTxt: '提交中...',
  239. isSubmitting: true,
  240. successFun: true
  241. }).then(res => {
  242. wx.showToast({
  243. title: '修改成功',
  244. icon: 'success',
  245. duration: 2000,
  246. mask:true,
  247. complete: function () {
  248. setTimeout(() => {
  249. wx.navigateBack()
  250. }, 1500) //延迟时间
  251. }
  252. })
  253. })
  254. }
  255. }
  256. })