WarningPileForm.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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" 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()"></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. getwarningPileInfo(value)
  86. {
  87. service.getwarningPileInfo(value).then(res => {
  88. this.form=res
  89. if(null!=res.photoList)
  90. {
  91. //this.imgymxs=res.photoList
  92. if(null!=res.photoList)
  93. {
  94. res.photoList.forEach(item=>{
  95. let url={}
  96. url.url=item
  97. url.type='image'
  98. this.imgymxs.push(url)
  99. })
  100. }
  101. }
  102. console.log(this.imgymxs)
  103. })
  104. },
  105. save()
  106. {
  107. let _this=this
  108. this.form.photoList=this.imgArr
  109. service.setwarningPile(this.form
  110. ).then(res => {
  111. console.log(res)
  112. _this.$UTILS.showPrompt('上报成功')
  113. setTimeout(()=>{
  114. console.log('跳')
  115. uni.switchTab({
  116. url: `/pages/index/index`
  117. })
  118. },2000)
  119. })
  120. },
  121. choose() {
  122. let _this = this;
  123. uni.showActionSheet({
  124. title: '上传',
  125. itemList: ['图片', '视频'],
  126. success: (res) => {
  127. // console.log(res)
  128. if (res.tapIndex == 0) {
  129. this.chooseimage()
  130. } else {
  131. this.choosevideo()
  132. }
  133. }
  134. })
  135. },
  136. chooseimage() {
  137. console.log('图片')
  138. let _this = this;
  139. uni.chooseImage({
  140. sizeType: [ 'camera'],
  141. success(resp) {
  142. console.log('res--uni.chooseMedia', resp);
  143. resp.tempFiles.forEach((item, index) => {
  144. const task = uni.uploadFile({
  145. url: _this.$HTTP.webUrl + `/obs`,
  146. filePath: item.path,
  147. name: 'file',
  148. formData: {},
  149. header: _this.headers,
  150. success: res => {
  151. // 判断是否json字符串,将其转为json格式
  152. let data = _this.$u.test.jsonString(res
  153. .data) ? JSON.parse(res.data) : res.data;
  154. if (![200, 201, 204].includes(res.statusCode)) {
  155. // this.uploadError(index, data);
  156. _this.$UTILS.showPrompt('选取失败!')
  157. } else {
  158. // 上传成功
  159. // this.lists[index].response = data;
  160. // this.lists[index].progress = 100;
  161. // this.lists[index].error = false;
  162. // this.$emit('on-success', data, index, this.lists, this
  163. // .index);
  164. if (_this.progress === 100) {
  165. // console.log('_this.progress', _this.progress)
  166. // console.log('data----', data)
  167. // console.log('res--', res)
  168. _this.imgymxs.push({url:data.data.url,type:'image'})
  169. _this.imgArr.push(data.data.url)
  170. // console.log('imgArr', _this.imgArr)
  171. _this.$UTILS.showPrompt('选取成功!')
  172. }
  173. }
  174. },
  175. fail: e => {
  176. _this.$UTILS.showPrompt('选取失败!')
  177. this.uploadError(index, e);
  178. },
  179. complete: res => {
  180. _this.uploading = false;
  181. // _this.uploadFile(index + 1);
  182. // this.$emit('on-change', res, index, this.lists, this
  183. // .index);
  184. }
  185. });
  186. task.onProgressUpdate(res => {
  187. // if (res.progress > 0) {
  188. // this.lists[index].progress = res.progress;
  189. // this.$emit('on-progress', res, index, this.lists, this.index);
  190. // }
  191. _this.progress = res.progress;
  192. console.log('onProgressUpdate', res)
  193. uni.showLoading({
  194. title: '选取中'
  195. })
  196. });
  197. })
  198. },
  199. })
  200. },
  201. choosevideo() {
  202. let _this = this;
  203. console.log('视频')
  204. uni.chooseVideo({
  205. sourceType: ['camera'],
  206. maxDuration: 30,
  207. success(resp) {
  208. const task = uni.uploadFile({
  209. url: _this.$HTTP.webUrl + `/obs`,
  210. filePath: resp.tempFilePath,
  211. name: 'file',
  212. formData: {},
  213. header: _this.headers,
  214. success: res => {
  215. // 判断是否json字符串,将其转为json格式
  216. let data = _this.$u.test.jsonString(res
  217. .data) ? JSON.parse(res.data) : res.data;
  218. if (![200, 201, 204].includes(res.statusCode)) {
  219. this.uploadError(index, data);
  220. } else {
  221. // 上传成功
  222. // this.lists[index].response = data;
  223. // this.lists[index].progress = 100;
  224. // this.lists[index].error = false;
  225. // this.$emit('on-success', data, index, this.lists, this
  226. // .index);
  227. if (_this.progress === 100) {
  228. console.log('_this.progress', _this.progress)
  229. console.log('data----', data)
  230. console.log('res--', res)
  231. // _this.imgArr.push(data.data.url)
  232. _this.imgymxs.push({url:data.data.url,type:'video'})
  233. _this.imgArr.push(data.data.url)
  234. console.log('imgArr', _this.imgArr)
  235. _this.$UTILS.showPrompt('选取成功!')
  236. }
  237. }
  238. },
  239. fail: e => {
  240. _this.$UTILS.showPrompt('选取失败!')
  241. this.uploadError(index, e);
  242. },
  243. complete: res => {
  244. uni.hideLoading();
  245. _this.uploading = false;
  246. // _this.uploadFile(index + 1);
  247. // this.$emit('on-change', res, index, this.lists, this
  248. // .index);
  249. }
  250. });
  251. task.onProgressUpdate(res => {
  252. // if (res.progress > 0) {
  253. // this.lists[index].progress = res.progress;
  254. // this.$emit('on-progress', res, index, this.lists, this.index);
  255. // }
  256. _this.progress = res.progress;
  257. console.log('onProgressUpdate', res)
  258. uni.showLoading({
  259. title: '选取中'
  260. })
  261. });
  262. },
  263. })
  264. },
  265. remove(index) {
  266. uni.showModal({
  267. title: '提示',
  268. content: '是否删除该图片或视频?',
  269. success: (res) => {
  270. if (res.confirm) {
  271. this.imgArr.splice(index, 1);
  272. this.imgymxs.splice(index, 1);
  273. console.log('this.imgarr',this.imgArr)
  274. }
  275. }
  276. })
  277. },
  278. }
  279. }
  280. </script>
  281. <style>
  282. .project-content {
  283. border: 4rpx solid #3857F3;
  284. margin: 40rpx 55rpx 0;
  285. padding: 30rpx 20rpx;
  286. border-radius: 48rpx;
  287. }
  288. .background {
  289. z-index: -1;
  290. position: fixed;
  291. width: 100%;
  292. height: 100%;
  293. background-size: 100% 100%;
  294. }
  295. </style>