orderSettlement.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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" :rules="rules" ref="ruleForm" class="demo-ruleForm">
  18. <el-form-item label="组织名称" prop="orgName">
  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>
  47. </template>
  48. <script>
  49. import TreeChart from "@/components/TreeData";
  50. import { Loading } from "element-ui";
  51. export default {
  52. name: "tree",
  53. components: {
  54. TreeChart,
  55. },
  56. data() {
  57. return {
  58. group: "",
  59. ppData: [],
  60. groupData: [],
  61. treeData: {
  62. //公司名称
  63. orgName: "大米科技公司",
  64. proportionShares: "100",
  65. //公司层级
  66. level: 2,
  67. //公司编号
  68. orgNo: 1,
  69. },
  70. isVertical: false, // 是否是竖方向,只给最外层的添加
  71. isDetail: false, // 是否是详情,不可编辑操作
  72. dialogVisible: false, // 添加股东弹框
  73. dialogVisible2: false, // 删除提示弹框
  74. //当前取到的对象
  75. currentSelectObj: {},
  76. //输入表单的对象
  77. ruleForm: {
  78. orgName: "",
  79. },
  80. rules: {
  81. orgName: [{ required: true, message: "请输入组织名称", trigger: "blur" }],
  82. },
  83. shareholderTypeOptions: [
  84. {
  85. labelEn: "Individual",
  86. labelZh: "个人",
  87. value: 1,
  88. },
  89. {
  90. labelEn: "Company",
  91. labelZh: "公司",
  92. value: 2,
  93. },
  94. {
  95. labelEn: "Other",
  96. labelZh: "其他",
  97. value: 3,
  98. },
  99. ], // 股东类型
  100. lastId: 11, // 最后一级id
  101. currentTreeData: {},
  102. };
  103. },
  104. mounted() {
  105. this.getChannel();
  106. },
  107. methods: {
  108. //获取组织架构方法--------------------开始-----------------------
  109. getChannel() {
  110. this.$http.get(`/org/findAllOrgByPOrgNo`, {}, (res) => {
  111. // this.$toast.success({message:'成功'});
  112. if (res && res.code == 200) {
  113. //将值赋值给list
  114. if (res.data.length > 0) {
  115. let resAdd = this.addPro(res.data);
  116. this.ppData = JSON.parse(JSON.stringify(resAdd));
  117. let forRes = this.arrToTree(resAdd);
  118. // console.log('格式化的结构')
  119. // console.log(forRes)
  120. let resultRes = this.deleteChildren(forRes);
  121. let levelList = this.markersFun(resultRes, 1);
  122. console.log("格式化的结构且去掉children");
  123. // console.log(JSON.stringify(levelList));
  124. this.treeData = levelList[0];
  125. console.log(levelList[0]);
  126. } else {
  127. this.groupData = [];
  128. }
  129. // this.channelList = res.data;
  130. } else {
  131. this.$message.error(res.msg);
  132. }
  133. });
  134. },
  135. //z增加
  136. addPro(val) {
  137. let data = JSON.parse(JSON.stringify(val));
  138. for (let i = 0; i < val.length; i++) {
  139. data[i].value = val[i].orgNo;
  140. data[i].label = val[i].orgName;
  141. }
  142. return data;
  143. },
  144. //非递归方式:将平铺数据转换为树形结构数据
  145. arrToTree(arr) {
  146. let data = arr.filter((item) => {
  147. item.children = arr.filter((e) => {
  148. return item.orgNo === e.parentOrgNo;
  149. });
  150. return !item.parentOrgNo;
  151. });
  152. return data;
  153. },
  154. //去除转换树形结构数据后存在的空children
  155. deleteChildren(arr) {
  156. let childs = arr;
  157. for (let i = childs.length; i--; i > 0) {
  158. if (childs[i].children) {
  159. if (childs[i].children.length) {
  160. this.deleteChildren(childs[i].children);
  161. } else {
  162. delete childs[i].children;
  163. }
  164. }
  165. }
  166. return arr;
  167. },
  168. //标记层级
  169. markersFun(arr, level) {
  170. if (!arr || !arr.length) {
  171. return;
  172. }
  173. arr.forEach((item) => {
  174. item.level = level;
  175. if (item.children && item.children.length) {
  176. //
  177. this.markersFun(item.children, level + 1);
  178. }
  179. });
  180. return arr;
  181. },
  182. //获取组织架构方法--------------------结束-----------------------
  183. // 新增编辑股东,val: 0 新增, 1 编辑
  184. addStock(data) {
  185. console.log(data);
  186. this.currentSelectObj = data.data;
  187. // console.log(this.currentSelectObj);
  188. if (data.val) {
  189. // 不使用=赋值,内存相同,改变后,treeData数据也会改变
  190. // this.ruleForm = data.data;
  191. // this.ruleForm = Object.assign(this.ruleForm, data.data);
  192. // this.ruleForm.type = data.data.level;
  193. }
  194. this.isEdit = data.val;
  195. // 使用=赋值,编辑时改变currentTreeData, 源数据treeData也会改变
  196. this.currentTreeData = data.data;
  197. this.dialogVisible = true;
  198. },
  199. // 删除
  200. deleteStock(data) {
  201. this.currentSelectObj = data;
  202. console.log(this.currentSelectObj);
  203. this.dialogVisible2 = true;
  204. },
  205. // 确定删除
  206. confimdelete() {
  207. // 前端删除 遍历原数据,删除匹配id数据
  208. this.$http.get(`/org/deleteOrgById?id=${this.currentSelectObj.id}`, {}, (res) => {
  209. // this.$toast.success({message:'成功'});
  210. if (res && res.code == 200) {
  211. //将值赋值给list
  212. //调用查询全部的
  213. this.getChannel();
  214. this.$message.success(res.msg);
  215. // this.channelList = res.data;
  216. } else {
  217. this.$message.error(res.msg);
  218. }
  219. });
  220. this.dialogVisible2 = false;
  221. },
  222. // 保存添加股东
  223. confirm() {
  224. // let loading = Loading.service();
  225. this.$refs.ruleForm.validate((valid) => {
  226. if (valid) {
  227. this.sendData();
  228. } else {
  229. // loading.close();
  230. }
  231. });
  232. },
  233. // 发送添加股东数据
  234. sendData() {
  235. // let loading = Loading.service();
  236. if (this.isEdit) {
  237. // 编辑
  238. // data.id = this.treeData.id;
  239. //将参数调用接口
  240. this.currentSelectObj.orgName = this.ruleForm.orgName;
  241. this.$http.post(`/org/addOrUpdateOrg`, this.currentSelectObj, (res) => {
  242. // this.$toast.success({message:'成功'});
  243. if (res && res.code == 200) {
  244. //将值赋值给list
  245. //调用查询全部的
  246. this.getChannel();
  247. this.$message.success(res.msg);
  248. this.dialogVisible = false;
  249. // this.channelList = res.data;
  250. } else {
  251. this.$message.error(res.msg);
  252. // this.dialogVisible = false;
  253. }
  254. });
  255. // this.clearDialog();
  256. // loading.close();
  257. } else {
  258. let data = {
  259. parentOrgNo: this.currentSelectObj.orgNo,
  260. orgName: this.ruleForm.orgName,
  261. };
  262. //将参数调用接口
  263. this.$http.post(`/org/addOrUpdateOrg`, data, (res) => {
  264. // this.$toast.success({message:'成功'});
  265. if (res && res.code == 200) {
  266. //将值赋值给list
  267. //调用查询全部的
  268. this.getChannel();
  269. this.$message.success(res.msg);
  270. this.dialogVisible = false;
  271. // this.channelList = res.data;
  272. } else {
  273. this.$message.error(res.msg);
  274. }
  275. });
  276. //新增后接着查询就行了
  277. // 添加
  278. // 前端添加数据,需要自己生成子级id,可以传数据的时候把最后一级id传过来,进行累加
  279. // data.id = this.lastId++;
  280. // data.partnerCode = this.currentTreeData.id;
  281. // data.extend = true;
  282. // const render = (formData) => {
  283. // formData.some((item) => {
  284. // if (item.id === this.currentTreeData.id) {
  285. // if (item.children) {
  286. // item.children.push(data);
  287. // } else {
  288. // this.$set(item, "children", [data]);
  289. // }
  290. // return;
  291. // } else if (item.children) {
  292. // render(item.children);
  293. // }
  294. // });
  295. // };
  296. // let arr = [this.treeData];
  297. // render(arr);
  298. // this.treeData = arr[0];
  299. // this.clearDialog();
  300. // loading.close();
  301. }
  302. },
  303. },
  304. };
  305. </script>