8e6cd3310f5fce1fbc8f80b9fc1189677b25e12a.svn-base 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <div class="role-details inside-base">
  3. <div class="inside-base-main clearfix">
  4. <div class="inside-base-cont">
  5. <div class="role-cont clearfix">
  6. <div>
  7. <el-table
  8. ref="table"
  9. :data="tableData"
  10. style="width: 100%;margin-bottom: 20px;"
  11. row-key="id"
  12. border
  13. :indent="10"
  14. :select-on-indeterminate="true"
  15. :default-expand-all="false"
  16. show-checkbox
  17. :tree-props="{children: 'childList', hasChildren: 'hasChildren'}"
  18. >
  19. <el-table-column prop="name" label="页面" />
  20. <el-table-column label="查看">
  21. <template slot-scope="scope">
  22. <!-- <el-checkbox v-if="scope.row.fnList.includes('查看')" v-model="scope.row.fnCheck.see" label="查看" @change="fnCheckEv(scope, 'see')" /> -->
  23. <el-checkbox v-model="scope.row.fnCheck.see" label="查看" @change="fnCheckEv(scope, 'see')" />
  24. </template>
  25. </el-table-column>
  26. <el-table-column label="编辑">
  27. <template slot-scope="scope">
  28. <!-- <el-checkbox v-if="scope.row.fnList.includes('编辑')" v-model="scope.row.fnCheck.edit" label="编辑" @change="fnCheckEv(scope, 'edit')" /> -->
  29. <el-checkbox v-model="scope.row.fnCheck.edit" label="编辑" @change="fnCheckEv(scope, 'edit')" />
  30. </template>
  31. </el-table-column>
  32. </el-table>
  33. </div>
  34. </div>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. export default {
  41. name: 'FormulaStatistics',
  42. data() {
  43. return {
  44. msg: '',
  45. tableData: [
  46. {
  47. id: 1, name: '配方计划',
  48. // fnList: ['查看', '编辑'],
  49. fnCheck: { see: false, edit: false },
  50. childList: [
  51. {
  52. p_id: 1, id: 31, name: '配方模板',
  53. // fnList: ['查看', '编辑'],
  54. fnCheck: { see: false, edit: false }
  55. },
  56. {
  57. p_id: 1, id: 32, name: '栏舍配方',
  58. // fnList: ['查看', '编辑'],
  59. fnCheck: { see: false, edit: false }
  60. }
  61. ]
  62. }, {
  63. id: 2, name: '栏舍生产',
  64. // fnList: ['查看', '编辑'],
  65. fnCheck: { see: false, edit: false },
  66. childList: [
  67. {
  68. p_id: 2, id: 33, name: '栏舍产奶量',
  69. // fnList: ['查看', '编辑'],
  70. fnCheck: { see: false, edit: false }
  71. },
  72. {
  73. p_id: 2, id: 34, name: '栏舍剩料量',
  74. // fnList: ['查看', '编辑'],
  75. fnCheck: { see: false, edit: false }
  76. }
  77. ]
  78. }
  79. ]
  80. }
  81. },
  82. mounted() {
  83. },
  84. methods: {
  85. // 查找父级函数
  86. getParent(data2, nodeId2) {
  87. var arrRes = []
  88. if (data2.length === 0) {
  89. if (nodeId2) {
  90. arrRes.push(data2)
  91. }
  92. return arrRes
  93. }
  94. const rev = (data, nodeId) => {
  95. for (var i = 0, length = data.length; i < length; i++) {
  96. const node = data[i]
  97. if (node.id === nodeId) {
  98. arrRes.push(node)
  99. rev(data2, node.p_id)
  100. break
  101. } else {
  102. if (node.childList) {
  103. rev(node.childList, nodeId)
  104. }
  105. }
  106. }
  107. return arrRes
  108. }
  109. arrRes = rev(data2, nodeId2)
  110. return arrRes
  111. },
  112. /**
  113. * 功能选择
  114. */
  115. // 子选框事件
  116. fnCheckEv(scope, type) {
  117. // 如果有子项,则子项的选框选择跟当前一致
  118. if (scope.row.childList) {
  119. this.handleFnAll(scope.row, scope.row.fnCheck[type], type)
  120. }
  121. // 查找父级选框
  122. this.getParent(this.tableData, scope.row.id).forEach((item, i) => {
  123. if (!item.childList) {
  124. item.fnCheck[type] = scope.row.fnCheck[type]
  125. } else {
  126. var num = 0
  127. item.childList.forEach((item, i) => {
  128. if (item.fnCheck[type] === true) {
  129. num += 1
  130. }
  131. })
  132. if (num === item.childList.length) {
  133. item.fnCheck[type] = true
  134. } else {
  135. item.fnCheck[type] = false
  136. }
  137. }
  138. })
  139. },
  140. handleFnAll(row, fnCheck, type) {
  141. row.fnCheck[type] = fnCheck
  142. if (row.childList) {
  143. const that = this
  144. row.childList.forEach((element, i) => {
  145. that.handleFnAll(row.childList[i], fnCheck, type)
  146. })
  147. }
  148. },
  149. /**
  150. * 权限选择
  151. */
  152. // 权限:全部、自己
  153. // 子选框事件
  154. dataCheckEv(scope, type) {
  155. const temp = scope.row.dataCheck[type]
  156. for (const x in scope.row.dataCheck) {
  157. scope.row.dataCheck[x] = false
  158. }
  159. scope.row.dataCheck[type] = temp
  160. // 如果有子项,则子项的选框选择跟当前一致
  161. if (scope.row.childList) {
  162. this.handleDataAll(scope.row, scope.row.dataCheck[type], type)
  163. }
  164. // 查找父级选框
  165. this.getParent(this.tableData, scope.row.id).forEach((item, i) => {
  166. for (const x in item.dataCheck) {
  167. item.dataCheck[x] = false
  168. }
  169. if (!item.childList) {
  170. item.dataCheck[type] = temp
  171. } else {
  172. var num = 0
  173. item.childList.forEach((item, i) => {
  174. if (item.dataCheck[type] === true) {
  175. num += 1
  176. }
  177. })
  178. if (num === item.childList.length) {
  179. item.dataCheck[type] = true
  180. } else {
  181. item.dataCheck[type] = false
  182. }
  183. }
  184. })
  185. },
  186. handleDataAll(row, dataCheck, type) {
  187. for (const x in row.dataCheck) {
  188. row.dataCheck[x] = false
  189. }
  190. row.dataCheck[type] = dataCheck
  191. if (row.childList) {
  192. const that = this
  193. row.childList.forEach((element, i) => {
  194. that.handleDataAll(row.childList[i], dataCheck, type)
  195. })
  196. }
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. .inside-base {
  203. position: relative;
  204. }
  205. .inside-base-main {
  206. width: 100%;
  207. background: #ffffff;
  208. box-shadow: 0px 0px 10px 0px rgba(231,232,238,1);
  209. border-radius: 4px;
  210. margin-bottom: 30px;
  211. }
  212. // 中间内容
  213. .inside-base-cont {
  214. margin: 0 20px;
  215. }
  216. .role-cont {
  217. position: relative;
  218. font-size: 16px;
  219. color: #333333;
  220. line-height: 40px;
  221. > span {
  222. width: 90px;
  223. height: 40px;
  224. text-align: right;
  225. float: left;
  226. margin-right: 10px;
  227. margin-bottom: 20px;
  228. }
  229. > div {
  230. position: relative;
  231. width: 90%;
  232. float: left;
  233. margin-bottom: 20px;
  234. >>> .el-input__inner {
  235. width: 320px;
  236. }
  237. }
  238. }
  239. .check-page-all {
  240. position: absolute;
  241. top: 13px;
  242. left: 11px;
  243. z-index: 99;
  244. }
  245. /* element-ui css */
  246. .inside-base {
  247. >>> .el-input__inner {
  248. font-size: 16px;
  249. color: #333333;
  250. }
  251. }
  252. </style>