WarningPileForm.vue 9.0 KB

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