customerSelect.vue 11 KB

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