upload.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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" 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(index, lists) {
  118. this.imgUrl = lists
  119. },
  120. //上传图片
  121. submit(){
  122. let data = []
  123. this.upList.forEach(item => {
  124. if(item.imgUrl == ''){
  125. uni.showToast({
  126. icon:'none',
  127. title:'请上传全部图片'
  128. })
  129. return
  130. }else{
  131. item.merchantId = uni.getStorageSync('login_user_info').merchantId,
  132. item.merchantName = uni.getStorageSync('login_user_info').merchantName,
  133. item.merchantUserId = uni.getStorageSync('login_user_info').id
  134. item.businessType = this.type
  135. item.taskId = this.taskId
  136. }
  137. })
  138. this.$http.post("/ts/merchant/addImg", this.upList).then(res => {
  139. console.log(res)
  140. if (res.data.code == 200) {
  141. uni.showToast({
  142. icon:'none',
  143. title:'上传成功'
  144. })
  145. this.$emit('upSuccess')
  146. }
  147. })
  148. },
  149. cut(){
  150. this.$emit('cut')
  151. }
  152. },
  153. mounted() {
  154. console.log(this.type)
  155. this.type=='2' ||this.type=='1' ?this.upList = this.getCar:this.upList = this.servive
  156. },
  157. onShow() {
  158. }
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. .upload {
  163. padding: 20px;
  164. position: fixed;
  165. top: 0;
  166. left: 0;
  167. background: rgba(0, 0, 0, 0.7);
  168. width: 100%;
  169. height: 100vh;
  170. display: flex;
  171. align-items: center;
  172. justify-content: center;
  173. z-index: 9999 !important;
  174. .content {
  175. width: 570rpx;
  176. background-color: #fff;
  177. border-radius: 12px;
  178. overflow: hidden;
  179. display: flex;
  180. flex-direction: column;
  181. padding: 0 24rpx;
  182. .title {
  183. width: 100%;
  184. height: 86rpx;
  185. display: flex;
  186. align-items: center;
  187. justify-content: space-between;
  188. font-weight: 600;
  189. font-size: 32rpx;
  190. // background: url('/static/order/upload_bgi.png') no-repeat;
  191. // background-size: contain;
  192. image {
  193. width: 37rpx;
  194. height: 37rpx;
  195. }
  196. }
  197. .center {
  198. flex: 1;
  199. display: flex;
  200. flex-wrap: wrap;
  201. justify-content: space-between;
  202. overflow-y: auto;
  203. .item {
  204. width: 248rpx;
  205. height: 150rpx;
  206. border-radius: 4rpx;
  207. overflow: hidden;
  208. position: relative;
  209. margin-bottom: 33rpx;
  210. span {
  211. position: absolute;
  212. top: 0;
  213. left: 0;
  214. display: flex;
  215. padding: 2px 4px;
  216. background: #2D88F4;
  217. border-radius: 0px 4px 4px 0px;
  218. font-size: 16rpx;
  219. color: #FFFFFF;
  220. font-weight: normal;
  221. }
  222. }
  223. }
  224. .btn_box {
  225. width: 100%;
  226. height: 100rpx;
  227. border-top: 1px solid #eeeeee;
  228. display: flex;
  229. align-items: center;
  230. justify-content: space-around;
  231. .btn {
  232. width: 241rpx;
  233. height: 68rpx;
  234. border-radius: 54rpx;
  235. border: 1px solid #CCCCCC;
  236. font-size: 28rpx;
  237. color: #999999;
  238. display: flex;
  239. align-items: center;
  240. justify-content: space-around;
  241. }
  242. .sub {
  243. width: 241rpx;
  244. height: 68rpx;
  245. background: #449AFF;
  246. border-radius: 66rpx;
  247. font-size: 28rpx;
  248. color: #FFFFFF;
  249. display: flex;
  250. align-items: center;
  251. justify-content: space-around;
  252. }
  253. }
  254. }
  255. }
  256. ::v-deep .u-add-wrap {
  257. width: 248rpx !important;
  258. height: 150rpx !important;
  259. margin: 0;
  260. }
  261. </style>