main.vue 8.8 KB

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