upload.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="upload">
  3. <view class="content">
  4. <view class="title">
  5. 请上传照片
  6. <image src="/static/store/detele.png" mode="" @click="cut"></image>
  7. </view>
  8. <view class="center">
  9. <view class="item" v-for="(item,index) in upList" :key="index">
  10. <u-upload :action="action" :max-count="1" style="width: 100%;height: 100%;"
  11. @on-success="(res) => handleSuccess(res, index)"
  12. @on-remove="(file) => handleRemove(file, index)"></u-upload>
  13. <span>{{item.name}}</span>
  14. </view>
  15. </view>
  16. <view class="btn_box">
  17. <view class="btn" @click="cut">
  18. 稍后再传
  19. </view>
  20. <view class="sub" @click="submit">
  21. 确认上传
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import configService from '../../../common/service/config.service'
  29. export default {
  30. name: 'upload',
  31. props: {
  32. type: {
  33. type: Number,
  34. default: 0, // 默认值
  35. },
  36. taskId:{
  37. type:String,
  38. default:''
  39. }
  40. },
  41. data() {
  42. return {
  43. getCar: [{
  44. name: '正前方',
  45. imgUrl: '',
  46. imgType: '1'
  47. },
  48. {
  49. name: '车辆后侧',
  50. imgUrl: '',
  51. imgType: '4'
  52. },
  53. {
  54. name: '车辆左侧',
  55. imgUrl: '',
  56. imgType: '2'
  57. },
  58. {
  59. name: '车辆右侧',
  60. imgUrl: '',
  61. imgType: '3'
  62. },
  63. {
  64. name: '驾驶室',
  65. imgUrl: '',
  66. imgType: '6'
  67. },
  68. {
  69. name: '后排座',
  70. imgUrl: '',
  71. imgType: '7'
  72. },
  73. {
  74. name: '左前方45度全车照',
  75. imgUrl: '',
  76. imgType: '5'
  77. },
  78. ],
  79. servive:[
  80. {
  81. name: '服务前',
  82. imgUrl: '',
  83. imgType: '8'
  84. },
  85. {
  86. name: '服务中',
  87. imgUrl: '',
  88. imgType: '9'
  89. },
  90. {
  91. name: '服务后',
  92. imgUrl: '',
  93. imgType: '10'
  94. },
  95. ],
  96. upList:[],
  97. action: configService.apiUrl + '/sys/common/upload',
  98. imgUrl: [],
  99. imageHttp: configService.apiUrl + '/', //上传图片前缀+
  100. }
  101. },
  102. methods: {
  103. // 上传封面图成功回调
  104. handleSuccess(res, index) {
  105. const newUrl = this.imageHttp + res.message;
  106. // 获取当前 imgUrl 字符串
  107. let currentimgUrl = this.upList[index].imgUrl;
  108. // 如果是第一个文件,直接赋值;否则用逗号拼接
  109. currentimgUrl = currentimgUrl ?
  110. `${currentimgUrl},${newUrl}` :
  111. newUrl;
  112. // 更新数据(确保响应式)
  113. this.$set(this.upList[index], 'imgUrl', currentimgUrl);
  114. console.log(this.upList)
  115. },
  116. // 移除封面图文件回调
  117. handleRemove(file, index) {
  118. // 清空当前项的 imgUrl
  119. this.$set(this.upList[index], 'imgUrl', '');
  120. console.log('删除后:', this.upList);
  121. },
  122. //上传图片
  123. submit(){
  124. let data = []
  125. console.log(this.upList)
  126. const hasEmptyImg = this.upList.some(item => item.imgUrl === '');
  127. if (hasEmptyImg) {
  128. uni.showToast({
  129. icon: 'none',
  130. title: '请上传全部图片'
  131. });
  132. return; // 直接终止函数执行
  133. }
  134. // 所有图片都有内容,处理数据并发送请求
  135. this.upList.forEach(item => {
  136. item.merchantId = uni.getStorageSync('login_user_info').merchantId;
  137. item.merchantName = uni.getStorageSync('login_user_info').merchantName;
  138. item.merchantUserId = uni.getStorageSync('login_user_info').id;
  139. item.businessType = this.type;
  140. item.taskId = this.taskId;
  141. });
  142. this.$http.post("/ts/merchant/addImg", this.upList).then(res => {
  143. console.log(res);
  144. if (res.data.code == 200) {
  145. uni.showToast({
  146. icon: 'none',
  147. title: '上传成功'
  148. });
  149. this.$emit('upSuccess');
  150. }
  151. });
  152. },
  153. cut(){
  154. this.$emit('cut')
  155. }
  156. },
  157. mounted() {
  158. console.log(this.type)
  159. this.type=='2' ||this.type=='1' ?this.upList = this.getCar:this.upList = this.servive
  160. },
  161. onShow() {
  162. }
  163. }
  164. </script>
  165. <style lang="scss" scoped>
  166. .upload {
  167. padding: 20px;
  168. position: fixed;
  169. top: 0;
  170. left: 0;
  171. background: rgba(0, 0, 0, 0.7);
  172. width: 100%;
  173. height: 100vh;
  174. display: flex;
  175. align-items: center;
  176. justify-content: center;
  177. z-index: 9999 !important;
  178. .content {
  179. width: 570rpx;
  180. background-color: #fff;
  181. border-radius: 12px;
  182. overflow: hidden;
  183. display: flex;
  184. flex-direction: column;
  185. padding: 0 24rpx;
  186. .title {
  187. width: 100%;
  188. height: 86rpx;
  189. display: flex;
  190. align-items: center;
  191. justify-content: space-between;
  192. font-weight: 600;
  193. font-size: 32rpx;
  194. // background: url('/static/order/upload_bgi.png') no-repeat;
  195. // background-size: contain;
  196. image {
  197. width: 37rpx;
  198. height: 37rpx;
  199. }
  200. }
  201. .center {
  202. flex: 1;
  203. display: flex;
  204. flex-wrap: wrap;
  205. justify-content: space-between;
  206. overflow-y: auto;
  207. .item {
  208. width: 248rpx;
  209. height: 150rpx;
  210. border-radius: 4rpx;
  211. overflow: hidden;
  212. position: relative;
  213. margin-bottom: 33rpx;
  214. span {
  215. position: absolute;
  216. top: 0;
  217. left: 0;
  218. display: flex;
  219. padding: 2px 4px;
  220. background: #2D88F4;
  221. border-radius: 0px 4px 4px 0px;
  222. font-size: 16rpx;
  223. color: #FFFFFF;
  224. font-weight: normal;
  225. }
  226. }
  227. }
  228. .btn_box {
  229. width: 100%;
  230. height: 100rpx;
  231. border-top: 1px solid #eeeeee;
  232. display: flex;
  233. align-items: center;
  234. justify-content: space-around;
  235. .btn {
  236. width: 241rpx;
  237. height: 68rpx;
  238. border-radius: 54rpx;
  239. border: 1px solid #CCCCCC;
  240. font-size: 28rpx;
  241. color: #999999;
  242. display: flex;
  243. align-items: center;
  244. justify-content: space-around;
  245. }
  246. .sub {
  247. width: 241rpx;
  248. height: 68rpx;
  249. background: #449AFF;
  250. border-radius: 66rpx;
  251. font-size: 28rpx;
  252. color: #FFFFFF;
  253. display: flex;
  254. align-items: center;
  255. justify-content: space-around;
  256. }
  257. }
  258. }
  259. }
  260. ::v-deep .u-add-wrap {
  261. width: 248rpx !important;
  262. height: 150rpx !important;
  263. margin: 0;
  264. }
  265. </style>