signFor.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // pages/signReview/signFor.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. id:'',
  9. info:{},
  10. unloadWeight:'',
  11. fileList:[],
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad(options) {
  17. console.log(options)
  18. this.setData({
  19. id:options.id
  20. })
  21. },
  22. //图片上传
  23. afterRead:function(event){
  24. const { file } = event.detail;
  25. const { type } = event.currentTarget.dataset
  26. app.request.uploadDIY({
  27. url: app.API.uploadImgMap,
  28. page: this,
  29. filePaths:file.url,
  30. setfiled:'file',
  31. params: {},
  32. //isToken: false,
  33. isLoading: false,
  34. successFun: true
  35. }).then(res => {
  36. const imgArray = this.data[type];
  37. imgArray.push({
  38. ...file,
  39. url: app.host.BASEIMG_URL + JSON.parse(res.data).data.imageFile,
  40. imgUrl: JSON.parse(res.data).data.imageFile
  41. });
  42. this.setData({
  43. [type]: imgArray
  44. });
  45. })
  46. },
  47. // 删除图片
  48. deleteImg: function (event) {
  49. const { type } = event.currentTarget.dataset
  50. let getFileList = this.data[type];
  51. getFileList.splice(event.detail.index, 1)
  52. this.setData({
  53. [type]: getFileList
  54. })
  55. },
  56. //输入框实时更新
  57. onChange: function (e) {
  58. this.setData({
  59. unloadWeight: app.util.digitLength(e.detail)
  60. })
  61. },
  62. //表单提交
  63. formSubmit: function ({detail:{value}}) {
  64. let warn=''
  65. let getfileList = this.data.fileList
  66. if (value.unloadWeight == '') {
  67. warn = "请填写卸货重量!";
  68. }else if(getfileList.length<1){
  69. warn = "请上传图片!";
  70. }
  71. let fileNameList = []
  72. let filePathList = []
  73. getfileList.forEach((element,index) => {
  74. fileNameList.push('图片'+(index+1)+'.'+element.imgUrl.split('.')[1])
  75. filePathList.push(element.imgUrl)
  76. });
  77. value.fileNameList = fileNameList
  78. value.filePathList = filePathList
  79. // value.fileNameList = fileNameList.join(',')
  80. // value.filePathList = filePathList.join(',')
  81. if (warn != '') {
  82. app.util.checkForm(warn);
  83. } else {
  84. app.request.POST({
  85. url: app.API.updateWeight,
  86. params: value,
  87. page: this,
  88. isLoadingTxt: '提交中...',
  89. isSubmitting: true,
  90. successFun: true
  91. }).then(res => {
  92. wx.showToast({
  93. title: '签收成功',
  94. icon: 'success',
  95. duration: 2000,
  96. mask:true,
  97. complete: function () {
  98. setTimeout(() => {
  99. wx.navigateBack()
  100. }, 1500) //延迟时间
  101. }
  102. })
  103. })
  104. }
  105. },
  106. /**
  107. * 生命周期函数--监听页面初次渲染完成
  108. */
  109. onReady() {
  110. },
  111. /**
  112. * 生命周期函数--监听页面显示
  113. */
  114. onShow() {
  115. },
  116. /**
  117. * 生命周期函数--监听页面隐藏
  118. */
  119. onHide() {
  120. },
  121. /**
  122. * 生命周期函数--监听页面卸载
  123. */
  124. onUnload() {
  125. },
  126. /**
  127. * 页面相关事件处理函数--监听用户下拉动作
  128. */
  129. onPullDownRefresh() {
  130. },
  131. /**
  132. * 页面上拉触底事件的处理函数
  133. */
  134. onReachBottom() {
  135. },
  136. /**
  137. * 用户点击右上角分享
  138. */
  139. onShareAppMessage() {
  140. }
  141. })