159ae8e719976c8f41c23e6553979113085a004c.svn-base 10.0 KB

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