index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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="companyUserId">
  5. <el-select
  6. v-model="queryParams.companyUserId"
  7. placeholder="请输入销售id或名称筛选,默认100条"
  8. clearable
  9. filterable
  10. remote
  11. :remote-method="(keyword) => companyUserRemoteSearch(keyword, queryParams.companyUserId)"
  12. style="width: 290px;"
  13. >
  14. <el-option
  15. v-for="item in companyUserOptions"
  16. :key="item.dictValue"
  17. :label="`${item.dictLabel}(${item.dictValue})`"
  18. :value="item.dictValue"
  19. />
  20. </el-select>
  21. </el-form-item>
  22. <el-form-item label="部门" prop="deptId">
  23. <treeselect
  24. v-model="queryParams.deptId"
  25. :options="deptOptions"
  26. :normalizer="normalizer"
  27. placeholder="选择部门"
  28. style="width: 220px"
  29. />
  30. </el-form-item>
  31. <el-form-item label="含子部门" prop="includeChild">
  32. <el-switch v-model="queryParams.includeChild"/>
  33. </el-form-item>
  34. <el-form-item>
  35. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  36. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  37. </el-form-item>
  38. </el-form>
  39. <el-row :gutter="10" class="mb8">
  40. <el-col :span="1.5">
  41. <el-button
  42. type="primary"
  43. plain
  44. icon="el-icon-plus"
  45. size="mini"
  46. v-hasPermi="['app:comuserdept:add']"
  47. @click="handleAdd"
  48. >
  49. 新增
  50. </el-button>
  51. </el-col>
  52. <el-col :span="1.5">
  53. <el-button
  54. type="danger"
  55. plain
  56. icon="el-icon-delete"
  57. size="mini"
  58. :disabled="ids.length === 0"
  59. v-hasPermi="['app:comuserdept:delete']"
  60. @click="handleDelete"
  61. >
  62. 删除
  63. </el-button>
  64. </el-col>
  65. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  66. </el-row>
  67. <el-table v-loading="loading" :data="customerBindList" @selection-change="handleSelectionChange" border>
  68. <el-table-column type="selection" width="55" align="center"/>
  69. <el-table-column label="销售ID" align="center" prop="companyUserId" min-width="100"/>
  70. <el-table-column label="销售名称" align="center" prop="companyUserName" min-width="150"/>
  71. <el-table-column label="销售账号" align="center" prop="companyUserAccount" min-width="150"/>
  72. <el-table-column label="部门" align="center" prop="deptName" min-width="120"/>
  73. <el-table-column label="创建时间" align="center" prop="createTime" min-width="120"/>
  74. <el-table-column label="修改时间" align="center" prop="updateTime" min-width="120"/>
  75. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" min-width="120">
  76. <template slot-scope="scope">
  77. <el-button
  78. size="mini"
  79. type="text"
  80. icon="el-icon-edit"
  81. v-hasPermi="['app:comuserdept:edit']"
  82. @click="handleUpdate(scope.row)"
  83. >修改</el-button>
  84. </template>
  85. </el-table-column>
  86. </el-table>
  87. <pagination
  88. v-show="total>0"
  89. :total="total"
  90. :page.sync="queryParams.pageNum"
  91. :limit.sync="queryParams.pageSize"
  92. @pagination="getList"
  93. />
  94. <!-- 添加或修改客服绑定关系 -->
  95. <el-dialog
  96. :title="bindDialog.title"
  97. :visible.sync="bindDialog.visible"
  98. width="500px"
  99. append-to-body
  100. :close-on-click-modal="false"
  101. >
  102. <el-form ref="bindForm" :model="bindForm" :rules="rules" label-width="80px">
  103. <el-form-item label="销售" prop="companyUserId">
  104. <el-select
  105. v-model="bindForm.companyUserId"
  106. placeholder="请输入销售id或名称筛选,默认100条"
  107. clearable
  108. filterable
  109. remote
  110. style="width: 290px;"
  111. :remote-method="(keyword) => companyUserRemoteSearch(keyword, bindForm.companyUserId)"
  112. >
  113. <el-option
  114. v-for="item in companyUserOptions"
  115. :key="item.dictValue"
  116. :label="`${item.dictLabel}(${item.dictValue})`"
  117. :value="item.dictValue"
  118. />
  119. </el-select>
  120. </el-form-item>
  121. <el-form-item label="部门" prop="deptId">
  122. <treeselect
  123. v-model="bindForm.deptId"
  124. :options="deptOptions"
  125. :normalizer="normalizer"
  126. placeholder="选择部门"
  127. style="width: 290px;"
  128. />
  129. </el-form-item>
  130. </el-form>
  131. <div slot="footer" class="dialog-footer">
  132. <el-button type="primary" @click="submitForm">确 定</el-button>
  133. <el-button @click="cancel">取 消</el-button>
  134. </div>
  135. </el-dialog>
  136. </div>
  137. </template>
  138. <script>
  139. import { findList, getById, deleteByIds, add, edit, findCompanyUserOptions, } from "@/api/app/customerBind";
  140. import { listDept } from '@/api/system/appDept';
  141. import Treeselect from "@riophae/vue-treeselect";
  142. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  143. export default {
  144. name: "CustomerBind",
  145. components: { Treeselect },
  146. data() {
  147. return {
  148. // 部门树形选择器选项
  149. deptOptions: [],
  150. companyUserOptions: [],
  151. // 遮罩层
  152. loading: true,
  153. // 选中数组
  154. ids: [],
  155. // 显示搜索条件
  156. showSearch: true,
  157. // 总条数
  158. total: 0,
  159. // 客服/销售绑定部门表格数据
  160. customerBindList: [],
  161. bindDialog: {
  162. visible: false,
  163. loading: false,
  164. title: null,
  165. },
  166. // 表单参数
  167. bindForm: {
  168. id: null,
  169. companyUserId: null,
  170. deptId: null
  171. },
  172. // 表单校验
  173. rules: {
  174. companyUserId: [
  175. { required: true, message: "销售不可为空", trigger: "blur" },
  176. ],
  177. deptId: [
  178. { required: true, message: "部门不可为空", trigger: "blur" },
  179. ],
  180. },
  181. // 查询参数
  182. queryParams: {
  183. pageNum: 1,
  184. pageSize: 10,
  185. companyUserId: null,
  186. deptId: null,
  187. includeChild: false,
  188. },
  189. };
  190. },
  191. created() {
  192. this.getList();
  193. this.getDeptList();
  194. this.getCompanyUserOptions(null);
  195. },
  196. methods: {
  197. /** 列表查询 */
  198. getList() {
  199. this.loading = true;
  200. findList(this.queryParams).then(response => {
  201. this.customerBindList = response.rows;
  202. this.total = response.total;
  203. this.loading = false;
  204. });
  205. },
  206. /**
  207. * 获取部门树形数据
  208. */
  209. getDeptList() {
  210. listDept().then(response => {
  211. if (response.code === 200) {
  212. // 转换为树形结构
  213. this.deptOptions = this.handleTree(response.data, "deptId");
  214. } else {
  215. this.deptOptions = [];
  216. }
  217. }).catch(() => {
  218. this.deptOptions = [];
  219. });
  220. },
  221. /**
  222. * 获取销售列表
  223. */
  224. async getCompanyUserOptions(keyword, selectedId) {
  225. let res = await findCompanyUserOptions({keyword: keyword, selectedId: selectedId, pageNumber: 1, pageSize: 100});
  226. this.companyUserOptions = res.data;
  227. },
  228. companyUserRemoteSearch(keyword, selectedId) {
  229. this.getCompanyUserOptions(keyword, selectedId);
  230. },
  231. /**
  232. * 树形结构转换
  233. */
  234. handleTree(data, id, parentId, children) {
  235. id = id || 'id';
  236. parentId = parentId || 'parentId';
  237. children = children || 'children';
  238. var tree = [];
  239. var map = {};
  240. data.forEach(function(item) {
  241. map[item[id]] = item;
  242. });
  243. data.forEach(function(item) {
  244. var parent = map[item[parentId]];
  245. if (parent) {
  246. (parent[children] || (parent[children] = [])).push(item);
  247. } else {
  248. tree.push(item);
  249. }
  250. });
  251. return tree;
  252. },
  253. /**
  254. * 树形选择器数据格式化
  255. */
  256. normalizer(node) {
  257. if (node.children && !node.children.length) {
  258. delete node.children;
  259. }
  260. return {
  261. id: node.deptId,
  262. label: node.deptName,
  263. children: node.children
  264. };
  265. },
  266. // 取消按钮
  267. cancel() {
  268. this.bindDialog.visible = false;
  269. this.reset();
  270. },
  271. // 表单重置
  272. reset() {
  273. this.bindForm = {
  274. id: null,
  275. companyUserId: null,
  276. deptId: null,
  277. };
  278. this.resetForm("bindForm");
  279. },
  280. /** 搜索按钮操作 */
  281. handleQuery() {
  282. this.queryParams.pageNum = 1;
  283. this.getList();
  284. },
  285. /** 重置按钮操作 */
  286. resetQuery() {
  287. this.queryParams = {
  288. pageNum: 1,
  289. pageSize: 10,
  290. companyUserId: null,
  291. deptId: null,
  292. includeChild: false,
  293. };
  294. this.handleQuery();
  295. },
  296. // 多选框选中数据
  297. handleSelectionChange(selection) {
  298. this.ids = selection.map(item => item.id);
  299. },
  300. /** 新增按钮操作 */
  301. handleAdd() {
  302. this.reset();
  303. this.bindDialog.title = "添加绑定关系";
  304. this.bindDialog.visible = true;
  305. },
  306. /** 修改按钮操作 */
  307. handleUpdate(row) {
  308. this.reset();
  309. getById(row.id ).then(response => {
  310. for (let key in this.bindForm) {
  311. this.bindForm[key] = response.data[key] || null;
  312. }
  313. this.bindDialog.title = "修改绑定关系";
  314. this.bindDialog.visible = true;
  315. });
  316. },
  317. handleDelete() {
  318. this.$confirm('是否确认删除?', "警告", {
  319. confirmButtonText: "确定",
  320. cancelButtonText: "取消",
  321. type: "warning"
  322. }).then(async () => {
  323. await deleteByIds(this.ids);
  324. this.getList();
  325. this.msgSuccess("删除成功");
  326. });
  327. },
  328. /** 提交按钮 */
  329. submitForm() {
  330. this.$refs["bindForm"].validate(valid => {
  331. if (valid) {
  332. if (this.bindForm.id != null) {
  333. edit(this.bindForm).then(response => {
  334. this.msgSuccess("修改成功");
  335. this.bindDialog.visible = false;
  336. this.getList();
  337. });
  338. } else {
  339. add(this.bindForm).then(response => {
  340. this.msgSuccess("新增成功");
  341. this.bindDialog.visible = false;
  342. this.getList();
  343. });
  344. }
  345. }
  346. });
  347. },
  348. }
  349. };
  350. </script>