edit.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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. isImage:true
  77. })
  78. });
  79. }
  80. this.setData({
  81. info : getInfo,
  82. currentChoose : getInfo.arriveTime,
  83. fileList : fileList
  84. })
  85. //获取起卸预约信息
  86. this.getLoadappointData()
  87. app.request.GET({
  88. url: app.API.bizloadappointDetail,
  89. params: {'id' : getInfo.appointId},
  90. page: this,
  91. successFun: true
  92. }).then(res => {
  93. let getInfo = res.data.data;
  94. this.setData({
  95. customerName : getInfo.customerName?getInfo.customerName:"",
  96. customerContact : getInfo.customerContact?getInfo.customerContact:"",
  97. customerPhone : getInfo.customerPhone?getInfo.customerPhone:"",
  98. goodsName : getInfo.goodsName?getInfo.goodsName:"",
  99. goodsCode : getInfo.goodsCode?getInfo.goodsCode:"",
  100. })
  101. })
  102. },
  103. //选择起卸预约
  104. getLoadappointData:function(){
  105. app.request.GET({
  106. url: app.API.bizloadappointList,
  107. params: {'status' : '2,3'},
  108. page: this,
  109. successFun: true
  110. }).then(res => {
  111. let appointList = res.data.data
  112. appointList.forEach((element,index) => {
  113. appointList[index].name = element.loadNumber
  114. });
  115. this.setData({
  116. loadappointArray: appointList,
  117. loadappointIndex: app.util.getDicIndex(res.data.data, this.data.info.appointId, 'id')
  118. })
  119. })
  120. },
  121. //下拉选择
  122. bindPickerChange: function (e) {
  123. let { pickername } = e.target.dataset
  124. let getIndex = pickername + 'Index'
  125. app.util.getPickerIndex(this, getIndex, e);
  126. switch (pickername) {
  127. case 'loadappoint': //报港预约
  128. app.request.GET({
  129. url: app.API.bizloadappointDetail,
  130. params: {'id' : this.data.loadappointArray[this.data.loadappointIndex].id},
  131. page: this,
  132. successFun: true
  133. }).then(res => {
  134. let getInfo = res.data.data;
  135. this.setData({
  136. customerName : getInfo.customerName?getInfo.customerName:"",
  137. customerContact : getInfo.customerContact?getInfo.customerContact:"",
  138. customerPhone : getInfo.customerPhone?getInfo.customerPhone:"",
  139. goodsName : getInfo.goodsName?getInfo.goodsName:"",
  140. goodsCode : getInfo.goodsCode?getInfo.goodsCode:"",
  141. })
  142. })
  143. break;
  144. }
  145. },
  146. //图片上传
  147. afterRead:function(event){
  148. const { file } = event.detail;
  149. const { type } = event.currentTarget.dataset
  150. app.request.uploadDIY({
  151. url: app.API.uploadImgMap,
  152. page: this,
  153. filePaths:file.url,
  154. setfiled:'file',
  155. params: {},
  156. //isToken: false,
  157. isLoading: false,
  158. successFun: true
  159. }).then(res => {
  160. const imgArray = this.data[type];
  161. imgArray.push({
  162. ...file,
  163. url: app.host.BASEIMG_URL + JSON.parse(res.data).data.imageFile,
  164. imgUrl: JSON.parse(res.data).data.imageFile
  165. });
  166. this.setData({
  167. [type]: imgArray
  168. });
  169. })
  170. },
  171. // 删除图片
  172. deleteImg: function (event) {
  173. const { type } = event.currentTarget.dataset
  174. let getFileList = this.data[type];
  175. getFileList.splice(event.detail.index, 1)
  176. this.setData({
  177. [type]: getFileList
  178. })
  179. },
  180. // 单选
  181. dangerStatusChange: function (e) {
  182. this.setData({
  183. [e.currentTarget.dataset.radiotype]: e.detail.value
  184. })
  185. },
  186. //多选
  187. checkboxChange: function (e) {
  188. this.setData({
  189. [e.currentTarget.dataset.checkboxtype]: e.detail
  190. })
  191. },
  192. /**
  193. * 页面上拉触底事件的处理函数
  194. */
  195. bindscrolltolowerFun() {
  196. },
  197. //表单提交 carTaskAdd
  198. formSubmit: function ({detail:{value}}) {
  199. var warn = ""; //弹框时提示的内容
  200. if (value.appointId == '') {
  201. warn = "请选择起卸预约订单!";
  202. } else if(value.shipNo == ''){
  203. warn = "请输入船号!";
  204. } else if(value.arriveNumber == ''){
  205. warn = "请输入报港数量!";
  206. } else if(value.arriveTime == ''){
  207. warn = "请选择到港时间!";
  208. }
  209. /** 图片处理 START **/
  210. let getfileList = this.data.fileList
  211. if(getfileList.length < 1){
  212. warn = "请上传发航单!";
  213. }
  214. let fileNameList = []
  215. let filePathList = []
  216. getfileList.forEach((element,index) => {
  217. fileNameList.push('图片'+(index+1)+'.'+element.imgUrl.split('.')[1])
  218. filePathList.push(element.imgUrl)
  219. });
  220. value.fileNameList = fileNameList
  221. value.filePathList = filePathList
  222. /** 图片处理 END **/
  223. // 处理时间
  224. value.arriveTime = value.arriveTime + ":00"
  225. if (warn != '') {
  226. app.util.checkForm(warn);
  227. } else {
  228. app.request.POST({
  229. url: app.API.bizloadarriveEdit,
  230. params: value,
  231. page: this,
  232. isLoadingTxt: '提交中...',
  233. isSubmitting: true,
  234. successFun: true
  235. }).then(res => {
  236. wx.showToast({
  237. title: '修改成功',
  238. icon: 'success',
  239. duration: 2000,
  240. mask:true,
  241. complete: function () {
  242. setTimeout(() => {
  243. wx.navigateBack()
  244. }, 1500) //延迟时间
  245. }
  246. })
  247. })
  248. }
  249. },
  250. /**
  251. * 生命周期函数--监听页面初次渲染完成
  252. */
  253. onReady: function () {
  254. },
  255. /**
  256. * 生命周期函数--监听页面显示
  257. */
  258. onShow: function () {
  259. },
  260. /**
  261. * 生命周期函数--监听页面隐藏
  262. */
  263. onHide: function () {
  264. },
  265. /**
  266. * 生命周期函数--监听页面卸载
  267. */
  268. onUnload: function () {
  269. },
  270. /**
  271. * 页面相关事件处理函数--监听用户下拉动作
  272. */
  273. onPullDownRefresh: function () {
  274. },
  275. /**
  276. * 页面上拉触底事件的处理函数
  277. */
  278. onReachBottom: function () {
  279. },
  280. /**
  281. * 用户点击右上角分享
  282. */
  283. onShareAppMessage: function () {
  284. }
  285. })