main.vue 9.7 KB

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