main.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <div>
  3. <div style="display:flex">
  4. <el-select
  5. size="small"
  6. v-model="value"
  7. placeholder="请选择"
  8. @input="$emit('balabala', value)"
  9. :disabled="disabled"
  10. filterable
  11. clearable
  12. style="width:100%"
  13. :multiple="multiple? multiple : false"
  14. :collapse-tags="collapseTags?collapseTags: false"
  15. @change="corpChange"
  16. >
  17. <el-option
  18. v-for="item in corpList"
  19. :key="item.id"
  20. :label="item.cname"
  21. :value="item.id"
  22. >
  23. </el-option>
  24. </el-select>
  25. <el-button
  26. icon="el-icon-search"
  27. size="mini"
  28. :disabled="disabled"
  29. @click="openDialog()"
  30. ></el-button>
  31. </div>
  32. <el-dialog
  33. :title="title"
  34. :visible.sync="corpVisible"
  35. width="80%"
  36. top="5vh"
  37. append-to-body
  38. @closed="closed"
  39. class="el-dialogDeep"
  40. v-dialog-drag
  41. >
  42. <span>
  43. <el-row>
  44. <el-col :span="4">
  45. <el-scrollbar>
  46. <basic-container>
  47. <avue-tree
  48. :option="treeOption"
  49. :data="treeData"
  50. @node-click="nodeClick"
  51. :style="treeStyle"
  52. />
  53. </basic-container>
  54. </el-scrollbar>
  55. </el-col>
  56. <el-col :span="20">
  57. <avue-crud
  58. :option="tableOption"
  59. :data="data"
  60. ref="crud"
  61. v-model="form"
  62. :page.sync="page"
  63. :search.sync="search"
  64. @search-change="searchChange"
  65. @search-reset="searchReset"
  66. @selection-change="selectionChange"
  67. @on-load="onLoad"
  68. @tree-load="treeLoad"
  69. @saveColumn="saveColumn"
  70. @resetColumn="resetColumn"
  71. @refresh-change="refreshChange"
  72. :table-loading="loading"
  73. >
  74. </avue-crud>
  75. </el-col>
  76. </el-row>
  77. </span>
  78. <span slot="footer" class="dialog-footer">
  79. <el-button @click="corpVisible = false">取 消</el-button>
  80. <el-button
  81. type="primary"
  82. @click="importCorp"
  83. :disabled="selectionList.length != 1"
  84. >确 定</el-button
  85. >
  86. </span>
  87. </el-dialog>
  88. </div>
  89. </template>
  90. <script>
  91. import option from "./configuration/mainList.json";
  92. import {
  93. customerList,
  94. allCropList,
  95. getDeptLazyTree
  96. } from "@/api/basicData/customerInformation";
  97. import { getCustomerCode, getCustomerName } from "@/enums/management-type";
  98. export default {
  99. data() {
  100. return {
  101. corpList: [],
  102. loading: false,
  103. data: [],
  104. tableOption: {},
  105. form: {},
  106. search: {},
  107. treeDeptId: "",
  108. treeDeptName: "",
  109. page: {
  110. currentPage: 1,
  111. pageSize: 10,
  112. total: 0
  113. },
  114. treeOption: {
  115. nodeKey: "id",
  116. lazy: true,
  117. addBtn: false,
  118. menu: false,
  119. size: "small",
  120. props: {
  121. labelText: "标题",
  122. label: "title",
  123. value: "value",
  124. children: "children"
  125. }
  126. },
  127. corpVisible: false,
  128. selectionList: [],
  129. title: null,
  130. treeStyle:'height:'+(window.innerHeight - 315)+'px'
  131. };
  132. },
  133. props: {
  134. value: String,
  135. disabled: Boolean,
  136. cropIndex: Number,
  137. corpType: String,
  138. multiple: Boolean,
  139. collapseTags: Boolean,
  140. },
  141. model: {
  142. prop: "value",
  143. event: "balabala"
  144. },
  145. async created() {
  146. this.tableOption = await this.getColumnData(this.getColumnName(51), option);
  147. this.title = getCustomerName(this.corpType);
  148. allCropList({
  149. corpType: getCustomerCode(this.corpType)
  150. }).then(res => {
  151. this.corpList = res.data.data;
  152. });
  153. },
  154. mounted() {},
  155. methods: {
  156. init() {
  157. this.openDialog();
  158. },
  159. openDialog() {
  160. let _this = this;
  161. this.treeOption.treeLoad = function(node, resolve) {
  162. const parentId = node.level === 0 ? 0 : node.data.id;
  163. getDeptLazyTree({
  164. parentId: parentId,
  165. corpType: getCustomerCode(_this.corpType)
  166. }).then(res => {
  167. resolve(
  168. res.data.data.map(item => {
  169. return {
  170. ...item,
  171. leaf: !item.hasChildren
  172. };
  173. })
  174. );
  175. });
  176. };
  177. this.corpVisible = true;
  178. },
  179. closed() {
  180. this.$refs.crud.toggleSelection();
  181. },
  182. importCorp() {
  183. this.$emit("balabala", this.selectionList[0].id);
  184. this.$emit("getCorpData", {
  185. ...this.selectionList[0],
  186. index: this.cropIndex
  187. });
  188. this.corpVisible = false;
  189. },
  190. corpChange(row) {
  191. this.corpList.forEach(e => {
  192. if (row == e.id) {
  193. this.$emit("getCorpData", { ...e, index: this.cropIndex });
  194. }
  195. });
  196. },
  197. refreshChange() {
  198. this.onLoad(this.page, this.search);
  199. },
  200. onLoad(page, params = { parentId: 0 }) {
  201. let queryParams = Object.assign({}, params, {
  202. size: page.pageSize,
  203. current: page.currentPage,
  204. corpsTypeId: this.treeDeptId,
  205. corpType: getCustomerCode(this.corpType)
  206. });
  207. this.loading = true;
  208. customerList(queryParams)
  209. .then(res => {
  210. this.data = res.data.data.records;
  211. this.page.total = res.data.data.total;
  212. if (this.page.total) {
  213. this.tableOption.height = window.innerHeight - 350;
  214. }
  215. })
  216. .finally(() => {
  217. this.loading = false;
  218. });
  219. },
  220. selectionChange(list) {
  221. this.selectionList = list;
  222. },
  223. sizeChange(val) {
  224. this.page.pageSize = val;
  225. this.onLoad();
  226. },
  227. currentChange(val) {
  228. this.page.currentPage = val;
  229. this.onLoad();
  230. },
  231. //列表内展开树节点
  232. treeLoad(tree, treeNode, resolve) {
  233. const parentId = tree.id;
  234. customerList({ parentId: parentId }).then(res => {
  235. resolve(res.data.data.records);
  236. });
  237. },
  238. //点击搜索按钮触发
  239. searchChange(params, done) {
  240. this.page.currentPage = 1;
  241. this.onLoad(this.page, params);
  242. done();
  243. },
  244. searchReset() {
  245. this.treeDeptId = null;
  246. },
  247. nodeClick(data) {
  248. this.treeDeptId = data.id;
  249. this.page.currentPage = 1;
  250. this.onLoad(this.page);
  251. },
  252. //列保存触发
  253. async saveColumn() {
  254. const inSave = await this.saveColumnData(
  255. this.getColumnName(51),
  256. this.option
  257. );
  258. if (inSave) {
  259. this.$message.success("保存成功");
  260. //关闭窗口
  261. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  262. }
  263. },
  264. async resetColumn() {
  265. this.option = option;
  266. const inSave = await this.delColumnData(this.getColumnName(51), option);
  267. if (inSave) {
  268. this.$message.success("重置成功");
  269. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  270. }
  271. }
  272. }
  273. };
  274. </script>
  275. <style scoped lang="scss"></style>