roadSection.vue 12 KB

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