main.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. if (this.multiple && this.selectionList.length == 0) return this.$message.error('请选择明细')
  217. this.$emit("balabala", this.selectionList[0].id);
  218. this.$emit("getCorpData", {
  219. ...this.selectionList[0],
  220. index: this.cropIndex
  221. });
  222. this.$emit("getCorpList", [...this.selectionList])
  223. this.corpVisible = false;
  224. },
  225. corpChange(row) {
  226. this.corpList.forEach(e => {
  227. if (row == e.id) {
  228. this.$emit("getCorpData", { ...e, index: this.cropIndex });
  229. }
  230. });
  231. },
  232. refreshChange() {
  233. this.onLoad(this.page, this.search);
  234. },
  235. onLoad(page, params = { parentId: 0 }) {
  236. let userObj = JSON.parse(localStorage.getItem("saber-userInfo")).content;
  237. let queryParams = Object.assign({}, params, {
  238. size: page.pageSize,
  239. current: page.currentPage,
  240. corpsTypeId: this.treeDeptId,
  241. corpType: getCustomerCode(this.corpType),
  242. adminProfiles: userObj.role_name != "admin" ? userObj.user_id : null,
  243. corpsTypeName: this.treeType == "CK" ? "货代和物流" : null,
  244. belongtocompany: this.belongtocompany
  245. });
  246. this.loading = true;
  247. customerList(queryParams)
  248. .then(res => {
  249. this.data = res.data.data.records;
  250. this.page.total = res.data.data.total;
  251. if (this.page.total) {
  252. this.tableOption.height = window.innerHeight - 350;
  253. }
  254. })
  255. .finally(() => {
  256. this.loading = false;
  257. });
  258. },
  259. selectionChange(list) {
  260. this.selectionList = list;
  261. },
  262. sizeChange(val) {
  263. this.page.pageSize = val;
  264. this.onLoad();
  265. },
  266. currentChange(val) {
  267. this.page.currentPage = val;
  268. this.onLoad();
  269. },
  270. //列表内展开树节点
  271. treeLoad(tree, treeNode, resolve) {
  272. const parentId = tree.id;
  273. customerList({ parentId: parentId }).then(res => {
  274. resolve(res.data.data.records);
  275. });
  276. },
  277. //点击搜索按钮触发
  278. searchChange(params, done) {
  279. this.page.currentPage = 1;
  280. this.onLoad(this.page, params);
  281. done();
  282. },
  283. searchReset() {
  284. this.treeDeptId = null;
  285. },
  286. nodeClick(data) {
  287. this.treeDeptId = data.id;
  288. this.page.currentPage = 1;
  289. this.onLoad(this.page);
  290. },
  291. //列保存触发
  292. async saveColumn() {
  293. const inSave = await this.saveColumnData(
  294. this.getColumnName(51),
  295. this.option
  296. );
  297. if (inSave) {
  298. this.$message.success("保存成功");
  299. //关闭窗口
  300. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  301. }
  302. },
  303. async resetColumn() {
  304. this.option = option;
  305. const inSave = await this.delColumnData(this.getColumnName(51), option);
  306. if (inSave) {
  307. this.$message.success("重置成功");
  308. this.$refs.crud.$refs.dialogColumn.columnBox = false;
  309. }
  310. },
  311. // 更新数据
  312. updateData(belongToCompany) {
  313. let userObj = JSON.parse(localStorage.getItem("saber-userInfo")).content;
  314. allCropList({
  315. corpType: getCustomerCode(this.corpType),
  316. adminProfiles: !userObj.role_name.split(',').some(item => item == 'admin' || item == 'administrator') ? userObj.user_id : null,
  317. belongtocompany: belongToCompany,
  318. }).then(res => {
  319. this.corpList = res.data.data;
  320. });
  321. },
  322. }
  323. };
  324. </script>
  325. <style scoped lang="scss"></style>