roadSection.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <view>
  3. <image src="https://cczdsz.cn/app/images/background-from.png" 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" labelWidth="140">
  7. <u-input v-model="form.sectionName" borderBottom @click="showbuilding= true "
  8. placeholder="请输入路段名称"></u-input>
  9. </u-form-item>
  10. <u-form-item label="抽检米数" labelWidth="140" borderBottom ref="item1">
  11. <u-input v-model="form.samplingMeterCount" borderBottom @click="showbuilding= true "
  12. placeholder="请输入抽检米数" @input="checksamplingMeterCount()"></u-input>
  13. </u-form-item>
  14. <u-form-item label="发现问题" labelWidth="140" borderBottom ref="item1">
  15. <u-radio-group v-model="form.findProblem" >
  16. <u-radio @change="confirm"
  17. v-for="(item, index) in typelist.find_problem"
  18. :key="index" :name="item.dictValue">
  19. {{item.dictLabel}}
  20. </u-radio>
  21. </u-radio-group>
  22. </u-form-item>
  23. <!-- <u-form-item label="发现时间" labelWidth="140" borderBottom ref="item1">
  24. <u-input v-model="form.findTime" borderBottom placeholder="请选择接警时间" disabled
  25. @click="showtime=true "></u-input>
  26. <u-picker v-model="showtime" mode="time" :params="params" @confirm="time()"></u-picker>
  27. </u-form-item> -->
  28. <u-form-item borderBottom ref="item1">
  29. <view>巡检照片</view>
  30. <u-input v-model="WarningColumnInformation" disabled placeholder="请上传巡检照片"></u-input>
  31. <view class="" style="display: flex; flex-wrap: wrap; margin: 0 55rpx;">
  32. <image src="https://cczdsz.cn/app/images/chooseimg.png" mode=""
  33. style="width: 190rpx; height: 190rpx; margin: 0 12rpx; " @click="choose()" >
  34. </image>
  35. <view v-for="(item,index) in imgymxs" :key="index" style="position: relative;">
  36. <view v-if="item.type == 'image'">
  37. <image :src="item.url" mode="" style="width: 190rpx; height: 190rpx; margin: 0 20rpx;"
  38. @click="showPhoto(index)">
  39. </image>
  40. </view>
  41. <view v-else>
  42. <video :src="item" style="width: 190rpx; height: 190rpx; margin: 0 20rpx;"></video>
  43. </view>
  44. <view @click="remove(index)"
  45. style="position: absolute; top: 0; right: 14rpx; border-radius: 50%; background-color: #FF0000;">
  46. <u-icon name="close" color="#FFFFFF" size="35" ></u-icon>
  47. </view>
  48. </view>
  49. </view>
  50. </u-form-item>
  51. <u-form-item borderBottom ref="item1">
  52. <view>备注</view>
  53. <u-input v-model="form.remark" type="textarea" placeholder="请输入备注" ></u-input>
  54. </u-form-item>
  55. </u-form>
  56. <u-button style="background: #2d95f4;color: #fff;border-radius: 20rpx;" @click="save()"
  57. type='primary' v-if="type!=1">确认上传</u-button>
  58. <u-button style="background: #2d95f4;color: #fff;border-radius: 20rpx;" @click="update()"
  59. type='primary ' v-else>确认修改</u-button>
  60. </view>
  61. </view>
  62. </template>
  63. <script>
  64. import service from '@/api/index.js'
  65. export default {
  66. data() {
  67. return {
  68. repairType: [{
  69. label: '施工问题',
  70. value: 1
  71. }, {
  72. label: '施工问题',
  73. value: 2
  74. }, ],
  75. showrepairType: false,
  76. action: this.$HTTP.webUrl + `/obs`,
  77. headers: {
  78. MAuthorization: "wxBearer " + uni.getStorageSync('token')
  79. },
  80. url: [],
  81. params: {
  82. year: true,
  83. month: true,
  84. day: true,
  85. hour: true,
  86. minute: true,
  87. second: false
  88. },
  89. uploading: false,
  90. showtime:false,
  91. imgArr: [],
  92. imgymxs: [],
  93. progress: 0, //图片或视频上传百分比
  94. form: {
  95. findProblem:1
  96. },
  97. typelist: [],
  98. causesOfFamageLabel: null,
  99. dictlist: ['find_problem'],
  100. buildingName: null,
  101. unit: null,
  102. unitName: null,
  103. showbuilding: false,
  104. showunit: false,
  105. buildingList: [],
  106. unitList: [],
  107. type: 2,
  108. id: null,
  109. community: null,
  110. createBy:null
  111. }
  112. },
  113. onLoad(e) {
  114. // this.building = e.building
  115. // this.buildingName = e.buildingName
  116. // this.community = e.community
  117. // this.unitName = e.unitName
  118. // this.unit = e.unit
  119. this.id = e.id
  120. this.type = e.type
  121. console.log(e)
  122. this.getdictsysinfo()
  123. uni.setNavigationBarTitle({
  124. title: '路段巡查'
  125. });
  126. uni.setNavigationBarColor({
  127. frontColor: '#ffffff',
  128. backgroundColor: '#2d95f4',
  129. })
  130. // if (this.type != 1) {
  131. // this.getBuildingList()
  132. // }
  133. this.getUserName()
  134. },
  135. methods: {
  136. time(e) {
  137. console.log(`${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}`)
  138. this.form.findTime = `${e.year}-${e.month}-${e.day} ${e.hour}:${e.minute}`
  139. },
  140. checksamplingMeterCount(e) {
  141. console.log(e)
  142. //正则表达试
  143. e = (e.match(/^\d*(\.?\d{0,10})/g)[0]) || null
  144. //重新赋值给input
  145. this.$nextTick(() => {
  146. this.form.samplingMeterCount= e
  147. })
  148. },
  149. getUserName(){
  150. service.getUserName().then(res=>{
  151. this.userId=res.id
  152. this.createBy=res.name
  153. })
  154. },
  155. // showPhoto(index) {
  156. // uni.previewImage({
  157. // current: index,
  158. // urls: this.imgArr,
  159. // })
  160. // },
  161. // showPhotos(index) {
  162. // uni.previewImage({
  163. // current: index,
  164. // urls: this.photo,
  165. // })
  166. // },
  167. // buildingconfirm(e) {
  168. // this.buildingName = e[0].label
  169. // this.building = e[0].value
  170. // console.log(this.building)
  171. // //this.getUnitList(e[0].value)
  172. // },
  173. // unitconfirm(e) {
  174. // this.unitName = e[0].label
  175. // this.unit = e[0].value
  176. // },
  177. // getBuildingList() {
  178. // const _this = this
  179. // service.getBuildingList({
  180. // areaId: this.community
  181. // }).then(res => {
  182. // _this.buildingList = res
  183. // })
  184. // },
  185. // getUnitList(building) {
  186. // const _this = this
  187. // service.getUnitList({
  188. // buildingId: building
  189. // }).then(res => {
  190. // _this.unitList = res
  191. // })
  192. // },
  193. save() {
  194. let _this = this
  195. this.form.photoList = this.imgArr
  196. // if(this.building==null)
  197. // {
  198. // uni.showToast({
  199. // title: '请选择楼栋',
  200. // icon: 'none'
  201. // })
  202. // return
  203. // }
  204. if(this.imgArr.length==0)
  205. {
  206. uni.showToast({
  207. title: '请上传图片或视频!',
  208. icon: 'none'
  209. })
  210. return
  211. }
  212. // this.form.buildingId = this.building
  213. // this.form.communityId=this.community
  214. this.form.userId=this.userId
  215. this.form.createBy=this.userId
  216. service.saveroadSectionInspection(this.form).then(res => {
  217. console.log(res)
  218. _this.$UTILS.showPrompt('上报成功!')
  219. // setTimeout(() => {
  220. // console.log('跳')
  221. // uni.switchTab({
  222. // url: '/pages/index/index'
  223. // })
  224. // }, 2000)
  225. this.form={findProblem:1}
  226. // this.buildingName=''
  227. this.imgArr=[]
  228. this.imgymxs=[]
  229. })
  230. },
  231. update() {
  232. let _this = this
  233. this.form.pressureStatus = null
  234. this.form.photoList = this.imgArr
  235. // if(this.building==null)
  236. // {
  237. // uni.showToast({
  238. // title: '请选择楼栋',
  239. // icon: 'none'
  240. // })
  241. // return
  242. // }
  243. if(this.imgArr.length==0)
  244. {
  245. uni.showToast({
  246. title: '请上传图片或视频!',
  247. icon: 'none'
  248. })
  249. return
  250. }
  251. // this.form.buildingId = this.building
  252. // this.form.communityId=this.community
  253. this.form.userId=this.userId
  254. this.form.createBy=this.userId
  255. service.updateroadSectionInspection(this.form).then(res => {
  256. console.log(res)
  257. _this.$UTILS.showPrompt('修改成功!')
  258. // setTimeout(() => {
  259. // console.log('跳')
  260. // uni.switchTab({
  261. // url: '/pages/index/index'
  262. // })
  263. // }, 2000)
  264. //this.form={findProblem:1}
  265. // this.buildingName=''
  266. // this.imgArr=[]
  267. // this.imgymxs=[]
  268. })
  269. },
  270. getdictsysinfo() {
  271. let _this = this
  272. service.getDictInfoList({
  273. type: this.dictlist
  274. }).then(res => {
  275. if (this.type == 1) {
  276. let _this = this
  277. console.log(this.id)
  278. service.getroadSectionInspection(this.id).then(res => {
  279. // console.log(_this.typelist)
  280. // _this.buildingName = res.buildingName
  281. // _this.unitName = res.unitName
  282. // let list = []
  283. // list = _this.typelist.find_problem
  284. // list.forEach((item) => {
  285. // if (item.dictValue == res.findProblem) {
  286. // _this.causesOfFamageLabel = item.dictLabel
  287. // }
  288. // })
  289. if (null != res.photoList) {
  290. res.photoList.forEach(item => {
  291. let url = {}
  292. url.url = item
  293. url.type = 'image'
  294. this.imgymxs.push(url)
  295. this.imgArr.push(item)
  296. })
  297. }
  298. this.form = res
  299. })
  300. }
  301. _this.typelist = res
  302. console.log(res)
  303. })
  304. },
  305. confirm(e) {
  306. this.form.findProblem =e
  307. },
  308. choose() {
  309. let _this = this;
  310. uni.showActionSheet({
  311. title: '上传',
  312. itemList: ['图片', '视频'],
  313. success: (res) => {
  314. // console.log(res)
  315. if (res.tapIndex == 0) {
  316. this.chooseimage()
  317. } else {
  318. this.choosevideo()
  319. }
  320. }
  321. })
  322. },
  323. chooseimage() {
  324. console.log('图片')
  325. let _this = this;
  326. uni.chooseImage({
  327. sourceType: ['camera'],
  328. success(resp) {
  329. console.log('res--uni.chooseMedia', resp);
  330. resp.tempFiles.forEach((item, index) => {
  331. const task = uni.uploadFile({
  332. url: _this.$HTTP.webUrl + `/obs`,
  333. filePath: item.path,
  334. name: 'file',
  335. formData: {},
  336. header: _this.headers,
  337. success: res => {
  338. // 判断是否json字符串,将其转为json格式
  339. let data = _this.$u.test.jsonString(res.data) ? JSON.parse(
  340. res.data) : res.data;
  341. if (![200, 201, 204].includes(res.statusCode)) {
  342. // this.uploadError(index, data);
  343. _this.$UTILS.showPrompt('选取失败!')
  344. } else {
  345. // 上传成功
  346. // this.lists[index].response = data;
  347. // this.lists[index].progress = 100;
  348. // this.lists[index].error = false;
  349. // this.$emit('on-success', data, index, this.lists, this
  350. // .index);
  351. if (_this.progress === 100) {
  352. // console.log('_this.progress', _this.progress)
  353. // console.log('data----', data)
  354. // console.log('res--', res)
  355. _this.imgymxs.push({
  356. url: data.data.url,
  357. type: 'image'
  358. })
  359. _this.imgArr.push(data.data.url)
  360. // console.log('imgArr', _this.imgArr)
  361. _this.$UTILS.showPrompt('选取成功!')
  362. }
  363. }
  364. },
  365. fail: e => {
  366. _this.$UTILS.showPrompt('选取失败!')
  367. this.uploadError(index, e);
  368. },
  369. complete: res => {
  370. _this.uploading = false;
  371. // _this.uploadFile(index + 1);
  372. // this.$emit('on-change', res, index, this.lists, this
  373. // .index);
  374. }
  375. });
  376. task.onProgressUpdate(res => {
  377. // if (res.progress > 0) {
  378. // this.lists[index].progress = res.progress;
  379. // this.$emit('on-progress', res, index, this.lists, this.index);
  380. // }
  381. _this.progress = res.progress;
  382. console.log('onProgressUpdate', res)
  383. uni.showLoading({
  384. title: '选取中'
  385. })
  386. });
  387. })
  388. },
  389. })
  390. },
  391. choosevideo() {
  392. let _this = this;
  393. console.log('视频')
  394. uni.chooseVideo({
  395. sourceType: ['camera'],
  396. maxDuration: 30,
  397. success(resp) {
  398. const task = uni.uploadFile({
  399. url: _this.$HTTP.webUrl + `/obs`,
  400. filePath: resp.tempFilePath,
  401. name: 'file',
  402. formData: {},
  403. header: _this.headers,
  404. success: res => {
  405. // 判断是否json字符串,将其转为json格式
  406. let data = _this.$u.test.jsonString(res.data) ? JSON.parse(res.data) :
  407. res.data;
  408. if (![200, 201, 204].includes(res.statusCode)) {
  409. this.uploadError(index, data);
  410. } else {
  411. // 上传成功
  412. // this.lists[index].response = data;
  413. // this.lists[index].progress = 100;
  414. // this.lists[index].error = false;
  415. // this.$emit('on-success', data, index, this.lists, this
  416. // .index);
  417. if (_this.progress === 100) {
  418. console.log('_this.progress', _this.progress)
  419. console.log('data----', data)
  420. console.log('res--', res)
  421. // _this.imgArr.push(data.data.url)
  422. _this.imgymxs.push({
  423. url: data.data.url,
  424. type: 'video'
  425. })
  426. _this.imgArr.push(data.data.url)
  427. console.log('imgArr', _this.imgArr)
  428. _this.$UTILS.showPrompt('选取成功!')
  429. }
  430. }
  431. },
  432. fail: e => {
  433. _this.$UTILS.showPrompt('选取失败!')
  434. this.uploadError(index, e);
  435. },
  436. complete: res => {
  437. uni.hideLoading();
  438. _this.uploading = false;
  439. // _this.uploadFile(index + 1);
  440. // this.$emit('on-change', res, index, this.lists, this
  441. // .index);
  442. }
  443. });
  444. task.onProgressUpdate(res => {
  445. // if (res.progress > 0) {
  446. // this.lists[index].progress = res.progress;
  447. // this.$emit('on-progress', res, index, this.lists, this.index);
  448. // }
  449. _this.progress = res.progress;
  450. console.log('onProgressUpdate', res)
  451. uni.showLoading({
  452. title: '选取中'
  453. })
  454. });
  455. },
  456. })
  457. },
  458. remove(index) {
  459. uni.showModal({
  460. title: '提示',
  461. content: '是否删除该图片或视频?',
  462. success: (res) => {
  463. if (res.confirm) {
  464. this.imgArr.splice(index, 1);
  465. this.imgymxs.splice(index, 1);
  466. console.log('this.imgarr', this.imgArr)
  467. }
  468. }
  469. })
  470. },
  471. }
  472. }
  473. </script>
  474. <style>
  475. .project-content {
  476. padding: 10rpx 20rpx;
  477. border-radius: 20rpx;
  478. background: #fff;
  479. width: 90%;
  480. margin: 0 auto;
  481. }
  482. .background {
  483. z-index: -1;
  484. position: fixed;
  485. width: 100%;
  486. height: 100%;
  487. background-size: 100% 100%;
  488. }
  489. </style>