SubForm.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <div class="form-subform">
  3. <div class="form-subform-item"
  4. v-for="(t, index) in (paging ? pagingLength : subformData)"
  5. :key="(paging ? pageSize * (currentPage - 1) : 0) + index"
  6. @mouseover.stop="handleMouseover((paging ? pageSize * (currentPage - 1) : 0) + index)"
  7. @mouseout="handleMouseout((paging ? pageSize * (currentPage - 1) : 0) + index)"
  8. :ref="`formSubformItem_${(paging ? pageSize * (currentPage - 1) : 0) + index}`"
  9. >
  10. <div class="form-subform-index" v-if="showControl">
  11. <a-tag color="processing">#{{(paging ? pageSize * (currentPage - 1) : 0) + index + 1}}</a-tag>
  12. </div>
  13. <div class="form-subform-remove" v-if="showControl">
  14. <a-popconfirm :disabled="disableddata" v-if="!printRead && isDelete" :title="$t('fm.description.deleteConfirm')" @confirm="handleRemove((paging ? pageSize * (currentPage - 1) : 0) + index)">
  15. <a-button :disabled="disableddata" danger size="small" shape="circle"><i class="fm-iconfont icon-trash" style="font-size: 12px; margin: 5px;"></i></a-button>
  16. </a-popconfirm>
  17. <a-tag color="processing" v-if="printRead || !isDelete">#{{(paging ? pageSize * (currentPage - 1) : 0) + index + 1}}</a-tag>
  18. </div>
  19. <div class="form-subform-content">
  20. <template v-for="item in list">
  21. <generate-col-item
  22. v-if="item.type == 'grid'"
  23. :key="`grid-${item.key}`"
  24. :model="subformData[(paging ? pageSize * (currentPage - 1) : 0) + index]"
  25. :rules="rules"
  26. :element="item"
  27. :remote="remote"
  28. :blanks="blanks"
  29. :display="displayFields"
  30. :sub-hide-fields="subHideFields"
  31. :sub-disabled-fields="subDisabledFields"
  32. :edit="!disableddata"
  33. :remote-option="remoteOption"
  34. :platform="platform"
  35. :preview="preview"
  36. :container-key="containerKey"
  37. :data-source-value="dataSourceValue"
  38. :event-function="eventFunction"
  39. :print-read="printRead"
  40. :is-subform="true"
  41. :row-index="(paging ? pageSize * (currentPage - 1) : 0) + index"
  42. :sub-name="name"
  43. :config="config"
  44. :is-dialog="isDialog"
  45. :dialog-name="dialogName"
  46. :is-group="false"
  47. :group="group ? `${group}.${name}` : name"
  48. :field-node="`${fieldNode}.${(paging ? pageSize * (currentPage - 1) : 0) + index}`"
  49. >
  50. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  51. <slot :name="blank.name" :model="scope.model"></slot>
  52. </template>
  53. </generate-col-item>
  54. <generate-tab-item
  55. v-else-if="item.type == 'tabs'"
  56. :key="`tabs-${item.key}`"
  57. :model="subformData[(paging ? pageSize * (currentPage - 1) : 0) + index]"
  58. :rules="rules"
  59. :element="item"
  60. :remote="remote"
  61. :blanks="blanks"
  62. :display="displayFields"
  63. :sub-hide-fields="subHideFields"
  64. :sub-disabled-fields="subDisabledFields"
  65. :edit="!disableddata"
  66. :remote-option="remoteOption"
  67. :platform="platform"
  68. :preview="preview"
  69. :container-key="containerKey"
  70. :data-source-value="dataSourceValue"
  71. :event-function="eventFunction"
  72. :print-read="printRead"
  73. :is-subform="true"
  74. :row-index="(paging ? pageSize * (currentPage - 1) : 0) + index"
  75. :sub-name="name"
  76. :config="config"
  77. :is-dialog="isDialog"
  78. :dialog-name="dialogName"
  79. :is-group="false"
  80. :group="group ? `${group}.${name}` : name"
  81. :field-node="`${fieldNode}.${(paging ? pageSize * (currentPage - 1) : 0) + index}`"
  82. >
  83. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  84. <slot :name="blank.name" :model="scope.model"></slot>
  85. </template>
  86. </generate-tab-item>
  87. <generate-collapse
  88. v-else-if="item.type == 'collapse'"
  89. :key="`collapse-${item.key}`"
  90. :model="subformData[(paging ? pageSize * (currentPage - 1) : 0) + index]"
  91. :rules="rules"
  92. :element="item"
  93. :remote="remote"
  94. :blanks="blanks"
  95. :display="displayFields"
  96. :sub-hide-fields="subHideFields"
  97. :sub-disabled-fields="subDisabledFields"
  98. :edit="!disableddata"
  99. :remote-option="remoteOption"
  100. :platform="platform"
  101. :preview="preview"
  102. :container-key="containerKey"
  103. :data-source-value="dataSourceValue"
  104. :event-function="eventFunction"
  105. :print-read="printRead"
  106. :is-subform="true"
  107. :row-index="(paging ? pageSize * (currentPage - 1) : 0) + index"
  108. :sub-name="name"
  109. :config="config"
  110. :is-dialog="isDialog"
  111. :dialog-name="dialogName"
  112. :is-group="false"
  113. :group="group ? `${group}.${name}` : name"
  114. :field-node="`${fieldNode}.${(paging ? pageSize * (currentPage - 1) : 0) + index}`"
  115. >
  116. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  117. <slot :name="blank.name" :model="scope.model"></slot>
  118. </template>
  119. </generate-collapse>
  120. <generate-report
  121. v-else-if="item.type == 'report'"
  122. :key="`report-${item.key}`"
  123. :model="subformData[(paging ? pageSize * (currentPage - 1) : 0) + index]"
  124. :rules="rules"
  125. :element="item"
  126. :remote="remote"
  127. :blanks="blanks"
  128. :display="displayFields"
  129. :sub-hide-fields="subHideFields"
  130. :sub-disabled-fields="subDisabledFields"
  131. :edit="!disableddata"
  132. :remote-option="remoteOption"
  133. :platform="platform"
  134. :preview="preview"
  135. :container-key="containerKey"
  136. :data-source-value="dataSourceValue"
  137. :event-function="eventFunction"
  138. :print-read="printRead"
  139. :is-subform="true"
  140. :row-index="(paging ? pageSize * (currentPage - 1) : 0) + index"
  141. :sub-name="name"
  142. :config="config"
  143. :is-dialog="isDialog"
  144. :dialog-name="dialogName"
  145. :is-group="false"
  146. :group="group ? `${group}.${name}` : name"
  147. :field-node="`${fieldNode}.${(paging ? pageSize * (currentPage - 1) : 0) + index}`"
  148. >
  149. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  150. <slot :name="blank.name" :model="scope.model"></slot>
  151. </template>
  152. </generate-report>
  153. <generate-card
  154. v-else-if="item.type == 'card'"
  155. :key="`card-${item.key}`"
  156. :model="subformData[(paging ? pageSize * (currentPage - 1) : 0) + index]"
  157. :rules="rules"
  158. :element="item"
  159. :remote="remote"
  160. :blanks="blanks"
  161. :display="displayFields"
  162. :sub-hide-fields="subHideFields"
  163. :sub-disabled-fields="subDisabledFields"
  164. :edit="!disableddata"
  165. :remote-option="remoteOption"
  166. :platform="platform"
  167. :preview="preview"
  168. :container-key="containerKey"
  169. :data-source-value="dataSourceValue"
  170. :event-function="eventFunction"
  171. :print-read="printRead"
  172. :is-subform="true"
  173. :row-index="(paging ? pageSize * (currentPage - 1) : 0) + index"
  174. :sub-name="name"
  175. :config="config"
  176. :is-dialog="isDialog"
  177. :dialog-name="dialogName"
  178. :is-group="false"
  179. :group="group ? `${group}.${name}` : name"
  180. :field-node="`${fieldNode}.${(paging ? pageSize * (currentPage - 1) : 0) + index}`"
  181. >
  182. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  183. <slot :name="blank.name" :model="scope.model"></slot>
  184. </template>
  185. </generate-card>
  186. <generate-inline
  187. v-else-if="item.type == 'inline'"
  188. :key="`inline-${item.key}`"
  189. :model="subformData[(paging ? pageSize * (currentPage - 1) : 0) + index]"
  190. :rules="rules"
  191. :element="item"
  192. :remote="remote"
  193. :blanks="blanks"
  194. :display="displayFields"
  195. :sub-hide-fields="subHideFields"
  196. :sub-disabled-fields="subDisabledFields"
  197. :edit="!disableddata"
  198. :remote-option="remoteOption"
  199. :platform="platform"
  200. :preview="preview"
  201. :container-key="containerKey"
  202. :data-source-value="dataSourceValue"
  203. :event-function="eventFunction"
  204. :print-read="printRead"
  205. :is-subform="true"
  206. :row-index="(paging ? pageSize * (currentPage - 1) : 0) + index"
  207. :sub-name="name"
  208. :config="config"
  209. :is-dialog="isDialog"
  210. :dialog-name="dialogName"
  211. :is-group="false"
  212. :group="group ? `${group}.${name}` : name"
  213. :field-node="`${fieldNode}.${(paging ? pageSize * (currentPage - 1) : 0) + index}`"
  214. >
  215. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  216. <slot :name="blank.name" :model="scope.model"></slot>
  217. </template>
  218. </generate-inline>
  219. <generate-form-item
  220. v-else
  221. :key="`form-item-${item.key}`"
  222. :models="subformData[(paging ? pageSize * (currentPage - 1) : 0) + index]"
  223. :rules="rules"
  224. :widget="item"
  225. :remote="remote"
  226. :blanks="blanks"
  227. :display="displayFields"
  228. :sub-hide-fields="subHideFields"
  229. :sub-disabled-fields="subDisabledFields"
  230. :edit="!disableddata"
  231. :remote-option="remoteOption"
  232. :platform="platform"
  233. :preview="preview"
  234. :container-key="containerKey"
  235. :data-source-value="dataSourceValue"
  236. :event-function="eventFunction"
  237. :print-read="printRead"
  238. :is-subform="true"
  239. :row-index="(paging ? pageSize * (currentPage - 1) : 0) + index"
  240. :sub-name="name"
  241. :config="config"
  242. :is-dialog="isDialog"
  243. :dialog-name="dialogName"
  244. :is-group="false"
  245. :group="group ? `${group}.${name}` : name"
  246. :field-node="`${fieldNode}.${(paging ? pageSize * (currentPage - 1) : 0) + index}`"
  247. >
  248. <template v-slot:[blank.name]="scope" v-for="blank in blanks">
  249. <slot :name="blank.name" :model="scope.model"></slot>
  250. </template>
  251. </generate-form-item>
  252. </template>
  253. </div>
  254. </div>
  255. <a-row class="form-subform-action">
  256. <a-col :md="(preview && platform != 'mobile') || !preview ? 12 : 24" :sm="24">
  257. <a-button type="link" @click="handleAddRow" v-if="!disableddata && isAdd">
  258. <i class="fm-iconfont icon-plus" style="font-size: 12px; margin: 5px;"></i>{{$t('fm.actions.add')}}
  259. </a-button>
  260. </a-col>
  261. <a-col :md="((preview && platform != 'mobile') || !preview) && !disableddata ? 12 : 24" :xs="24" :sm="24">
  262. <a-pagination
  263. style="float: right; padding-top: 5px;white-space: nowrap;"
  264. layout="total, prev, pager, next"
  265. :page-size="pageSize"
  266. v-model:current="currentPage"
  267. :total="subformData.length"
  268. :pager-count="5"
  269. @change="handlePageChange"
  270. v-if="paging && subformData.length"
  271. show-less-items
  272. >
  273. </a-pagination>
  274. </a-col>
  275. </a-row>
  276. </div>
  277. </template>
  278. <script>
  279. import { defineAsyncComponent } from 'vue'
  280. import { subFormMixin } from '../../mixins/subForm';
  281. export default {
  282. name: 'fm-sub-form',
  283. components: {
  284. GenerateColItem: defineAsyncComponent(() => import('./GenerateColItem.vue')),
  285. GenerateFormItem: defineAsyncComponent(() => import('./GenerateFormItem.vue')),
  286. GenerateInline: defineAsyncComponent(() => import('./GenereteInline.vue')),
  287. GenerateReport: defineAsyncComponent(() => import('./GenerateReport.vue')),
  288. GenerateTabItem: defineAsyncComponent(() => import('./GenerateTabItem.vue')),
  289. GenerateCollapse: defineAsyncComponent(() => import('./GenerateCollapse.vue')),
  290. GenerateCard: defineAsyncComponent(() => import('./GenerateCard.vue'))
  291. },
  292. mixins: [subFormMixin]
  293. }
  294. </script>
  295. <style lang="scss">
  296. .form-subform{
  297. .form-subform-item{
  298. display: flex;
  299. padding: 6px;
  300. &.is-hover{
  301. background-color: #fafafa;
  302. >.form-subform-index{
  303. display: none;
  304. }
  305. >.form-subform-remove{
  306. display: block;
  307. }
  308. }
  309. .form-subform-index{
  310. width: 50px;
  311. text-align: center;
  312. }
  313. .form-subform-content{
  314. flex: 1;
  315. >.fm-report-table__wrapper{
  316. margin: 0;
  317. }
  318. }
  319. .form-subform-remove{
  320. width: 50px;
  321. text-align: center;
  322. display: none;
  323. }
  324. }
  325. }
  326. html.dark{
  327. .form-subform{
  328. .form-subform-item{
  329. &.is-hover{
  330. background-color: #1d1d1d;
  331. }
  332. }
  333. }
  334. }
  335. </style>