WarningPileForm.vue 8.6 KB

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