main.vue 9.9 KB

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