orderSettlement.vue 9.6 KB

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