08afbfdeb1854e40d0bdcd129260784f9eec1132.svn-base 36 KB

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