CourtyardNetworkManagement.vue 11 KB

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