edit.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. // pages/loadArrive/edit.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. showModal: false,
  9. defaultText: '请选择',
  10. isSubmitting: false,
  11. loadappointArray:[], //起卸预约
  12. loadappointIndex:null,
  13. fileList:[],
  14. minHour: 0,
  15. maxHour: 24,
  16. minDate: new Date().getTime(),
  17. maxDate: new Date(9999, 12, 31).getTime(),
  18. currentDate: new Date().getTime(),
  19. show: false,
  20. currentChoose: ''
  21. },
  22. openPicker() {
  23. this.setData({ show: true })
  24. },
  25. onConfirm(e) {
  26. this.setData({ show: false, currentChoose: this.formatDate(new Date(e.detail)) })
  27. },
  28. onClose() {
  29. this.setData({ show: false })
  30. },
  31. onCancel() {
  32. this.setData({ show: false })
  33. },
  34. formatDate(date) {
  35. let taskStartTime
  36. if (date.getMonth() < 9) {
  37. taskStartTime = date.getFullYear() + "-0" + (date.getMonth() + 1) + "-"
  38. } else {
  39. taskStartTime = date.getFullYear() + "-" + (date.getMonth() + 1) + "-"
  40. }
  41. if (date.getDate() < 10) {
  42. taskStartTime += "0" + date.getDate()
  43. } else {
  44. taskStartTime += date.getDate()
  45. }
  46. if (date.getHours() < 10) {
  47. taskStartTime += " " + "0" + date.getHours()
  48. } else {
  49. taskStartTime += " " + date.getHours()
  50. }
  51. if (date.getMinutes() < 10) {
  52. taskStartTime += ":" + "0" + date.getMinutes()
  53. } else {
  54. taskStartTime += ":" + date.getMinutes()
  55. }
  56. this.setData({
  57. taskStartTime: taskStartTime,
  58. })
  59. return taskStartTime;
  60. },
  61. /**
  62. * 生命周期函数--监听页面加载
  63. */
  64. onLoad: function (options) {
  65. //根据列表页面获取详情
  66. var pages = getCurrentPages();
  67. var prevPage = pages[pages.length - 2];
  68. let getInfo = prevPage.data.resData[options.index]
  69. //司机回签图片
  70. let fileList = []
  71. if(getInfo.sailFilePath){
  72. let unloadImgArr = getInfo.sailFilePath.split(',')
  73. unloadImgArr.forEach(element => {
  74. fileList.push({
  75. url : app.host.BASEIMG_URL+element,
  76. imgUrl : element,
  77. isImage : true
  78. })
  79. });
  80. }
  81. this.setData({
  82. info : getInfo,
  83. currentChoose : getInfo.arriveTime,
  84. fileList : fileList
  85. })
  86. //获取起卸预约信息
  87. this.getLoadappointData()
  88. app.request.GET({
  89. url: app.API.bizloadappointDetail,
  90. params: {'id' : getInfo.appointId},
  91. page: this,
  92. successFun: true
  93. }).then(res => {
  94. let getInfo = res.data.data;
  95. this.setData({
  96. customerName : getInfo.customerName?getInfo.customerName:"",
  97. customerContact : getInfo.customerContact?getInfo.customerContact:"",
  98. customerPhone : getInfo.customerPhone?getInfo.customerPhone:"",
  99. goodsName : getInfo.goodsName?getInfo.goodsName:"",
  100. goodsCode : getInfo.goodsCode?getInfo.goodsCode:"",
  101. })
  102. })
  103. },
  104. //选择起卸预约
  105. getLoadappointData:function(){
  106. app.request.GET({
  107. url: app.API.bizloadappointList,
  108. params: {'status' : '2,3'},
  109. page: this,
  110. successFun: true
  111. }).then(res => {
  112. let appointList = res.data.data
  113. appointList.forEach((element,index) => {
  114. appointList[index].name = element.loadNumber
  115. });
  116. this.setData({
  117. loadappointArray: appointList,
  118. loadappointIndex: app.util.getDicIndex(res.data.data, this.data.info.appointId, 'id')
  119. })
  120. })
  121. },
  122. //下拉选择
  123. bindPickerChange: function (e) {
  124. let { pickername } = e.target.dataset
  125. let getIndex = pickername + 'Index'
  126. app.util.getPickerIndex(this, getIndex, e);
  127. switch (pickername) {
  128. case 'loadappoint': //报港预约
  129. app.request.GET({
  130. url: app.API.bizloadappointDetail,
  131. params: {'id' : this.data.loadappointArray[this.data.loadappointIndex].id},
  132. page: this,
  133. successFun: true
  134. }).then(res => {
  135. let getInfo = res.data.data;
  136. this.setData({
  137. customerName : getInfo.customerName?getInfo.customerName:"",
  138. customerContact : getInfo.customerContact?getInfo.customerContact:"",
  139. customerPhone : getInfo.customerPhone?getInfo.customerPhone:"",
  140. goodsName : getInfo.goodsName?getInfo.goodsName:"",
  141. goodsCode : getInfo.goodsCode?getInfo.goodsCode:"",
  142. })
  143. })
  144. break;
  145. }
  146. },
  147. //图片上传
  148. afterRead:function(event){
  149. const { file } = event.detail;
  150. const { type } = event.currentTarget.dataset
  151. app.request.uploadDIY({
  152. url: app.API.uploadImgMap,
  153. page: this,
  154. filePaths:file.url,
  155. setfiled:'file',
  156. params: {},
  157. //isToken: false,
  158. isLoading: false,
  159. successFun: true
  160. }).then(res => {
  161. const imgArray = this.data[type];
  162. imgArray.push({
  163. ...file,
  164. url: app.host.BASEIMG_URL + JSON.parse(res.data).data.imageFile,
  165. imgUrl: JSON.parse(res.data).data.imageFile
  166. });
  167. this.setData({
  168. [type]: imgArray
  169. });
  170. })
  171. },
  172. // 删除图片
  173. deleteImg: function (event) {
  174. const { type } = event.currentTarget.dataset
  175. let getFileList = this.data[type];
  176. getFileList.splice(event.detail.index, 1)
  177. this.setData({
  178. [type]: getFileList
  179. })
  180. },
  181. // 单选
  182. dangerStatusChange: function (e) {
  183. this.setData({
  184. [e.currentTarget.dataset.radiotype]: e.detail.value
  185. })
  186. },
  187. //多选
  188. checkboxChange: function (e) {
  189. this.setData({
  190. [e.currentTarget.dataset.checkboxtype]: e.detail
  191. })
  192. },
  193. /**
  194. * 页面上拉触底事件的处理函数
  195. */
  196. bindscrolltolowerFun() {
  197. },
  198. //表单提交 carTaskAdd
  199. formSubmit: function ({detail:{value}}) {
  200. var warn = ""; //弹框时提示的内容
  201. if (value.appointId == '') {
  202. warn = "请选择起卸预约订单!";
  203. } else if(value.shipNo == ''){
  204. warn = "请输入船号!";
  205. } else if(value.arriveNumber == ''){
  206. warn = "请输入报港数量!";
  207. } else if(value.arriveTime == ''){
  208. warn = "请选择到港时间!";
  209. }
  210. /** 图片处理 START **/
  211. let getfileList = this.data.fileList
  212. if(getfileList.length < 1){
  213. warn = "请上传发航单!";
  214. }
  215. let fileNameList = []
  216. let filePathList = []
  217. getfileList.forEach((element,index) => {
  218. fileNameList.push('图片'+(index+1)+'.'+element.imgUrl.split('.')[1])
  219. filePathList.push(element.imgUrl)
  220. });
  221. value.fileNameList = fileNameList
  222. value.filePathList = filePathList
  223. /** 图片处理 END **/
  224. // 处理时间
  225. value.arriveTime = value.arriveTime + ":00"
  226. if (warn != '') {
  227. app.util.checkForm(warn);
  228. } else {
  229. app.request.POST({
  230. url: app.API.bizloadarriveEdit,
  231. params: value,
  232. page: this,
  233. isLoadingTxt: '提交中...',
  234. isSubmitting: true,
  235. successFun: true
  236. }).then(res => {
  237. wx.showToast({
  238. title: '修改成功',
  239. icon: 'success',
  240. duration: 2000,
  241. mask:true,
  242. complete: function () {
  243. setTimeout(() => {
  244. wx.navigateBack()
  245. }, 1500) //延迟时间
  246. }
  247. })
  248. })
  249. }
  250. },
  251. /**
  252. * 生命周期函数--监听页面初次渲染完成
  253. */
  254. onReady: function () {
  255. },
  256. /**
  257. * 生命周期函数--监听页面显示
  258. */
  259. onShow: function () {
  260. },
  261. /**
  262. * 生命周期函数--监听页面隐藏
  263. */
  264. onHide: function () {
  265. },
  266. /**
  267. * 生命周期函数--监听页面卸载
  268. */
  269. onUnload: function () {
  270. },
  271. /**
  272. * 页面相关事件处理函数--监听用户下拉动作
  273. */
  274. onPullDownRefresh: function () {
  275. },
  276. /**
  277. * 页面上拉触底事件的处理函数
  278. */
  279. onReachBottom: function () {
  280. },
  281. /**
  282. * 用户点击右上角分享
  283. */
  284. onShareAppMessage: function () {
  285. }
  286. })