detail.js 4.0 KB

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