main.vue 9.4 KB

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