CourtyardNetworkManagement.vue 11 KB

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