index_20190321144258.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div class="cost-team">
  3. <el-button type="primary" class="add" @click="append">增加收入部门</el-button>
  4. <el-card class="right-card">
  5. <el-table
  6. :data="costTeamData"
  7. style="width: 100%">
  8. <!-- <el-table-column type="expand">
  9. <template slot-scope="props">
  10. <el-form label-position="left" inline class="demo-table-expand">
  11. <el-form-item label="收入部门名称">
  12. <span>{{ props.row.name }}</span>
  13. </el-form-item>
  14. <el-form-item label="收入部门 ID">
  15. <span>{{ props.row.id }}</span>
  16. </el-form-item>
  17. </el-form>
  18. </template>
  19. </el-table-column> -->
  20. <el-table-column
  21. label="收入部门编号"
  22. prop="code">
  23. </el-table-column>
  24. <el-table-column
  25. label="收入部门名称"
  26. prop="name">
  27. </el-table-column>
  28. <el-table-column label="操作" width="80">
  29. <template slot-scope="scope">
  30. <el-button
  31. size="mini"
  32. @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
  33. <!--
  34. <el-button
  35. size="mini"
  36. type="danger"
  37. @click="handleDelete(scope.$index, scope.row)">删除</el-button>
  38. -->
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. </el-card>
  43. <el-dialog title="新增收入部门" :visible.sync="dialogFormVisible">
  44. <el-form :model="form" ref="form">
  45. <el-form-item label="收入部门编码" prop="code" :label-width="formLabelWidth" :rules="[{ required: true, message: '编码不能为空'}]">
  46. <el-input v-model="form.code" autocomplete="off"></el-input>
  47. </el-form-item>
  48. <el-form-item label="收入部门名称" prop="name" :label-width="formLabelWidth" :rules="[{ required: true, message: '名称不能为空'}]">
  49. <el-input v-model="form.name" autocomplete="off"></el-input>
  50. </el-form-item>
  51. <!--
  52. <el-form-item label="收入部门状态" prop="status" :label-width="formLabelWidth" :rules="[{ required: true, message: '状态不能为空'}]">
  53. <el-select v-model="form.status" placeholder="请选择状态值">
  54. <el-option label="正常" value="NORMAL"></el-option>
  55. <el-option label="已删除" value="DEL"></el-option>
  56. </el-select>
  57. </el-form-item>
  58. -->
  59. <el-form-item label="收入部门排序" prop="sort" :label-width="formLabelWidth" >
  60. <el-input v-model.number="form.sort" autocomplete="off"></el-input>
  61. </el-form-item>
  62. </el-form>
  63. <div slot="footer" class="dialog-footer">
  64. <el-button @click="resetForm('form')">取 消</el-button>
  65. <el-button type="primary" @click="submitForm('form')">确 定</el-button>
  66. </div>
  67. </el-dialog>
  68. </div>
  69. </template>
  70. <script scoped>
  71. import { getCostTeamList, addCostTeam, setCostTeam } from '@/api/costTeamApi'
  72. export default {
  73. data () {
  74. return {
  75. costTeamData: [],
  76. dialogFormVisible: false,
  77. addFlag: false,
  78. id: '',
  79. form: {
  80. code: '',
  81. name: '',
  82. status: 'NORMAL',
  83. sort: ''
  84. },
  85. formLabelWidth: '120px',
  86. index: ''
  87. }
  88. },
  89. created () {
  90. getCostTeamList().then(res => {
  91. this.costTeamData = res.data
  92. });
  93. },
  94. methods: {
  95. // 新增收入部门
  96. append() {
  97. this.addFlag = true;
  98. this.dialogFormVisible = true;
  99. },
  100. // 编辑收入部门
  101. handleEdit(index, row) {
  102. this.form.code = row.code;
  103. this.form.name = row.name;
  104. // this.form.status = row.status;
  105. this.form.sort = row.sort;
  106. this.id = row.id;
  107. this.index = index;
  108. this.dialogFormVisible = true;
  109. this.addFlag = false;
  110. },
  111. //删除收入部门
  112. handleDelete(index, row) {
  113. console.log(index, row);
  114. setCostTeam({
  115. id: row.id,
  116. status: 'DEL'
  117. }).then(res => {
  118. console.log(res);
  119. })
  120. },
  121. // 提交新增
  122. submitForm(formName) {
  123. //验证表单
  124. this.$refs[formName].validate((valid, value) => {
  125. if (valid) {
  126. console.log(this.form);
  127. if(this.addFlag) {
  128. addCostTeam(this.form).then(res => {
  129. this.costTeamData.unshift(res.data)
  130. this.$refs[formName].resetFields();
  131. })
  132. } else {
  133. this.form.id = this.id;
  134. setCostTeam(this.form).then(res => {
  135. console.log(res);
  136. console.log(this.index)
  137. this.costTeamData.splice(this.index, 1, res.data)
  138. this.$refs[formName].resetFields();
  139. })
  140. }
  141. this.dialogFormVisible = false;
  142. } else {
  143. return false;
  144. }
  145. });
  146. },
  147. // 取消
  148. resetForm (formName) {
  149. this.$refs[formName].resetFields();
  150. this.dialogFormVisible = false;
  151. }
  152. },
  153. }
  154. </script>
  155. <style scope>
  156. .cost-team {
  157. padding: 20px;
  158. box-sizing: border-box;
  159. }
  160. .add {
  161. float: right;
  162. margin-bottom: 20px;
  163. }
  164. .right-card {
  165. width: 100%;
  166. margin: 0 auto;
  167. }
  168. .demo-table-expand {
  169. font-size: 0;
  170. }
  171. .demo-table-expand label {
  172. width: 90px;
  173. color: #99a9bf;
  174. }
  175. .demo-table-expand .el-form-item {
  176. margin-right: 0;
  177. margin-bottom: 0;
  178. width: 50%;
  179. }
  180. </style>