detail.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import * as requestAPI from '../../models/dataModel'
  2. Page({
  3. data: {
  4. contractDetail: {},
  5. mark: '',
  6. tempMark: '',
  7. sscId: '',
  8. pId: '',
  9. imageList: [],
  10. showAllPic: false,
  11. allImgList: []
  12. },
  13. onLoad: function (options) {
  14. this.setData({
  15. sscId: options.sscId,
  16. pId: options.pId
  17. })
  18. this.getDetail(options.sscId, options.pId)
  19. this.getQaLog(options.sscId, options.pId)
  20. },
  21. // 获取采购合同详情
  22. getDetail(sscId, pId) {
  23. requestAPI.getContractDetail(sscId, pId).then(res => {
  24. this.setData({
  25. contractDetail: res.data.data
  26. })
  27. })
  28. },
  29. // 获取qa日志
  30. getQaLog(sscId, pId) {
  31. requestAPI.getContractQaLog(sscId, pId).then(res => {
  32. let allImgList = [] // 全部图片
  33. let lessImgList = [] // 部分图片
  34. if (res.data.data.length !== 0) {
  35. this.setData({
  36. mark: res.data.data[0].mark
  37. })
  38. if(res.data.data[0].picture) {
  39. allImgList = res.data.data[0].picture.split(',')
  40. for(let i = 0;i<res.data.data[0].picture.split(',').length&&i<2;i++) {
  41. lessImgList.push(res.data.data[0].picture.split(',')[i])
  42. }
  43. this.setData({
  44. allImgList: allImgList
  45. })
  46. this.setData({
  47. imageList: this.data.showAllPic?allImgList:lessImgList
  48. })
  49. }
  50. }
  51. })
  52. },
  53. getAllImg() {
  54. this.setData({
  55. showAllPic: true
  56. })
  57. this.getQaLog(this.data.sscId, this.data.pId)
  58. },
  59. getTempMark(e) {
  60. this.setData({
  61. tempMark: e.detail.value
  62. })
  63. },
  64. // 保存或添加qa日志
  65. saveQaLog(e) {
  66. this.setData({
  67. mark: e.detail.value
  68. })
  69. if (this.data.mark !== this.data.tempMark) {
  70. if (this.data.tempMark) {
  71. requestAPI.changeContractQaLog(this.data.sscId, this.data.pId, this.data.mark).then(res => {
  72. if (res.data.code === 0) {
  73. wx.showToast({
  74. title: '保存成功',
  75. icon: 'success',
  76. duration: 3000
  77. })
  78. setTimeout(() => {
  79. this.getQaLog(this.data.sscId, this.data.pId)
  80. }, 500)
  81. }
  82. })
  83. } else {
  84. requestAPI.addContractQaLog(this.data.sscId, this.data.pId, this.data.mark).then(res => {
  85. if (res.data.code === 0) {
  86. wx.showToast({
  87. title: '保存成功',
  88. icon: 'success',
  89. duration: 3000
  90. })
  91. setTimeout(() => {
  92. this.getQaLog(this.data.sscId, this.data.pId)
  93. }, 500)
  94. }
  95. })
  96. }
  97. }
  98. },
  99. // 拍照
  100. takePhoto() {
  101. this.getPhotos(1, 'camera')
  102. },
  103. choosePhoto() {
  104. this.getPhotos(9, 'albumn')
  105. },
  106. getPhotos(count, type) {
  107. let _this = this
  108. wx.chooseImage({
  109. count: count,
  110. sizeType: ['original', 'compressed'],
  111. sourceType: [type],
  112. success(res) {
  113. for (let i of res.tempFilePaths) {
  114. wx.uploadFile({
  115. url: `http://192.168.20.52:9999/inventory/supplier/contract/qalog/upload/picture?sscId=${_this.data.sscId}&pId=${_this.data.pId}`, //此处换上你的接口地址
  116. filePath: i,
  117. name: 'file',
  118. header: {
  119. "Content-Type": "multipart/form-data",
  120. 'Authorization': `Bearer ${wx.getStorageSync('token')}`,
  121. },
  122. success: function (res) {
  123. wx.showToast({
  124. title: '上传成功',
  125. icon: 'success',
  126. duration: 2000
  127. })
  128. _this.getQaLog(_this.data.sscId, _this.data.pId)
  129. }
  130. })
  131. }
  132. }
  133. })
  134. },
  135. // 删除qa图片
  136. delImg: function (event) {
  137. requestAPI.delContractPic(this.data.sscId, this.data.pId, event.currentTarget.dataset.url).then(res=>{
  138. this.getQaLog(this.data.sscId, this.data.pId)
  139. })
  140. },
  141. openPreview: function (event) {
  142. wx.previewImage({
  143. urls: this.data.imageList,
  144. current: event.currentTarget.dataset.current
  145. })
  146. }
  147. })