4253a2c6102fd883ec7a4212861668378415e3ce.svn-base 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <div class="app-container">
  3. <div class="operation">
  4. <el-button class="success" @click="handleCreate">新增</el-button>
  5. <el-button class="danger" @click="handleDelete">删除</el-button>
  6. </div>
  7. <div class="search">
  8. <el-input v-model="table.getdataListParm.parammaps.assetCode" placeholder="驾驶员名称" style="width: 180px;" class="filter-item" clearable />
  9. <el-input v-model="table.getdataListParm.parammaps.assetCode" placeholder="班组" style="width: 180px;" class="filter-item" clearable />
  10. <el-select v-model="table.getdataListParm.parammaps.enable" placeholder="是否启用" class="filter-item" style="width: 120px;" clearable>
  11. <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.name" />
  12. </el-select>
  13. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  14. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  15. </div>
  16. <div class="table">
  17. <el-table
  18. :key="table.tableKey"
  19. v-loading="table.listLoading"
  20. element-loading-text="给我一点时间"
  21. :data="table.list"
  22. border
  23. fit
  24. highlight-current-row
  25. style="width: 100%;"
  26. :row-style="rowStyle"
  27. :cell-style="cellStyle"
  28. class="elTable table-fixed"
  29. @selection-change="handleSelectionChange"
  30. >
  31. <el-table-column type="selection" align="center" width="50" />
  32. <el-table-column label="序号" align="center" type="index" width="50px">
  33. <template slot-scope="scope">
  34. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="驾驶员编号" min-width="130px" align="center">
  38. <template slot-scope="scope">
  39. <span v-if="scope.row.NoEdit">{{ scope.row.brandName }}</span>
  40. <el-input v-if="scope.row.Edit" v-model="scope.row.brandName" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:80%;padding:10px 0;" maxlength="32" />
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="驾驶员名称" min-width="130px" align="center">
  44. <template slot-scope="scope">
  45. <span v-if="scope.row.NoEdit">{{ scope.row.brandName }}</span>
  46. <el-input v-if="scope.row.Edit" v-model="scope.row.brandName" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" style="width:80%;padding:10px 0;" maxlength="32" />
  47. </template>
  48. </el-table-column>
  49. <el-table-column label="班组" min-width="110px" align="center">
  50. <template slot-scope="scope">
  51. <span v-if="scope.row.NoEdit">{{ scope.row.brandName }}</span>
  52. <el-input v-if="scope.row.Edit" v-model="scope.row.brandName" style="width:80%;padding:10px 0;" />
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="是否启用" min-width="110px" align="center">
  56. <template slot-scope="scope">
  57. <el-switch v-model="scope.row.enable" :disabled="scope.row.NoEdit==true" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="handleEnableChange(scope.$index, scope.row)" />
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width" fixed="right">
  61. <template slot-scope="{row}">
  62. <!-- 新增 -->
  63. <el-button v-if="row.isCreate" class="miniSuccess" @click="createData(row)">保存</el-button>
  64. <el-button v-if="row.isCreate" class="minCancel" @click="createCancel(row)">取消</el-button>
  65. <!-- 编辑 -->
  66. <el-button v-if="row.isUpdate" class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  67. <el-button v-if="row.isUpdate" class="miniDanger" @click="handleRowDelete(row)">删除</el-button>
  68. <!-- 编辑保存 -->
  69. <el-button v-if="row.isUpdateSave" class="miniSuccess" @click="updateData(row)">保存</el-button>
  70. <el-button v-if="row.isUpdateSave" class="minCancel" @click="updateCancel(row)">取消</el-button>
  71. </template>
  72. </el-table-column>
  73. </el-table>
  74. <pagination v-show="table.total>0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  75. </div>
  76. </div>
  77. </template>
  78. <script>
  79. import { GetDataByName } from '@/api/common'
  80. import Pagination from '@/components/Pagination'
  81. export default {
  82. name: 'Driver',
  83. components: { Pagination },
  84. data() {
  85. return {
  86. enableList: [{ id: 0, name: '是' }, { id: 1, name: '否' }], // 是否启用
  87. table: {
  88. getdataListParm: {
  89. name: 'getAssetList',
  90. page: 1,
  91. offset: 1,
  92. pagecount: 10,
  93. returntype: 'Map',
  94. parammaps: {
  95. enable: ''
  96. }
  97. },
  98. tableKey: 0,
  99. list: [],
  100. total: 0,
  101. listLoading: true
  102. },
  103. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  104. cellStyle: { padding: 0 + 'px' }
  105. }
  106. },
  107. created() {
  108. this.getList()
  109. },
  110. methods: {
  111. getList() {
  112. this.table.listLoading = true
  113. GetDataByName(this.table.getdataListParm).then(response => {
  114. console.log('table数据', response.data.list)
  115. if (response.data.list !== null) {
  116. for (let i = 0; i < response.data.list.length; i++) {
  117. this.$set(response.data.list[i], 'Edit', false) // 编辑
  118. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  119. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  120. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  121. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  122. }
  123. this.table.list = response.data.list
  124. this.table.pageNum = response.data.pageNum
  125. this.table.pageSize = response.data.pageSize
  126. this.table.total = response.data.total
  127. } else {
  128. this.table.list = []
  129. }
  130. setTimeout(() => {
  131. this.table.listLoading = false
  132. }, 100)
  133. })
  134. },
  135. handleEnableChange() {
  136. console.log('点击了是否启用')
  137. },
  138. handleSearch() {
  139. console.log('点击了查询')
  140. this.getList()
  141. },
  142. handleRefresh() {
  143. console.log('点击了重置')
  144. },
  145. handleSelectionChange(val) {
  146. console.log('勾选数据', val)
  147. },
  148. handleCreate() {
  149. // 编辑true/不可编辑false
  150. // 新增操true,编辑false,编辑保存false
  151. console.log(11)
  152. for (let i = 0; i < this.table.list.length; i++) {
  153. if (this.table.list[i].Edit === true) {
  154. console.log(123)
  155. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  156. return false
  157. }
  158. }
  159. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1 })
  160. },
  161. createData(row) {
  162. console.log('点击了新增保存', row)
  163. },
  164. createCancel(row) {
  165. console.log('点击了新增取消')
  166. for (let i = 0; i < this.table.list.length; i++) {
  167. if (row.myId === this.table.list[i].myId) {
  168. var listIndex = this.table.list.indexOf(this.table.list[i])
  169. }
  170. if (listIndex > -1) {
  171. this.table.list.splice(listIndex, 1)
  172. return
  173. }
  174. }
  175. },
  176. handleUpdate(row) {
  177. for (let i = 0; i < this.table.list.length; i++) {
  178. if (this.table.list[i].Edit == true) {
  179. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  180. return false
  181. }
  182. }
  183. // 编辑true,不可编辑false
  184. row.Edit = true
  185. row.NoEdit = false
  186. // 新增false,编辑false,编辑保存true
  187. row.isCreate = false
  188. row.isUpdate = false
  189. row.isUpdateSave = true
  190. },
  191. updateData(row) {
  192. console.log('点击了编辑保存', row)
  193. },
  194. updateCancel(row) {
  195. console.log('点击了编辑取消')
  196. // 编辑false,不可编辑true
  197. row.Edit = false
  198. row.NoEdit = true
  199. // 新增false,编辑true,编辑保存false
  200. row.isCreate = false
  201. row.isUpdate = true
  202. row.isUpdateSave = false
  203. },
  204. handleRowDelete(row) {
  205. console.log('点击了行内删除')
  206. },
  207. handleDelete() {
  208. console.log('点击了删除')
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .search{margin-top:10px;}
  215. .table{margin-top:10px;}
  216. </style>