detail.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import * as requestAPI from '../../models/dataModel'
  2. Page({
  3. data: {
  4. sampleDetail: {},
  5. mark: '',
  6. tempMark: '',
  7. sdpId: '',
  8. imageList: []
  9. },
  10. onLoad: function (options) {
  11. this.setData({
  12. sdpId: options.sdpId
  13. })
  14. this.getDetail(options.sdpId)
  15. this.getQaLog(options.sdpId)
  16. },
  17. // 获取样品单详情
  18. getDetail(sdpId) {
  19. requestAPI.getSampleDetail(sdpId).then(res => {
  20. this.setData({
  21. sampleDetail: res.data.data
  22. })
  23. })
  24. },
  25. // 获取qa日志
  26. getQaLog(sdpId) {
  27. requestAPI.getSampleQaLog(sdpId).then(res => {
  28. if (res.data.data.length !== 0) {
  29. this.setData({
  30. mark: res.data.data[0].mark
  31. })
  32. }
  33. })
  34. },
  35. getTempMark(e) {
  36. this.setData({
  37. tempMark: e.detail.value
  38. })
  39. },
  40. // 保存或添加qa日志
  41. saveQaLog(e) {
  42. this.setData({
  43. mark: e.detail.value
  44. })
  45. if (this.data.mark !== this.data.tempMark) {
  46. if (this.data.tempMark) {
  47. requestAPI.changeSampleQaLog(this.data.sdpId, this.data.mark).then(res => {
  48. if (res.data.code === 0) {
  49. wx.showToast({
  50. title: '保存成功',
  51. icon: 'success',
  52. duration: 3000
  53. })
  54. setTimeout(() => {
  55. this.getQaLog(this.data.sdpId)
  56. }, 500)
  57. }
  58. })
  59. } else {
  60. requestAPI.addSampleQaLog(this.data.sdpId, this.data.mark).then(res => {
  61. if (res.data.code === 0) {
  62. wx.showToast({
  63. title: '保存成功',
  64. icon: 'success',
  65. duration: 3000
  66. })
  67. setTimeout(() => {
  68. this.getQaLog(this.data.sdpId)
  69. }, 500)
  70. }
  71. })
  72. }
  73. }
  74. },
  75. // 拍照
  76. takePhoto() {
  77. this.getPhotos(1, 'camera')
  78. },
  79. choosePhoto() {
  80. this.getPhotos(9, 'albumn')
  81. },
  82. getPhotos(count, type) {
  83. let tempList = this.data.imageList
  84. let _this = this
  85. wx.chooseImage({
  86. count: count,
  87. sizeType: ['original', 'compressed'],
  88. sourceType: [type],
  89. success(res) {
  90. for (let i of res.tempFilePaths) {
  91. console.log(i)
  92. wx.uploadFile({
  93. url: `http://192.168.20.111:9999/inventory/sample/qalog/upload/picture?sdpId=${_this.data.sdpId}`, //此处换上你的接口地址
  94. filePath: i,
  95. name: 'file',
  96. header: {
  97. "Content-Type": "multipart/form-data",
  98. 'Authorization': `Bearer ${wx.getStorageSync('token')}`,
  99. },
  100. success: function (res) {
  101. console.log(res);
  102. // let data = JSON.parse(res.data); // 这个很关键
  103. // tempList.push(data.data.url);
  104. // _this.setData({
  105. // imageList: tempList
  106. // })
  107. }
  108. })
  109. }
  110. // for(let i of res.tempFilePaths) {
  111. // tempList.push(i)
  112. // }
  113. // _this.setData({
  114. // imageList: tempList
  115. // })
  116. }
  117. })
  118. },
  119. delImg: function (event) {
  120. console.log('s')
  121. let tempList = this.data.imageList
  122. tempList.splice(event.currentTarget.dataset.index, 1)
  123. this.setData({
  124. imageList: tempList
  125. })
  126. },
  127. openPreview: function (event) {
  128. wx.previewImage({
  129. urls: this.data.imageList,
  130. current: event.currentTarget.dataset.current
  131. })
  132. }
  133. })