streetDpccdtfpczl.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="uni-container">
  3. <view class="example container" :style="'height: ' + (screenHeight - wheight - 75) + 'px'">
  4. <u--form ref="customForm" :model="formData" labelPosition="left" labelWidth="100%" labelAlign="left">
  5. <view class="juli-bottom">
  6. <u-form-item label="检查单位或小区 (个)" prop="jcdwhxq">
  7. <u-input v-model="formData.jcdwhxq" placeholder="请输入" :disabled="isview" />
  8. </u-form-item>
  9. <u-form-item label="制止、整改违规停放充电 (处)" prop="zzzgwgtfcd">
  10. <u-input v-model="formData.zzzgwgtfcd" placeholder="请输入" :disabled="isview" />
  11. </u-form-item>
  12. <u-form-item label="新建智能充电装置(处)" prop="xjzncdzz">
  13. <u-input v-model="formData.xjzncdzz" placeholder="请输入" :disabled="isview" />
  14. </u-form-item>
  15. <u-form-item label="新建普通集中充电装置 (处)" prop="xjptjzcdzz">
  16. <u-input v-model="formData.xjptjzcdzz" placeholder="请输入" :disabled="isview" />
  17. </u-form-item>
  18. <u-form-item label="辖区内集中充电装置总数普通型 (总数)" prop="xqnjzcdzzptx">
  19. <u-input v-model="formData.xqnjzcdzzptx" placeholder="请输入" :disabled="isview" />
  20. </u-form-item>
  21. <u-form-item label="辖区内集中充电装置智能型 (总数)" prop="xqnjzcdzzznx">
  22. <u-input v-model="formData.xqnjzcdzzznx" placeholder="请输入" :disabled="isview" />
  23. </u-form-item>
  24. <picker mode="date" :value="dateTime" @change="bindDateChange" :disabled="isview">
  25. <view class="datatime-street">
  26. <u-form-item label="填报日期" prop="reporttime" :required="true">
  27. <u-input v-model="formData.reporttime" placeholder="选择日期" class="add-date"
  28. :disabled="isview" />
  29. </u-form-item>
  30. </view>
  31. </picker>
  32. <view>
  33. <view class="paizhao">现场照片</view>
  34. <view class="paizhao-posit" v-if="!isview">
  35. <image :src="photograph" @click="photoUpload" class="tiantupian-photo"></image>
  36. <view>
  37. 拍照上传
  38. </view>
  39. </view>
  40. </view>
  41. <view v-if="formData.streetRepPicsDOList" class="show-photo">
  42. <view v-for="(items,indexs) in formData.streetRepPicsDOList" :key="indexs">
  43. <view class="show-photo-main">
  44. <view class="show-photo-main-img">
  45. <image :src="items.url" class="show-photo-main-img-item">
  46. <u-icon name="close" color="#4CB2B6" size="19" @click="closeImage(items,indexs)"
  47. v-if="!isview">
  48. </u-icon>
  49. </view>
  50. <view class="">
  51. <view>
  52. 图片名称
  53. </view>
  54. <view class="img-name-street">
  55. <u-input v-model="items.feildname" placeholder="请输入图片名称" :disabled="isview" />
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </u--form>
  63. </view>
  64. <view class="sub-botn heigthButton">
  65. <u-button v-if="isedit" @click="submit('customForm')" type="primary" shape="circle" size="large"
  66. color="#4CB2B6" text="确认修改" style="width:200px">
  67. </u-button>
  68. <u-button v-else-if="!formData.id" @click="submit('customForm')" type="primary" shape="circle" size="large"
  69. color="#4CB2B6" text="确认新增" style="width:200px">
  70. </u-button>
  71. <u-button v-else-if="isview" @click="submit('customForm')" type="primary" shape="circle" size="large"
  72. color="#4CB2B6" text="返回" style="width:200px">
  73. </u-button>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import {
  79. createDpccdtfpczl,
  80. getIdDpccdtfpczl,
  81. updateDpccdtfpczl
  82. }
  83. from '@/api/fire_inspetItem/index';
  84. import {
  85. takePhotos,
  86. NumericRule
  87. } from '@/utils/common.js';
  88. import config from '@/config'
  89. const baseUrlImg = config.baseUrlImg
  90. export default {
  91. data() {
  92. return {
  93. screenHeight: this.$screenHeight,
  94. wheight: '',
  95. photograph: `${baseUrlImg}/checkActive/photograph.png`,
  96. dateTime: '',
  97. formData: {
  98. jcdwhxq: '',
  99. zzzgwgtfcd: '',
  100. xjzncdzz: '',
  101. xjptjzcdzz: '',
  102. xqnjzcdzzptx: '',
  103. xqnjzcdzzznx: '',
  104. reporttime: '',
  105. streetRepPicsDOList: []
  106. },
  107. rules: {
  108. jcdwhxq: NumericRule(),
  109. zzzgwgtfcd: NumericRule(),
  110. xjzncdzz: NumericRule(),
  111. xjptjzcdzz: NumericRule(),
  112. xqnjzcdzzptx: NumericRule(),
  113. xqnjzcdzzznx: NumericRule(),
  114. reporttime: [{
  115. required: true,
  116. message: '请输入日期',
  117. trigger: ['change', 'blur'],
  118. }],
  119. },
  120. isedit: false, //编辑
  121. isview: false, //查看
  122. }
  123. },
  124. mounted() {
  125. uni.createSelectorQuery().in(this).select('.heigthButton').boundingClientRect(data => {
  126. this.wheight = data.height
  127. }).exec()
  128. },
  129. onReady() {
  130. this.$refs.customForm.setRules(this.rules);
  131. },
  132. onLoad(option) {
  133. if (option.editData) {
  134. this.isedit = true
  135. this.parentId = option.editData
  136. this.getIdData()
  137. // this.formData = JSON.parse(option.editData)
  138. } else if (option.viewData) {
  139. this.isview = true
  140. this.parentId = option.viewData
  141. this.getIdData()
  142. // this.formData = JSON.parse(option.viewData)
  143. }
  144. },
  145. methods: {
  146. getIdData() {
  147. getIdDpccdtfpczl({
  148. id: this.parentId
  149. }).then(response => {
  150. this.formData = response.data
  151. console.log(response, 'response')
  152. })
  153. },
  154. //拍照
  155. closeImage(val, index) {
  156. this.formData.streetRepPicsDOList.splice(index, 1)
  157. },
  158. photoUpload() {
  159. takePhotos(this)
  160. },
  161. bindDateChange(e) {
  162. this.formData.reporttime = e.detail.value
  163. },
  164. submit(ref) {
  165. this.$refs[ref].validate().then(res => {
  166. const formList = this.formData
  167. Object.keys(formList).forEach(key => {
  168. formList[key] = formList[key] === '' ? 0 : formList[key];
  169. });
  170. formList.streetRepPicsDOList.forEach((item) => {
  171. // 删除除了feildname和url以外的多余字段
  172. Object.keys(item).forEach((key) => {
  173. if (key !== 'feildname' && key !== 'url' && key !== 'repid') {
  174. delete item[key];
  175. }
  176. });
  177. // 如果feildname为空,赋值为默认名称
  178. if (!item.feildname) {
  179. item.feildname = '默认名称';
  180. }
  181. });
  182. console.log(formList, 'this.formData');
  183. if (this.isedit) {
  184. updateDpccdtfpczl(JSON.stringify(this.formData)).then(res => {
  185. this.$modal.msg('修改成功')
  186. this.isedit = false
  187. setTimeout(() => {
  188. uni.navigateBack()
  189. }, 400)
  190. })
  191. } else if (this.isview) {
  192. this.isview = false
  193. uni.navigateBack()
  194. } else {
  195. createDpccdtfpczl(JSON.stringify(this.formData)).then(res => {
  196. this.$modal.msg('新增成功')
  197. setTimeout(() => {
  198. uni.navigateBack()
  199. }, 400)
  200. })
  201. }
  202. }).catch(err => {
  203. console.log(err);
  204. })
  205. }
  206. }
  207. }
  208. </script>
  209. <style lang="scss" scoped>
  210. body {
  211. background-color: #f5f7f9;
  212. }
  213. page {
  214. background-color: #f5f7f9 !important;
  215. }
  216. .uni-container {
  217. height: 100vh;
  218. background-color: #f5f7f9 !important;
  219. }
  220. /deep/.uni-card {
  221. position: relative;
  222. box-shadow: 0px 0px 3px 0px rgba(86, 165, 168, 0.15);
  223. border-radius: 30rpx;
  224. }
  225. .example {
  226. overflow-y: auto;
  227. }
  228. </style>