orderSettlement.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. :before-close="closeDig"
  16. >
  17. <!-- 当符合条件时需要暂时属于哪一届 -->
  18. <div class="tips">
  19. <el-form :model="ruleForm" ref="ruleForm" :rules="rules" class="demo-ruleForm">
  20. <el-form-item
  21. label="所属年级"
  22. prop="grade"
  23. class="imput_com"
  24. v-show="isShowGrade"
  25. >
  26. <el-select
  27. v-model="ruleForm.grade"
  28. clearable
  29. placeholder="请选择所属年级"
  30. style="width: 100%"
  31. >
  32. <el-option
  33. v-for="item in gradeOption"
  34. :key="item.value"
  35. :label="item.label"
  36. :value="item.value"
  37. >
  38. </el-option>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item label="组织架构名称" prop="orgName" class="imput_com">
  42. <el-input
  43. placeholder="输入组织架构名称"
  44. :maxlength="32"
  45. v-model="ruleForm.orgName"
  46. ></el-input>
  47. </el-form-item>
  48. </el-form>
  49. </div>
  50. <span slot="footer" class="dialog-footer">
  51. <div class="tip-left">
  52. <el-button type="info" @click="closeDig">取消</el-button>
  53. <el-button type="primary" @click="confirm">确定</el-button>
  54. </div>
  55. </span>
  56. </el-dialog>
  57. <!-- 删除提示弹框 -->
  58. <el-dialog title="提示" :visible.sync="dialogVisible2" width="30%">
  59. <div class="tips">
  60. <p style="text-align: left">确定删除该组织信息?</p>
  61. </div>
  62. <span slot="footer" class="dialog-footer">
  63. <div class="tip-left">
  64. <el-button type="info" @click="dialogVisible2 = false">取消</el-button>
  65. <el-button type="primary" @click="confimdelete">确定</el-button>
  66. </div>
  67. </span>
  68. </el-dialog>
  69. <!-- <div class="changeDirection" @click="changeDir">切换方向</div> -->
  70. </div>
  71. </template>
  72. <script>
  73. import TreeChart from "@/components/TreeData";
  74. import { Loading } from "element-ui";
  75. import { oSessionStorage } from "../../../utils/utils";
  76. export default {
  77. name: "tree",
  78. components: {
  79. TreeChart,
  80. },
  81. data() {
  82. return {
  83. group: "",
  84. ppData: [],
  85. groupData: [],
  86. // treeData: {
  87. // //公司名称
  88. // orgName: "大米科技公司",
  89. // proportionShares: "100",
  90. // //公司层级
  91. // level: 2,
  92. // //公司编号
  93. // orgNo: 1,
  94. // },
  95. treeData: {
  96. //公司名称
  97. orgName: "大米科技公司",
  98. proportionShares: "100",
  99. //公司层级
  100. level: 2,
  101. //公司编号
  102. orgNo: 1,
  103. },
  104. isVertical: false, // 是否是竖方向,只给最外层的添加
  105. isDetail: false, // 是否是详情,不可编辑操作
  106. dialogVisible: false, // 添加股东弹框
  107. dialogVisible2: false, // 删除提示弹框
  108. //当前取到的对象
  109. currentSelectObj: {},
  110. //输入表单的对象
  111. ruleForm: {
  112. orgName: "",
  113. grade: "",
  114. },
  115. rules: {
  116. orgName: [{ required: true, message: "请输入组织名称", trigger: "blur" }],
  117. grade: [{ required: true, message: "请选择年级", trigger: "change" }],
  118. },
  119. shareholderTypeOptions: [
  120. {
  121. labelEn: "Individual",
  122. labelZh: "个人",
  123. value: 1,
  124. },
  125. {
  126. labelEn: "Company",
  127. labelZh: "公司",
  128. value: 2,
  129. },
  130. {
  131. labelEn: "Other",
  132. labelZh: "其他",
  133. value: 3,
  134. },
  135. ], // 股东类型
  136. lastId: 11, // 最后一级id
  137. currentTreeData: {},
  138. userInfo: {},
  139. gradeOption: [],
  140. isShowGrade: false,
  141. };
  142. },
  143. mounted() {
  144. this.userInfo = JSON.parse(oSessionStorage.getItem("userInfo"));
  145. this.getChannel();
  146. this.getGradeFun();
  147. },
  148. methods: {
  149. //新增修改框关闭后的回调
  150. closeDig(){
  151. //重置数据
  152. this.$refs['ruleForm'].resetFields();
  153. this.dialogVisible=false;
  154. },
  155. //获取当前届数
  156. getGradeFun() {
  157. this.gradeOption = [];
  158. //获取当前届数
  159. //获取当前年份
  160. let date = new Date();
  161. let currentYear = date.getFullYear();
  162. let preYear = currentYear - 12;
  163. let list = [];
  164. for (let i = preYear; i < currentYear + 1; i++) {
  165. //
  166. let obj = {
  167. value: i + "",
  168. label: i + "级",
  169. };
  170. list.push(obj);
  171. }
  172. this.gradeOption = list.reverse();
  173. },
  174. changeDir() {
  175. //改变方向
  176. this.isVertical = !this.isVertical;
  177. },
  178. //获取组织架构方法--------------------开始-----------------------
  179. getChannel() {
  180. this.$http.get(
  181. `/org/findAllOrgByPOrgNo?orgNo=${this.userInfo.orgNo}`,
  182. {},
  183. (res) => {
  184. // this.$toast.success({message:'成功'});
  185. if (res && res.code == 200) {
  186. //将值赋值给list
  187. if (res.data.length > 0) {
  188. let resAdd = this.addPro(res.data);
  189. this.ppData = JSON.parse(JSON.stringify(resAdd));
  190. let forRes = this.arrToTree(resAdd);
  191. console.log("forRes");
  192. console.log(forRes);
  193. // console.log('格式化的结构')
  194. // console.log(forRes)
  195. let resultRes = this.deleteChildren(forRes);
  196. let levelList = this.markersFun(resultRes, 1);
  197. console.log("格式化的结构且去掉children");
  198. // console.log(JSON.stringify(levelList));
  199. this.treeData = levelList[0];
  200. console.log(levelList[0]);
  201. } else {
  202. this.groupData = [];
  203. }
  204. // this.channelList = res.data;
  205. } else {
  206. this.$message.error(res.msg);
  207. }
  208. }
  209. );
  210. },
  211. //z增加
  212. addPro(val) {
  213. let data = JSON.parse(JSON.stringify(val));
  214. for (let i = 0; i < val.length; i++) {
  215. data[i].value = val[i].orgNo;
  216. data[i].label = val[i].orgName;
  217. }
  218. return data;
  219. },
  220. //非递归方式:将平铺数据转换为树形结构数据
  221. arrToTree(arr) {
  222. let data = arr.filter((item) => {
  223. item.children = arr.filter((e) => {
  224. return item.orgNo === e.parentOrgNo;
  225. });
  226. return item.orgNo == this.userInfo.orgNo;
  227. });
  228. return data;
  229. },
  230. //去除转换树形结构数据后存在的空children
  231. deleteChildren(arr) {
  232. let childs = arr;
  233. for (let i = childs.length; i--; i > 0) {
  234. if (childs[i].children) {
  235. if (childs[i].children.length) {
  236. this.deleteChildren(childs[i].children);
  237. } else {
  238. delete childs[i].children;
  239. }
  240. }
  241. }
  242. return arr;
  243. },
  244. //标记层级
  245. markersFun(arr, level) {
  246. if (!arr || !arr.length) {
  247. return;
  248. }
  249. arr.forEach((item) => {
  250. item.level = level;
  251. //设置都可以编辑
  252. item.isEdit = true;
  253. //设置都可以增加
  254. item.isAdd = true;
  255. //设置都可以删除
  256. item.isDelete = true;
  257. // item.extend = true;
  258. item.isExtend = true;
  259. //当角色是超级管理员时
  260. if (this.userInfo.roleType == "5") {
  261. //则level 是三级时
  262. if (level == "3") {
  263. item.isAdd = false;
  264. }
  265. }
  266. // //当角色是院管理员时
  267. if (this.userInfo.roleType == "4") {
  268. //则level 是三级时
  269. if (level == "2") {
  270. item.isAdd = false;
  271. }
  272. }
  273. if (item.children && item.children.length) {
  274. //
  275. this.markersFun(item.children, level + 1);
  276. }
  277. });
  278. return arr;
  279. },
  280. //获取组织架构方法--------------------结束-----------------------
  281. // 新增编辑股东,val: 0 新增, 1 编辑
  282. addStock(data) {
  283. this.isShowGrade = false;
  284. //判断是新增还是编辑
  285. //当等于0时是新增
  286. //当等于1时是修改
  287. if (data.val == "1") {
  288. //管理员编辑
  289. if (this.userInfo.roleType == "5" && data.data.level == "3") {
  290. this.isShowGrade = true;
  291. }
  292. //院管理员编辑
  293. if (this.userInfo.roleType == "4" && data.data.level == "2") {
  294. this.isShowGrade = true;
  295. }
  296. }
  297. if (data.val == "0") {
  298. //管理员新增 是否显示届数
  299. if (this.userInfo.roleType == "5" && data.data.level == "2") {
  300. this.isShowGrade = true;
  301. }
  302. //院管理员新增 是否显示届数
  303. if (this.userInfo.roleType == "4" && data.data.level == "1") {
  304. this.isShowGrade = true;
  305. }
  306. }
  307. //当是管理员登录时
  308. // if(this.userInfo.roleType=='5'&&data.data.level=='3'){
  309. // }
  310. // this.isShowGrade = true;
  311. //判断是修改还是
  312. console.log(data);
  313. this.currentSelectObj = data.data;
  314. // console.log(this.currentSelectObj);
  315. if (data.val) {
  316. this.ruleForm.orgName = data.data.orgName;
  317. this.ruleForm.grade = data.data.extend;
  318. // 不使用=赋值,内存相同,改变后,treeData数据也会改变
  319. // this.ruleForm = data.data;
  320. // this.ruleForm = Object.assign(this.ruleForm, data.data);
  321. // this.ruleForm.type = data.data.level;
  322. } else {
  323. this.ruleForm.orgName = "";
  324. this.ruleForm.grade = "";
  325. }
  326. this.isEdit = data.val;
  327. // 使用=赋值,编辑时改变currentTreeData, 源数据treeData也会改变
  328. this.currentTreeData = data.data;
  329. this.dialogVisible = true;
  330. },
  331. // 删除
  332. deleteStock(data) {
  333. this.currentSelectObj = data;
  334. console.log(this.currentSelectObj);
  335. this.dialogVisible2 = true;
  336. },
  337. // 确定删除
  338. confimdelete() {
  339. // 前端删除 遍历原数据,删除匹配id数据
  340. this.$http.get(`/org/deleteOrgById?id=${this.currentSelectObj.id}`, {}, (res) => {
  341. // this.$toast.success({message:'成功'});
  342. if (res && res.code == 200) {
  343. //将值赋值给list
  344. //调用查询全部的
  345. this.getChannel();
  346. this.$message.success(res.msg);
  347. // this.channelList = res.data;
  348. } else {
  349. this.$message.error(res.msg);
  350. }
  351. });
  352. this.dialogVisible2 = false;
  353. },
  354. // 保存添加股东
  355. confirm() {
  356. // let loading = Loading.service();
  357. //判断是否输入值了
  358. // if (this.ruleForm.orgName != "" && this.ruleForm.orgName != null) {
  359. // this.sendData();
  360. // } else {
  361. // this.$message.warning("请输入组织架构名称");
  362. // }
  363. //当届数显示时--需要校验届数字段
  364. //
  365. let validSp = [];
  366. let aa = [];
  367. if (this.isShowGrade) {
  368. validSp = ["orgName", "grade"];
  369. } else {
  370. validSp = ["orgName"];
  371. }
  372. this.$refs["ruleForm"].validateField(validSp, (valid) => {
  373. if (!valid) {
  374. aa.push(valid);
  375. if (this.isShowGrade) {
  376. if (aa.length == 2) {
  377. this.sendData();
  378. }
  379. } else {
  380. if (aa.length == 1) {
  381. this.sendData();
  382. }
  383. }
  384. } else {
  385. // console.log("error submit!!");
  386. // return false;
  387. }
  388. });
  389. },
  390. // 发送添加股东数据
  391. sendData() {
  392. // let loading = Loading.service();
  393. if (this.isEdit) {
  394. // 编辑
  395. // data.id = this.treeData.id;
  396. //将参数调用接口
  397. this.currentSelectObj.orgName = this.ruleForm.orgName;
  398. this.currentSelectObj.extend = this.ruleForm.grade;
  399. this.$http.post(`/org/addOrUpdateOrg`, this.currentSelectObj, (res) => {
  400. // this.$toast.success({message:'成功'});
  401. if (res && res.code == 200) {
  402. //将值赋值给list
  403. //调用查询全部的
  404. this.getChannel();
  405. this.$message.success(res.msg);
  406. this.dialogVisible = false;
  407. // this.channelList = res.data;
  408. } else {
  409. this.$message.error(res.msg);
  410. // this.dialogVisible = false;
  411. }
  412. });
  413. // this.clearDialog();
  414. // loading.close();
  415. } else {
  416. let data = {
  417. parentOrgNo: this.currentSelectObj.orgNo,
  418. orgName: this.ruleForm.orgName,
  419. extend: this.ruleForm.grade,
  420. };
  421. //将参数调用接口
  422. this.$http.post(`/org/addOrUpdateOrg`, data, (res) => {
  423. // this.$toast.success({message:'成功'});
  424. if (res && res.code == 200) {
  425. //将值赋值给list
  426. //调用查询全部的
  427. this.getChannel();
  428. this.$message.success(res.msg);
  429. this.dialogVisible = false;
  430. // this.channelList = res.data;
  431. } else {
  432. this.$message.error(res.msg);
  433. }
  434. });
  435. //新增后接着查询就行了
  436. // 添加
  437. // 前端添加数据,需要自己生成子级id,可以传数据的时候把最后一级id传过来,进行累加
  438. // data.id = this.lastId++;
  439. // data.partnerCode = this.currentTreeData.id;
  440. // data.extend = true;
  441. // const render = (formData) => {
  442. // formData.some((item) => {
  443. // if (item.id === this.currentTreeData.id) {
  444. // if (item.children) {
  445. // item.children.push(data);
  446. // } else {
  447. // this.$set(item, "children", [data]);
  448. // }
  449. // return;
  450. // } else if (item.children) {
  451. // render(item.children);
  452. // }
  453. // });
  454. // };
  455. // let arr = [this.treeData];
  456. // render(arr);
  457. // this.treeData = arr[0];
  458. // this.clearDialog();
  459. // loading.close();
  460. }
  461. },
  462. },
  463. };
  464. </script>
  465. <style scoped>
  466. .imput_com >>> .el-input__inner {
  467. width: 400px !important;
  468. }
  469. .imput_com >>> .el-input {
  470. width: 400px !important;
  471. }
  472. </style>
  473. <style lang="less" scoped>
  474. .changeDirection {
  475. position: fixed;
  476. right: 50px;
  477. bottom: 80px;
  478. margin: auto;
  479. background-color: #48d68e;
  480. padding: 10px;
  481. color: #ffffff;
  482. cursor: pointer;
  483. }
  484. </style>