eb6b43e04a13df3e705dd4c5c0309a60ed645bb3.svn-base 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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.rolename" placeholder="角色名称" style="width: 180px;" class="filter-item" clearable />
  9. <el-input v-model="table.getdataListParm.parammaps.createmp" 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.id" />
  12. </el-select>
  13. <el-date-picker ref="inputDatetime" v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" 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.rolename }}</span>
  41. <el-input v-if="scope.row.Edit" v-model="scope.row.rolename" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  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.remark }}</span>
  47. <el-input v-if="scope.row.Edit" v-model="scope.row.remark" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
  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.createdtime }}</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.createmp }}</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 v-if="row.NoEdit" class="miniSuccess" @click="handleRole(row)">页面权限</el-button>
  69. <!-- 新增 -->
  70. <el-button v-if="row.isCreate" class="miniSuccess" :disabled="isokDisable" @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" :disabled="isokDisable" @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="role-details inside-base">
  85. <div class="inside-base-main clearfix">
  86. <div class="inside-base-cont">
  87. <div class="role-cont clearfix">
  88. <div>
  89. <el-table
  90. ref="table"
  91. :data="tableData"
  92. style="width: 100%;margin-bottom: 20px;"
  93. row-key="id"
  94. border
  95. :indent="10"
  96. :select-on-indeterminate="true"
  97. :default-expand-all="false"
  98. show-checkbox
  99. :checked-keys="defaultCheckedKeys"
  100. :tree-props="{children: 'childList', hasChildren: 'hasChildren'}"
  101. >
  102. <el-table-column prop="name" label="页面" />
  103. <el-table-column label="查看" :render-header="renderSeeHeader">
  104. <template slot-scope="scope">
  105. <el-checkbox v-model="scope.row.fnCheck.seebutton" :indeterminate="scope.row.indeterminate.seebutton" label="查看" @change="fnCheckEv(scope, 'seebutton')" />
  106. </template>
  107. </el-table-column>
  108. <el-table-column label="编辑" :render-header="renderEditHeader">
  109. <template slot-scope="scope">
  110. <el-checkbox v-model="scope.row.fnCheck.editbutton" :indeterminate="scope.row.indeterminate.editbutton" label="编辑" @change="fnCheckEv(scope, 'editbutton')" />
  111. </template>
  112. </el-table-column>
  113. </el-table>
  114. </div>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. <div slot="footer" class="dialog-footer" style="right:30px;position:absolute;bottom:5px">
  120. <el-button @click="role.dialogFormVisible = false; ">关闭</el-button>
  121. <el-button v-if="role.dialogStatus==='role'" type="success" :disabled="isokDisable" @click="roleData()">确认</el-button>
  122. </div>
  123. </el-dialog>
  124. </div>
  125. </template>
  126. <script>
  127. import { GetDataByName, PostDataByName, failproccess, transData, ExecDataByConfig } from '@/api/common'
  128. import Cookies from 'js-cookie'
  129. import { parseTime } from '@/utils/index.js'
  130. import { MessageBox } from 'element-ui'
  131. import Pagination from '@/components/Pagination'
  132. export default {
  133. name: 'Role',
  134. components: { Pagination },
  135. data() {
  136. return {
  137. enableList: [{ id: 1, name: '是' }, { id: 0, name: '否' }], // 是否启用
  138. table: {
  139. getdataListParm: {
  140. name: 'getRoleList',
  141. page: 1,
  142. offset: 1,
  143. pagecount: 10,
  144. returntype: 'Map',
  145. parammaps: {
  146. pastureid: Cookies.get('pastureid'),
  147. rolename: '',
  148. createmp: '',
  149. enable: '',
  150. starTime: '',
  151. stopTime: '',
  152. inputDatetime: ''
  153. }
  154. },
  155. tableKey: 0,
  156. list: [],
  157. total: 0,
  158. listLoading: true,
  159. temp: {}
  160. },
  161. requestParam: {},
  162. selectList: [],
  163. role: {
  164. dialogFormVisible: false,
  165. dialogStatus: '',
  166. temp: {}
  167. },
  168. // parentType: [],
  169. getRecuListParm: {
  170. name: 'getMenuByRole',
  171. parammaps: {
  172. pastureid: Cookies.get('pastureid')
  173. }
  174. },
  175. tableData: [],
  176. defaultCheckedKeys: [],
  177. // tableData: [
  178. // {
  179. // id: 1, page: '配方计划', pageCheck: false,
  180. // fnList: ['查看', '编辑'],
  181. // fnCheck: { see: false, edit: false },
  182. // childList: [
  183. // { p_id: 1, id: 31, page: '配方模板', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }},
  184. // { p_id: 1, id: 32, page: '栏舍配方', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }}
  185. // ]
  186. // }, {
  187. // id: 2, page: '栏舍生产', pageCheck: false,
  188. // fnList: ['查看', '编辑'],
  189. // fnCheck: { see: false, edit: false },
  190. // childList: [
  191. // { p_id: 2, id: 33, page: '栏舍产奶量', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }},
  192. // { p_id: 2, id: 34, page: '栏舍剩料量', pageCheck: false, fnList: ['查看', '编辑'], fnCheck: { see: false, edit: false }}
  193. // ]
  194. // }
  195. // ],
  196. isokDisable: false,
  197. textMap: {
  198. role: '权限管理'
  199. },
  200. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  201. cellStyle: { padding: 0 + 'px' }
  202. }
  203. },
  204. created() {
  205. this.getList()
  206. },
  207. methods: {
  208. getList() {
  209. this.table.listLoading = true
  210. GetDataByName(this.table.getdataListParm).then(response => {
  211. console.log('table数据', response.data.list)
  212. if (response.data.list !== null) {
  213. for (let i = 0; i < response.data.list.length; i++) {
  214. this.$set(response.data.list[i], 'Edit', false) // 编辑
  215. this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
  216. this.$set(response.data.list[i], 'isCreate', false) // 新增操作
  217. this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
  218. this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
  219. }
  220. this.table.list = response.data.list
  221. this.table.pageNum = response.data.pageNum
  222. this.table.pageSize = response.data.pageSize
  223. this.table.total = response.data.total
  224. } else {
  225. this.table.list = []
  226. }
  227. setTimeout(() => {
  228. this.table.listLoading = false
  229. }, 100)
  230. })
  231. },
  232. handleEnableChange() {
  233. console.log('点击了是否启用')
  234. },
  235. handleConfirmStartChange() {
  236. console.log('点击了确认开始')
  237. },
  238. handleSearch() {
  239. console.log('点击了查询')
  240. if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
  241. this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
  242. this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
  243. } else {
  244. this.table.getdataListParm.parammaps.inputDatetime = ''
  245. this.table.getdataListParm.parammaps.startTime = ''
  246. this.table.getdataListParm.parammaps.stopTime = ''
  247. }
  248. this.table.getdataListParm.offset = 1
  249. this.getList()
  250. },
  251. handleRefresh() {
  252. console.log('点击了重置')
  253. this.table.getdataListParm.parammaps.rolename = ''
  254. this.table.getdataListParm.parammaps.createmp = ''
  255. this.table.getdataListParm.parammaps.enable = ''
  256. this.table.getdataListParm.parammaps.startTime = ''
  257. this.table.getdataListParm.parammaps.stopTime = ''
  258. this.table.getdataListParm.parammaps.inputDatetime = ''
  259. this.table.getdataListParm.offset = 1
  260. this.getList()
  261. },
  262. handleCreate() {
  263. console.log('点击了新增')
  264. // 编辑true/不可编辑false
  265. // 新增操true,编辑false,编辑保存false
  266. for (let i = 0; i < this.table.list.length; i++) {
  267. if (this.table.list[i].Edit == true) {
  268. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  269. return false
  270. }
  271. }
  272. this.table.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'confirmStart': 1, 'createdtime': parseTime(new Date(), '{y}-{m}-{d}'), 'createmp': Cookies.get('employename'), 'rolename': '' })
  273. },
  274. createData(row) {
  275. console.log('点击了新增保存', row)
  276. this.table.temp.pastureid = Cookies.get('pastureid')
  277. this.table.temp.empname = row.empname
  278. this.table.temp.rolename = row.rolename
  279. this.table.temp.enable = row.enable
  280. this.table.temp.remark = row.remark
  281. this.table.temp.createmp = row.createmp
  282. // 检验角色名称/角色是否为空
  283. if (this.table.temp.rolename == '') {
  284. this.$message({ type: 'error', message: '角色名称不能为空', duration: 2000 })
  285. return false
  286. }
  287. this.isokDisable = true
  288. setTimeout(() => {
  289. this.isokDisable = false
  290. }, 1000)
  291. this.requestParam.name = 'createRole'
  292. this.requestParam.parammaps = this.table.temp
  293. PostDataByName(this.requestParam).then(response => {
  294. console.log('新增保存发送参数', this.requestParam)
  295. if (response.msg !== 'fail') {
  296. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  297. this.getList()
  298. } else {
  299. failproccess(response, this.$notify)
  300. }
  301. })
  302. },
  303. createCancel(row) {
  304. console.log('点击了新增取消')
  305. for (let i = 0; i < this.table.list.length; i++) {
  306. if (row.myId === this.table.list[i].myId) {
  307. var listIndex = this.table.list.indexOf(this.table.list[i])
  308. }
  309. if (listIndex > -1) {
  310. this.table.list.splice(listIndex, 1)
  311. return
  312. }
  313. }
  314. },
  315. handleUpdate(row) {
  316. console.log('点击了编辑')
  317. for (let i = 0; i < this.table.list.length; i++) {
  318. if (this.table.list[i].Edit == true) {
  319. this.$message({ type: 'error', message: '当前内容未保存,请点击取消或保存继续进行操作', duration: 2000 })
  320. return false
  321. }
  322. }
  323. // 编辑true,不可编辑false
  324. row.Edit = true
  325. row.NoEdit = false
  326. // 新增false,编辑false,编辑保存true
  327. row.isCreate = false
  328. row.isUpdate = false
  329. row.isUpdateSave = true
  330. },
  331. updateData(row) {
  332. console.log('点击了编辑保存', row)
  333. this.table.temp.pastureid = Cookies.get('pastureid')
  334. this.table.temp.id = row.id
  335. this.table.temp.empname = row.empname
  336. this.table.temp.rolename = row.rolename
  337. this.table.temp.enable = row.enable
  338. this.table.temp.remark = row.remark
  339. // 检验角色名称/角色是否为空
  340. if (this.table.temp.rolename == '') {
  341. this.$message({ type: 'error', message: '角色名称不能为空', duration: 2000 })
  342. return false
  343. }
  344. this.isokDisable = true
  345. setTimeout(() => {
  346. this.isokDisable = false
  347. }, 1000)
  348. this.requestParam.name = 'updateRole'
  349. this.requestParam.parammaps = this.table.temp
  350. PostDataByName(this.requestParam).then(response => {
  351. console.log('新增保存发送参数', this.requestParam)
  352. if (response.msg !== 'fail') {
  353. this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
  354. this.getList()
  355. } else {
  356. failproccess(response, this.$notify)
  357. }
  358. })
  359. },
  360. updateCancel(row) {
  361. console.log('点击了编辑取消')
  362. // 编辑false,不可编辑true
  363. row.Edit = false
  364. row.NoEdit = true
  365. // 新增false,编辑true,编辑保存false
  366. row.isCreate = false
  367. row.isUpdate = true
  368. row.isUpdateSave = false
  369. },
  370. handleRowDelete(row) {
  371. console.log('点击了行内删除')
  372. MessageBox.confirm('是否确认删除此信息?', {
  373. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  374. }).then(() => {
  375. console.log(this.selectList)
  376. this.selectList = []
  377. this.requestParam = {}
  378. this.requestParam.common = { 'returnmap': '0' }
  379. this.requestParam.data = []
  380. this.requestParam.data[0] = { 'name': 'checkroleuser', 'type': 'v', 'parammaps': {
  381. 'pastureid': row.pastureid,
  382. 'roleid': row.id
  383. }}
  384. this.requestParam.data[1] = { 'name': 'deleteRole', 'type': 'e', 'parammaps': {
  385. 'pastureid': row.pastureid,
  386. 'id': row.id
  387. }}
  388. ExecDataByConfig(this.requestParam).then(response => {
  389. console.log('删除保存发送参数', this.requestParam)
  390. if (response.msg === 'fail') {
  391. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  392. } else {
  393. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  394. this.getList()
  395. }
  396. })
  397. }).catch(() => {
  398. this.$message({ type: 'info', message: '已取消删除' })
  399. })
  400. },
  401. handleSelectionChange(val) {
  402. console.log('勾选数据', val)
  403. this.selectList = val
  404. },
  405. handleDelete() {
  406. console.log('点击了删除')
  407. if (this.selectList.length == 0) {
  408. this.$message({ type: 'error', message: '请选择角色信息', duration: 2000 })
  409. } else {
  410. MessageBox.confirm('是否确认删除此信息?', {
  411. confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
  412. }).then(() => {
  413. console.log(this.selectList)
  414. this.requestParam.common = { 'returnmap': '0' }
  415. this.requestParam.data = []
  416. for (let i = 0; i < this.selectList.length; i++) {
  417. this.requestParam.data[i] = { 'name': 'checkroleuser', 'type': 'v', 'parammaps': {
  418. 'pastureid': this.selectList[i].pastureid,
  419. 'roleid': this.selectList[i].id
  420. }}
  421. }
  422. this.requestParam.data[this.selectList.length] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
  423. this.requestParam.data[this.selectList.length].children = []
  424. this.requestParam.data[this.selectList.length].children[0] = { 'name': 'deleteRole', 'type': 'e', 'parammaps': {
  425. 'pastureid': '@insertSpotList.pastureid',
  426. 'id': '@insertSpotList.id'
  427. }}
  428. ExecDataByConfig(this.requestParam).then(response => {
  429. console.log('删除保存发送参数', this.requestParam)
  430. if (response.msg === 'fail') {
  431. this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
  432. } else {
  433. this.$notify({ title: '', message: '删除成功', type: 'success', duration: 2000 })
  434. this.getList()
  435. }
  436. })
  437. })
  438. }
  439. },
  440. handleRole(row) {
  441. this.role.temp = Object.assign({}, row)
  442. console.log('点击了行内页面权限')
  443. this.role.dialogStatus = 'role'
  444. this.role.dialogFormVisible = true
  445. this.tableData = []
  446. this.getRecuListParm.parammaps.roleid = row.id
  447. this.getRoleList()
  448. },
  449. getRoleList() {
  450. GetDataByName(this.getRecuListParm).then(response => {
  451. if (response.data.list !== null) {
  452. this.tableData = transData(response.data.list, 'id', 'pid', 'children')
  453. console.log(this.tableData)
  454. this.tableData.forEach((item, i) => {
  455. item.childList = item.children
  456. this.$set(item, 'fnCheck', {})
  457. this.$set(item, 'indeterminate', { 'seebutton': false, 'editbutton': false })
  458. if (item.seebutton == 1) { this.$set(item.fnCheck, 'seebutton', true) } else if (item.seebutton == 0) { this.$set(item.fnCheck, 'seebutton', false) } else if (item.seebutton == 2) { this.$set(item.indeterminate, 'seebutton', true) } else if (item.seebutton == 3) { this.$set(item.indeterminate, 'seebutton', false) }
  459. if (item.editbutton == 1) { this.$set(item.fnCheck, 'editbutton', true) } else if (item.editbutton == 0) { this.$set(item.fnCheck, 'editbutton', false) } else if (item.seebutton == 2) { this.$set(item.indeterminate, 'editbutton', true) } else if (item.seebutton == 3) { this.$set(item.indeterminate, 'editbutton', false) }
  460. if (item.seebutton == 2) { this.$set(item.indeterminate, 'seebutton', true) } else if (item.seebutton == 0) { this.$set(item.indeterminate, 'seebutton', false) }
  461. if (item.editbutton == 3) { this.$set(item.indeterminate, 'editbutton', true) } else if (item.editbutton == 0) { this.$set(item.indeterminate, 'editbutton', false) }
  462. if (item.childList !== undefined && item.childList.length > 0) {
  463. item.childList.forEach((item, i) => {
  464. this.$set(item, 'fnCheck', {})
  465. this.$set(item, 'indeterminate', { 'seebutton': false, 'editbutton': false })
  466. if (item.seebutton == 1) { this.$set(item.fnCheck, 'seebutton', true) } else if (item.seebutton == 0) { this.$set(item.fnCheck, 'seebutton', false) }
  467. if (item.editbutton == 1) { this.$set(item.fnCheck, 'editbutton', true) } else if (item.editbutton == 0) { this.$set(item.fnCheck, 'editbutton', false) }
  468. })
  469. }
  470. })
  471. console.log(this.tableData)
  472. }
  473. })
  474. },
  475. // 查找父级函数
  476. getParent(data2, nodeId2) {
  477. var arrRes = []
  478. if (data2.length === 0) {
  479. if (nodeId2) {
  480. arrRes.push(data2)
  481. }
  482. return arrRes
  483. }
  484. const rev = (data, nodeId) => {
  485. for (var i = 0, length = data.length; i < length; i++) {
  486. const node = data[i]
  487. if (node.id === nodeId) {
  488. arrRes.push(node)
  489. rev(data2, node.pid)
  490. break
  491. } else {
  492. if (node.childList) {
  493. rev(node.childList, nodeId)
  494. }
  495. }
  496. }
  497. return arrRes
  498. }
  499. arrRes = rev(data2, nodeId2)
  500. return arrRes
  501. },
  502. /**
  503. * 功能选择
  504. */
  505. // 子选框事件
  506. fnCheckEv(scope, type) {
  507. // 如果有子项,则子项的选框选择跟当前一致
  508. if (scope.row.childList) {
  509. console.log(scope.row)
  510. this.handleFnAll(scope.row, scope.row.fnCheck[type], scope.row.indeterminate[type], type)
  511. }
  512. // 查找父级选框
  513. this.getParent(this.tableData, scope.row.id).forEach((item, i) => {
  514. // console.log(item)
  515. if (type == 'seebutton') {
  516. if (!item.childList) {
  517. console.log(item)
  518. item.fnCheck[type] = scope.row.fnCheck[type]
  519. } else {
  520. let num = 0
  521. item.childList.forEach((item, i) => {
  522. if (item.fnCheck[type] === true) {
  523. num += 1
  524. }
  525. })
  526. if (num === item.childList.length) {
  527. console.log(item)
  528. item.fnCheck[type] = true
  529. item.indeterminate[type] = false
  530. } else {
  531. item.fnCheck[type] = false
  532. item.fnCheck['editbutton'] = false
  533. const childListArr = []
  534. const childEditListArr = []
  535. console.log(item.childList)
  536. item.childList.forEach((item, index) => {
  537. console.log(item) // d打印正常
  538. console.log(item.fnCheck) // d打印正常
  539. // console.log(item.fnCheck['editbutton'])//错误?
  540. console.log(item.fnCheck.editbutton)// 错误?
  541. childListArr.push(item.fnCheck[type])
  542. childEditListArr.push(item.fnCheck['editbutton'])
  543. })
  544. console.log(childEditListArr)
  545. if (childListArr.includes(true)) {
  546. item.indeterminate[type] = true
  547. item.fnCheck['editbutton'] = false
  548. console.log(childEditListArr)
  549. if (childEditListArr.includes(true)) { // 判断编辑子级是否有true
  550. item.indeterminate['editbutton'] = true
  551. } else {
  552. item.indeterminate['editbutton'] = false
  553. }
  554. if (item.childList.length > 0) {
  555. item.childList.forEach((item, i) => {
  556. if (item.fnCheck['editbutton'] === false) {
  557. item.fnCheck['editbutton'] = false
  558. } else {
  559. item.fnCheck['editbutton'] = item.fnCheck[type]
  560. }
  561. })
  562. }
  563. } else {
  564. item.indeterminate[type] = false
  565. console.log(item)
  566. // item.indeterminate['editbutton'] = false
  567. const editArr = []
  568. if (item.childList.length > 0) {
  569. item.childList.forEach((item, i) => {
  570. item.fnCheck['editbutton'] = item.fnCheck[type]
  571. editArr.push(item.fnCheck['editbutton'])
  572. })
  573. }
  574. if (editArr.includes(true)) { // 判断编辑子级是否有true
  575. item.indeterminate['editbutton'] = true
  576. } else {
  577. item.indeterminate['editbutton'] = false
  578. }
  579. }
  580. }
  581. }
  582. } else if (type == 'editbutton') {
  583. if (!item.childList) {
  584. item.fnCheck[type] = scope.row.fnCheck[type]
  585. } else {
  586. let num = 0
  587. item.childList.forEach((item, i) => {
  588. if (item.fnCheck[type] === true) {
  589. num += 1
  590. }
  591. })
  592. if (num === item.childList.length) {
  593. item.fnCheck[type] = true
  594. item.fnCheck['seebutton'] = true
  595. item.indeterminate[type] = false
  596. item.indeterminate['seebutton'] = false
  597. item.childList.forEach((item, i) => { // 编辑时,选中编辑的同时,选中查看
  598. console.log(item)
  599. if (item.fnCheck['seebutton'] === false) { // 查看未选中时,选中编辑可控制查看
  600. item.fnCheck['seebutton'] = item.fnCheck['editbutton']
  601. }
  602. })
  603. console.log(item)
  604. } else {
  605. console.log(item)
  606. item.fnCheck[type] = false
  607. console.log(item.fnCheck['seebutton'])
  608. if (item.fnCheck['seebutton'] === false) { // 查看未选中时,选中编辑可控制查看
  609. item.fnCheck['seebutton'] = false
  610. }
  611. const childListArr = []
  612. for (let i = 0; i < item.childList.length; i++) {
  613. childListArr.push(item.childList[i].fnCheck[type])
  614. }
  615. childListArr.includes(true)
  616. if (childListArr.includes(true)) {
  617. if (item.fnCheck['seebutton'] === false) {
  618. item.indeterminate['seebutton'] = true
  619. }
  620. item.indeterminate[type] = true
  621. } else {
  622. // if (item.fnCheck['seebutton'] === false) {
  623. // item.indeterminate['seebutton'] = false
  624. // }
  625. item.indeterminate[type] = false
  626. }
  627. // item.indeterminate[type] = true
  628. item.childList.forEach((item, i) => { // 编辑时,选中编辑的同时,选中查看
  629. if (item.fnCheck['seebutton'] === false) {
  630. item.fnCheck['seebutton'] = item.fnCheck['editbutton']
  631. }
  632. })
  633. console.log(item)
  634. }
  635. }
  636. }
  637. })
  638. },
  639. handleFnAll(row, fnCheck, indeterminate, type) {
  640. console.log(row, fnCheck, indeterminate, type)
  641. row.fnCheck[type] = fnCheck
  642. if (row.childList) {
  643. const that = this
  644. row.childList.forEach((element, i) => {
  645. row.indeterminate[type] = false
  646. console.log(fnCheck, indeterminate)
  647. // console.log(element, row.childList[i], fnCheck, indeterminate, type)
  648. that.handleFnAll(row.childList[i], fnCheck, indeterminate, type)
  649. })
  650. }
  651. },
  652. /**
  653. * 权限选择
  654. */
  655. // 权限:全部、自己
  656. // 子选框事件
  657. dataCheckEv(scope, type) {
  658. console.log(scope)
  659. const temp = scope.row.dataCheck[type]
  660. console.log(scope, type)
  661. for (const x in scope.row.dataCheck) {
  662. scope.row.dataCheck[x] = false
  663. }
  664. scope.row.dataCheck[type] = temp
  665. // 如果有子项,则子项的选框选择跟当前一致
  666. if (scope.row.childList) {
  667. this.handleDataAll(scope.row, scope.row.dataCheck[type], type)
  668. }
  669. // 查找父级选框
  670. this.getParent(this.tableData, scope.row.id).forEach((item, i) => {
  671. console.log(item, '==============674')
  672. for (const x in item.dataCheck) {
  673. item.dataCheck[x] = false
  674. }
  675. if (!item.childList) {
  676. console.log(item, '==============679')
  677. item.dataCheck[type] = temp
  678. } else {
  679. var num = 0
  680. item.childList.forEach((item, i) => {
  681. if (item.dataCheck[type] === true) {
  682. num += 1
  683. }
  684. })
  685. if (num === item.childList.length) {
  686. console.log(item, '==============689')
  687. item.dataCheck[type] = true
  688. } else {
  689. console.log(item, '==============691')
  690. item.dataCheck[type] = false
  691. }
  692. }
  693. })
  694. },
  695. handleDataAll(row, dataCheck, type) {
  696. for (const x in row.dataCheck) {
  697. row.dataCheck[x] = false
  698. }
  699. row.dataCheck[type] = dataCheck
  700. if (row.childList) {
  701. console.log(row, dataCheck, type)
  702. const that = this
  703. row.childList.forEach((element, i) => {
  704. that.handleDataAll(row.childList[i], dataCheck, type)
  705. })
  706. } else {
  707. console.log(row, dataCheck, type)
  708. }
  709. },
  710. renderSeeHeader(h, { column }) {
  711. return h(
  712. 'div',
  713. [
  714. h('span', column.label),
  715. h('el-checkbox', {
  716. style: 'display:inline-flex;margin-left:5px;',
  717. on: {
  718. change: ($event, column) => this.selectSee($event, column, 'see') // 选中事件 $event, column,这里$event=true,column是input的dom当在select里打印的时候
  719. }
  720. })
  721. ],
  722. )
  723. },
  724. renderEditHeader(h, { column }) {
  725. return h(
  726. 'div',
  727. [
  728. h('span', column.label),
  729. h('el-checkbox', {
  730. style: 'display:inline-flex;margin-left:5px;',
  731. on: {
  732. change: ($event, column) => this.selectEdit($event, column, 'edit') // 选中事件 $event, column,这里$event=true,column是input的dom当在select里打印的时候
  733. }
  734. })
  735. ],
  736. )
  737. },
  738. selectSee(obj, $event = this.targetEv, title) {
  739. const _this = this
  740. if ($event) {
  741. this.targetEv = $event // 这里是获取当前点击的input的dom元素赋值给this.targetEv,方便提交后初始化使用
  742. }
  743. if (obj === true) {
  744. this.flag = false
  745. } else {
  746. this.flag = true
  747. }
  748. this.targetEv.target.checked = obj
  749. this.targetEv.target.parentNode.className = obj ? 'el-checkbox__input is-checked' : 'el-checkbox__input'
  750. _this.tableData.forEach((item, index) => {
  751. _this.$set(_this.tableData[index], 'check', obj.toString())
  752. if (title === 'see') {
  753. if (obj === true) {
  754. item.fnCheck['seebutton'] = true
  755. if (item.childList.length > 0) {
  756. item.childList.forEach((item, index) => {
  757. item.fnCheck['seebutton'] = true
  758. })
  759. }
  760. } else {
  761. item.fnCheck['seebutton'] = false
  762. if (item.childList.length > 0) {
  763. item.childList.forEach((item, index) => {
  764. item.fnCheck['seebutton'] = false
  765. })
  766. }
  767. }
  768. }
  769. })
  770. },
  771. selectEdit(obj, $event = this.targetEv, title) {
  772. const _this = this
  773. if ($event) {
  774. this.targetEv = $event // 这里是获取当前点击的input的dom元素赋值给this.targetEv,方便提交后初始化使用
  775. }
  776. console.log('进来就错了', obj)
  777. if (obj === true) {
  778. this.flag = false
  779. } else {
  780. this.flag = true
  781. }
  782. this.targetEv.target.checked = obj
  783. this.targetEv.target.parentNode.className = obj ? 'el-checkbox__input is-checked' : 'el-checkbox__input'
  784. _this.tableData.forEach((item, index) => {
  785. _this.$set(_this.tableData[index], 'check', obj.toString())
  786. if (title === 'edit') {
  787. if (obj === true) {
  788. item.fnCheck['editbutton'] = true
  789. if (item.fnCheck['seebutton'] === false) {
  790. item.fnCheck['seebutton'] = true
  791. }
  792. if (item.childList.length > 0) {
  793. item.childList.forEach((item, index) => {
  794. item.fnCheck['editbutton'] = true
  795. if (item.fnCheck['seebutton'] === false) {
  796. item.fnCheck['seebutton'] = true
  797. }
  798. })
  799. }
  800. } else {
  801. item.fnCheck['editbutton'] = false
  802. if (item.childList.length > 0) {
  803. item.childList.forEach((item, index) => {
  804. item.fnCheck['editbutton'] = false
  805. })
  806. }
  807. }
  808. }
  809. })
  810. },
  811. roleData(row) {
  812. console.log('点击了权限确认', this.tableData)
  813. // console.log('点击了权限确认', JSON.stringify(this.tableData))
  814. const dataAll = []
  815. const dataArr = []
  816. const dataArr2 = []
  817. this.tableData.forEach((item, index) => {
  818. if (item.fnCheck.seebutton === true) { item.seebutton = 1 } else { item.seebutton = 0 }
  819. if (item.fnCheck.editbutton === true) { item.editbutton = 1 } else { item.editbutton = 0 }
  820. if (item.indeterminate.seebutton === true) { item.seebutton = 2 }
  821. if (item.indeterminate.editbutton === true) { item.editbutton = 3 }
  822. if (item.childList.length > 0) {
  823. item.childList.forEach((item, index) => {
  824. if (item.fnCheck.seebutton === true) { item.seebutton = 1 } else { item.seebutton = 0 }
  825. if (item.fnCheck.editbutton === true) { item.editbutton = 1 } else { item.editbutton = 0 }
  826. dataArr2.push({ 'menuid': item.menu_id, 'seebutton': item.seebutton, 'editbutton': item.editbutton })
  827. })
  828. }
  829. dataArr.push({ 'menuid': item.menu_id, 'seebutton': item.seebutton, 'editbutton': item.editbutton })
  830. })
  831. dataArr.forEach((item, index) => {
  832. dataAll.push({ 'menuid': item.menuid, 'seebutton': item.seebutton, 'editbutton': item.editbutton })
  833. })
  834. dataArr2.forEach((item, index) => {
  835. dataAll.push({ 'menuid': item.menuid, 'seebutton': item.seebutton, 'editbutton': item.editbutton })
  836. })
  837. this.requestParam.common = { 'returnmap': '0' }
  838. this.requestParam.data = []
  839. this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': dataAll }}
  840. this.requestParam.data[0].children = []
  841. this.requestParam.data[0].children[0] = { 'name': 'insertRolemenu', 'type': 'e', 'parammaps': {
  842. pastureid: this.role.temp.pastureid,
  843. roleid: this.role.temp.id,
  844. menuid: '@insertSpotList.menuid',
  845. seebutton: '@insertSpotList.seebutton',
  846. editbutton: '@insertSpotList.editbutton'
  847. }}
  848. ExecDataByConfig(this.requestParam).then(response => {
  849. console.log('权限菜单保存发送参数', this.requestParam)
  850. if (response.msg === 'fail') {
  851. this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
  852. } else {
  853. this.$notify({ title: '', message: '保存成功', type: 'success', duration: 2000 })
  854. this.role.dialogFormVisible = false
  855. this.getList()
  856. }
  857. })
  858. }
  859. }
  860. }
  861. </script>
  862. <style lang="scss" scoped>
  863. .search{margin-top:10px;}
  864. .table{margin-top:10px;}
  865. .inside-base {
  866. position: relative;
  867. }
  868. .inside-base-main {
  869. width: 100%;
  870. background: #ffffff;
  871. box-shadow: 0px 0px 10px 0px rgba(231,232,238,1);
  872. border-radius: 4px;
  873. margin-bottom: 30px;
  874. }
  875. // 中间内容
  876. .inside-base-cont {
  877. margin: 0 20px;
  878. }
  879. .role-cont {
  880. position: relative;
  881. font-size: 16px;
  882. color: #333333;
  883. line-height: 40px;
  884. > span {
  885. width: 90px;
  886. height: 40px;
  887. text-align: right;
  888. float: left;
  889. margin-right: 10px;
  890. margin-bottom: 20px;
  891. }
  892. > div {
  893. position: relative;
  894. width: 100%;
  895. float: left;
  896. margin-bottom: 20px;
  897. >>> .el-input__inner {
  898. width: 320px;
  899. }
  900. }
  901. }
  902. .check-page-all {
  903. position: absolute;
  904. top: 13px;
  905. left: 11px;
  906. z-index: 99;
  907. }
  908. /* element-ui css */
  909. .inside-base {
  910. >>> .el-input__inner {
  911. font-size: 16px;
  912. color: #333333;
  913. }
  914. }
  915. </style>