index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <div class="app-container">
  3. <!-- <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">-->
  4. <!-- <el-form-item label="销售公司" prop="companyId">-->
  5. <!-- <el-input-->
  6. <!-- v-model="queryParams.companyId"-->
  7. <!-- placeholder="请输入销售公司"-->
  8. <!-- clearable-->
  9. <!-- size="small"-->
  10. <!-- @keyup.enter.native="handleQuery"-->
  11. <!-- />-->
  12. <!-- </el-form-item>-->
  13. <!-- <el-form-item label="权限名称" prop="roleName">-->
  14. <!-- <el-input-->
  15. <!-- v-model="queryParams.roleName"-->
  16. <!-- placeholder="请输入权限名称"-->
  17. <!-- clearable-->
  18. <!-- size="small"-->
  19. <!-- @keyup.enter.native="handleQuery"-->
  20. <!-- />-->
  21. <!-- </el-form-item>-->
  22. <!-- <el-form-item>-->
  23. <!-- <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
  24. <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
  25. <!-- </el-form-item>-->
  26. <!-- </el-form>-->
  27. <!-- <el-row :gutter="10" class="mb8">-->
  28. <!-- <el-col :span="1.5">-->
  29. <!-- <el-button-->
  30. <!-- type="primary"-->
  31. <!-- plain-->
  32. <!-- icon="el-icon-plus"-->
  33. <!-- size="mini"-->
  34. <!-- @click="handleAdd"-->
  35. <!-- v-hasPermi="['sop:companySopRole:add']"-->
  36. <!-- >新增</el-button>-->
  37. <!-- </el-col>-->
  38. <!-- <el-col :span="1.5">-->
  39. <!-- <el-button-->
  40. <!-- type="success"-->
  41. <!-- plain-->
  42. <!-- icon="el-icon-edit"-->
  43. <!-- size="mini"-->
  44. <!-- :disabled="single"-->
  45. <!-- @click="handleUpdate"-->
  46. <!-- v-hasPermi="['sop:companySopRole:edit']"-->
  47. <!-- >修改</el-button>-->
  48. <!-- </el-col>-->
  49. <!-- <el-col :span="1.5">-->
  50. <!-- <el-button-->
  51. <!-- type="danger"-->
  52. <!-- plain-->
  53. <!-- icon="el-icon-delete"-->
  54. <!-- size="mini"-->
  55. <!-- :disabled="multiple"-->
  56. <!-- @click="handleDelete"-->
  57. <!-- v-hasPermi="['sop:companySopRole:remove']"-->
  58. <!-- >删除</el-button>-->
  59. <!-- </el-col>-->
  60. <!-- <el-col :span="1.5">-->
  61. <!-- <el-button-->
  62. <!-- type="warning"-->
  63. <!-- plain-->
  64. <!-- icon="el-icon-download"-->
  65. <!-- size="mini"-->
  66. <!-- :loading="exportLoading"-->
  67. <!-- @click="handleExport"-->
  68. <!-- v-hasPermi="['sop:companySopRole:export']"-->
  69. <!-- >导出</el-button>-->
  70. <!-- </el-col>-->
  71. <!-- </el-row>-->
  72. <el-table border v-loading="loading" :data="companySopRoleList">
  73. <el-table-column label="销售公司" align="center" prop="companyId">
  74. <template slot-scope="scope">
  75. <el-tag v-for="item in companyList" v-if="item.companyId == scope.row.companyId">
  76. {{ scope.row.companyName }}
  77. </el-tag>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="权限" align="center">
  81. <template slot-scope="scope">
  82. <div style="display: flex;flex-flow: wrap;justify-content: flex-start;">
  83. <el-tag style="width: 30%;margin: 0 5px" v-for="item in scope.row.rules">{{ roleMap[item] }}</el-tag>
  84. </div>
  85. </template>
  86. </el-table-column>
  87. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  88. <template slot-scope="scope">
  89. <el-button
  90. size="mini"
  91. type="text"
  92. icon="el-icon-edit"
  93. @click="handleUpdate(scope.row)"
  94. v-hasPermi="['sop:companySopRole:edit']"
  95. >修改
  96. </el-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. <pagination
  101. v-show="total>0"
  102. :total="total"
  103. :page.sync="queryParams.pageNum"
  104. :limit.sync="queryParams.pageSize"
  105. @pagination="getList"
  106. />
  107. <!-- 添加或修改公司SOP权限对话框 -->
  108. <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
  109. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  110. <el-form-item label="销售公司" prop="companyId">
  111. <el-select filterable v-model="form.companyId" placeholder="请选择公司名" size="small">
  112. <el-option
  113. v-for="item in companyList"
  114. :key="item.companyId"
  115. :label="item.companyName"
  116. :value="item.companyId"
  117. />
  118. </el-select>
  119. </el-form-item>
  120. <el-form-item label="权限" prop="rules">
  121. <div style="margin: 15px 0;"></div>
  122. <el-checkbox-group v-model="form.rules" style="display: flex;flex-flow: wrap;justify-content: flex-start;">
  123. <el-checkbox style="width: 28%" v-for="item in roleOptions" :label="item.dictValue" :key="item.dictValue">
  124. {{ item.dictLabel }}
  125. </el-checkbox>
  126. </el-checkbox-group>
  127. </el-form-item>
  128. </el-form>
  129. <div slot="footer" class="dialog-footer">
  130. <el-button type="primary" @click="submitForm">确 定</el-button>
  131. <el-button @click="cancel">取 消</el-button>
  132. </div>
  133. </el-dialog>
  134. </div>
  135. </template>
  136. <script>
  137. import {
  138. listCompanySopRole,
  139. getCompanySopRole,
  140. delCompanySopRole,
  141. addCompanySopRole,
  142. updateCompanySopRole,
  143. exportCompanySopRole
  144. } from '@/api/sop/companySopRole'
  145. import { getCompanyList } from '@/api/company/company'
  146. export default {
  147. name: 'CompanySopRole',
  148. data() {
  149. return {
  150. // 遮罩层
  151. loading: true,
  152. // 导出遮罩层
  153. exportLoading: false,
  154. // 选中数组
  155. ids: [],
  156. // 非单个禁用
  157. single: true,
  158. // 非多个禁用
  159. multiple: true,
  160. // 显示搜索条件
  161. showSearch: true,
  162. // 总条数
  163. total: 0,
  164. // 公司SOP权限表格数据
  165. companySopRoleList: [],
  166. roleOptions: [],
  167. roleMap: [],
  168. // 弹出层标题
  169. title: '',
  170. // 是否显示弹出层
  171. open: false,
  172. companyList: [],
  173. // 查询参数
  174. queryParams: {
  175. pageNum: 1,
  176. pageSize: 10,
  177. companyId: null,
  178. roleName: null,
  179. roleValue: null
  180. },
  181. // 表单参数
  182. form: {},
  183. // 表单校验
  184. rules: {}
  185. }
  186. },
  187. created() {
  188. this.getList()
  189. this.getDicts('company_sop_role').then(response => {
  190. this.roleOptions = response.data
  191. this.roleMap = response.data.reduce((obj, item) => {
  192. obj[item.dictValue] = item.dictLabel
  193. return obj
  194. }, {})
  195. })
  196. getCompanyList().then(response => {
  197. this.companyList = response.data
  198. })
  199. },
  200. methods: {
  201. /** 查询公司SOP权限列表 */
  202. getList() {
  203. this.loading = true
  204. listCompanySopRole(this.queryParams).then(response => {
  205. console.info(response.rows)
  206. this.companySopRoleList = response.rows
  207. this.total = response.total
  208. this.loading = false
  209. })
  210. },
  211. // 取消按钮
  212. cancel() {
  213. this.open = false
  214. this.reset()
  215. },
  216. // 表单重置
  217. reset() {
  218. this.form = {
  219. id: null,
  220. companyId: null,
  221. roleName: null,
  222. roleValue: null,
  223. createTime: null,
  224. createBy: null,
  225. updateBy: null,
  226. updateTime: null,
  227. rules: this.roleOptions.map(e => e.dictValue),
  228. remark: null
  229. }
  230. this.resetForm('form')
  231. },
  232. /** 搜索按钮操作 */
  233. handleQuery() {
  234. this.queryParams.pageNum = 1
  235. this.getList()
  236. },
  237. /** 重置按钮操作 */
  238. resetQuery() {
  239. this.resetForm('queryForm')
  240. this.handleQuery()
  241. },
  242. // 多选框选中数据
  243. handleSelectionChange(selection) {
  244. this.ids = selection.map(item => item.id)
  245. this.single = selection.length !== 1
  246. this.multiple = !selection.length
  247. },
  248. /** 新增按钮操作 */
  249. handleAdd() {
  250. this.reset()
  251. this.open = true
  252. this.title = '添加公司SOP权限'
  253. },
  254. /** 修改按钮操作 */
  255. handleUpdate(row) {
  256. this.reset()
  257. if (row.rules && row.rules.length > 0) {
  258. this.form.rules = row.rules
  259. }
  260. this.form.companyId = row.companyId
  261. this.open = true
  262. this.title = '修改公司SOP权限'
  263. },
  264. /** 提交按钮 */
  265. submitForm() {
  266. this.$refs['form'].validate(valid => {
  267. if (valid) {
  268. updateCompanySopRole(this.form).then(response => {
  269. this.msgSuccess('修改成功')
  270. this.open = false
  271. this.getList()
  272. })
  273. }
  274. })
  275. },
  276. /** 删除按钮操作 */
  277. handleDelete(row) {
  278. const ids = row.id || this.ids
  279. this.$confirm('是否确认删除公司SOP权限编号为"' + ids + '"的数据项?', '警告', {
  280. confirmButtonText: '确定',
  281. cancelButtonText: '取消',
  282. type: 'warning'
  283. }).then(function() {
  284. return delCompanySopRole(ids)
  285. }).then(() => {
  286. this.getList()
  287. this.msgSuccess('删除成功')
  288. }).catch(() => {
  289. })
  290. },
  291. /** 导出按钮操作 */
  292. handleExport() {
  293. const queryParams = this.queryParams
  294. this.$confirm('是否确认导出所有公司SOP权限数据项?', '警告', {
  295. confirmButtonText: '确定',
  296. cancelButtonText: '取消',
  297. type: 'warning'
  298. }).then(() => {
  299. this.exportLoading = true
  300. return exportCompanySopRole(queryParams)
  301. }).then(response => {
  302. this.download(response.msg)
  303. this.exportLoading = false
  304. }).catch(() => {
  305. })
  306. }
  307. }
  308. }
  309. </script>