WarningPileForm.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <template>
  2. <view>
  3. <image src="/static/icon/background.png" mode="" class="background"></image>
  4. <view class="project-content">
  5. <u-form :model="form" :rules="rules" ref="form" >
  6. <u-form-item label=" " borderBottom ref="item1">
  7. <view>警示柱信息</view>
  8. <u-input v-model="form.warningPileInfo" :disabled="type==1" type="textarea" ></u-input>
  9. </u-form-item>
  10. <u-form-item label=" " borderBottom ref="item1">
  11. <view>警示柱照片</view>
  12. <view class="" style="display: flex; flex-wrap: wrap; margin: 0 55rpx;">
  13. <image src="/static/icon/chooseimg.png" mode="" style="width: 190rpx; height: 190rpx; margin: 0 12rpx; "
  14. @click="choose()" v-if="type!=1"></image>
  15. <view v-for="(item,index) in imgymxs" :key="index" style="position: relative;">
  16. <view v-if="item.type == 'image'">
  17. <image :src="item.url" mode=""
  18. style="width: 190rpx; height: 190rpx; margin: 0 20rpx;" @click="showPhoto(index)">
  19. </image>
  20. </view>
  21. <view v-else>
  22. <video :src="item"
  23. style="width: 190rpx; height: 190rpx; margin: 0 20rpx;"></video>
  24. </view>
  25. <view @click="remove(index)" style="position: absolute; top: 0; right: 14rpx; border-radius: 50%; background-color: #FF0000;">
  26. <u-icon name="close" color="#FFFFFF" size="35" ></u-icon>
  27. </view>
  28. </view>
  29. </view>
  30. </u-form-item>
  31. </u-form>
  32. <u-button style="margin: 500rpx 155rpx 0;" @click="save()" v-if="type!=1">确认上传</u-button>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import service from '@/api/index.js'
  38. export default {
  39. data() {
  40. return {
  41. action: this.$HTTP.webUrl + `/obs`,
  42. headers: {
  43. MAuthorization: "wxBearer " + uni.getStorageSync('token')
  44. },
  45. url: [],
  46. uploading: false,
  47. imgymxs: [],
  48. progress: 0 ,//图片或视频上传百分比
  49. form:{},
  50. value:null,
  51. imgArr: [],
  52. type:2,
  53. id:null
  54. }
  55. },
  56. onLoad(e)
  57. {
  58. console.log(e)
  59. this.id=e.id
  60. if(e.type==1)
  61. {
  62. this.type=e.type
  63. console.log(this.id)
  64. service.getwarningPile(this.id).then(res => {
  65. this.form=res
  66. //this.imgymxs=res.photoList
  67. if(null!=res.photoList)
  68. {
  69. res.photoList.forEach(item=>{
  70. let url={}
  71. url.url=item
  72. url.type='image'
  73. this.imgymxs.push(url)
  74. })
  75. }
  76. })
  77. }else{
  78. this.getwarningPileInfo(e.value)
  79. }
  80. uni.setNavigationBarTitle({
  81. title: '抢险维修单'
  82. });
  83. },
  84. methods: {
  85. showPhoto(index){
  86. uni.previewImage({
  87. current:index,
  88. urls:this.imgArr,
  89. })
  90. },
  91. showPhotos(index){
  92. uni.previewImage({
  93. current:index,
  94. urls:this.photo,
  95. })
  96. },
  97. getwarningPileInfo(value)
  98. {
  99. service.getwarningPileInfo(value).then(res => {
  100. this.form=res
  101. if(null!=res.photoList)
  102. {
  103. //this.imgymxs=res.photoList
  104. if(null!=res.photoList)
  105. {
  106. res.photoList.forEach(item=>{
  107. let url={}
  108. url.url=item
  109. url.type='image'
  110. this.imgymxs.push(url)
  111. })
  112. }
  113. }
  114. console.log(this.imgymxs)
  115. })
  116. },
  117. save()
  118. {
  119. let _this=this
  120. this.form.photoList=this.imgArr
  121. service.setwarningPile(this.form
  122. ).then(res => {
  123. console.log(res)
  124. _this.$UTILS.showPrompt('上报成功')
  125. setTimeout(()=>{
  126. console.log('跳')
  127. uni.switchTab({
  128. url: `/pages/index/index`
  129. })
  130. },2000)
  131. })
  132. },
  133. choose() {
  134. let _this = this;
  135. uni.showActionSheet({
  136. title: '上传',
  137. itemList: ['图片', '视频'],
  138. success: (res) => {
  139. // console.log(res)
  140. if (res.tapIndex == 0) {
  141. this.chooseimage()
  142. } else {
  143. this.choosevideo()
  144. }
  145. }
  146. })
  147. },
  148. chooseimage() {
  149. console.log('图片')
  150. let _this = this;
  151. uni.chooseImage({
  152. sizeType: [ 'camera'],
  153. success(resp) {
  154. console.log('res--uni.chooseMedia', resp);
  155. resp.tempFiles.forEach((item, index) => {
  156. const task = uni.uploadFile({
  157. url: _this.$HTTP.webUrl + `/obs`,
  158. filePath: item.path,
  159. name: 'file',
  160. formData: {},
  161. header: _this.headers,
  162. success: res => {
  163. // 判断是否json字符串,将其转为json格式
  164. let data = _this.$u.test.jsonString(res
  165. .data) ? JSON.parse(res.data) : res.data;
  166. if (![200, 201, 204].includes(res.statusCode)) {
  167. // this.uploadError(index, data);
  168. _this.$UTILS.showPrompt('选取失败!')
  169. } else {
  170. // 上传成功
  171. // this.lists[index].response = data;
  172. // this.lists[index].progress = 100;
  173. // this.lists[index].error = false;
  174. // this.$emit('on-success', data, index, this.lists, this
  175. // .index);
  176. if (_this.progress === 100) {
  177. // console.log('_this.progress', _this.progress)
  178. // console.log('data----', data)
  179. // console.log('res--', res)
  180. _this.imgymxs.push({url:data.data.url,type:'image'})
  181. _this.imgArr.push(data.data.url)
  182. // console.log('imgArr', _this.imgArr)
  183. _this.$UTILS.showPrompt('选取成功!')
  184. }
  185. }
  186. },
  187. fail: e => {
  188. _this.$UTILS.showPrompt('选取失败!')
  189. this.uploadError(index, e);
  190. },
  191. complete: res => {
  192. _this.uploading = false;
  193. // _this.uploadFile(index + 1);
  194. // this.$emit('on-change', res, index, this.lists, this
  195. // .index);
  196. }
  197. });
  198. task.onProgressUpdate(res => {
  199. // if (res.progress > 0) {
  200. // this.lists[index].progress = res.progress;
  201. // this.$emit('on-progress', res, index, this.lists, this.index);
  202. // }
  203. _this.progress = res.progress;
  204. console.log('onProgressUpdate', res)
  205. uni.showLoading({
  206. title: '选取中'
  207. })
  208. });
  209. })
  210. },
  211. })
  212. },
  213. choosevideo() {
  214. let _this = this;
  215. console.log('视频')
  216. uni.chooseVideo({
  217. sourceType: ['camera'],
  218. maxDuration: 30,
  219. success(resp) {
  220. const task = uni.uploadFile({
  221. url: _this.$HTTP.webUrl + `/obs`,
  222. filePath: resp.tempFilePath,
  223. name: 'file',
  224. formData: {},
  225. header: _this.headers,
  226. success: res => {
  227. // 判断是否json字符串,将其转为json格式
  228. let data = _this.$u.test.jsonString(res
  229. .data) ? JSON.parse(res.data) : res.data;
  230. if (![200, 201, 204].includes(res.statusCode)) {
  231. this.uploadError(index, data);
  232. } else {
  233. // 上传成功
  234. // this.lists[index].response = data;
  235. // this.lists[index].progress = 100;
  236. // this.lists[index].error = false;
  237. // this.$emit('on-success', data, index, this.lists, this
  238. // .index);
  239. if (_this.progress === 100) {
  240. console.log('_this.progress', _this.progress)
  241. console.log('data----', data)
  242. console.log('res--', res)
  243. // _this.imgArr.push(data.data.url)
  244. _this.imgymxs.push({url:data.data.url,type:'video'})
  245. _this.imgArr.push(data.data.url)
  246. console.log('imgArr', _this.imgArr)
  247. _this.$UTILS.showPrompt('选取成功!')
  248. }
  249. }
  250. },
  251. fail: e => {
  252. _this.$UTILS.showPrompt('选取失败!')
  253. this.uploadError(index, e);
  254. },
  255. complete: res => {
  256. uni.hideLoading();
  257. _this.uploading = false;
  258. // _this.uploadFile(index + 1);
  259. // this.$emit('on-change', res, index, this.lists, this
  260. // .index);
  261. }
  262. });
  263. task.onProgressUpdate(res => {
  264. // if (res.progress > 0) {
  265. // this.lists[index].progress = res.progress;
  266. // this.$emit('on-progress', res, index, this.lists, this.index);
  267. // }
  268. _this.progress = res.progress;
  269. console.log('onProgressUpdate', res)
  270. uni.showLoading({
  271. title: '选取中'
  272. })
  273. });
  274. },
  275. })
  276. },
  277. remove(index) {
  278. uni.showModal({
  279. title: '提示',
  280. content: '是否删除该图片或视频?',
  281. success: (res) => {
  282. if (res.confirm) {
  283. this.imgArr.splice(index, 1);
  284. this.imgymxs.splice(index, 1);
  285. console.log('this.imgarr',this.imgArr)
  286. }
  287. }
  288. })
  289. },
  290. }
  291. }
  292. </script>
  293. <style>
  294. .project-content {
  295. border: 4rpx solid #3857F3;
  296. margin: 40rpx 55rpx 0;
  297. padding: 30rpx 20rpx;
  298. border-radius: 48rpx;
  299. }
  300. .background {
  301. z-index: -1;
  302. position: fixed;
  303. width: 100%;
  304. height: 100%;
  305. background-size: 100% 100%;
  306. }
  307. </style>