order.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // pages/control/order/order.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. fileList: [],
  9. },
  10. /**
  11. * 生命周期函数--监听页面加载
  12. */
  13. onLoad: function (options) {
  14. this.setData({
  15. wash_code:options.wash_code
  16. })
  17. this.getdesc()
  18. },
  19. toResult(){
  20. var that = this;
  21. var fileList=this.data.fileList;
  22. var images=[]
  23. fileList.map((item, index) => {
  24. images[index]=item.url
  25. })
  26. if(images=="" || images==[]){
  27. wx.showLoading({
  28. title: "你忘记拍照了",
  29. })
  30. setTimeout(function () {
  31. wx.hideLoading();
  32. }, 1000);
  33. return false;
  34. }
  35. app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/hand/hand_up", {
  36. wash_code:this.data.wash_code,
  37. images:images
  38. }, "post").then(function (res) {
  39. console.log(res);
  40. if (res.code != 200) {
  41. wx.showLoading({
  42. title: res.message.msg,
  43. })
  44. setTimeout(function () {
  45. wx.hideLoading();
  46. }, 1000);
  47. } else {
  48. wx.hideLoading();
  49. var data = res.message.data
  50. wx.showLoading({
  51. title: res.message.msg,
  52. })
  53. setTimeout(function () {
  54. wx.hideLoading();
  55. wx.navigateTo({
  56. url: '../result/result?data='+JSON.stringify(data),
  57. })
  58. }, 1000);
  59. }
  60. }).catch(function (err) {
  61. console.log(222);
  62. })
  63. },
  64. getdesc(){
  65. var that = this;
  66. app.api.useApi(app.globalData.baseAppUrl + "api/admin/sorting/entry/desc", {
  67. wash_code:this.data.wash_code,
  68. }, "get").then(function (res) {
  69. console.log(res);
  70. if (res.code != 200) {
  71. wx.showLoading({
  72. title: res.message.msg,
  73. })
  74. setTimeout(function () {
  75. wx.hideLoading();
  76. wx.navigateBack({
  77. delta: 1 //想要返回的层级
  78. })
  79. }, 1000);
  80. } else {
  81. wx.hideLoading();
  82. let data = res.message.data
  83. that.setData({
  84. data
  85. })
  86. }
  87. }).catch(function (err) {
  88. console.log(222);
  89. })
  90. },
  91. afterRead(event) {
  92. var that=this;
  93. const { file } = event.detail;
  94. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  95. wx.uploadFile({
  96. url: app.globalData.baseAppUrl + 'api/common/uploadImg', // 仅为示例,非真实的接口地址
  97. filePath: file.url,
  98. header: {
  99. "Content-Type": "multipart/form-data",
  100. 'accept': 'application/json',
  101. },
  102. name: 'file',
  103. formData: { user: 'test' },
  104. success(res) {
  105. var datas = JSON.parse(res.data)
  106. console.log(datas);
  107. if(datas.code==200){
  108. // 上传完成需要更新 fileList
  109. const { fileList = [] } = that.data;
  110. fileList.push({ ...file, url: datas.message.data.path });
  111. that.setData({ fileList });
  112. }else{
  113. wx.showLoading({
  114. title: datas.message.msg,
  115. })
  116. setTimeout(function () {
  117. wx.hideLoading();
  118. }, 1000);
  119. }
  120. },
  121. });
  122. },
  123. oncloes(){
  124. wx.navigateBack({
  125. delta: 1 //想要返回的层级
  126. })
  127. }
  128. })