mp_excelRcXcdjl_edit.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <template>
  2. <!-- <view> 日程id : {{ rcid }}</view> -->
  3. <Form :rules="fieldConfigs" v-model="formData" ref="formRef" style="height: calc(100vh - 212rpx);">
  4. <!-- 循环遍历巡查点数据 -->
  5. <view v-for="(item, index) in xunchaList" :key="item.xcdid">
  6. <table-title>{{ item.xcdmc }}</table-title>
  7. <up-table>
  8. <up-tr>
  9. <up-th>情况描述</up-th>
  10. <Td :field="`xcd_${index}.qkms`">
  11. <SsInput v-model="formData[`xcd_${index}`].qkms" placeholder="请输入情况描述" />
  12. </Td>
  13. </up-tr>
  14. <up-tr>
  15. <up-th>处理描述</up-th>
  16. <Td :field="`xcd_${index}.clms`">
  17. <SsInput v-model="formData[`xcd_${index}`].clms" placeholder="请输入处理描述" />
  18. </Td>
  19. </up-tr>
  20. <up-tr>
  21. <up-th>责任人</up-th>
  22. <Td :field="`xcd_${index}.zrr`">
  23. <SsInput v-model="formData[`xcd_${index}`].zrr" placeholder="请输入责任人" />
  24. </Td>
  25. </up-tr>
  26. </up-table>
  27. </view>
  28. </Form>
  29. <SsBottom
  30. :buttons="bottomButtons"
  31. @button-click="handleBottomAction"
  32. />
  33. </template>
  34. <script setup>
  35. import { ref } from 'vue'
  36. import { onLoad } from '@dcloudio/uni-app'
  37. import Form from '@/components/Form/index.vue'
  38. import Td from '@/components/Td/index.vue'
  39. import SsInput from '@/components/SsInput/index.vue'
  40. import TableTitle from '@/components/SsTableTitle/index.vue'
  41. import SsBottom from '@/components/SsBottom/index.vue'
  42. import { xunchaApi } from '@/api/xuncha'
  43. const rcid = ref(0)
  44. const xunchaList = ref([])
  45. // 表单数据
  46. const formData = ref({})
  47. // 加载巡查数据
  48. const loadXunchaData = async () => {
  49. try {
  50. const res = await xunchaApi.initZxxzEdit({rcid: rcid.value})
  51. console.log('返回数据:', res)
  52. // 直接使用返回的 xcdjlList 数组
  53. if (res.data && res.data.xcdjlList) {
  54. xunchaList.value = res.data.xcdjlList
  55. console.log('巡查点数据:', xunchaList.value)
  56. } else {
  57. console.warn('未找到 xcdjlList 数据')
  58. xunchaList.value = []
  59. }
  60. // 数据加载完成后生成字段配置
  61. generateFieldConfigs()
  62. } catch (error) {
  63. console.error('加载巡查数据失败:', error)
  64. uni.showToast({
  65. title: '加载数据失败',
  66. icon: 'none'
  67. })
  68. }
  69. }
  70. const fieldConfigs = ref({})
  71. // 动态生成字段配置和初始化表单数据(参考 dynamic-form.vue)
  72. const generateFieldConfigs = () => {
  73. const newFormData = {}
  74. const newFieldConfigs = {}
  75. xunchaList.value.forEach((item, index) => {
  76. const areaKey = `xcd_${index}`
  77. // 初始化嵌套数据结构
  78. newFormData[areaKey] = {
  79. qkms: item.qkms || '',
  80. clms: item.clms || '',
  81. zrr: item.zrr || ''
  82. }
  83. // 生成字段配置 - 使用嵌套字段名(点号分隔)
  84. newFieldConfigs[`${areaKey}.qkms`] = {
  85. rules: [{ required: true, message: `${item.xcdmc}的情况描述不能为空` }]
  86. }
  87. newFieldConfigs[`${areaKey}.clms`] = {
  88. rules: [{ required: true, message: `${item.xcdmc}的处理描述不能为空` }]
  89. }
  90. newFieldConfigs[`${areaKey}.zrr`] = {
  91. rules: [{ required: true, message: `${item.xcdmc}的责任人不能为空` }]
  92. }
  93. })
  94. // 更新响应式数据
  95. formData.value = newFormData
  96. fieldConfigs.value = newFieldConfigs
  97. console.log('初始化完成:', {
  98. formData: formData.value,
  99. fieldConfigs: fieldConfigs.value
  100. })
  101. }
  102. // 获取Form组件的引用
  103. const formRef = ref(null)
  104. // 提交状态
  105. const submitting = ref(false)
  106. // 底部按钮配置
  107. const bottomButtons = [
  108. { text: '取消', action: 'cancel' },
  109. { text: '保存并提交', action: 'submit' }
  110. ]
  111. // 底部按钮事件处理
  112. const handleBottomAction = (data) => {
  113. console.log('底部按钮操作:', data)
  114. switch(data.action) {
  115. case 'cancel':
  116. uni.navigateBack() // 返回上一页
  117. break
  118. case 'submit':
  119. handleSubmit()
  120. break
  121. }
  122. }
  123. // 提交表单逻辑(模拟JSP表单提交方式)
  124. const handleSubmit = async () => {
  125. if (formRef.value) {
  126. try {
  127. submitting.value = true
  128. // 校验表单
  129. const isValid = formRef.value.validateForm(formData.value, fieldConfigs.value)
  130. console.log('校验结果:', isValid)
  131. if (isValid) {
  132. // 构建表单数据,模拟JSP中的表单提交格式
  133. const formSubmitData = {
  134. // 隐藏字段
  135. rcid: rcid.value,
  136. // 巡查点数据 - 使用JSP中的字段名格式
  137. xcdid: [],
  138. xcdjlid: [],
  139. qkms: [],
  140. clms: [],
  141. zrr: []
  142. }
  143. // 填充数组数据(按JSP中的格式)
  144. xunchaList.value.forEach((item, index) => {
  145. formSubmitData.xcdid.push(item.xcdid)
  146. formSubmitData.xcdjlid.push(item.xcdjlid || 'null')
  147. formSubmitData.qkms.push(formData.value[`xcd_${index}`].qkms)
  148. formSubmitData.clms.push(formData.value[`xcd_${index}`].clms)
  149. formSubmitData.zrr.push(formData.value[`xcd_${index}`].zrr)
  150. })
  151. console.log('提交数据(JSP格式):', formSubmitData)
  152. const res = await xunchaApi.submZxxzEdit(formSubmitData)
  153. console.log('提交结果:', res)
  154. uni.showToast({
  155. title: '提交成功',
  156. icon: 'success'
  157. })
  158. // 延迟返回上一页
  159. setTimeout(() => {
  160. uni.navigateBack()
  161. }, 1500)
  162. } else {
  163. uni.showToast({
  164. title: '请检查表单信息',
  165. icon: 'none'
  166. })
  167. }
  168. } catch (error) {
  169. console.error('提交失败:', error)
  170. uni.showToast({
  171. title: '提交失败',
  172. icon: 'error'
  173. })
  174. } finally {
  175. submitting.value = false
  176. }
  177. }
  178. }
  179. onLoad((options) => {
  180. console.log('onLoad', options)
  181. rcid.value = options.rcid || 521188
  182. // 加载巡查数据
  183. loadXunchaData()
  184. })
  185. </script>
  186. <style lang="scss" scoped>
  187. // 巡查页面样式
  188. </style>