customerSelect.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <span class="select-component" style="display:inline-flex;width: 100%;">
  3. <el-select
  4. v-model="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="configuration.collapseTags?configuration.collapseTags:false"
  12. filterable
  13. remote
  14. @change="changeName"
  15. :remote-method="remoteMethod"
  16. >
  17. <el-option
  18. v-for="item in configuration.dicData.length !== 0?dicData.length !== 0?dicData:configuration.dicData:dicData"
  19. :key="item.id"
  20. :label="item.cname"
  21. :value="item.id"
  22. />
  23. </el-select>
  24. <el-button slot="append" icon="el-icon-search" size="mini" @click="dialogVisible = true"
  25. :disabled="disabled?disabled:false"></el-button>
  26. <el-dialog
  27. v-dialogdrag
  28. title="导入客户"
  29. :visible.sync="dialogVisible"
  30. class="el-dialogDeep"
  31. append-to-body
  32. width="80%">
  33. <el-row style="height: 0">
  34. <el-col :span="5">
  35. <div class="box">
  36. <el-scrollbar>
  37. <basic-container>
  38. <avue-tree :option="treeOption" :data="treeData" @node-click="nodeClick"/>
  39. </basic-container>
  40. </el-scrollbar>
  41. </div>
  42. </el-col>
  43. <el-col :span="19">
  44. <basic-container>
  45. <avue-crud :option="option"
  46. :data="dataList"
  47. ref="crud"
  48. v-model="form"
  49. :page.sync="page"
  50. :before-close="beforeClose"
  51. @search-change="searchChange"
  52. @search-reset="searchReset"
  53. @refresh-change="refreshChange"
  54. @selection-change="selectionChange"
  55. @on-load="onLoad"
  56. @tree-load="treeLoad">
  57. </avue-crud>
  58. </basic-container>
  59. </el-col>
  60. </el-row>
  61. <span slot="footer" class="dialog-footer">
  62. <el-button @click="dialogVisible = false">取 消</el-button>
  63. <el-button type="primary" @click="confirmSelection"
  64. :disabled="configuration.multipleChoices === true?false:selection.length === 1?false:true">确 定</el-button>
  65. </span>
  66. </el-dialog>
  67. </span>
  68. </template>
  69. <script>
  70. import option from "./configuration/mainList.json";
  71. import {customerList, typeSave, deleteDetails, getDeptLazyTree} from "@/api/basicData/customerInformation"
  72. export default {
  73. name: "customerInformation",
  74. props: {
  75. disabled: Boolean,
  76. value: String,
  77. configuration: Object,
  78. },
  79. model: {
  80. prop: 'value',
  81. event: 'returnBack'
  82. },
  83. data() {
  84. return {
  85. form: {},
  86. dicData: [],
  87. dialogVisible: false,
  88. value: '',
  89. option: option,
  90. parentId: 0,
  91. dataList: [],
  92. selection: [],
  93. treeOption: {
  94. nodeKey: 'id',
  95. lazy: true,
  96. treeLoad: function (node, resolve) {
  97. const parentId = (node.level === 0) ? 0 : node.data.id;
  98. getDeptLazyTree(parentId).then(res => {
  99. resolve(res.data.data.map(item => {
  100. return {
  101. ...item,
  102. leaf: !item.hasChildren
  103. }
  104. }))
  105. });
  106. },
  107. addBtn: false,
  108. menu: false,
  109. size: 'small',
  110. props: {
  111. labelText: '标题',
  112. label: 'title',
  113. value: 'value',
  114. children: 'children'
  115. }
  116. },
  117. page: {
  118. pageSize: 10,
  119. pagerCount: 5,
  120. total: 0,
  121. },
  122. // 远程模糊查找loading
  123. loading: false,
  124. queryParams: {
  125. size: 10,
  126. current: 1
  127. },
  128. }
  129. },
  130. created() {
  131. this.option.searchShow = this.configuration.searchShow ? this.configuration.searchShow : false
  132. this.remoteMethod()
  133. },
  134. methods: {
  135. changeName(){
  136. this.$emit('returnBack', this.value)
  137. },
  138. //刷新触发
  139. refreshChange() {
  140. this.page = {
  141. pageSize: 10,
  142. pagerCount: 5,
  143. total: 0,
  144. }
  145. },
  146. //确认导出触发
  147. confirmSelection() {
  148. this.dicData = []
  149. if (this.configuration.multipleChoices === true) {
  150. let value = []
  151. for (let item in this.selection) {
  152. this.dicData.push({id: this.selection[item].id, cname: this.selection[item].cname})
  153. value.push(this.selection[item].id)
  154. }
  155. this.value = value
  156. } else {
  157. this.dicData.push({id: this.selection[0].id, cname: this.selection[0].cname})
  158. this.value = this.selection[0].id
  159. }
  160. this.selection = []
  161. this.$emit('returnBack', this.value)
  162. this.dialogVisible = false
  163. this.$emit('receiveList',this.dicData)
  164. },
  165. //选中触发
  166. selectionChange(selection) {
  167. this.selection = selection
  168. },
  169. nodeClick(data) {
  170. this.treeDeptId = data.id;
  171. this.page.currentPage = 1;
  172. this.onLoad(this.page);
  173. },
  174. //查询全部
  175. initData() {
  176. customerList().then(res => {
  177. console.log(this.form);
  178. const column = this.findObject(this.option.column, "parentId");
  179. column.dicData = res.data.data.records;
  180. });
  181. },
  182. //新增子项触发
  183. handleAdd(row) {
  184. this.parentId = row.id;
  185. const column = this.findObject(this.option.column, "parentId");
  186. column.value = row.id;
  187. column.addDisabled = true;
  188. this.$refs.crud.rowAdd();
  189. },
  190. //点击新增时触发
  191. beforeClose(done) {
  192. this.parentId = "";
  193. const column = this.findObject(this.option.column, "parentId");
  194. column.value = "";
  195. column.addDisabled = false;
  196. done();
  197. },
  198. //点击搜索按钮触发
  199. searchChange(params, done) {
  200. console.log(params)
  201. this.page.currentPage = 1;
  202. this.onLoad(this.page, params);
  203. done()
  204. },
  205. //搜索重置按钮触发
  206. searchReset() {
  207. this.treeDeptId = '';
  208. this.onLoad(this.page);
  209. },
  210. onLoad(page, params = {parentId: 0}) {
  211. let queryParams = Object.assign({}, params, {
  212. size: page.pageSize,
  213. current: page.currentPage,
  214. corpsTypeId: this.treeDeptId
  215. })
  216. customerList(queryParams).then(res => {
  217. this.dataList = res.data.data.records
  218. this.page.total = res.data.data.total
  219. if (this.page.total) {
  220. this.option.height = window.innerHeight - 500;
  221. } else {
  222. this.option.height = window.innerHeight - 200;
  223. }
  224. })
  225. },
  226. //树桩列点击展开触发
  227. treeLoad(tree, treeNode, resolve) {
  228. const parentId = tree.id;
  229. customerList({parentId: parentId}).then(res => {
  230. resolve(res.data.data.records);
  231. });
  232. },
  233. // 远程模糊查找
  234. remoteMethod(query) {
  235. if (query !== '') {
  236. this.loading = true;
  237. this.queryParams = {
  238. size: 10,
  239. current: 1,
  240. cname: query
  241. }
  242. customerList(this.queryParams).then(res => {
  243. this.dicData = res.data.data.records
  244. this.loading = false;
  245. });
  246. } else {
  247. this.loading = true
  248. this.queryParams = {
  249. size: 10,
  250. current: 1
  251. }
  252. customerList(this.queryParams).then(res => {
  253. this.dicData = res.data.data.records
  254. this.loading = false;
  255. });
  256. }
  257. },
  258. }
  259. };
  260. </script>
  261. <style scoped lang="scss">
  262. .el-dialogDeep {
  263. ::v-deep .el-dialog {
  264. .el-dialog__body, .el-dialog__footer {
  265. padding-bottom: 0 !important;
  266. padding-top: 0 !important;
  267. }
  268. }
  269. }
  270. </style>