customerSelect.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. <template>
  2. <span class="select-component" style="display:inline-flex;width: 100%;">
  3. <el-select
  4. v-model.trim="value"
  5. size="small"
  6. :placeholder="configuration.placeholder"
  7. style="border-right: none;width: 100%"
  8. :disabled="disabled ? disabled : false"
  9. :multiple="configuration.multiple ? configuration.multiple : false"
  10. :clearable="configuration.clearable ? configuration.clearable : false"
  11. :collapse-tags="
  12. configuration.collapseTags ? configuration.collapseTags : false
  13. "
  14. filterable
  15. remote
  16. @change="changeName"
  17. :remote-method="remoteMethod"
  18. >
  19. <el-option
  20. v-for="item in configuration.dicData.length !== 0
  21. ? dicData.length !== 0
  22. ? dicData
  23. : configuration.dicData
  24. : dicData"
  25. :key="item.id"
  26. :label="item.cname"
  27. :value="item.id"
  28. />
  29. </el-select>
  30. <el-button
  31. slot="append"
  32. icon="el-icon-search"
  33. size="mini"
  34. @click="open"
  35. :disabled="disabled ? disabled : false"
  36. ></el-button>
  37. <el-dialog
  38. v-dialogdrag
  39. title="导入客户"
  40. :fullscreen="dialogFull"
  41. :visible.sync="dialogVisible"
  42. class="el-dialogDeep"
  43. append-to-body
  44. width="80%"
  45. >
  46. <template slot="title">
  47. <span class="el-dialog__title">
  48. <span
  49. style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"
  50. ></span>
  51. 导入客户
  52. </span>
  53. <div
  54. style="float: right"
  55. class="avue-crud__dialog__menu"
  56. @click="dialogFull ? (dialogFull = false) : (dialogFull = true)"
  57. >
  58. <i class="el-icon-full-screen"></i>
  59. </div>
  60. </template>
  61. <el-row style="height: 0">
  62. <el-col :span="5">
  63. <div class="box">
  64. <el-scrollbar>
  65. <basic-container>
  66. <avue-tree
  67. :option="treeOption"
  68. :data="treeData"
  69. @node-click="nodeClick"
  70. />
  71. </basic-container>
  72. </el-scrollbar>
  73. </div>
  74. </el-col>
  75. <el-col :span="19">
  76. <basic-container>
  77. <avue-crud
  78. :option="option"
  79. :data="dataList"
  80. ref="crud"
  81. v-model="form"
  82. :page.sync="page"
  83. :before-close="beforeClose"
  84. @search-change="searchChange"
  85. @search-reset="searchReset"
  86. @refresh-change="refreshChange"
  87. @selection-change="selectionChange"
  88. @on-load="onLoad"
  89. @saveColumn="saveColumn"
  90. @tree-load="treeLoad"
  91. >
  92. </avue-crud>
  93. </basic-container>
  94. </el-col>
  95. </el-row>
  96. <span slot="footer" class="dialog-footer">
  97. <el-button @click="dialogVisible = false">取 消</el-button>
  98. <el-button
  99. type="primary"
  100. @click="confirmSelection"
  101. :disabled="
  102. configuration.multipleChoices === true
  103. ? false
  104. : selection.length === 1
  105. ? false
  106. : true
  107. "
  108. >确 定</el-button
  109. >
  110. </span>
  111. </el-dialog>
  112. </span>
  113. </template>
  114. <script>
  115. import option from "./configuration/mainList.json";
  116. import {
  117. customerList,
  118. typeSave,
  119. deleteDetails,
  120. getDeptLazyTree
  121. } from "@/api/basicData/customerInformation";
  122. import {
  123. customerParameter,
  124. supplierParameter,
  125. companyParameter
  126. } from "@/enums/management-type";
  127. export default {
  128. name: "customerInformation",
  129. props: {
  130. disabled: Boolean,
  131. value: String,
  132. configuration: Object,
  133. typeData: String
  134. },
  135. model: {
  136. prop: "value",
  137. event: "returnBack"
  138. },
  139. data() {
  140. return {
  141. corpType: null,
  142. dialogFull: false,
  143. form: {},
  144. dicData: [],
  145. dialogVisible: false,
  146. value: "",
  147. option: {},
  148. parentId: 0,
  149. dataList: [],
  150. selection: [],
  151. treeOption: {
  152. nodeKey: "id",
  153. lazy: true,
  154. // treeLoad: function(node, resolve) {
  155. // const parentId = (node.level === 0) ? 0 : node.data.id;
  156. // getDeptLazyTree({parentId:parentId,corpType:"KH"}).then(res => {
  157. // resolve(res.data.data.map(item => {
  158. // return {
  159. // ...item,
  160. // leaf: !item.hasChildren
  161. // }
  162. // }))
  163. // });
  164. // },
  165. addBtn: false,
  166. menu: false,
  167. size: "small",
  168. props: {
  169. labelText: "标题",
  170. label: "title",
  171. value: "value",
  172. children: "children"
  173. }
  174. },
  175. page: {
  176. pageSize: 10,
  177. pagerCount: 5,
  178. total: 0
  179. },
  180. // 远程模糊查找loading
  181. loading: false,
  182. queryParams: {
  183. size: 10,
  184. current: 1
  185. }
  186. };
  187. },
  188. async created() {
  189. this.option = await this.getColumnData(this.getColumnName(47), option);
  190. // this.option.searchShow = this.configuration.searchShow ? this.configuration.searchShow : false
  191. this.remoteMethod();
  192. },
  193. methods: {
  194. changeName(value) {
  195. let optionList =
  196. this.configuration.dicData.length !== 0
  197. ? this.dicData.length !== 0
  198. ? this.dicData
  199. : this.configuration.dicData
  200. : this.dicData;
  201. let valueName;
  202. let data;
  203. optionList.map(item => {
  204. if (item.id === this.value) {
  205. valueName = item.cname;
  206. data = item;
  207. }
  208. });
  209. this.$emit("returnBack", this.value);
  210. this.$emit("valueName", valueName);
  211. this.$emit("getRow", data);
  212. },
  213. //刷新触发
  214. refreshChange() {
  215. this.page = {
  216. pageSize: 10,
  217. pagerCount: 5,
  218. total: 0
  219. };
  220. },
  221. //确认导出触发
  222. confirmSelection() {
  223. this.dicData = [];
  224. if (this.configuration.multipleChoices === true) {
  225. let value = [];
  226. for (let item in this.selection) {
  227. this.dicData.push({
  228. id: this.selection[item].id,
  229. cname: this.selection[item].cname
  230. });
  231. value.push(this.selection[item].id);
  232. }
  233. this.value = value;
  234. } else {
  235. this.dicData.push({
  236. id: this.selection[0].id,
  237. cname: this.selection[0].cname
  238. });
  239. this.value = this.selection[0].id;
  240. }
  241. this.$emit("returnBack", this.value);
  242. this.$emit("receiveList", this.dicData);
  243. this.$emit("valueName", this.dicData[0].cname);
  244. this.$emit("getRow", this.selection[0]);
  245. this.selection = [];
  246. this.dialogVisible = false;
  247. },
  248. //选中触发
  249. selectionChange(selection) {
  250. this.selection = selection;
  251. },
  252. nodeClick(data) {
  253. this.treeDeptId = data.id;
  254. this.page.currentPage = 1;
  255. this.onLoad(this.page);
  256. },
  257. //查询全部
  258. initData() {
  259. customerList().then(res => {
  260. console.log(this.form);
  261. const column = this.findObject(this.option.column, "parentId");
  262. column.dicData = res.data.data.records;
  263. });
  264. },
  265. //新增子项触发
  266. handleAdd(row) {
  267. this.parentId = row.id;
  268. const column = this.findObject(this.option.column, "parentId");
  269. column.value = row.id;
  270. column.addDisabled = true;
  271. this.$refs.crud.rowAdd();
  272. },
  273. //点击新增时触发
  274. beforeClose(done) {
  275. this.parentId = "";
  276. const column = this.findObject(this.option.column, "parentId");
  277. column.value = "";
  278. column.addDisabled = false;
  279. done();
  280. },
  281. //点击搜索按钮触发
  282. searchChange(params, done) {
  283. console.log(params);
  284. this.treeDeptId = "";
  285. this.page.currentPage = 1;
  286. this.onLoad(this.page, params);
  287. done();
  288. },
  289. //搜索重置按钮触发
  290. searchReset() {
  291. this.treeDeptId = "";
  292. this.onLoad(this.page);
  293. },
  294. onLoad(page, params = { parentId: 0 }) {
  295. let queryParams = Object.assign({}, params, {
  296. size: page.pageSize,
  297. current: page.currentPage,
  298. corpsTypeId: this.treeDeptId,
  299. corpType: this.corpType ? this.corpType : "KH"
  300. });
  301. customerList(queryParams).then(res => {
  302. this.dataList = res.data.data.records;
  303. this.page.total = res.data.data.total;
  304. if (this.page.total) {
  305. this.option.height = window.innerHeight - 500;
  306. } else {
  307. this.option.height = window.innerHeight - 200;
  308. }
  309. });
  310. },
  311. open() {
  312. if (this.typeData == "KH") {
  313. this.corpType = customerParameter;
  314. }
  315. if (this.typeData == "GYS") {
  316. this.corpType = supplierParameter;
  317. }
  318. if (this.typeData == "GS") {
  319. this.corpType = companyParameter;
  320. }
  321. this.dialogVisible = true;
  322. let _this = this;
  323. this.treeOption.treeLoad = function(node, resolve) {
  324. const parentId = node.level === 0 ? 0 : node.data.id;
  325. getDeptLazyTree({
  326. parentId: parentId,
  327. corpType: _this.corpType ? _this.corpType : "KH"
  328. }).then(res => {
  329. resolve(
  330. res.data.data.map(item => {
  331. return {
  332. ...item,
  333. leaf: !item.hasChildren
  334. };
  335. })
  336. );
  337. });
  338. };
  339. },
  340. //树桩列点击展开触发
  341. treeLoad(tree, treeNode, resolve) {
  342. const parentId = tree.id;
  343. customerList({
  344. parentId: parentId,
  345. corpType: this.corpType ? this.corpType : "KH"
  346. }).then(res => {
  347. resolve(res.data.data.records);
  348. });
  349. },
  350. // 远程模糊查找
  351. remoteMethod(query) {
  352. if (query) {
  353. this.loading = true;
  354. this.queryParams = {
  355. size: 10,
  356. current: 1,
  357. cname: query,
  358. corpType: this.typeData ? this.corpType : "KH"
  359. };
  360. customerList(this.queryParams).then(res => {
  361. this.dicData = res.data.data.records;
  362. this.loading = false;
  363. });
  364. } else {
  365. this.loading = true;
  366. this.queryParams = {
  367. size: 10,
  368. current: 1,
  369. corpType: this.typeData ? this.typeData : "KH"
  370. };
  371. customerList(this.queryParams).then(res => {
  372. this.dicData = [];
  373. this.configuration.dicData = this.configuration.dicData.concat(
  374. res.data.data.records
  375. );
  376. // this.configuration.dicData = res.data.data.records
  377. this.removeRepeat();
  378. this.loading = false;
  379. });
  380. }
  381. },
  382. // 去重
  383. removeRepeat() {
  384. let obj = [];
  385. this.configuration.dicData = this.configuration.dicData.reduce(
  386. (current, next) => {
  387. obj[next.id] ? "" : (obj[next.id] = true && current.push(next));
  388. return current;
  389. },
  390. []
  391. );
  392. },
  393. //列保存触发
  394. async saveColumn() {
  395. const inSave = await this.saveColumnData(
  396. this.getColumnName(47),
  397. this.option
  398. );
  399. if (inSave) {
  400. this.$message.success("保存成功");
  401. //关闭窗口
  402. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  403. }
  404. }
  405. }
  406. };
  407. </script>
  408. <style scoped lang="scss">
  409. .el-dialogDeep {
  410. ::v-deep .el-dialog {
  411. .el-dialog__body,
  412. .el-dialog__footer {
  413. padding-bottom: 0 !important;
  414. padding-top: 0 !important;
  415. }
  416. }
  417. }
  418. </style>