70024358257e3c569f759038ebeffd39328c9c8d.svn-base 39 KB

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