streetXftdpczl.vue 7.1 KB

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