add.js 6.8 KB

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