index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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.cname"
  22. @click.native="getRow(item)"
  23. />
  24. </el-select>
  25. <el-button slot="append" icon="el-icon-search" size="mini" @click="dialogVisible = true"
  26. :disabled="disabled?disabled:false"></el-button>
  27. <el-dialog
  28. v-dialogdrag
  29. title="导入商品"
  30. :fullscreen="dialogFull"
  31. :visible.sync="dialogVisible"
  32. class="el-dialogDeep"
  33. append-to-body
  34. width="80%">
  35. <template slot="title">
  36. <span class="el-dialog__title">
  37. <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
  38. 导入客户
  39. </span>
  40. <div style="float: right" class="avue-crud__dialog__menu" @click="dialogFull? dialogFull=false: dialogFull=true">
  41. <i class="el-icon-full-screen"></i>
  42. </div>
  43. </template>
  44. <el-row style="height: 0">
  45. <el-col :span="5">
  46. <div class="box">
  47. <el-scrollbar>
  48. <basic-container>
  49. <avue-tree :option="treeOption" :data="treeData" @node-click="nodeClick"/>
  50. </basic-container>
  51. </el-scrollbar>
  52. </div>
  53. </el-col>
  54. <el-col :span="19">
  55. <basic-container>
  56. <avue-crud :option="option"
  57. :data="dataList"
  58. ref="crud"
  59. v-model="form"
  60. :page.sync="page"
  61. :before-close="beforeClose"
  62. @search-change="searchChange"
  63. @search-reset="searchReset"
  64. @refresh-change="refreshChange"
  65. @selection-change="selectionChange"
  66. @on-load="onLoad"
  67. @saveColumn="saveColumn"
  68. @tree-load="treeLoad">
  69. </avue-crud>
  70. </basic-container>
  71. </el-col>
  72. </el-row>
  73. <span slot="footer" class="dialog-footer">
  74. <el-button @click="dialogVisible = false">取 消</el-button>
  75. <el-button type="primary" @click="confirmSelection"
  76. :disabled="configuration.multipleChoices === true?false:selection.length === 1?false:true">确 定</el-button>
  77. </span>
  78. </el-dialog>
  79. </span>
  80. </template>
  81. <script>
  82. import option from "./configuration/mainList.json";
  83. import {getGoods, getDeptLazyTree} from "@/api/basicData/customerInquiry"
  84. export default {
  85. name: "index",
  86. props: {
  87. disabled: Boolean,
  88. value: String,
  89. configuration: Object,
  90. },
  91. model: {
  92. prop: 'value',
  93. event: 'returnBack'
  94. },
  95. data() {
  96. return {
  97. dialogFull: false,
  98. form: {},
  99. dicData: [],
  100. dialogVisible: false,
  101. value: '',
  102. option: {},
  103. parentId: 0,
  104. dataList: [],
  105. selection: [],
  106. treeOption: {
  107. nodeKey: 'id',
  108. lazy: true,
  109. treeLoad: function (node, resolve) {
  110. const parentId = (node.level === 0) ? 0 : node.data.id;
  111. getDeptLazyTree(parentId).then(res => {
  112. resolve(res.data.data.map(item => {
  113. return {
  114. ...item,
  115. leaf: !item.hasChildren
  116. }
  117. }))
  118. });
  119. },
  120. addBtn: false,
  121. menu: false,
  122. size: 'small',
  123. props: {
  124. labelText: '标题',
  125. label: 'title',
  126. value: 'value',
  127. children: 'children'
  128. }
  129. },
  130. page: {
  131. pageSize: 10,
  132. pagerCount: 5,
  133. total: 0,
  134. },
  135. // 远程模糊查找loading
  136. loading: false,
  137. queryParams: {
  138. size: 10,
  139. current: 1
  140. },
  141. }
  142. },
  143. async created() {
  144. this.option = await this.getColumnData(this.getColumnName(49), option);
  145. // this.option.searchShow = this.configuration.searchShow ? this.configuration.searchShow : false
  146. this.remoteMethod()
  147. },
  148. methods: {
  149. changeName(){
  150. this.$emit('returnBack', this.value)
  151. },
  152. getRow(row) {
  153. this.$emit('getRow', row)
  154. },
  155. //刷新触发
  156. refreshChange() {
  157. this.page = {
  158. pageSize: 10,
  159. pagerCount: 5,
  160. total: 0,
  161. }
  162. },
  163. //确认导出触发
  164. confirmSelection() {
  165. this.dicData = []
  166. if (this.configuration.multipleChoices === true) {
  167. let value = []
  168. for (let item in this.selection) {
  169. this.dicData.push({cname: this.selection[item].cname})
  170. value.push(this.selection[item].cname)
  171. }
  172. this.value = value
  173. } else {
  174. this.dicData.push({cname: this.selection[0].cname})
  175. this.value = this.selection[0].cname
  176. }
  177. this.$emit('returnRow', this.selection)
  178. this.selection = []
  179. this.$emit('returnBack', this.value)
  180. this.dialogVisible = false
  181. this.$emit('receiveList',this.dicData)
  182. },
  183. //选中触发
  184. selectionChange(selection) {
  185. this.selection = selection
  186. },
  187. nodeClick(data) {
  188. this.treeDeptId = data.id;
  189. this.page.currentPage = 1;
  190. this.onLoad(this.page);
  191. },
  192. //查询全部
  193. initData() {
  194. getGoods().then(res => {
  195. console.log(this.form);
  196. const column = this.findObject(this.option.column, "parentId");
  197. column.dicData = res.data.data.records;
  198. });
  199. },
  200. //新增子项触发
  201. handleAdd(row) {
  202. this.parentId = row.id;
  203. const column = this.findObject(this.option.column, "parentId");
  204. column.value = row.id;
  205. column.addDisabled = true;
  206. this.$refs.crud.rowAdd();
  207. },
  208. //点击新增时触发
  209. beforeClose(done) {
  210. this.parentId = "";
  211. const column = this.findObject(this.option.column, "parentId");
  212. column.value = "";
  213. column.addDisabled = false;
  214. done();
  215. },
  216. //点击搜索按钮触发
  217. searchChange(params, done) {
  218. console.log(params)
  219. this.page.currentPage = 1;
  220. this.onLoad(this.page, params);
  221. done()
  222. },
  223. //搜索重置按钮触发
  224. searchReset() {
  225. this.treeDeptId = '';
  226. this.onLoad(this.page);
  227. },
  228. onLoad(page, params = {parentId: 0}) {
  229. // let queryParams = Object.assign({}, params, {
  230. // size: page.pageSize,
  231. // current: page.currentPage,
  232. // corpsTypeId: this.treeDeptId
  233. // })
  234. getGoods(page.currentPage, page.pageSize, this.treeDeptId,params).then(res => {
  235. this.dataList = res.data.data.records
  236. this.page.total = res.data.data.total
  237. if (this.page.total) {
  238. this.option.height = window.innerHeight - 500;
  239. } else {
  240. this.option.height = window.innerHeight - 200;
  241. }
  242. })
  243. },
  244. //树桩列点击展开触发
  245. treeLoad(tree, treeNode, resolve) {
  246. const parentId = tree.id;
  247. getGoods({parentId: parentId}).then(res => {
  248. resolve(res.data.data.records);
  249. });
  250. },
  251. // 远程模糊查找
  252. remoteMethod(query) {
  253. if (query) {
  254. this.loading = true;
  255. let params = {
  256. // size: 10,
  257. // current: 1,
  258. cname: query
  259. }
  260. getGoods(1, 10, '', params).then(res => {
  261. this.dicData = res.data.data.records
  262. this.loading = false;
  263. });
  264. } else {
  265. this.loading = true
  266. this.queryParams = {
  267. size: 10,
  268. current: 1
  269. }
  270. getGoods(1, 10, '').then(res => {
  271. this.dicData = []
  272. this.configuration.dicData.forEach((e,index) => {
  273. res.data.data.records.forEach(item => {
  274. if (e.cname == item.cname) {
  275. this.configuration.dicData.splice(index, 1)
  276. }
  277. })
  278. })
  279. this.configuration.dicData = this.configuration.dicData.concat(res.data.data.records)
  280. // this.configuration.dicData = res.data.data.records
  281. this.removeRepeat()
  282. this.loading = false;
  283. });
  284. }
  285. },
  286. // 去重
  287. removeRepeat() {
  288. let obj = []
  289. this.configuration.dicData = this.configuration.dicData.reduce((current,next) => {
  290. obj[next.id] ? '': obj[next.id] = true && current.push(next)
  291. return current
  292. }, [])
  293. },
  294. //列保存触发
  295. async saveColumn() {
  296. const inSave = await this.saveColumnData(
  297. this.getColumnName(49),
  298. this.option
  299. );
  300. if (inSave) {
  301. this.$message.success("保存成功");
  302. //关闭窗口
  303. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  304. }
  305. },
  306. }
  307. };
  308. </script>
  309. <style scoped lang="scss">
  310. .el-dialogDeep {
  311. ::v-deep .el-dialog {
  312. .el-dialog__body, .el-dialog__footer {
  313. padding-bottom: 0 !important;
  314. padding-top: 0 !important;
  315. }
  316. }
  317. }
  318. </style>