BigForm.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. <template>
  2. <a-card :bordered="false">
  3. <a-form :form="form1" :self-update="true" @submit="handleForm1Submit">
  4. <a-row class="form-row" :gutter="16">
  5. <a-col :lg="6" :md="12" :sm="24">
  6. <a-form-item label="仓库名">
  7. <a-input
  8. placeholder="请输入仓库名称"
  9. v-decorator="[
  10. 'name',
  11. {rules: [{ required: true, message: '请输入仓库名称', whitespace: true}]}
  12. ]" />
  13. </a-form-item>
  14. </a-col>
  15. <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
  16. <a-form-item
  17. label="仓库域名">
  18. <a-input
  19. addonBefore="http://"
  20. addonAfter=".com"
  21. placeholder="请输入"
  22. v-decorator="[
  23. 'url',
  24. {rules: [{ required: true, message: '请输入仓库域名', whitespace: true}]}
  25. ]" />
  26. </a-form-item>
  27. </a-col>
  28. <a-col :xl="{span: 9, offset: 1}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
  29. <a-form-item
  30. label="仓库管理员">
  31. <a-select placeholder="请选择管理员" v-decorator="[ 'owner', {rules: [{ required: true, message: '请选择管理员'}]} ]">
  32. <a-select-option value="王同学">王同学</a-select-option>
  33. <a-select-option value="李同学">李同学</a-select-option>
  34. <a-select-option value="黄同学">黄同学</a-select-option>
  35. </a-select>
  36. </a-form-item>
  37. </a-col>
  38. </a-row>
  39. <a-row class="form-row" :gutter="16">
  40. <a-col :lg="6" :md="12" :sm="24">
  41. <a-form-item
  42. label="审批人">
  43. <a-select placeholder="请选择审批员" v-decorator="[ 'approver', {rules: [{ required: true, message: '请选择审批员'}]} ]">
  44. <a-select-option value="王晓丽">王晓丽</a-select-option>
  45. <a-select-option value="李军">李军</a-select-option>
  46. </a-select>
  47. </a-form-item>
  48. </a-col>
  49. <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
  50. <a-form-item
  51. label="生效日期">
  52. <a-range-picker
  53. style="width: 100%"
  54. v-decorator="[
  55. 'dateRange',
  56. {rules: [{ required: true, message: '请选择生效日期'}]}
  57. ]" />
  58. </a-form-item>
  59. </a-col>
  60. <a-col :xl="{span: 9, offset: 1}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
  61. <a-form-item
  62. label="仓库类型">
  63. <a-select
  64. placeholder="请选择仓库类型"
  65. v-decorator="[
  66. 'type',
  67. {rules: [{ required: true, message: '请选择仓库类型'}]}
  68. ]" >
  69. <a-select-option value="公开">公开</a-select-option>
  70. <a-select-option value="私密">私密</a-select-option>
  71. </a-select>
  72. </a-form-item>
  73. </a-col>
  74. </a-row>
  75. <a-form-item v-if="showSubmit">
  76. <a-button htmlType="submit" >Submit</a-button>
  77. </a-form-item>
  78. </a-form>
  79. <a-form :form="form2" :self-update="true" @submit="handleForm2Submit">
  80. <a-row class="form-row" :gutter="16">
  81. <a-col :lg="6" :md="12" :sm="24">
  82. <a-form-item label="仓库名">
  83. <a-input
  84. placeholder="请输入仓库名称"
  85. v-decorator="[
  86. 'name',
  87. {rules: [{ required: true, message: '请输入仓库名称', whitespace: true}]}
  88. ]" />
  89. </a-form-item>
  90. </a-col>
  91. <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
  92. <a-form-item
  93. label="仓库域名">
  94. <a-input
  95. addonBefore="http://"
  96. addonAfter=".com"
  97. placeholder="请输入"
  98. v-decorator="[
  99. 'url',
  100. {rules: [{ required: true, message: '请输入仓库域名', whitespace: true}]}
  101. ]" />
  102. </a-form-item>
  103. </a-col>
  104. <a-col :xl="{span: 9, offset: 1}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
  105. <a-form-item
  106. label="仓库管理员">
  107. <a-select placeholder="请选择管理员" v-decorator="[ 'owner', {rules: [{ required: true, message: '请选择管理员'}]} ]">
  108. <a-select-option value="王同学">王同学</a-select-option>
  109. <a-select-option value="李同学">李同学</a-select-option>
  110. <a-select-option value="黄同学">黄同学</a-select-option>
  111. </a-select>
  112. </a-form-item>
  113. </a-col>
  114. </a-row>
  115. <a-row class="form-row" :gutter="16">
  116. <a-col :lg="6" :md="12" :sm="24">
  117. <a-form-item
  118. label="审批人">
  119. <a-select placeholder="请选择审批员" v-decorator="[ 'approver', {rules: [{ required: true, message: '请选择审批员'}]} ]">
  120. <a-select-option value="王晓丽">王晓丽</a-select-option>
  121. <a-select-option value="李军">李军</a-select-option>
  122. </a-select>
  123. </a-form-item>
  124. </a-col>
  125. <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
  126. <a-form-item
  127. label="生效日期">
  128. <a-range-picker
  129. style="width: 100%"
  130. v-decorator="[
  131. 'dateRange',
  132. {rules: [{ required: true, message: '请选择生效日期'}]}
  133. ]" />
  134. </a-form-item>
  135. </a-col>
  136. <a-col :xl="{span: 9, offset: 1}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
  137. <a-form-item
  138. label="仓库类型">
  139. <a-select
  140. placeholder="请选择仓库类型"
  141. v-decorator="[
  142. 'type',
  143. {rules: [{ required: true, message: '请选择仓库类型'}]}
  144. ]" >
  145. <a-select-option value="公开">公开</a-select-option>
  146. <a-select-option value="私密">私密</a-select-option>
  147. </a-select>
  148. </a-form-item>
  149. </a-col>
  150. </a-row>
  151. <a-form-item v-if="showSubmit">
  152. <a-button htmlType="submit" >Submit</a-button>
  153. </a-form-item>
  154. </a-form>
  155. <a-form :form="form3" :self-update="true" @submit="handleForm2Submit">
  156. <a-row class="form-row" :gutter="16">
  157. <a-col :lg="6" :md="12" :sm="24">
  158. <a-form-item label="仓库名">
  159. <a-input
  160. placeholder="请输入仓库名称"
  161. v-decorator="[
  162. 'name',
  163. {rules: [{ required: true, message: '请输入仓库名称', whitespace: true}]}
  164. ]" />
  165. </a-form-item>
  166. </a-col>
  167. <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
  168. <a-form-item
  169. label="仓库域名">
  170. <a-input
  171. addonBefore="http://"
  172. addonAfter=".com"
  173. placeholder="请输入"
  174. v-decorator="[
  175. 'url',
  176. {rules: [{ required: true, message: '请输入仓库域名', whitespace: true}]}
  177. ]" />
  178. </a-form-item>
  179. </a-col>
  180. <a-col :xl="{span: 9, offset: 1}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
  181. <a-form-item
  182. label="仓库管理员">
  183. <a-select placeholder="请选择管理员" v-decorator="[ 'owner', {rules: [{ required: true, message: '请选择管理员'}]} ]">
  184. <a-select-option value="王同学">王同学</a-select-option>
  185. <a-select-option value="李同学">李同学</a-select-option>
  186. <a-select-option value="黄同学">黄同学</a-select-option>
  187. </a-select>
  188. </a-form-item>
  189. </a-col>
  190. </a-row>
  191. <a-row class="form-row" :gutter="16">
  192. <a-col :lg="6" :md="12" :sm="24">
  193. <a-form-item
  194. label="审批人">
  195. <a-select placeholder="请选择审批员" v-decorator="[ 'approver', {rules: [{ required: true, message: '请选择审批员'}]} ]">
  196. <a-select-option value="王晓丽">王晓丽</a-select-option>
  197. <a-select-option value="李军">李军</a-select-option>
  198. </a-select>
  199. </a-form-item>
  200. </a-col>
  201. <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
  202. <a-form-item
  203. label="生效日期">
  204. <a-range-picker
  205. style="width: 100%"
  206. v-decorator="[
  207. 'dateRange',
  208. {rules: [{ required: true, message: '请选择生效日期'}]}
  209. ]" />
  210. </a-form-item>
  211. </a-col>
  212. <a-col :xl="{span: 9, offset: 1}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
  213. <a-form-item
  214. label="仓库类型">
  215. <a-select
  216. placeholder="请选择仓库类型"
  217. v-decorator="[
  218. 'type',
  219. {rules: [{ required: true, message: '请选择仓库类型'}]}
  220. ]" >
  221. <a-select-option value="公开">公开</a-select-option>
  222. <a-select-option value="私密">私密</a-select-option>
  223. </a-select>
  224. </a-form-item>
  225. </a-col>
  226. </a-row>
  227. <a-form-item v-if="showSubmit">
  228. <a-button htmlType="submit" >Submit</a-button>
  229. </a-form-item>
  230. </a-form>
  231. <a-form :form="form4" :self-update="true" @submit="handleForm2Submit">
  232. <a-row class="form-row" :gutter="16">
  233. <a-col :lg="6" :md="12" :sm="24">
  234. <a-form-item label="仓库名">
  235. <a-input
  236. placeholder="请输入仓库名称"
  237. v-decorator="[
  238. 'name',
  239. {rules: [{ required: true, message: '请输入仓库名称', whitespace: true}]}
  240. ]" />
  241. </a-form-item>
  242. </a-col>
  243. <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
  244. <a-form-item
  245. label="仓库域名">
  246. <a-input
  247. addonBefore="http://"
  248. addonAfter=".com"
  249. placeholder="请输入"
  250. v-decorator="[
  251. 'url',
  252. {rules: [{ required: true, message: '请输入仓库域名', whitespace: true}]}
  253. ]" />
  254. </a-form-item>
  255. </a-col>
  256. <a-col :xl="{span: 9, offset: 1}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
  257. <a-form-item
  258. label="仓库管理员">
  259. <a-select placeholder="请选择管理员" v-decorator="[ 'owner', {rules: [{ required: true, message: '请选择管理员'}]} ]">
  260. <a-select-option value="王同学">王同学</a-select-option>
  261. <a-select-option value="李同学">李同学</a-select-option>
  262. <a-select-option value="黄同学">黄同学</a-select-option>
  263. </a-select>
  264. </a-form-item>
  265. </a-col>
  266. </a-row>
  267. <a-row class="form-row" :gutter="16">
  268. <a-col :lg="6" :md="12" :sm="24">
  269. <a-form-item
  270. label="审批人">
  271. <a-select placeholder="请选择审批员" v-decorator="[ 'approver', {rules: [{ required: true, message: '请选择审批员'}]} ]">
  272. <a-select-option value="王晓丽">王晓丽</a-select-option>
  273. <a-select-option value="李军">李军</a-select-option>
  274. </a-select>
  275. </a-form-item>
  276. </a-col>
  277. <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
  278. <a-form-item
  279. label="生效日期">
  280. <a-range-picker
  281. style="width: 100%"
  282. v-decorator="[
  283. 'dateRange',
  284. {rules: [{ required: true, message: '请选择生效日期'}]}
  285. ]" />
  286. </a-form-item>
  287. </a-col>
  288. <a-col :xl="{span: 9, offset: 1}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
  289. <a-form-item
  290. label="仓库类型">
  291. <a-select
  292. placeholder="请选择仓库类型"
  293. v-decorator="[
  294. 'type',
  295. {rules: [{ required: true, message: '请选择仓库类型'}]}
  296. ]" >
  297. <a-select-option value="公开">公开</a-select-option>
  298. <a-select-option value="私密">私密</a-select-option>
  299. </a-select>
  300. </a-form-item>
  301. </a-col>
  302. </a-row>
  303. <a-form-item v-if="showSubmit">
  304. <a-button htmlType="submit" >Submit</a-button>
  305. </a-form-item>
  306. </a-form>
  307. <a-form :form="form5" :self-update="true" @submit="handleForm2Submit">
  308. <a-row class="form-row" :gutter="16">
  309. <a-col :lg="6" :md="12" :sm="24">
  310. <a-form-item label="仓库名">
  311. <a-input
  312. placeholder="请输入仓库名称"
  313. v-decorator="[
  314. 'name',
  315. {rules: [{ required: true, message: '请输入仓库名称', whitespace: true}]}
  316. ]" />
  317. </a-form-item>
  318. </a-col>
  319. <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
  320. <a-form-item
  321. label="仓库域名">
  322. <a-input
  323. addonBefore="http://"
  324. addonAfter=".com"
  325. placeholder="请输入"
  326. v-decorator="[
  327. 'url',
  328. {rules: [{ required: true, message: '请输入仓库域名', whitespace: true}]}
  329. ]" />
  330. </a-form-item>
  331. </a-col>
  332. <a-col :xl="{span: 9, offset: 1}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
  333. <a-form-item
  334. label="仓库管理员">
  335. <a-select placeholder="请选择管理员" v-decorator="[ 'owner', {rules: [{ required: true, message: '请选择管理员'}]} ]">
  336. <a-select-option value="王同学">王同学</a-select-option>
  337. <a-select-option value="李同学">李同学</a-select-option>
  338. <a-select-option value="黄同学">黄同学</a-select-option>
  339. </a-select>
  340. </a-form-item>
  341. </a-col>
  342. </a-row>
  343. <a-row class="form-row" :gutter="16">
  344. <a-col :lg="6" :md="12" :sm="24">
  345. <a-form-item
  346. label="审批人">
  347. <a-select placeholder="请选择审批员" v-decorator="[ 'approver', {rules: [{ required: true, message: '请选择审批员'}]} ]">
  348. <a-select-option value="王晓丽">王晓丽</a-select-option>
  349. <a-select-option value="李军">李军</a-select-option>
  350. </a-select>
  351. </a-form-item>
  352. </a-col>
  353. <a-col :xl="{span: 7, offset: 1}" :lg="{span: 8}" :md="{span: 12}" :sm="24">
  354. <a-form-item
  355. label="生效日期">
  356. <a-range-picker
  357. style="width: 100%"
  358. v-decorator="[
  359. 'dateRange',
  360. {rules: [{ required: true, message: '请选择生效日期'}]}
  361. ]" />
  362. </a-form-item>
  363. </a-col>
  364. <a-col :xl="{span: 9, offset: 1}" :lg="{span: 10}" :md="{span: 24}" :sm="24">
  365. <a-form-item
  366. label="仓库类型">
  367. <a-select
  368. placeholder="请选择仓库类型"
  369. v-decorator="[
  370. 'type',
  371. {rules: [{ required: true, message: '请选择仓库类型'}]}
  372. ]" >
  373. <a-select-option value="公开">公开</a-select-option>
  374. <a-select-option value="私密">私密</a-select-option>
  375. </a-select>
  376. </a-form-item>
  377. </a-col>
  378. </a-row>
  379. <a-form-item v-if="showSubmit">
  380. <a-button htmlType="submit" >Submit</a-button>
  381. </a-form-item>
  382. </a-form>
  383. <a-divider />
  384. <a-table
  385. :columns="columns"
  386. :dataSource="data"
  387. :pagination="false"
  388. :loading="tableLoading"
  389. >
  390. <template v-for="(col, i) in ['name', 'workId', 'department']" :slot="col" slot-scope="text, record">
  391. <a-input
  392. :key="col"
  393. v-if="record.editable"
  394. style="margin: -5px 0"
  395. :value="text"
  396. :placeholder="columns[i].title"
  397. @change="e => handleChange(e.target.value, record.key, col)"
  398. />
  399. <template v-else>{{ text }}</template>
  400. </template>
  401. <template slot="operation" slot-scope="text, record">
  402. <template v-if="record.editable">
  403. <span v-if="record.isNew">
  404. <a @click="saveRow(record)">添加</a>
  405. <a-divider type="vertical" />
  406. <a-popconfirm title="是否要删除此行?" @confirm="remove(record.key)">
  407. <a>删除</a>
  408. </a-popconfirm>
  409. </span>
  410. <span v-else>
  411. <a @click="saveRow(record)">保存</a>
  412. <a-divider type="vertical" />
  413. <a @click="cancel(record.key)">取消</a>
  414. </span>
  415. </template>
  416. <span v-else>
  417. <a @click="toggle(record.key)">编辑</a>
  418. <a-divider type="vertical" />
  419. <a-popconfirm title="是否要删除此行?" @confirm="remove(record.key)">
  420. <a>删除</a>
  421. </a-popconfirm>
  422. </span>
  423. </template>
  424. </a-table>
  425. <a-button style="width: 100%; margin-top: 16px; margin-bottom: 8px" type="dashed" icon="plus" @click="newMember">新增成员</a-button>
  426. </a-card>
  427. </template>
  428. <script>
  429. const columns = [
  430. {
  431. title: '成员姓名',
  432. dataIndex: 'name',
  433. key: 'name',
  434. width: '20%',
  435. scopedSlots: { customRender: 'name' }
  436. },
  437. {
  438. title: '工号',
  439. dataIndex: 'workId',
  440. key: 'workId',
  441. width: '20%',
  442. scopedSlots: { customRender: 'workId' }
  443. },
  444. {
  445. title: '所属部门',
  446. dataIndex: 'department',
  447. key: 'department',
  448. width: '40%',
  449. scopedSlots: { customRender: 'department' }
  450. },
  451. {
  452. title: '操作',
  453. key: 'action',
  454. scopedSlots: { customRender: 'operation' }
  455. }
  456. ]
  457. export default {
  458. name: 'BigForm',
  459. data () {
  460. return {
  461. showSubmit: true,
  462. form1: this.$form.createForm(this),
  463. form2: this.$form.createForm(this),
  464. form3: this.$form.createForm(this),
  465. form4: this.$form.createForm(this),
  466. form5: this.$form.createForm(this),
  467. tableLoading: false,
  468. columns,
  469. data: [{
  470. key: '1',
  471. name: '小明',
  472. workId: '001',
  473. editable: false,
  474. department: '行政部'
  475. },
  476. {
  477. key: '2',
  478. name: '李莉',
  479. workId: '002',
  480. editable: false,
  481. department: 'IT部'
  482. },
  483. {
  484. key: '3',
  485. name: '王小帅',
  486. workId: '003',
  487. editable: false,
  488. department: '财务部'
  489. }]
  490. }
  491. },
  492. mounted () {
  493. // 加 10 个表单行
  494. new Array(10).fill(0).forEach(() => {
  495. this.newMember()
  496. })
  497. },
  498. methods: {
  499. handleForm1Submit (e) {
  500. e.preventDefault()
  501. this.form1.validateFields()
  502. },
  503. handleForm2Submit (e) {
  504. e.preventDefault()
  505. this.form2.validateFields()
  506. },
  507. handleChange (value, key, column) {
  508. const target = this.data.find(item => key === item.key)
  509. if (target) {
  510. target[column] = value
  511. }
  512. },
  513. toggle (record) {
  514. },
  515. saveRow (record) {
  516. },
  517. cancel (key) {
  518. },
  519. remove (key) {
  520. this.data = this.data.filter(item => item.key !== key)
  521. },
  522. newMember () {
  523. const length = this.data.length
  524. this.data.push({
  525. key: length === 0 ? '1' : (parseInt(this.data[length - 1].key) + 1).toString(),
  526. name: '',
  527. workId: '',
  528. department: '',
  529. editable: true,
  530. isNew: true
  531. })
  532. }
  533. }
  534. }
  535. </script>
  536. <style scoped>
  537. </style>