orderSettlement.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <div style="overflow: auto; width: 100%">
  3. <TreeChart
  4. :json="treeData"
  5. :class="{ landscape: isVertical }"
  6. :isDetail="isDetail"
  7. @add="addStock"
  8. @delete="deleteStock"
  9. />
  10. <el-dialog
  11. title="提示"
  12. :visible.sync="dialogVisible"
  13. :close-on-click-modal="false"
  14. width="500px"
  15. >
  16. <div class="tips">
  17. <el-form :model="ruleForm" ref="ruleForm" class="demo-ruleForm">
  18. <el-form-item label="组织架构名称" prop="orgName" class="imput_com">
  19. <el-input
  20. placeholder="输入组织架构名称"
  21. :maxlength="32"
  22. v-model="ruleForm.orgName"
  23. ></el-input>
  24. </el-form-item>
  25. </el-form>
  26. </div>
  27. <span slot="footer" class="dialog-footer">
  28. <div class="tip-left">
  29. <el-button type="info" @click="dialogVisible = false">取消</el-button>
  30. <el-button type="primary" @click="confirm">确定</el-button>
  31. </div>
  32. </span>
  33. </el-dialog>
  34. <!-- 删除提示弹框 -->
  35. <el-dialog title="提示" :visible.sync="dialogVisible2" width="30%">
  36. <div class="tips">
  37. <p style="text-align: left">确定删除该组织信息?</p>
  38. </div>
  39. <span slot="footer" class="dialog-footer">
  40. <div class="tip-left">
  41. <el-button type="info" @click="dialogVisible2 = false">取消</el-button>
  42. <el-button type="primary" @click="confimdelete">确定</el-button>
  43. </div>
  44. </span>
  45. </el-dialog>
  46. <div class="changeDirection" @click="changeDir">切换方向</div>
  47. </div>
  48. </template>
  49. <script>
  50. import TreeChart from "@/components/TreeData";
  51. import { Loading } from "element-ui";
  52. import { oSessionStorage } from "../../../utils/utils";
  53. export default {
  54. name: "tree",
  55. components: {
  56. TreeChart,
  57. },
  58. data() {
  59. return {
  60. group: "",
  61. ppData: [],
  62. groupData: [],
  63. treeData: {
  64. //公司名称
  65. orgName: "大米科技公司",
  66. proportionShares: "100",
  67. //公司层级
  68. level: 2,
  69. //公司编号
  70. orgNo: 1,
  71. },
  72. isVertical: false, // 是否是竖方向,只给最外层的添加
  73. isDetail: false, // 是否是详情,不可编辑操作
  74. dialogVisible: false, // 添加股东弹框
  75. dialogVisible2: false, // 删除提示弹框
  76. //当前取到的对象
  77. currentSelectObj: {},
  78. //输入表单的对象
  79. ruleForm: {
  80. orgName: "",
  81. },
  82. shareholderTypeOptions: [
  83. {
  84. labelEn: "Individual",
  85. labelZh: "个人",
  86. value: 1,
  87. },
  88. {
  89. labelEn: "Company",
  90. labelZh: "公司",
  91. value: 2,
  92. },
  93. {
  94. labelEn: "Other",
  95. labelZh: "其他",
  96. value: 3,
  97. },
  98. ], // 股东类型
  99. lastId: 11, // 最后一级id
  100. currentTreeData: {},
  101. userInfo: {},
  102. };
  103. },
  104. mounted() {
  105. this.userInfo = JSON.parse(oSessionStorage.getItem("userInfo"));
  106. this.getChannel();
  107. },
  108. methods: {
  109. changeDir() {
  110. //改变方向
  111. this.isVertical = !this.isVertical;
  112. },
  113. //获取组织架构方法--------------------开始-----------------------
  114. getChannel() {
  115. this.$http.get(
  116. `/org/findAllOrgByPOrgNo?orgNo=${this.userInfo.orgNo}`,
  117. {},
  118. (res) => {
  119. // this.$toast.success({message:'成功'});
  120. if (res && res.code == 200) {
  121. //将值赋值给list
  122. if (res.data.length > 0) {
  123. let resAdd = this.addPro(res.data);
  124. this.ppData = JSON.parse(JSON.stringify(resAdd));
  125. let forRes = this.arrToTree(resAdd);
  126. console.log("forRes")
  127. console.log(forRes)
  128. // console.log('格式化的结构')
  129. // console.log(forRes)
  130. let resultRes = this.deleteChildren(forRes);
  131. let levelList = this.markersFun(resultRes, 1);
  132. console.log("格式化的结构且去掉children");
  133. // console.log(JSON.stringify(levelList));
  134. this.treeData = levelList[0];
  135. console.log(levelList[0]);
  136. } else {
  137. this.groupData = [];
  138. }
  139. // this.channelList = res.data;
  140. } else {
  141. this.$message.error(res.msg);
  142. }
  143. }
  144. );
  145. },
  146. //z增加
  147. addPro(val) {
  148. let data = JSON.parse(JSON.stringify(val));
  149. for (let i = 0; i < val.length; i++) {
  150. data[i].value = val[i].orgNo;
  151. data[i].label = val[i].orgName;
  152. }
  153. return data;
  154. },
  155. //非递归方式:将平铺数据转换为树形结构数据
  156. arrToTree(arr) {
  157. let data = arr.filter((item) => {
  158. item.children = arr.filter((e) => {
  159. return item.orgNo === e.parentOrgNo;
  160. });
  161. return item.orgNo==this.userInfo.orgNo;
  162. });
  163. return data;
  164. },
  165. //去除转换树形结构数据后存在的空children
  166. deleteChildren(arr) {
  167. let childs = arr;
  168. for (let i = childs.length; i--; i > 0) {
  169. if (childs[i].children) {
  170. if (childs[i].children.length) {
  171. this.deleteChildren(childs[i].children);
  172. } else {
  173. delete childs[i].children;
  174. }
  175. }
  176. }
  177. return arr;
  178. },
  179. //标记层级
  180. markersFun(arr, level) {
  181. if (!arr || !arr.length) {
  182. return;
  183. }
  184. arr.forEach((item) => {
  185. item.level = level;
  186. if (item.children && item.children.length) {
  187. //
  188. this.markersFun(item.children, level + 1);
  189. }
  190. });
  191. return arr;
  192. },
  193. //获取组织架构方法--------------------结束-----------------------
  194. // 新增编辑股东,val: 0 新增, 1 编辑
  195. addStock(data) {
  196. console.log(data);
  197. this.currentSelectObj = data.data;
  198. // console.log(this.currentSelectObj);
  199. if (data.val) {
  200. this.ruleForm.orgName = data.data.orgName;
  201. // 不使用=赋值,内存相同,改变后,treeData数据也会改变
  202. // this.ruleForm = data.data;
  203. // this.ruleForm = Object.assign(this.ruleForm, data.data);
  204. // this.ruleForm.type = data.data.level;
  205. } else {
  206. this.ruleForm.orgName = "";
  207. }
  208. this.isEdit = data.val;
  209. // 使用=赋值,编辑时改变currentTreeData, 源数据treeData也会改变
  210. this.currentTreeData = data.data;
  211. this.dialogVisible = true;
  212. },
  213. // 删除
  214. deleteStock(data) {
  215. this.currentSelectObj = data;
  216. console.log(this.currentSelectObj);
  217. this.dialogVisible2 = true;
  218. },
  219. // 确定删除
  220. confimdelete() {
  221. // 前端删除 遍历原数据,删除匹配id数据
  222. this.$http.get(`/org/deleteOrgById?id=${this.currentSelectObj.id}`, {}, (res) => {
  223. // this.$toast.success({message:'成功'});
  224. if (res && res.code == 200) {
  225. //将值赋值给list
  226. //调用查询全部的
  227. this.getChannel();
  228. this.$message.success(res.msg);
  229. // this.channelList = res.data;
  230. } else {
  231. this.$message.error(res.msg);
  232. }
  233. });
  234. this.dialogVisible2 = false;
  235. },
  236. // 保存添加股东
  237. confirm() {
  238. // let loading = Loading.service();
  239. //判断是否输入值了
  240. if (this.ruleForm.orgName != "" && this.ruleForm.orgName != null) {
  241. this.sendData();
  242. } else {
  243. this.$message.warning("请输入组织架构名称");
  244. }
  245. },
  246. // 发送添加股东数据
  247. sendData() {
  248. // let loading = Loading.service();
  249. if (this.isEdit) {
  250. // 编辑
  251. // data.id = this.treeData.id;
  252. //将参数调用接口
  253. this.currentSelectObj.orgName = this.ruleForm.orgName;
  254. this.$http.post(`/org/addOrUpdateOrg`, this.currentSelectObj, (res) => {
  255. // this.$toast.success({message:'成功'});
  256. if (res && res.code == 200) {
  257. //将值赋值给list
  258. //调用查询全部的
  259. this.getChannel();
  260. this.$message.success(res.msg);
  261. this.dialogVisible = false;
  262. // this.channelList = res.data;
  263. } else {
  264. this.$message.error(res.msg);
  265. // this.dialogVisible = false;
  266. }
  267. });
  268. // this.clearDialog();
  269. // loading.close();
  270. } else {
  271. let data = {
  272. parentOrgNo: this.currentSelectObj.orgNo,
  273. orgName: this.ruleForm.orgName,
  274. };
  275. //将参数调用接口
  276. this.$http.post(`/org/addOrUpdateOrg`, data, (res) => {
  277. // this.$toast.success({message:'成功'});
  278. if (res && res.code == 200) {
  279. //将值赋值给list
  280. //调用查询全部的
  281. this.getChannel();
  282. this.$message.success(res.msg);
  283. this.dialogVisible = false;
  284. // this.channelList = res.data;
  285. } else {
  286. this.$message.error(res.msg);
  287. }
  288. });
  289. //新增后接着查询就行了
  290. // 添加
  291. // 前端添加数据,需要自己生成子级id,可以传数据的时候把最后一级id传过来,进行累加
  292. // data.id = this.lastId++;
  293. // data.partnerCode = this.currentTreeData.id;
  294. // data.extend = true;
  295. // const render = (formData) => {
  296. // formData.some((item) => {
  297. // if (item.id === this.currentTreeData.id) {
  298. // if (item.children) {
  299. // item.children.push(data);
  300. // } else {
  301. // this.$set(item, "children", [data]);
  302. // }
  303. // return;
  304. // } else if (item.children) {
  305. // render(item.children);
  306. // }
  307. // });
  308. // };
  309. // let arr = [this.treeData];
  310. // render(arr);
  311. // this.treeData = arr[0];
  312. // this.clearDialog();
  313. // loading.close();
  314. }
  315. },
  316. },
  317. };
  318. </script>
  319. <style scoped>
  320. .imput_com >>> .el-input__inner {
  321. width: 400px !important;
  322. }
  323. </style>
  324. <style lang="less" scoped>
  325. // :deep(.el-input__inner) {
  326. // }
  327. .changeDirection {
  328. position: fixed;
  329. right: 50px;
  330. bottom: 80px;
  331. margin: auto;
  332. background-color: #48d68e;
  333. padding: 10px;
  334. color: #ffffff;
  335. cursor: pointer;
  336. }
  337. </style>