You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

400 lines
13 KiB

1 year ago
  1. <template>
  2. <div>
  3. <el-form :model="form" label-width="80px" :rules="rules" ref="form">
  4. <el-row>
  5. <el-col :span="8">
  6. <el-form-item prop="displayName" label="分组名称">
  7. <el-input v-model="form.displayName" size="small" />
  8. </el-form-item>
  9. </el-col>
  10. <el-col :span="8">
  11. <el-form-item label="金额">
  12. <el-input v-model="form.price" type="number" size="small" />
  13. </el-form-item>
  14. </el-col>
  15. <el-col :span="8">
  16. <el-form-item label="适用性别">
  17. <el-select v-model="form.forSexId" placeholder="请选择" size="small">
  18. <el-option v-for="item in dict.forSex" :key="item.id" :label="item.displayName" :value="item.id">
  19. </el-option>
  20. </el-select>
  21. </el-form-item>
  22. </el-col>
  23. </el-row>
  24. <el-row>
  25. <el-col :span="8">
  26. <el-form-item label="婚姻状况">
  27. <el-select v-model="form.maritalStatusId" placeholder="请选择" style="width: 100%" size="small">
  28. <el-option v-for="item in dict.forMaritalStatus" :key="item.id" :label="item.displayName" :value="item.id">
  29. </el-option>
  30. </el-select>
  31. </el-form-item>
  32. </el-col>
  33. <el-col :span="8">
  34. <el-form-item label="年龄下限">
  35. <el-input v-model="form.ageLowerLimit" type="number" min="1" max="200" size="small" />
  36. </el-form-item>
  37. </el-col>
  38. <el-col :span="8">
  39. <el-form-item label="年龄上限">
  40. <el-input v-model="form.ageUpperLimit" type="number" min="1" max="200" size="small" />
  41. </el-form-item>
  42. </el-col>
  43. </el-row>
  44. <el-row>
  45. <el-col :span="8">
  46. <el-form-item label="适用职务">
  47. <el-input v-model="form.jobPost" size="small" />
  48. </el-form-item>
  49. </el-col>
  50. <el-col :span="8">
  51. <el-form-item label="适用职称">
  52. <el-input v-model="form.jobTitle" size="small" />
  53. </el-form-item>
  54. </el-col>
  55. <el-col :span="8">
  56. <el-form-item label="可自选金额">
  57. <el-input type="number" v-model="form.canAddMoney" size="small" />
  58. </el-form-item>
  59. </el-col>
  60. </el-row>
  61. <el-row>
  62. <el-col :span="24">
  63. <el-form-item label="备注">
  64. <el-input v-model="form.remark" size="small" />
  65. </el-form-item>
  66. </el-col>
  67. </el-row>
  68. </el-form>
  69. <div style="display: flex;margin-top: 5px;justify-content:space-between;">
  70. <div></div>
  71. <div style="display: flex;">
  72. <el-button class="commonbutton" @click="dialogWin.CustomerOrgGroupEdit = false">关闭</el-button>
  73. <!--
  74. <el-button type="success" @click="computePrice">同比折算组合项目价格</el-button>
  75. -->
  76. <el-button class="commonbutton" type="primary" @click="onSubmit('form')">确定</el-button>
  77. </div>
  78. </div>
  79. </div>
  80. </template>
  81. <script>
  82. import moment from "moment";
  83. import { getapi, postapi, putapi, deletapi } from "@/api/api";
  84. import { mapState } from "vuex";
  85. import {
  86. dddw,
  87. deepCopy,
  88. objCopy,
  89. arrayExistObj,
  90. } from "../../utlis/proFunc";
  91. import CustomerOrgGroupAsbitem from "../../components/customerOrg/customerOrgGroupAsbitem.vue";
  92. export default {
  93. components: {
  94. CustomerOrgGroupAsbitem,
  95. },
  96. props: ["params"],
  97. data() {
  98. return {
  99. form: {
  100. //体检单位分组
  101. customerOrgId: "", //复制分组时用到(预留查历次分组)
  102. isComplete: "N", //体检次数是否完成,如完成不允许调整分组项目
  103. id: "",
  104. customerOrgRegisterId: null, //所属体检次数
  105. displayName: "",
  106. price: 0,
  107. forSexId: "A",
  108. maritalStatusId: "A",
  109. ageLowerLimit: 0,
  110. ageUpperLimit: 200,
  111. canAddMoney:0,
  112. jobPost: "",
  113. jobTitle: "",
  114. remark: "",
  115. isMaxMedicalTimes: "N",
  116. },
  117. formOri: {}, //用于对比分析哪些信息更改了(主要是价格)
  118. formInit: {}, //表单初始值
  119. rules: {
  120. displayName: [{ required: true, message: "请填写分组名称", trigger: "blur" }],
  121. },
  122. };
  123. },
  124. computed: {
  125. ...mapState(["dict", "dialogWin", "dataTransOpts"]),
  126. },
  127. created() {
  128. this.formInit = deepCopy(this.form);
  129. this.form.customerOrgId = this.params.customerOrgId
  130. this.form.customerOrgRegisterId = this.params.customerOrgRegisterId
  131. },
  132. mounted() {
  133. // 获取初始数据(单位、适用性别)
  134. this.dictInit();
  135. this.getFormData(this.dataTransOpts.tableS.customer_org_group.id);
  136. },
  137. methods: {
  138. moment, dddw, deepCopy,
  139. // 获取初始数据
  140. dictInit() {
  141. //获取单位列表
  142. getapi("/api/app/customer-org/parent-all").then((res) => {
  143. if (res.code != -1) {
  144. this.customerOrgAll = res.data;
  145. let lfind = arrayExistObj(this.customerOrgAll, "id", this.dict.personOrgId);
  146. if (lfind > -1) this.customerOrgAll.splice(lfind, 1);
  147. this.customerOrg = deepCopy(this.customerOrgAll);
  148. }
  149. });
  150. //获取适用性别
  151. getapi("/api/app/for-sex").then((res) => {
  152. if (res.code != -1) {
  153. this.dict.forSex = res.data;
  154. }
  155. });
  156. },
  157. // 生成表单数据
  158. getFormData(id) {
  159. if (id) {
  160. getapi(`/api/app/customer-org-group/${id}`)
  161. .then(res => {
  162. if (res.code != -1) {
  163. this.formOri = deepCopy(res.data)
  164. this.form = deepCopy(res.data)
  165. }
  166. })
  167. } else {
  168. console.log('this.formInit',this.formInit)
  169. this.form = deepCopy(this.formInit)
  170. this.form.customerOrgId = this.params.customerOrgId
  171. this.form.customerOrgRegisterId = this.params.customerOrgRegisterId
  172. }
  173. },
  174. onSubmit(formName) {
  175. this.$refs[formName].validate((valid, fields) => {
  176. if (!valid) {
  177. this.$message.warning(fields[Object.keys(fields)[0]][0].message);
  178. return false;
  179. }
  180. if (!this.form.id && !this.form.customerOrgRegisterId) {
  181. this.$message.warning("请选择单位体检次数!");
  182. return false;
  183. }
  184. let body = deepCopy(this.form);
  185. delete body.id;
  186. delete body.customerOrgId;
  187. delete body.isComplete;
  188. if (this.form.id) {
  189. let customerOrgGroupId = this.form.id;
  190. let customerOrgGroupAsbitems = []; //分组包含的套餐
  191. //编辑
  192. /*
  193. putapi(`/api/app/customer-org-group/${this.form.id}`, body)
  194. .then((res) => {
  195. // console.log(res)
  196. if (res.code != -1) {
  197. console.log("保存分组成功!");
  198. // 价格是否有调整
  199. if (this.formOri.price != this.form.price) {
  200. return getapi(`/api/app/customerorggroupdetail/getcustomerorggroupdetailinasbitem?CustomerOrgGroupId=${customerOrgGroupId}`);
  201. } else {
  202. this.dialogWin.CustomerOrgGroupEdit = false;
  203. }
  204. }
  205. })
  206. .then((res) => {
  207. if (res && res.code != -1) {
  208. customerOrgGroupAsbitems = res.data;
  209. if (customerOrgGroupAsbitems.length < 1) {
  210. console.log("该分组暂没有组合项目!");
  211. this.dialogWin.CustomerOrgGroupEdit = false;
  212. } else {
  213. let detailsBody = {
  214. customerOrgGroupId,
  215. details: this.madeNewGroupAsbitems(customerOrgGroupAsbitems, this.form.price),
  216. };
  217. return postapi("/api/app/customerorggroupdetail/createcustomerorggroupdetailmany", detailsBody);
  218. }
  219. }
  220. })
  221. .then((res) => {
  222. if (res && res.code != -1) {
  223. console.log("操作成功!并自动按总价同比折算组合项目价格!");
  224. this.dialogWin.CustomerOrgGroupEdit = false;
  225. // 刷新明细
  226. let id = this.form.id;
  227. this.form.id = "";
  228. setTimeout(() => {
  229. this.form.id = id;
  230. }, 100);
  231. }
  232. });
  233. */
  234. // 合并事务更新明细金额
  235. putapi(`/api/app/customer-org-group/${this.form.id}`, body)
  236. .then((res) => {
  237. // console.log(res)
  238. if (res.code != -1) {
  239. console.log("保存分组成功!");
  240. this.dataTransOpts.refresh.customer_org_group_detail.M
  241. }
  242. })
  243. } else {
  244. //新增
  245. postapi("/api/customerorggroup/createcustomerorggroupincustomerorgregister", body)
  246. .then(res => {
  247. if (res.code != -1) {
  248. console.log("操作成功!");
  249. this.dataTransOpts.tableS.customer_org_group.id = res.data.id
  250. this.dialogWin.CustomerOrgGroupEdit = false;
  251. }
  252. });
  253. }
  254. });
  255. },
  256. //
  257. computePrice() {
  258. if (!this.form.id) {
  259. this.$message.warning("尚未保存信息,不可执行此操作!");
  260. return;
  261. }
  262. let customerOrgGroupId = this.form.id;
  263. let customerOrgGroupAsbitems = []; //分组包含的套餐
  264. getapi(`/api/app/customerorggroupdetail/getcustomerorggroupdetailinasbitem?CustomerOrgGroupId=${customerOrgGroupId}`)
  265. .then((res) => {
  266. if (res.code != -1) {
  267. customerOrgGroupAsbitems = res.data;
  268. if (customerOrgGroupAsbitems.length < 1) {
  269. this.$message.warning("当前分组尚未设置组合项目,不可执行此操作!");
  270. } else {
  271. let body = {
  272. customerOrgGroupId,
  273. details: this.madeNewGroupAsbitems(
  274. customerOrgGroupAsbitems,
  275. this.form.price
  276. ),
  277. };
  278. console.log("body", body);
  279. return postapi("/api/app/customerorggroupdetail/createcustomerorggroupdetailmany", body);
  280. }
  281. }
  282. })
  283. .then((res) => {
  284. if (res.code != -1) {
  285. //console.log("操作成功");
  286. //触发分组明细刷新
  287. this.form.id = "";
  288. //要做延时处理,否则不会触发监听
  289. setTimeout(() => {
  290. this.form.id = customerOrgGroupId;
  291. this.onSubmit("form");
  292. }, 100);
  293. }
  294. });
  295. },
  296. madeNewGroupAsbitems(oldGroupAsbitems, newTotal) {
  297. newTotal = Math.round(Number(newTotal) * 100) / 100;
  298. let newGroupAsbitems = [];
  299. let oldTotal = Number(0);
  300. oldGroupAsbitems.forEach((e) => {
  301. oldTotal += Number(e.asbitemMoney); //customerOrgGroupDetailMoney
  302. });
  303. oldTotal = Math.round(Number(oldTotal) * 100) / 100;
  304. let discount = 0;
  305. if (oldTotal != 0) discount = Math.round((newTotal * 10000) / oldTotal) / 100;
  306. oldTotal = Number(0);
  307. oldGroupAsbitems.forEach((e) => {
  308. e.customerOrgGroupDetailPrice = Math.round(e.price * discount) / 100;
  309. e.customerOrgGroupDetailMoney =
  310. Math.round(
  311. e.customerOrgGroupDetailPrice * e.customerOrgGroupDetailAmount * 100
  312. ) / 100;
  313. oldTotal += Number(e.customerOrgGroupDetailMoney);
  314. });
  315. oldTotal = Math.round(Number(oldTotal) * 100) / 100;
  316. //console.log('discount,oldTotal',discount,oldTotal)
  317. let didTotal = Math.round(Number(newTotal - oldTotal) * 100) / 100;
  318. if (didTotal != 0) {
  319. for (let i = 0; i < oldGroupAsbitems.length; i++) {
  320. if (oldGroupAsbitems[i].customerOrgGroupDetailAmount == 1) {
  321. oldGroupAsbitems[i].customerOrgGroupDetailPrice =
  322. Math.round(
  323. (Number(oldGroupAsbitems[i].customerOrgGroupDetailPrice) +
  324. Number(didTotal)) *
  325. 100
  326. ) / 100;
  327. break;
  328. }
  329. }
  330. }
  331. oldGroupAsbitems.forEach((e) => {
  332. newGroupAsbitems.push({
  333. customerOrgGroupId: e.customerOrgGroupId,
  334. asbitemId: e.asbitemId,
  335. price: e.customerOrgGroupDetailPrice,
  336. amount: e.customerOrgGroupDetailAmount,
  337. });
  338. });
  339. return newGroupAsbitems;
  340. },
  341. },
  342. //监听事件
  343. watch: {
  344. //
  345. // "customerOrgGroup.id"(newVal, oldVal) {
  346. // console.log("customerOrgGroup.id ",newVal,oldVal);
  347. // if (newVal != oldVal) {
  348. // this.getCustomerOrgGroupAsbitems(newVal);
  349. // }
  350. // },
  351. // 体检分组ID未切换换时 也可以强制刷新数据
  352. "dataTransOpts.refresh.customer_org_group.S": {
  353. // immediate: true,
  354. handler(newVal, oldVal) {
  355. console.log(`watch 体检分组 newVal:${newVal} oldVal:${oldVal} customerOrgGroupId: ${this.dataTransOpts.tableS.customer_org_group.id}`);
  356. this.getFormData(this.dataTransOpts.tableS.customer_org_group.id);
  357. }
  358. },
  359. },
  360. };
  361. </script>
  362. <style scoped>
  363. @import "../../assets/css/global_button.css";
  364. @import "../../assets/css/global_dialog.css";
  365. @import "../../assets/css/global_table.css";
  366. @import "../../assets/css/global_form.css";
  367. @import "../../assets/css/global_input.css";
  368. @import "../../assets/css/global.css";
  369. .btnClass {
  370. width: 100px;
  371. margin-bottom: 5px;
  372. }
  373. </style>