CourtyardNetworkManagement.vue 11 KB

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