index.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 = option
  145. // this.option = await this.getColumnData(this.getColumnName(49), option);
  146. // this.option.searchShow = this.configuration.searchShow ? this.configuration.searchShow : false
  147. this.remoteMethod()
  148. },
  149. methods: {
  150. changeName(){
  151. this.$emit('returnBack', this.value)
  152. },
  153. getRow(row) {
  154. this.$emit('getRow', row)
  155. },
  156. //刷新触发
  157. refreshChange() {
  158. this.page = {
  159. pageSize: 10,
  160. pagerCount: 5,
  161. total: 0,
  162. }
  163. },
  164. //确认导出触发
  165. confirmSelection() {
  166. this.dicData = []
  167. if (this.configuration.multipleChoices === true) {
  168. let value = []
  169. for (let item in this.selection) {
  170. this.dicData.push({cname: this.selection[item].cname})
  171. value.push(this.selection[item].cname)
  172. }
  173. this.value = value
  174. } else {
  175. this.dicData.push({cname: this.selection[0].cname})
  176. this.value = this.selection[0].cname
  177. }
  178. this.$emit('returnRow', this.selection)
  179. this.selection = []
  180. this.$emit('returnBack', this.value)
  181. this.dialogVisible = false
  182. this.$emit('receiveList',this.dicData)
  183. },
  184. //选中触发
  185. selectionChange(selection) {
  186. this.selection = selection
  187. },
  188. nodeClick(data) {
  189. this.treeDeptId = data.id;
  190. this.page.currentPage = 1;
  191. this.onLoad(this.page);
  192. },
  193. //查询全部
  194. initData() {
  195. getGoods().then(res => {
  196. console.log(this.form);
  197. const column = this.findObject(this.option.column, "parentId");
  198. column.dicData = res.data.data.records;
  199. });
  200. },
  201. //新增子项触发
  202. handleAdd(row) {
  203. this.parentId = row.id;
  204. const column = this.findObject(this.option.column, "parentId");
  205. column.value = row.id;
  206. column.addDisabled = true;
  207. this.$refs.crud.rowAdd();
  208. },
  209. //点击新增时触发
  210. beforeClose(done) {
  211. this.parentId = "";
  212. const column = this.findObject(this.option.column, "parentId");
  213. column.value = "";
  214. column.addDisabled = false;
  215. done();
  216. },
  217. //点击搜索按钮触发
  218. searchChange(params, done) {
  219. console.log(params)
  220. this.page.currentPage = 1;
  221. this.onLoad(this.page, params);
  222. done()
  223. },
  224. //搜索重置按钮触发
  225. searchReset() {
  226. this.treeDeptId = '';
  227. this.onLoad(this.page);
  228. },
  229. onLoad(page, params = {parentId: 0}) {
  230. // let queryParams = Object.assign({}, params, {
  231. // size: page.pageSize,
  232. // current: page.currentPage,
  233. // corpsTypeId: this.treeDeptId
  234. // })
  235. getGoods(page.currentPage, page.pageSize, this.treeDeptId,params).then(res => {
  236. this.dataList = res.data.data.records
  237. this.page.total = res.data.data.total
  238. if (this.page.total) {
  239. this.option.height = window.innerHeight - 500;
  240. } else {
  241. this.option.height = window.innerHeight - 200;
  242. }
  243. })
  244. },
  245. //树桩列点击展开触发
  246. treeLoad(tree, treeNode, resolve) {
  247. const parentId = tree.id;
  248. getGoods({parentId: parentId}).then(res => {
  249. resolve(res.data.data.records);
  250. });
  251. },
  252. // 远程模糊查找
  253. remoteMethod(query) {
  254. if (query) {
  255. this.loading = true;
  256. let params = {
  257. // size: 10,
  258. // current: 1,
  259. cname: query
  260. }
  261. getGoods(1, 10, '', params).then(res => {
  262. this.dicData = res.data.data.records
  263. this.loading = false;
  264. });
  265. } else {
  266. this.loading = true
  267. this.queryParams = {
  268. size: 10,
  269. current: 1
  270. }
  271. getGoods(1, 10, '').then(res => {
  272. this.dicData = []
  273. this.configuration.dicData.forEach((e,index) => {
  274. res.data.data.records.forEach(item => {
  275. if (e.cname == item.cname) {
  276. this.configuration.dicData.splice(index, 1)
  277. }
  278. })
  279. })
  280. this.configuration.dicData = this.configuration.dicData.concat(res.data.data.records)
  281. // this.configuration.dicData = res.data.data.records
  282. this.removeRepeat()
  283. this.loading = false;
  284. });
  285. }
  286. },
  287. // 去重
  288. removeRepeat() {
  289. let obj = []
  290. this.configuration.dicData = this.configuration.dicData.reduce((current,next) => {
  291. obj[next.id] ? '': obj[next.id] = true && current.push(next)
  292. return current
  293. }, [])
  294. },
  295. //列保存触发
  296. async saveColumn() {
  297. const inSave = await this.saveColumnData(
  298. this.getColumnName(49),
  299. this.option
  300. );
  301. if (inSave) {
  302. this.$message.success("保存成功");
  303. //关闭窗口
  304. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  305. }
  306. },
  307. }
  308. };
  309. </script>
  310. <style scoped lang="scss">
  311. .el-dialogDeep {
  312. ::v-deep .el-dialog {
  313. .el-dialog__body, .el-dialog__footer {
  314. padding-bottom: 0 !important;
  315. padding-top: 0 !important;
  316. }
  317. }
  318. }
  319. </style>