WarningPileForm.vue 9.1 KB

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