WarningPileForm.vue 8.8 KB

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