spare-img.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <template>
  2. <view class="mt-3 px3">
  3. <view class="f-size-30 f-weight-bold py2 border-bottom my3">备件图片</view>
  4. <u-upload
  5. width="180"
  6. height="180"
  7. :action="action"
  8. :file-list="fileList"
  9. max-count="1"
  10. :max-size="5 * 100 * 1024"
  11. @on-success="uploadSuccess"
  12. @on-remove="uploadRemove"
  13. :header="header">
  14. </u-upload>
  15. <view class="d-flex j-around a-center footer">
  16. <view
  17. class="main-color-bg text-color-white common"
  18. @tap="handleSubmit"
  19. >提交</view
  20. >
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import {updateSparePartInfoImage} from "../../api/sqarepartmanage/sparepartinfo";
  26. export default {
  27. data() {
  28. return {
  29. infoData: {},
  30. detailId: '',
  31. fileList: [],
  32. action: this.$BaseTool.UserUtil.getUploadUrl(),
  33. header: {
  34. Authorization: 'Bearer ' + uni.getStorageSync('accessToken')
  35. },
  36. imagesList: []
  37. };
  38. },
  39. onLoad(options) {
  40. this.detailId = options.detailId;
  41. this.initData();
  42. },
  43. methods: {
  44. initData() {
  45. this.$Http
  46. .fetchSparePartInfo({
  47. id: this.detailId
  48. })
  49. .then((res) => {
  50. if(res.data.image){
  51. this.fileList.push({url: res.data.image})
  52. this.imagesList.push({url: res.data.image})
  53. this.fileList.forEach((d) => {
  54. d.url = this.$BaseTool.UserUtil.getFileUrl(d.url);
  55. });
  56. }
  57. });
  58. },
  59. // 删除成功
  60. uploadRemove(index, lists, name) {
  61. this.fileList = lists;
  62. this.imagesList.splice(index, 1)
  63. console.log(this.imagesList);
  64. },
  65. // 上传成功
  66. uploadSuccess(data, index, lists, name) {
  67. console.log(data);
  68. this.fileList = lists;
  69. this.imagesList.push({url: data.data.url})
  70. this.imagesList.map((item) => {
  71. console.log(item.url);
  72. });
  73. },
  74. handleSubmit() {
  75. const params = {
  76. image: this.imagesList[0].url,
  77. id: this.detailId
  78. };
  79. this.imagesList.map((item) => {
  80. return item.url;
  81. });
  82. this.$Http.updateSparePartInfoImage(params).then((res) => {
  83. uni.showToast({ title: '添加成功' });
  84. });
  85. }
  86. }
  87. };
  88. </script>
  89. <style lang="less" scoped>
  90. .main {
  91. .img {
  92. width: 76rpx;
  93. height: 76rpx;
  94. border-radius: 10rpx;
  95. image {
  96. width: 76rpx;
  97. height: 76rpx;
  98. border-radius: 10rpx;
  99. }
  100. }
  101. .content {
  102. .text-color-3 {
  103. width: 500rpx;
  104. }
  105. }
  106. }
  107. .footer {
  108. bottom: 150rpx;
  109. left: 0;
  110. right: 0;
  111. z-index: 10000;
  112. border-top: 1rpx solid #f4f4f4;
  113. height: 100rpx;
  114. .common {
  115. padding: 15rpx 200rpx;
  116. border-radius: 30rpx;
  117. background-color: #0082ff;
  118. color: #fff;
  119. }
  120. }
  121. </style>