index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <div class="user-management-container">
  3. <el-row :gutter="20">
  4. <el-col :span="5" :xs="24">
  5. <div class="head-container" style="margin-bottom: 5px">
  6. <el-input v-model="filterText" placeholder="输入关键字进行过滤" />
  7. <el-tree
  8. ref="tree"
  9. class="filter-tree"
  10. :data="deptOptions"
  11. default-expand-all
  12. :default-expanded-keys="[1]"
  13. :filter-node-method="filterNode"
  14. highlight-current
  15. node-key="id"
  16. :props="defaultProps"
  17. @node-click="handleNodeClick" />
  18. </div>
  19. <vab-query-form-left-panel>
  20. <el-button icon="el-icon-plus" type="primary" @click="getCheckedNodes($event)">添加区域</el-button>
  21. </vab-query-form-left-panel>
  22. </el-col>
  23. <el-col :sapn="19">
  24. <vab-query-form>
  25. <vab-query-form-top-panel>
  26. <el-form :inline="true" :model="queryForm" @submit.native.prevent>
  27. <el-form-item prop="custCode">
  28. <el-input v-model="queryForm.custCode" clearable placeholder="客户编码" />
  29. </el-form-item>
  30. <el-form-item prop="custName">
  31. <el-input v-model="queryForm.custName" clearable placeholder="客户名称" />
  32. </el-form-item>
  33. <el-form-item label="" prop="custIndustry">
  34. <el-select v-model="custIndustry" placeholder="请选择客户行业" style="width: 100%">
  35. <el-option
  36. v-for="item in industryOptions"
  37. :key="item.value"
  38. :label="item.value"
  39. :value="item.value" />
  40. </el-select>
  41. </el-form-item>
  42. <el-form-item>
  43. <el-button icon="el-icon-search" type="primary" @click="queryData">查询</el-button>
  44. <el-button icon="el-icon-refresh-right" @click="reset">重置</el-button>
  45. </el-form-item>
  46. </el-form>
  47. </vab-query-form-top-panel>
  48. </vab-query-form>
  49. <vab-query-form-left-panel>
  50. <el-button icon="el-icon-plus" type="primary" @click="handleEdit($event)">添加</el-button>
  51. </vab-query-form-left-panel>
  52. <vab-query-form-right-panel>
  53. <el-button icon="el-icon-download" />
  54. <table-tool :check-list.sync="checkList" :columns="columns" />
  55. </vab-query-form-right-panel>
  56. <el-table
  57. v-loading="listLoading"
  58. border
  59. :data="list"
  60. style="width: 100%; height: 500px"
  61. @selection-change="setSelectRows">
  62. <el-table-column
  63. v-for="(item, index) in finallyColumns"
  64. :key="index"
  65. align="center"
  66. :label="item.label"
  67. :prop="item.prop"
  68. show-overflow-tooltip
  69. :sortable="item.sortable"
  70. :width="item.width">
  71. <template #default="{ row }">
  72. <span>{{ row[item.prop] }}</span>
  73. </template>
  74. </el-table-column>
  75. <el-table-column align="center" label="操作" show-overflow-tooltip width="85">
  76. <template #default="{ row }">
  77. <el-button type="text" @click="handleEdit(row)">编辑</el-button>
  78. <el-button type="text" @click="handleDelete(row)">删除</el-button>
  79. </template>
  80. </el-table-column>
  81. <template #empty>
  82. <el-image class="vab-data-empty" :src="require('@/assets/empty_images/data_empty.png')" />
  83. </template>
  84. </el-table>
  85. <el-pagination
  86. background
  87. :current-page="queryForm.pageNum"
  88. :layout="layout"
  89. :page-size="queryForm.pageSize"
  90. :total="total"
  91. @current-change="handleCurrentChange"
  92. @size-change="handleSizeChange" />
  93. </el-col>
  94. </el-row>
  95. <edit ref="edit" @fetch-data="fetchData" />
  96. <reg-edit ref="reg-edit" @fetch-data="fetchData" />
  97. </div>
  98. </template>
  99. <script>
  100. import Edit from './components/RegionEdit'
  101. import RegEdit from './components/RegEdit'
  102. import regionApi from '@/api/base/region/region'
  103. import TableTool from '@/components/table/TableTool'
  104. export default {
  105. name: 'Distr',
  106. components: { Edit, RegEdit, TableTool },
  107. data() {
  108. return {
  109. current: '',
  110. list: [],
  111. listLoading: true,
  112. layout: 'total, sizes, prev, pager, next, jumper',
  113. total: 0,
  114. selectRows: '',
  115. filterText: '',
  116. custIndustry: '', // 客户行业 (没数据)
  117. queryForm: {
  118. pageNum: 1,
  119. pageSize: 10,
  120. userName: '',
  121. },
  122. deptOptions: undefined,
  123. defaultProps: {
  124. id: 'id',
  125. regionCode: 'regionCode',
  126. label: 'regionDesc',
  127. },
  128. treeDefaultExpandAll: true,
  129. regionId: 0,
  130. industryOptions: [], //客户行业
  131. checkList: [],
  132. columns: [
  133. {
  134. label: '省份',
  135. width: '100px',
  136. prop: 'distName',
  137. sortable: false,
  138. },
  139. {
  140. label: '客户数量',
  141. width: 'auto',
  142. prop: 'count',
  143. sortable: false,
  144. disableCheck: true,
  145. },
  146. ],
  147. }
  148. },
  149. computed: {
  150. height() {
  151. return this.$baseTableHeight(10)
  152. },
  153. finallyColumns() {
  154. console.log('finallyColums')
  155. return this.columns.filter((item) => this.checkList.includes(item.label))
  156. },
  157. },
  158. watch: {
  159. filterText(val) {
  160. this.$refs.tree.filter(val)
  161. },
  162. },
  163. created() {
  164. this.fetchData()
  165. this.getRegion()
  166. this.getOptions()
  167. },
  168. methods: {
  169. reset() {
  170. this.queryForm = {
  171. pageNum: 1,
  172. pageSize: 10,
  173. custCode: '',
  174. custName: '',
  175. custIndustry: '',
  176. }
  177. },
  178. getOptions() {
  179. Promise.all([this.getDicts('CustomerIndustry')])
  180. .then(([industry]) => {
  181. this.industryOptions = industry.data.values || []
  182. })
  183. .catch((err) => console.log(err))
  184. },
  185. async getRegion() {
  186. const { data: data } = await regionApi.getRegion({})
  187. var first_id = data.list[0].id
  188. console.log('区域', first_id)
  189. this.deptOptions = data.list
  190. this.queryForm.regionId = first_id //data.list[0].id
  191. this.$refs['edit'].setRegion(first_id)
  192. //默认第一选中
  193. this.$nextTick(() => {
  194. this.$refs.tree.setCurrentKey(first_id)
  195. })
  196. this.fetchData()
  197. },
  198. // 筛选节点
  199. filterNode(value, data) {
  200. if (!value) return true
  201. return data[this.defaultProps.label].indexOf(value) !== -1
  202. },
  203. // 节点单击事件
  204. handleNodeClick(data) {
  205. console.log('ID', data.id)
  206. this.$refs['edit'].setRegion(data.id)
  207. this.queryForm.regionId = data.id
  208. this.fetchData()
  209. },
  210. setSelectRows(val) {
  211. this.selectRows = val
  212. },
  213. getCheckedNodes() {
  214. this.$refs['reg-edit'].showEdit()
  215. },
  216. handleEdit(row) {
  217. if (row.id) {
  218. this.$refs['edit'].showEdit(row)
  219. } else {
  220. this.$refs['edit'].showEdit()
  221. }
  222. },
  223. handleDelete(row) {
  224. if (row.id) {
  225. console.log('deletedId', row.id)
  226. this.$baseConfirm('你确定要删除当前项吗', null, async () => {
  227. const { msg } = await regionApi.doDelete({ ids: row.id })
  228. this.$baseMessage(msg, 'success', 'vab-hey-message-success')
  229. await this.fetchData()
  230. })
  231. } else {
  232. if (this.selectRows.length > 0) {
  233. const ids = this.selectRows.map((item) => parseInt(item.id))
  234. console.log(ids)
  235. this.$baseConfirm('你确定要删除选中项吗', null, async () => {
  236. const { msg } = await regionApi.doDelete({ ids })
  237. this.$baseMessage(msg, 'success', 'vab-hey-message-success')
  238. await this.fetchData()
  239. })
  240. } else {
  241. this.$baseMessage('未选中任何行', 'error', 'vab-hey-message-error')
  242. }
  243. }
  244. },
  245. handleSizeChange(val) {
  246. this.queryForm.pageSize = val
  247. this.fetchData()
  248. },
  249. handleCurrentChange(val) {
  250. this.queryForm.pageNum = val
  251. this.fetchData()
  252. },
  253. queryData() {
  254. console.log('ffff')
  255. this.queryForm.pageNum = 1
  256. this.fetchData()
  257. },
  258. async fetchData() {
  259. this.listLoading = true
  260. const {
  261. data: { list, total },
  262. } = await regionApi.getList(this.queryForm)
  263. this.list = list
  264. this.total = total
  265. this.listLoading = false
  266. },
  267. },
  268. }
  269. </script>
  270. <style>
  271. .el-tree-node:focus > .el-tree-node__content {
  272. /*设置选中的样式 */
  273. background-color: #dde9ff !important;
  274. }
  275. .el-tree-node__content:hover {
  276. /*设置鼠标飘过的颜色 */
  277. background: #eaf9ff !important;
  278. color: #007bff;
  279. }
  280. .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
  281. /*current选中的样式 */
  282. color: #4d95fd;
  283. font-weight: bold;
  284. background-color: #dde9ff !important;
  285. }
  286. .el-form-item__content {
  287. margin-right: 3px;
  288. }
  289. .vab-query-form[data-v-64063760] .el-form-item:first-child .el-form-item--small {
  290. margin: 0 10px 10px 0 !important;
  291. }
  292. </style>