roadSection.vue 12 KB

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