main.vue 10 KB

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