main.vue 7.9 KB

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