53506e68410e7b6db4a1688f3cac242a9e09605d.svn-base 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template>
  2. <div>
  3. <a-card class="card" title="仓库管理" :bordered="false">
  4. <repository-form ref="repository" :showSubmit="false" />
  5. </a-card>
  6. <a-card class="card" title="任务管理" :bordered="false">
  7. <task-form ref="task" :showSubmit="false" />
  8. </a-card>
  9. <!-- table -->
  10. <a-card>
  11. <form :autoFormCreate="(form) => this.form = form">
  12. <a-table
  13. :columns="columns"
  14. :dataSource="data"
  15. :pagination="false"
  16. >
  17. <template v-for="(col, i) in ['name', 'workId', 'department']" :slot="col" slot-scope="text, record, index">
  18. <a-input
  19. :key="col"
  20. v-if="record.editable"
  21. style="margin: -5px 0"
  22. :value="text"
  23. :placeholder="columns[i].title"
  24. @change="e => handleChange(e.target.value, record.key, col)"
  25. />
  26. <template v-else>{{ text }}</template>
  27. </template>
  28. <template slot="operation" slot-scope="text, record, index">
  29. <template v-if="record.editable">
  30. <span v-if="record.isNew">
  31. <a @click="saveRow(record.key)">添加</a>
  32. <a-divider type="vertical" />
  33. <a-popconfirm title="是否要删除此行?" @confirm="remove(record.key)">
  34. <a>删除</a>
  35. </a-popconfirm>
  36. </span>
  37. <span v-else>
  38. <a @click="saveRow(record.key)">保存</a>
  39. <a-divider type="vertical" />
  40. <a @click="cancel(record.key)">取消</a>
  41. </span>
  42. </template>
  43. <span v-else>
  44. <a @click="toggle(record.key)">编辑</a>
  45. <a-divider type="vertical" />
  46. <a-popconfirm title="是否要删除此行?" @confirm="remove(record.key)">
  47. <a>删除</a>
  48. </a-popconfirm>
  49. </span>
  50. </template>
  51. </a-table>
  52. <a-button style="width: 100%; margin-top: 16px; margin-bottom: 8px" type="dashed" icon="plus" @click="newMember">新增成员</a-button>
  53. </form>
  54. </a-card>
  55. <!-- fixed footer toolbar -->
  56. <footer-tool-bar>
  57. <a-button type="primary" @click="validate" :loading="loading">提交</a-button>
  58. </footer-tool-bar>
  59. </div>
  60. </template>
  61. <script>
  62. import RepositoryForm from './RepositoryForm'
  63. import TaskForm from './TaskForm'
  64. import FooterToolBar from '@/components/tools/FooterToolBar'
  65. export default {
  66. name: "AdvancedForm",
  67. components: {
  68. FooterToolBar,
  69. RepositoryForm,
  70. TaskForm
  71. },
  72. data () {
  73. return {
  74. description: '高级表单常见于一次性输入和提交大批量数据的场景。',
  75. loading: false,
  76. // table
  77. columns: [
  78. {
  79. title: '成员姓名',
  80. dataIndex: 'name',
  81. key: 'name',
  82. width: '20%',
  83. scopedSlots: { customRender: 'name' }
  84. },
  85. // {
  86. // title: '工号',
  87. // dataIndex: 'workId',
  88. // key: 'workId',
  89. // width: '20%',
  90. // scopedSlots: { customRender: 'workId' }
  91. // },
  92. {
  93. title: '所属部门',
  94. dataIndex: 'department',
  95. key: 'department',
  96. width: '40%',
  97. scopedSlots: { customRender: 'department' }
  98. },
  99. {
  100. title: '操作',
  101. key: 'action',
  102. scopedSlots: { customRender: 'operation' }
  103. }
  104. ],
  105. data: [
  106. {
  107. key: '1',
  108. name: '小明',
  109. workId: '001',
  110. editable: false,
  111. department: '行政部'
  112. },
  113. {
  114. key: '2',
  115. name: '李莉',
  116. workId: '002',
  117. editable: false,
  118. department: 'IT部'
  119. },
  120. {
  121. key: '3',
  122. name: '王小帅',
  123. workId: '003',
  124. editable: false,
  125. department: '财务部'
  126. }
  127. ]
  128. }
  129. },
  130. methods: {
  131. handleSubmit (e) {
  132. e.preventDefault()
  133. },
  134. newMember () {
  135. this.data.push({
  136. key: '-1',
  137. name: '',
  138. workId: '',
  139. department: '',
  140. editable: true,
  141. isNew: true
  142. })
  143. },
  144. remove (key) {
  145. const newData = this.data.filter(item => item.key !== key)
  146. this.data = newData
  147. },
  148. saveRow (key) {
  149. let target = this.data.filter(item => item.key === key)[0]
  150. target.editable = false
  151. target.isNew = false
  152. },
  153. toggle (key) {
  154. let target = this.data.filter(item => item.key === key)[0]
  155. target.editable = !target.editable
  156. },
  157. getRowByKey (key, newData) {
  158. const data = this.data
  159. return (newData || data).filter(item => item.key === key)[0]
  160. },
  161. cancel (key) {
  162. let target = this.data.filter(item => item.key === key)[0]
  163. target.editable = false
  164. },
  165. handleChange (value, key, column) {
  166. const newData = [...this.data]
  167. const target = newData.filter(item => key === item.key)[0]
  168. if (target) {
  169. target[column] = value
  170. this.data = newData
  171. }
  172. },
  173. // 最终全页面提交
  174. validate () {
  175. this.$refs.repository.form.validateFields((err, values) => {
  176. if (!err) {
  177. this.$notification['error']({
  178. message: 'Received values of form:',
  179. description: values
  180. })
  181. }
  182. })
  183. this.$refs.task.form.validateFields((err, values) => {
  184. if (!err) {
  185. this.$notification['error']({
  186. message: 'Received values of form:',
  187. description: values
  188. })
  189. }
  190. })
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang="less" scoped>
  196. .card{
  197. margin-bottom: 24px;
  198. }
  199. </style>