index.vue 9.9 KB

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