main.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 v-if="refresh" 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. refresh: {
  121. type: Boolean,
  122. default: true
  123. },
  124. },
  125. model: {
  126. prop: "value",
  127. event: "balabala"
  128. },
  129. async created() {
  130. this.tableOption = await this.getColumnData(this.getColumnName(51), option);
  131. let userObj = JSON.parse(localStorage.getItem("saber-userInfo")).content;
  132. this.title = getCustomerName(this.corpType);
  133. if (!this.slot) {
  134. allCropList({
  135. corpType: getCustomerCode(this.corpType),
  136. adminProfiles: userObj.role_name != "admin" ? (userObj.role_name != "客户"?userObj.user_id : null): null,
  137. corpsTypeName: this.treeType == "CK" ? "货代和物流" : null,
  138. belongtocompany: this.belongtocompany
  139. }).then(res => {
  140. this.corpList = res.data.data;
  141. console.log(this.corpList)
  142. });
  143. }
  144. },
  145. mounted() { },
  146. methods: {
  147. init() {
  148. this.openDialog();
  149. },
  150. refreshData() {
  151. if (!this.slot) {
  152. let userObj = JSON.parse(localStorage.getItem("saber-userInfo")).content;
  153. allCropList({
  154. corpType: getCustomerCode(this.corpType),
  155. adminProfiles: userObj.role_name != "admin" ? userObj.user_id : null,
  156. corpsTypeName: this.treeType == "CK" ? "货代和物流" : null,
  157. belongtocompany: this.belongtocompany
  158. }).then(res => {
  159. this.corpList = res.data.data;
  160. });
  161. }
  162. },
  163. openDialog() {
  164. let _this = this;
  165. this.treeOption.treeLoad = function (node, resolve) {
  166. const parentId = node.level === 0 ? 0 : node.data.id;
  167. getDeptLazyTree({
  168. parentId: parentId,
  169. corpType: getCustomerCode(_this.corpType),
  170. cname: _this.treeType == "CK" ? "货代和物流" : null
  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. if (this.multiple && this.selectionList.length == 0) return this.$message.error('请选择明细')
  189. this.$emit("balabala", this.selectionList[0].id);
  190. this.$emit("getCorpData", {
  191. ...this.selectionList[0],
  192. index: this.cropIndex
  193. });
  194. this.$emit("getCorpList", [...this.selectionList])
  195. this.corpVisible = false;
  196. },
  197. clear() {
  198. this.$emit("clear");
  199. },
  200. corpChange(row) {
  201. if (!this.multiple) {
  202. this.corpList.forEach(e => {
  203. if (row == e.id) {
  204. this.$emit("getCorpData", { ...e, index: this.cropIndex });
  205. }
  206. });
  207. } else {
  208. let arr = [];
  209. row.forEach(item => {
  210. let obj = { id: item };
  211. this.$set(obj, 'cname', this.corpList.find(e => e.id == item).cname);
  212. arr.push(obj)
  213. })
  214. this.$nextTick(() => {
  215. this.$emit('getCorpList', [...arr]);
  216. })
  217. }
  218. },
  219. refreshChange() {
  220. this.onLoad(this.page, this.search);
  221. },
  222. onLoad(page, params = { parentId: 0 }) {
  223. let userObj = JSON.parse(localStorage.getItem("saber-userInfo")).content;
  224. let queryParams = Object.assign({}, params, {
  225. size: page.pageSize,
  226. current: page.currentPage,
  227. corpsTypeId: this.treeDeptId,
  228. corpType: getCustomerCode(this.corpType),
  229. adminProfiles: userObj.role_name != "admin" ? userObj.user_id : null,
  230. corpsTypeName: this.treeType == "CK" ? "货代和物流" : null,
  231. belongtocompany: this.belongtocompany
  232. });
  233. this.loading = true;
  234. customerList(queryParams)
  235. .then(res => {
  236. this.data = res.data.data.records;
  237. this.page.total = res.data.data.total;
  238. if (this.page.total) {
  239. this.tableOption.height = window.innerHeight - 350;
  240. }
  241. })
  242. .finally(() => {
  243. this.loading = false;
  244. });
  245. },
  246. selectionChange(list) {
  247. this.selectionList = list;
  248. },
  249. sizeChange(val) {
  250. this.page.pageSize = val;
  251. this.onLoad();
  252. },
  253. currentChange(val) {
  254. this.page.currentPage = val;
  255. this.onLoad();
  256. },
  257. //列表内展开树节点
  258. treeLoad(tree, treeNode, resolve) {
  259. const parentId = tree.id;
  260. customerList({ parentId: parentId }).then(res => {
  261. resolve(res.data.data.records);
  262. });
  263. },
  264. //点击搜索按钮触发
  265. searchChange(params, done) {
  266. this.page.currentPage = 1;
  267. this.onLoad(this.page, params);
  268. done();
  269. },
  270. searchReset() {
  271. this.treeDeptId = null;
  272. },
  273. nodeClick(data) {
  274. this.treeDeptId = data.id;
  275. this.page.currentPage = 1;
  276. this.onLoad(this.page);
  277. },
  278. //列保存触发
  279. async saveColumn() {
  280. const inSave = await this.saveColumnData(
  281. this.getColumnName(51),
  282. this.option
  283. );
  284. if (inSave) {
  285. this.$message.success("保存成功");
  286. //关闭窗口
  287. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  288. }
  289. },
  290. async resetColumn() {
  291. this.option = option;
  292. const inSave = await this.delColumnData(this.getColumnName(51), option);
  293. if (inSave) {
  294. this.$message.success("重置成功");
  295. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  296. }
  297. },
  298. // 更新数据
  299. updateData(belongToCompany) {
  300. let userObj = JSON.parse(localStorage.getItem("saber-userInfo")).content;
  301. allCropList({
  302. corpType: getCustomerCode(this.corpType),
  303. adminProfiles: !userObj.role_name.split(',').some(item => item == 'admin' || item == 'administrator') ? userObj.user_id : null,
  304. belongtocompany: belongToCompany,
  305. }).then(res => {
  306. this.corpList = res.data.data;
  307. });
  308. },
  309. }
  310. };
  311. </script>
  312. <style scoped lang="scss">
  313. </style>