6eed1b13161de3c6170d4950bd183b0d2fb7e5c6.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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-date-picker ref="inputDatetime" v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
  14. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  15. <el-button class="successBorder" @click="handleRefresh">重置</el-button>
  16. </div>
  17. <div class="table">
  18. <el-table
  19. :key="table.tableKey"
  20. v-loading="table.listLoading"
  21. element-loading-text="给我一点时间"
  22. :data="table.list"
  23. border
  24. fit
  25. highlight-current-row
  26. style="width: 100%;"
  27. :row-style="rowStyle"
  28. :cell-style="cellStyle"
  29. class="elTable table-fixed"
  30. @selection-change="handleSelectionChange"
  31. >
  32. <el-table-column type="selection" align="center" width="50" />
  33. <el-table-column label="序号" align="center" type="index" width="50px">
  34. <template slot-scope="scope">
  35. <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
  36. </template>
  37. </el-table-column>
  38. <el-table-column label="角色名称" min-width="130px" align="center">
  39. <template slot-scope="scope">
  40. <span v-if="scope.row.NoEdit">{{ scope.row.brandName }}</span>
  41. <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" />
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="备注" min-width="130px" align="center">
  45. <template slot-scope="scope">
  46. <span v-if="scope.row.NoEdit">{{ scope.row.brandName }}</span>
  47. <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" />
  48. </template>
  49. </el-table-column>
  50. <el-table-column label="创建时间" min-width="150px" align="center">
  51. <template slot-scope="scope">
  52. <span>{{ scope.row.brandName }}</span>
  53. </template>
  54. </el-table-column>
  55. <el-table-column label="创建人" min-width="150px" align="center">
  56. <template slot-scope="scope">
  57. <span>{{ scope.row.brandName }}</span>
  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 class="miniSuccess" @click="handleRole(row)">页面权限</el-button>
  69. <!-- 新增 -->
  70. <el-button v-if="row.isCreate" class="miniSuccess" @click="createData(row)">保存</el-button>
  71. <el-button v-if="row.isCreate" class="minCancel" @click="createCancel(row)">取消</el-button>
  72. <!-- 编辑 -->
  73. <el-button v-if="row.isUpdate" class="miniSuccess" @click="handleUpdate(row)">编辑</el-button>
  74. <el-button v-if="row.isUpdate" class="miniDanger" @click="handleRowDelete(row)">删除</el-button>
  75. <!-- 编辑保存 -->
  76. <el-button v-if="row.isUpdateSave" class="miniSuccess" @click="updateData(row)">保存</el-button>
  77. <el-button v-if="row.isUpdateSave" class="minCancel" @click="updateCancel(row)">取消</el-button>
  78. </template>
  79. </el-table-column>
  80. </el-table>
  81. <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
  82. </div>
  83. <el-dialog :title="textMap[role.dialogStatus]" :visible.sync="role.dialogFormVisible" :close-on-click-modal="false" width="70%">
  84. <div class="app-role">
  85. <el-tree :data="role.list" show-checkbox node-key="id" default-expand-all :expand-on-click-node="false">
  86. <span slot-scope="{ node, data }" class="custom-tree-node">
  87. <span>{{ node.label }}</span>
  88. <span>
  89. <el-checkbox v-model="data.checked1" @change="() => append(node,data)">
  90. <el-button type="text" size="mini">查看</el-button>
  91. </el-checkbox>
  92. <el-checkbox @change="() => remove(node,data)">
  93. <el-button type="text" size="mini">编辑</el-button>
  94. </el-checkbox>
  95. </span>
  96. </span>
  97. </el-tree>
  98. </el-tree></div>
  99. </el-dialog>
  100. </div>
  101. </template>
  102. <script>
  103. import { GetDataByName } from '@/api/common'
  104. import Pagination from '@/components/Pagination'
  105. export default {
  106. name: 'Role',
  107. components: { Pagination },
  108. data() {
  109. return {
  110. enableList: [{ id: 0, name: '是' }, { id: 1, name: '否' }], jumpDelayList: [{ id: 0, name: '禁用' }, { id: 1, name: '3秒' }, { id: 2, name: '6秒' }, { id: 3, name: '9秒' }],
  111. table: {
  112. getdataListParm: {
  113. name: 'getAssetList',
  114. page: 1,
  115. offset: 1,
  116. pagecount: 10,
  117. returntype: 'Map',
  118. parammaps: {
  119. enable: ''
  120. }
  121. },
  122. tableKey: 0,
  123. list: [],
  124. total: 0,
  125. listLoading: true
  126. },
  127. role: {
  128. dialogFormVisible: false,
  129. dialogStatus: '',
  130. list: [{
  131. id: 1, label: '配方计划', 'checked1': true,
  132. children: [{ id: 4, label: '配方模板', 'checked1': true }, { id: 5, label: '栏舍配方' }]
  133. }, {
  134. id: 2, label: '栏舍生产',
  135. children: [{ id: 6, label: '栏舍产奶量' }, { id: 7, label: '栏舍剩料量' }]
  136. }],
  137. temp: {}
  138. },
  139. textMap: {
  140. role: '权限管理'
  141. },
  142. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  143. cellStyle: { padding: 0 + 'px' }
  144. }
  145. },
  146. created() {
  147. this.getList()
  148. },
  149. methods: {
  150. getList() {
  151. this.table.listLoading = true
  152. GetDataByName(this.table.getdataListParm).then(response => {
  153. console.log('table数据', response.data.list)
  154. if (response.data.list !== null) {
  155. for (let i = 0; i < response.data.list.length; i++) {
  156. this.$set(response.data.list[i], 'Edit', false) // 编辑
  157. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  158. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  159. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  160. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  161. }
  162. this.table.list = response.data.list
  163. this.table.pageNum = response.data.pageNum
  164. this.table.pageSize = response.data.pageSize
  165. this.table.total = response.data.total
  166. } else {
  167. this.table.list = []
  168. }
  169. setTimeout(() => {
  170. this.table.listLoading = false
  171. }, 100)
  172. })
  173. },
  174. handleEnableChange() {
  175. console.log('点击了是否启用')
  176. },
  177. handleConfirmStartChange() {
  178. console.log('点击了确认开始')
  179. },
  180. handleSearch() {
  181. console.log('点击了查询')
  182. this.getList()
  183. },
  184. handleRefresh() {
  185. console.log('点击了重置')
  186. },
  187. handleSelectionChange(val) {
  188. console.log('勾选数据', val)
  189. },
  190. handleCreate() {
  191. console.log('点击了新增')
  192. // 编辑true/不可编辑false
  193. // 新增操true,编辑false,编辑保存false
  194. for (let i = 0; i < this.table.list.length; i++) {
  195. if (this.table.list[i].Edit == true) {
  196. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  197. return false
  198. }
  199. }
  200. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'confirmStart': 1 })
  201. },
  202. createData(row) {
  203. console.log('点击了新增保存', row)
  204. },
  205. createCancel(row) {
  206. console.log('点击了新增取消')
  207. for (let i = 0; i < this.table.list.length; i++) {
  208. if (row.myId === this.table.list[i].myId) {
  209. var listIndex = this.table.list.indexOf(this.table.list[i])
  210. }
  211. if (listIndex > -1) {
  212. this.table.list.splice(listIndex, 1)
  213. return
  214. }
  215. }
  216. },
  217. handleUpdate(row) {
  218. console.log('点击了编辑')
  219. for (let i = 0; i < this.table.list.length; i++) {
  220. if (this.table.list[i].Edit == true) {
  221. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  222. return false
  223. }
  224. }
  225. // 编辑true,不可编辑false
  226. row.Edit = true
  227. row.NoEdit = false
  228. // 新增false,编辑false,编辑保存true
  229. row.isCreate = false
  230. row.isUpdate = false
  231. row.isUpdateSave = true
  232. },
  233. updateData(row) {
  234. console.log('点击了编辑保存', row)
  235. },
  236. updateCancel(row) {
  237. console.log('点击了编辑取消')
  238. // 编辑false,不可编辑true
  239. row.Edit = false
  240. row.NoEdit = true
  241. // 新增false,编辑true,编辑保存false
  242. row.isCreate = false
  243. row.isUpdate = true
  244. row.isUpdateSave = false
  245. },
  246. handleRowDelete(row) {
  247. console.log('点击了行内删除')
  248. },
  249. handleDelete() {
  250. console.log('点击了删除')
  251. },
  252. handleRole(row) {
  253. console.log('点击了行内页面权限')
  254. this.role.dialogStatus = 'role'
  255. this.role.dialogFormVisible = true
  256. },
  257. append(node, data) {
  258. console.log('点击了查看', node, data)
  259. if (node.childNodes.length > 0) {
  260. node.checked = true
  261. for (let i = 0; i < node.childNodes.length; i++) {
  262. node.childNodes[i].checked = true
  263. }
  264. }
  265. },
  266. remove(node, data) {
  267. console.log('点击了编辑', node, data)
  268. },
  269. renderContent(h, { node, data, store }) {
  270. return (
  271. <span class='custom-tree-node'>
  272. <span>{node.label}</span>
  273. <span>
  274. <el-button size='mini' type='text' on-click={ () => this.append(data) }>Append</el-button>
  275. <el-button size='mini' type='text' on-click={ () => this.remove(node, data) }>Delete</el-button>
  276. </span>
  277. </span>)
  278. }
  279. }
  280. }
  281. </script>
  282. <style lang="scss" scoped>
  283. .search{margin-top:10px;}
  284. .table{margin-top:10px;}
  285. .custom-tree-node {
  286. flex: 1;
  287. display: flex;
  288. align-items: center;
  289. justify-content: space-between;
  290. font-size: 14px;
  291. padding-right: 8px;
  292. }
  293. </style>