commissionAgreement.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <view>
  3. <view class="cmain" style="padding-bottom: 85px">
  4. <view class="form_group">
  5. <view class="lable re">互助委托协议上传</view>
  6. <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple style="margin: 15px auto;"></u-upload>
  7. </view>
  8. </view>
  9. <view class="mfooter">
  10. <view class="flex">
  11. <view class="f"><button class="btn" @click="save()">提交</button></view>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. fileList1: [],
  21. imgList: [],
  22. id: null,
  23. importOrderList: {}
  24. }
  25. },
  26. onLoad(e) {
  27. this.fileList1 = []
  28. imgList: []
  29. if(e.id) {
  30. this.id = e.id
  31. this.http.request({
  32. url: '/level-one-server/app/TbImportOrder/getById',
  33. data: { id: this.id },
  34. success: res => {//this.http.ip
  35. this.importOrderList = res.data.data;
  36. console.log(JSON.parse(this.importOrderList.cooperEntrustImg))
  37. let data = JSON.parse(this.importOrderList.cooperEntrustImg)
  38. data.forEach((item) => {
  39. this.fileList1.push({url: this.http.ip+item});
  40. this.imgList.push({item});
  41. })
  42. }
  43. });
  44. }
  45. },
  46. methods: {
  47. save() {
  48. /* let rule = [
  49. {
  50. name: 'cardFront',
  51. checkType: 'notnull',
  52. errorMsg: '请上传互助委托协议'
  53. }
  54. ];
  55. if (!this.verify.check(this.item, rule)) {
  56. uni.showModal({
  57. content: this.verify.error,
  58. showCancel: false
  59. });
  60. return false;
  61. } */
  62. this.http.request({
  63. url: '/level-one-server/app/TbImportOrder/update',
  64. data: { id: this.id, cooperEntrustImg: JSON.stringify(this.imgList) },
  65. method: 'POST',
  66. success: res => {
  67. uni.showToast({ title: '操作成功' });
  68. setTimeout(() => {
  69. uni.navigateBack();
  70. }, 1500);
  71. }
  72. });
  73. },
  74. // 删除图片
  75. deletePic(event) {
  76. this[`fileList${event.name}`].splice(event.index, 1)
  77. if(`fileList${event.name}` == 'fileList1'){
  78. this.fileList1.splice(event.index,1)
  79. this.imgList.splice(event.index,1)
  80. }
  81. },
  82. // 新增图片
  83. async afterRead(event) {
  84. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  85. let lists = [].concat(event.file)
  86. let fileListLen = this[`fileList${event.name}`].length
  87. lists.map((item) => {
  88. this[`fileList${event.name}`].push({
  89. ...item,
  90. status: 'uploading',
  91. message: '上传中'
  92. })
  93. })
  94. for (let i = 0; i < lists.length; i++) {
  95. const result = await this.uploadFilePromise(lists[i].url)
  96. let item = this[`fileList${event.name}`][fileListLen]
  97. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  98. status: 'success',
  99. message: '',
  100. url: this.http.ip+result
  101. }))
  102. fileListLen++
  103. }
  104. },
  105. uploadFilePromise(url) {
  106. return new Promise((resolve, reject) => {
  107. let a = uni.uploadFile({
  108. url: this.http.ip+'/sp-admin/upload/image',
  109. header:{
  110. "Authorization": uni.getStorageSync('user').token ? uni.getStorageSync('user').token : ''
  111. },
  112. filePath: url,
  113. name: 'file',
  114. success: (res) => {
  115. setTimeout(() => {
  116. this.imgList.push(JSON.parse(res.data).data);
  117. resolve(res.data.data)
  118. }, 1000)
  119. }
  120. });
  121. })
  122. },
  123. }
  124. }
  125. </script>
  126. <style>
  127. </style>