jubao.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view>
  3. <view class="Regular header-title">{{jubaolist.compName}}</view>
  4. <view class='content'>
  5. <view class='matter'>
  6. <view class="title Regular">举报事项<text style='color:#FB1E1E;'>*</text></view>
  7. <view style='position:relative;'>
  8. <textarea class='textarea Regular' maxlength="150" v-model='jubaolist.error' placeholder="请输入举报事项" placeholder-style="color:#AFB3BF;" />
  9. <view class='Regular words'>{{jubaolist.error.length}}/150个字</view>
  10. </view>
  11. </view>
  12. <view class="uploading">
  13. <view class="title Regular">上传图片</view>
  14. <u-upload @on-remove="onRemove" @on-success="onSuccess" @on-error='onError' width='140' height='140' :file-list="fileList" :custom-btn="true" ref="uUpload" :max-size="5 * 1024 * 1024" max-count="6" :action="$ossUrl">
  15. <view slot="addBtn" class="slot-btn" hover-class="slot-btn__hover" hover-stay-time="150">
  16. <image style='width:23px;height:23px;margin-top:10px;' src="../../static/img/liangmai/xiangji-2.png" mode=""></image>
  17. <view style='color:#AFB3BF;font-size:10px;' class='Medium'>上传图片</view>
  18. </view>
  19. </u-upload>
  20. </view>
  21. </view>
  22. <view class="commitwrap">
  23. <view class='commit' @click='commit'>提交</view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. components: {
  30. },
  31. data() {
  32. return {
  33. status:'',
  34. fileList:[],
  35. jubaolist:{
  36. error:''
  37. }
  38. }
  39. },
  40. onReady() {
  41. // 得到整个组件对象,内部图片列表变量为"lists"
  42. this.fileList = this.$refs.uUpload.lists;
  43. },
  44. onLoad(options){
  45. this.jubaolist.id=options.id
  46. this.jubaolist.compName=options.compName
  47. },
  48. methods: {
  49. commit(){
  50. console.log(this.fileList,this.$uploadUrl)
  51. },
  52. //图片成功上传后的回调 data为服务器返回的数据,包括图片的存放地址和名称
  53. onSuccess(data, index, lists){
  54. console.log('https://taohaoliang.oss-cn-beijing.aliyuncs.com/appData/'+data.data)
  55. // console.log(data, index, lists)
  56. //页面上定义的临时存放图片的对象,提示也保存后台返回的图片名称
  57. // let currentFile = {name: '', url: ''};
  58. // currentFile.name = JSON.parse(data).name;
  59. // currentFile.url = JSON.parse(data).imgUrl;
  60. // //成功上传一个图片就往fileList里面添加一个图片对象
  61. // this.fileList.push(currentFile);
  62. // //this.form.pictureUrl为后台图片字段来保存字符串类型的图片集合
  63. // this.form.pictureUrl = JSON.stringify(this.fileList)
  64. //console.log("打印图片List:onSuccess", this.fileList);
  65. },
  66. onError(res, index, lists, name){
  67. console.log(res, index, lists, name)
  68. },
  69. //删除一张图片的回调,lists这是成功删除一个图片后,还剩余的图片集合
  70. onRemove(data, lists){
  71. //lists.length > 0说明删除之前已经上传了多余两张的图片
  72. if(lists.length > 0 ){
  73. var currentfileList = [];
  74. //遍历this.fileList 与剩余的lists进行匹配,来组成一个新的格式合适的剩余图片集合
  75. this.fileList.forEach((item, index)=>{
  76. lists.forEach((item1, index1)=>{
  77. if(item.name == JSON.parse(item1.response).name){
  78. currentfileList.push(item);
  79. }
  80. });
  81. })
  82. //删除后对图片集合及时冬天更新,即对this.fileList重新赋值
  83. this.fileList = currentfileList;
  84. }else{//说明删除之前只有一张图片,删除成功后把this.fileList清空即可
  85. this.fileList = [];
  86. }
  87. this.form.pictureUrl = JSON.stringify(this.fileList)
  88. //console.log("打印图片List:onRemove", this.fileList);
  89. }
  90. }
  91. }
  92. </script>
  93. <style lang="scss" scoped>
  94. page{
  95. background:#F5F6FA;
  96. }
  97. .header-title{
  98. margin:9.5px;
  99. padding:16.5px 12.5px;
  100. background:#fff;
  101. border-radius:10px;
  102. height:51px;
  103. }
  104. .content{
  105. padding:12.5px;margin:9px;
  106. background:#fff;
  107. border-radius:10px;
  108. }
  109. .matter .title{
  110. font-size:14px;
  111. margin-bottom:15px;
  112. }
  113. .uploading .title{
  114. font-size:14px;margin-top:13px;margin-bottom:13px;
  115. }
  116. .textarea{
  117. background:#F9F9FA;
  118. font-size:12px;
  119. padding:6.5px;
  120. width:326.5px;height:70px;
  121. border-radius:5px;
  122. }
  123. .words{
  124. font-size:10px;color:#AFB3BF;position: absolute;right:5px;
  125. bottom:8px;
  126. }
  127. .slot-btn{
  128. width: 70px;
  129. height: 70px;
  130. border-radius: 4px;
  131. border: 2px dashed #AFB3BF;
  132. text-align:center;
  133. }
  134. .commitwrap{
  135. position:fixed;bottom:0;left:0;
  136. width:100%;
  137. }
  138. .commit{
  139. background:#22C572;
  140. margin:10px 24px;
  141. text-align:center;
  142. height:46px;line-height:46px;
  143. color:#fff;
  144. font-size:17px;
  145. border-radius:20px;
  146. }
  147. /deep/.u-delete-icon{
  148. top:0;
  149. right:0;
  150. border-radius:0 0 0 15px;
  151. background:rgba(17, 26, 52, 0.5) !important;
  152. }
  153. </style>