576b001b2ea71b1c91ba8beef132e1c8c2599546.svn-base 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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.enable" placeholder="饲料大类" class="filter-item" style="width: 120px;" clearable>
  9. <el-option v-for="item in feedCategoryList" :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" clearable />
  12. <el-input v-model="table.getdataListParm.parammaps.assetCode" placeholder="饲料分类编号" style="width: 180px;" class="filter-item" clearable />
  13. <el-select v-model="table.getdataListParm.parammaps.enable" placeholder="是否启用" class="filter-item" style="width: 120px;" clearable>
  14. <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.name" />
  15. </el-select>
  16. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  17. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  18. </div>
  19. <div class="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="130px" 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: 120px;" clearable>
  44. <el-option v-for="item in feedCategoryList" :key="item.id" :label="item.name" :value="item.name" />
  45. </el-select>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="饲料分类" min-width="130px" 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:10px 0;" maxlength="32" />
  52. </template>
  53. </el-table-column>
  54. <el-table-column label="饲料分类编号" min-width="110px" 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:10px 0;" 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. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  80. </div>
  81. </div>
  82. </template>
  83. <script>
  84. import { GetDataByName } from '@/api/common'
  85. import Pagination from '@/components/Pagination'
  86. export default {
  87. name: 'FeedClassification',
  88. components: { Pagination },
  89. data() {
  90. return {
  91. enableList: [{ id: 0, name: '是' }, { id: 1, name: '否' }],
  92. feedCategoryList: [{ id: 0, name: '精料' }, { id: 1, name: '粗料' }, { id: 2, name: '精粗各半' }],
  93. table: {
  94. getdataListParm: {
  95. name: 'getAssetList',
  96. page: 1,
  97. offset: 1,
  98. pagecount: 10,
  99. returntype: 'Map',
  100. parammaps: {
  101. enable: ''
  102. }
  103. },
  104. tableKey: 0,
  105. list: [],
  106. total: 0,
  107. listLoading: true
  108. },
  109. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  110. cellStyle: { padding: 0 + 'px' }
  111. }
  112. },
  113. created() {
  114. this.getList()
  115. },
  116. methods: {
  117. getList() {
  118. this.table.listLoading = true
  119. GetDataByName(this.table.getdataListParm).then(response => {
  120. console.log('table数据', response.data.list)
  121. if (response.data.list !== null) {
  122. for (let i = 0; i < response.data.list.length; i++) {
  123. this.$set(response.data.list[i], 'Edit', false) // 编辑
  124. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  125. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  126. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  127. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  128. }
  129. this.table.list = response.data.list
  130. this.table.pageNum = response.data.pageNum
  131. this.table.pageSize = response.data.pageSize
  132. this.table.total = response.data.total
  133. } else {
  134. this.table.list = []
  135. }
  136. setTimeout(() => {
  137. this.table.listLoading = false
  138. }, 100)
  139. })
  140. },
  141. handleEnableChange() {
  142. console.log('点击了是否启用')
  143. },
  144. handleSearch() {
  145. console.log('点击了查询')
  146. this.getList()
  147. },
  148. handleRefresh() {
  149. console.log('点击了重置')
  150. },
  151. handleSelectionChange(val) {
  152. console.log('勾选数据', val)
  153. },
  154. handleCreate() {
  155. // 编辑true/不可编辑false
  156. // 新增操true,编辑false,编辑保存false
  157. for (let i = 0; i < this.table.list.length; i++) {
  158. if (this.table.list[i].Edit === true) {
  159. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  160. return false
  161. }
  162. }
  163. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1 })
  164. },
  165. createData(row) {
  166. console.log('点击了新增保存', row)
  167. },
  168. createCancel(row) {
  169. console.log('点击了新增取消')
  170. for (let i = 0; i < this.table.list.length; i++) {
  171. if (row.myId === this.table.list[i].myId) {
  172. var listIndex = this.table.list.indexOf(this.table.list[i])
  173. }
  174. if (listIndex > -1) {
  175. this.table.list.splice(listIndex, 1)
  176. return
  177. }
  178. }
  179. },
  180. handleUpdate(row) {
  181. for (let i = 0; i < this.table.list.length; i++) {
  182. if (this.table.list[i].Edit == true) {
  183. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  184. return false
  185. }
  186. }
  187. // 编辑true,不可编辑false
  188. row.Edit = true
  189. row.NoEdit = false
  190. // 新增false,编辑false,编辑保存true
  191. row.isCreate = false
  192. row.isUpdate = false
  193. row.isUpdateSave = true
  194. },
  195. updateData(row) {
  196. console.log('点击了编辑保存', row)
  197. },
  198. updateCancel(row) {
  199. console.log('点击了编辑取消')
  200. // 编辑false,不可编辑true
  201. row.Edit = false
  202. row.NoEdit = true
  203. // 新增false,编辑true,编辑保存false
  204. row.isCreate = false
  205. row.isUpdate = true
  206. row.isUpdateSave = false
  207. },
  208. handleRowDelete(row) {
  209. console.log('点击了行内删除')
  210. },
  211. handleDelete() {
  212. console.log('点击了删除')
  213. }
  214. }
  215. }
  216. </script>
  217. <style lang="scss" scoped>
  218. .search{margin-top:10px;}
  219. .table{margin-top:10px;}
  220. </style>