orderSettlement.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. `/org/findAllOrgByCurrent`,
  183. {},
  184. (res) => {
  185. // this.$toast.success({message:'成功'});
  186. if (res && res.code == 200) {
  187. //将值赋值给list
  188. if (res.data.length > 0) {
  189. console.log(res.data)
  190. //
  191. let resAdd = this.addPro(res.data);
  192. this.ppData = JSON.parse(JSON.stringify(resAdd));
  193. let forRes = this.arrToTree(resAdd);
  194. let resultRes = this.deleteChildren(forRes);
  195. let levelList = this.markersFun(resultRes, 1);
  196. this.treeData = levelList[0];
  197. } else {
  198. this.groupData = [];
  199. }
  200. // this.channelList = res.data;
  201. } else {
  202. this.$message.error(res.msg);
  203. }
  204. }
  205. );
  206. },
  207. //z增加
  208. addPro(val) {
  209. let data = JSON.parse(JSON.stringify(val));
  210. for (let i = 0; i < val.length; i++) {
  211. data[i].value = val[i].orgNo;
  212. data[i].label = val[i].orgName;
  213. }
  214. return data;
  215. },
  216. //非递归方式:将平铺数据转换为树形结构数据
  217. arrToTree(arr) {
  218. let data = arr.filter((item) => {
  219. item.children = arr.filter((e) => {
  220. return item.orgNo === e.parentOrgNo;
  221. });
  222. return item.orgNo == this.userInfo.orgNo;
  223. });
  224. return data;
  225. },
  226. //去除转换树形结构数据后存在的空children
  227. deleteChildren(arr) {
  228. let childs = arr;
  229. for (let i = childs.length; i--; i > 0) {
  230. if (childs[i].children) {
  231. if (childs[i].children.length) {
  232. this.deleteChildren(childs[i].children);
  233. } else {
  234. delete childs[i].children;
  235. }
  236. }
  237. }
  238. return arr;
  239. },
  240. //标记层级
  241. markersFun(arr, level) {
  242. if (!arr || !arr.length) {
  243. return;
  244. }
  245. arr.forEach((item) => {
  246. item.level = level;
  247. //设置都可以编辑
  248. item.isEdit = true;
  249. //设置都可以增加
  250. item.isAdd = true;
  251. //设置都可以删除
  252. item.isDelete = true;
  253. // item.extend = true;
  254. item.isExtend = true;
  255. //当角色是超级管理员时
  256. if (this.userInfo.roleType == "5") {
  257. //则level 是三级时
  258. if (level == "3") {
  259. item.isAdd = false;
  260. }
  261. }
  262. // //当角色是院管理员时
  263. if (this.userInfo.roleType == "4") {
  264. //则level 是三级时
  265. if (level == "2") {
  266. item.isAdd = false;
  267. }
  268. }
  269. if (item.children && item.children.length) {
  270. //
  271. this.markersFun(item.children, level + 1);
  272. }
  273. });
  274. return arr;
  275. },
  276. //获取组织架构方法--------------------结束-----------------------
  277. // 新增编辑股东,val: 0 新增, 1 编辑
  278. addStock(data) {
  279. this.isShowGrade = false;
  280. //判断是新增还是编辑
  281. //当等于0时是新增
  282. //当等于1时是修改
  283. if (data.val == "1") {
  284. //管理员编辑
  285. if (this.userInfo.roleType == "5" && data.data.level == "3") {
  286. this.isShowGrade = true;
  287. }
  288. //院管理员编辑
  289. if (this.userInfo.roleType == "4" && data.data.level == "2") {
  290. this.isShowGrade = true;
  291. }
  292. }
  293. if (data.val == "0") {
  294. //管理员新增 是否显示届数
  295. if (this.userInfo.roleType == "5" && data.data.level == "2") {
  296. this.isShowGrade = true;
  297. }
  298. //院管理员新增 是否显示届数
  299. if (this.userInfo.roleType == "4" && data.data.level == "1") {
  300. this.isShowGrade = true;
  301. }
  302. }
  303. //当是管理员登录时
  304. // if(this.userInfo.roleType=='5'&&data.data.level=='3'){
  305. // }
  306. // this.isShowGrade = true;
  307. //判断是修改还是
  308. this.currentSelectObj = JSON.parse(JSON.stringify(data.data));
  309. if (data.val) {
  310. this.ruleForm.orgName = data.data.orgName;
  311. this.ruleForm.grade = data.data.extend;
  312. // 不使用=赋值,内存相同,改变后,treeData数据也会改变
  313. // this.ruleForm = data.data;
  314. // this.ruleForm = Object.assign(this.ruleForm, data.data);
  315. // this.ruleForm.type = data.data.level;
  316. } else {
  317. this.ruleForm.orgName = "";
  318. this.ruleForm.grade = "";
  319. }
  320. this.isEdit = data.val;
  321. // 使用=赋值,编辑时改变currentTreeData, 源数据treeData也会改变
  322. this.currentTreeData = data.data;
  323. this.dialogVisible = true;
  324. },
  325. // 删除
  326. deleteStock(data) {
  327. this.currentSelectObj = data;
  328. this.dialogVisible2 = true;
  329. },
  330. // 确定删除
  331. confimdelete() {
  332. // 前端删除 遍历原数据,删除匹配id数据
  333. this.$http.get(`/org/deleteOrgById?id=${this.currentSelectObj.id}`, {}, (res) => {
  334. // this.$toast.success({message:'成功'});
  335. if (res && res.code == 200) {
  336. //将值赋值给list
  337. //调用查询全部的
  338. this.getChannel();
  339. this.$message.success(res.msg);
  340. // this.channelList = res.data;
  341. } else {
  342. this.$message.error(res.msg);
  343. }
  344. });
  345. this.dialogVisible2 = false;
  346. },
  347. // 保存添加股东
  348. confirm() {
  349. // let loading = Loading.service();
  350. //判断是否输入值了
  351. // if (this.ruleForm.orgName != "" && this.ruleForm.orgName != null) {
  352. // this.sendData();
  353. // } else {
  354. // this.$message.warning("请输入组织架构名称");
  355. // }
  356. //当届数显示时--需要校验届数字段
  357. //
  358. let validSp = [];
  359. let aa = [];
  360. if (this.isShowGrade) {
  361. validSp = ["orgName", "grade"];
  362. } else {
  363. validSp = ["orgName"];
  364. }
  365. this.$refs["ruleForm"].validateField(validSp, (valid) => {
  366. if (!valid) {
  367. aa.push(valid);
  368. if (this.isShowGrade) {
  369. if (aa.length == 2) {
  370. this.sendData();
  371. }
  372. } else {
  373. if (aa.length == 1) {
  374. this.sendData();
  375. }
  376. }
  377. } else {
  378. // return false;
  379. }
  380. });
  381. },
  382. // 发送添加股东数据
  383. sendData() {
  384. // let loading = Loading.service();
  385. if (this.isEdit) {
  386. // 编辑
  387. // data.id = this.treeData.id;
  388. //将参数调用接口
  389. this.currentSelectObj.orgName = this.ruleForm.orgName;
  390. this.currentSelectObj.extend = this.ruleForm.grade;
  391. this.$http.post(`/org/addOrUpdateOrg`, this.currentSelectObj, (res) => {
  392. // this.$toast.success({message:'成功'});
  393. if (res && res.code == 200) {
  394. //将值赋值给list
  395. //调用查询全部的
  396. this.getChannel();
  397. this.$message.success(res.msg);
  398. this.dialogVisible = false;
  399. // this.channelList = res.data;
  400. } else {
  401. this.$message.error(res.msg);
  402. // this.dialogVisible = false;
  403. }
  404. });
  405. // this.clearDialog();
  406. // loading.close();
  407. } else {
  408. let data = {
  409. parentOrgNo: this.currentSelectObj.orgNo,
  410. orgName: this.ruleForm.orgName,
  411. extend: this.ruleForm.grade,
  412. };
  413. //将参数调用接口
  414. this.$http.post(`/org/addOrUpdateOrg`, data, (res) => {
  415. // this.$toast.success({message:'成功'});
  416. if (res && res.code == 200) {
  417. //将值赋值给list
  418. //调用查询全部的
  419. this.getChannel();
  420. this.$message.success(res.msg);
  421. this.dialogVisible = false;
  422. // this.channelList = res.data;
  423. } else {
  424. this.$message.error(res.msg);
  425. }
  426. });
  427. //新增后接着查询就行了
  428. // 添加
  429. // 前端添加数据,需要自己生成子级id,可以传数据的时候把最后一级id传过来,进行累加
  430. // data.id = this.lastId++;
  431. // data.partnerCode = this.currentTreeData.id;
  432. // data.extend = true;
  433. // const render = (formData) => {
  434. // formData.some((item) => {
  435. // if (item.id === this.currentTreeData.id) {
  436. // if (item.children) {
  437. // item.children.push(data);
  438. // } else {
  439. // this.$set(item, "children", [data]);
  440. // }
  441. // return;
  442. // } else if (item.children) {
  443. // render(item.children);
  444. // }
  445. // });
  446. // };
  447. // let arr = [this.treeData];
  448. // render(arr);
  449. // this.treeData = arr[0];
  450. // this.clearDialog();
  451. // loading.close();
  452. }
  453. },
  454. },
  455. };
  456. </script>
  457. <style scoped>
  458. .imput_com >>> .el-input__inner {
  459. width: 400px !important;
  460. }
  461. .imput_com >>> .el-input {
  462. width: 400px !important;
  463. }
  464. </style>
  465. <style lang="less" scoped>
  466. .changeDirection {
  467. position: fixed;
  468. right: 50px;
  469. bottom: 80px;
  470. margin: auto;
  471. background-color: #48d68e;
  472. padding: 10px;
  473. color: #ffffff;
  474. cursor: pointer;
  475. }
  476. </style>