index.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div class="app-container">
  3. <div class="app-container">
  4. <div class="filter-container">
  5. <el-button v-if="isWorkerAdd" class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="form_add">新增</el-button>
  6. </div>
  7. <el-table
  8. v-loading="table.listLoading"
  9. element-loading-text="给我一点时间"
  10. :data="table.list"
  11. border
  12. fit
  13. highlight-current-row
  14. style="width: 100%;"
  15. :row-style="rowStyle"
  16. :cell-style="cellStyle"
  17. class="elTable"
  18. row-key="id"
  19. default-expand-all
  20. @sort-change="tableSort"
  21. >
  22. <el-table-column label="序号" align="center" type="index" width="50px">
  23. <template slot-scope="scope">
  24. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  25. </template>
  26. </el-table-column>
  27. <el-table-column label="类别名称" min-width="110px" header-align="center" align="center" prop="typeName" />
  28. <el-table-column label="顺序" min-width="110px" sortable header-align="center" align="center" prop="sort" />
  29. <el-table-column label="启用" min-width="80px" header-align="center" align="center">
  30. <template slot-scope="scope">
  31. <el-switch v-model="scope.row.enable" disabled active-color="#13ce66" inactive-color="#ff4949" :active-value="'1'" :inactive-value="'0'" @change="handleEnableChange(scope.$index, scope.row)" />
  32. </template>
  33. </el-table-column>
  34. <el-table-column label="操作" header-align="center" align="center" width="160" class-name="small-padding fixed-width" fixed="right">
  35. <template slot-scope="{row}">
  36. <el-button v-if="isWorkerUpdate" type="primary" size="mini" @click="form_edit(row)">编辑</el-button>
  37. </template>
  38. </el-table-column>
  39. </el-table>
  40. <pagination v-show="table.total>0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  41. <el-dialog :title="textMap[dialogStatus]" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="50%">
  42. <el-form ref="createTemp" :rules="rules" :model="create.temp" label-position="right" label-width="150px">
  43. <el-form-item label="维修工类别:" prop="typeName">
  44. <el-row>
  45. <el-col :span="12">
  46. <el-input ref="typeName" v-model="create.temp.typeName" />
  47. </el-col>
  48. </el-row>
  49. </el-form-item>
  50. <el-form-item label="顺序:" prop="sort">
  51. <el-row>
  52. <el-col :span="12">
  53. <el-input ref="sort" v-model="create.temp.sort" />
  54. </el-col>
  55. </el-row>
  56. </el-form-item>
  57. <el-form-item label="启用:" prop="enable">
  58. <el-row>
  59. <el-col :span="12">
  60. <el-switch ref="enable" v-model="create.temp.enable" active-color="#13ce66" inactive-color="#ff4949" :active-value="'1'" :inactive-value="'0'" />
  61. </el-col>
  62. </el-row>
  63. </el-form-item>
  64. </el-form>
  65. <div slot="footer" class="dialog-footer">
  66. <el-button v-if="dialogStatus=='create'" type="success" @click="add_dialog_save_again()">保存并新增</el-button>
  67. <el-button type="primary" @click="dialogStatus=='create'?add_dialog_save():edit_dialog_save()">保存并关闭</el-button>
  68. <el-button @click="create.dialogFormVisible = false;getList()">取消并关闭</el-button>
  69. </div>
  70. </el-dialog>
  71. </div>
  72. </div>
  73. </template>
  74. <script>
  75. import waves from '@/directive/waves'
  76. import { PostDataByName, GetDataByName, GetDataByNames, checkButtons, failproccess } from '@/api/common'
  77. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  78. import { sortChange } from '@/utils/index.js'
  79. import { isIntegerZero } from '@/utils/validate'
  80. export default {
  81. name: 'MaintenanceWorkerCategory',
  82. components: { Pagination },
  83. directives: { waves },
  84. data() {
  85. return {
  86. isWorkerAdd: [], isWorkerUpdate: [],
  87. table: {
  88. tableKey: 0, total: 0, listLoading: true, list: [], pageNum: 0, pageSize: 10,
  89. getdataListParm: {
  90. name: 'getMaintence', page: 1, offset: 1, pagecount: 10, returntype: 'Map',
  91. parammaps: {}
  92. }
  93. },
  94. requestParam: { name: 'createapisql', offset: 0, pagecount: 0, parammaps: [] },
  95. create: {
  96. temp: { typeName: '', sort: '', enable: '1' }, dialogFormVisible: false
  97. },
  98. dialogStatus: '',
  99. rules: {
  100. typeName: [{ type: 'string', required: true, message: '必填', trigger: 'change' }],
  101. sort: [{ validator: isIntegerZero, trigger: 'blur' }]
  102. },
  103. textMap: { update: '编辑', create: '新增' },
  104. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  105. cellStyle: { padding: 0 + 'px' }
  106. }
  107. },
  108. created() {
  109. this.getList()
  110. this.getButtons()
  111. },
  112. methods: {
  113. tableSort(column) {
  114. sortChange(column, this.list)
  115. },
  116. getButtons() {
  117. // 新增
  118. const WorkerAdd = 'basic:worker:add'
  119. const isWorkerAdd = checkButtons(this.$store.state.user.buttons, WorkerAdd)
  120. this.isWorkerAdd = isWorkerAdd
  121. // 编辑
  122. const WorkerUpdate = 'basic:worker:update'
  123. const isWorkerUpdate = checkButtons(this.$store.state.user.buttons, WorkerUpdate)
  124. this.isWorkerUpdate = isWorkerUpdate
  125. },
  126. getList() {
  127. this.table.listLoading = true
  128. GetDataByName(this.table.getdataListParm).then(response => {
  129. this.table.list = response.data.list
  130. this.table.pageNum = response.data.pageNum
  131. this.table.pageSize = response.data.pageSize
  132. if (response.data.total) {
  133. this.table.total = response.data.total
  134. }
  135. setTimeout(() => {
  136. this.table.listLoading = false
  137. }, 1000)
  138. })
  139. },
  140. form_add() {
  141. this.create.temp = { typeName: '', sort: 0, enable: '1' }
  142. this.dialogStatus = 'create'
  143. this.create.dialogFormVisible = true
  144. },
  145. add_dialog_save() {
  146. this.$refs['createTemp'].validate(valid => {
  147. if (valid) {
  148. this.requestParam = {}
  149. this.requestParam.name = 'insertMaintenanceType'
  150. this.requestParam.parammaps = this.create.temp
  151. PostDataByName(this.requestParam).then(response => {
  152. if (response.msg !== 'fail') {
  153. this.getList()
  154. this.create.dialogFormVisible = false
  155. this.$notify({ title: '成功', message: '新增成功', type: 'success', duration: 2000 })
  156. } else {
  157. failproccess(response, this.$notify)
  158. }
  159. })
  160. }
  161. })
  162. },
  163. add_dialog_save_again() {
  164. this.$refs['createTemp'].validate(valid => {
  165. if (valid) {
  166. this.requestParam = {}
  167. this.requestParam.name = 'insertMaintenanceType'
  168. this.requestParam.parammaps = this.create.temp
  169. PostDataByName(this.requestParam).then(response => {
  170. if (response.msg !== 'fail') {
  171. this.create.temp = { typeName: '', sort: '', enable: '1' }
  172. this.$notify({ title: '成功', message: '新增成功', type: 'success', duration: 2000 })
  173. } else {
  174. failproccess(response, this.$notify)
  175. }
  176. })
  177. }
  178. })
  179. },
  180. form_edit(row) {
  181. this.create.temp = Object.assign(row, {})
  182. this.dialogStatus = 'update'
  183. this.create.dialogFormVisible = true
  184. },
  185. edit_dialog_save() {
  186. this.$refs['createTemp'].validate(valid => {
  187. if (valid) {
  188. this.requestParam = {}
  189. this.requestParam.name = 'updateMaintenanceType'
  190. this.requestParam.parammaps = this.create.temp
  191. PostDataByName(this.requestParam).then(response => {
  192. if (response.msg !== 'fail') {
  193. this.create.dialogFormVisible = false
  194. this.$notify({ title: '成功', message: '新增成功', type: 'success', duration: 2000 })
  195. } else {
  196. failproccess(response, this.$notify)
  197. }
  198. })
  199. }
  200. })
  201. }
  202. }
  203. }
  204. </script>