params3.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. <template>
  2. <div class="flex flex-justify-start flex-align-center flex-col">
  3. <div class="flex flex-center full-width flex-justify-between mt-10 mb-10">
  4. <span class="full-width text-left bold">{{ info.dictValue }}</span>
  5. <el-button
  6. v-if="detail.can_update"
  7. type="primary"
  8. @click="disabled = !disabled"
  9. >
  10. {{ disabled ? '编 辑' : '保 存' }}
  11. </el-button>
  12. </div>
  13. <div class="mt-10 mb-10 full-width" style="width: 93%">
  14. <base-button
  15. v-if="detail.can_update"
  16. title="新增年度"
  17. icon="Plus"
  18. @click="addYear(1)"
  19. />
  20. </div>
  21. <div class="mt-10" style="width: 90%">
  22. <el-form
  23. :model="form"
  24. label-width="180px"
  25. :disabled="disabled"
  26. label-position="left"
  27. class="form-content flex flex-col"
  28. >
  29. <el-form-item
  30. v-for="(item, index) in completeCount"
  31. :key="item"
  32. label-width="0"
  33. >
  34. <div class="flex flex-col flex-center full-width">
  35. <div class="flex flex-center flex-justify-between full-width">
  36. <div class="flex-child-average full-width flex flex-center">
  37. <span style="width: 320px"
  38. >{{
  39. form.month_plan_complete_amount[index]
  40. ? form.month_plan_complete_amount[index].year
  41. : ''
  42. }}年度计划投资(万元)</span
  43. >
  44. <div class="disable-input" @change="change(item)">
  45. {{
  46. form.month_plan_complete_amount[index]
  47. ? form.month_plan_complete_amount[index].sum
  48. : ''
  49. }}
  50. </div>
  51. </div>
  52. <div style="width: 20px"></div>
  53. <div class="flex-child-average full-width flex flex-center">
  54. <span style="width: 380px"
  55. >{{
  56. form.month_plan_complete_amount[index]
  57. ? form.month_plan_complete_amount[index].year
  58. : ''
  59. }}年度累计投资(万元)</span
  60. >
  61. <div class="disable-input" @change="change(item)">
  62. {{
  63. form.month_complete_amount[index]
  64. ? form.month_complete_amount[index].sum
  65. : ''
  66. }}
  67. </div>
  68. <div
  69. class="btnSub pointer"
  70. @click="
  71. showMonth(form.month_complete_amount[index].year, 1, index)
  72. "
  73. >
  74. 月填报
  75. </div>
  76. </div>
  77. </div>
  78. </div>
  79. </el-form-item>
  80. </el-form>
  81. </div>
  82. <div class="mt-20 mb-10 full-width" style="width: 93%">
  83. <base-button
  84. v-if="detail.can_update"
  85. title="新增年度"
  86. icon="Plus"
  87. @click="addYear(2)"
  88. />
  89. </div>
  90. <div class="mt-10" style="width: 90%">
  91. <el-form
  92. :model="form"
  93. label-width="180px"
  94. :disabled="disabled"
  95. label-position="left"
  96. class="form-content flex flex-col"
  97. >
  98. <el-form-item
  99. v-for="(item, index) in investmentCount"
  100. :key="item"
  101. label-width="0"
  102. >
  103. <div class="flex flex-col flex-center full-width">
  104. <div class="flex flex-center flex-justify-between full-width">
  105. <div class="flex-child-average full-width flex flex-center">
  106. <span style="width: 400px"
  107. >{{
  108. form.month_plan_investment[index].year
  109. }}年度计划纳统投资(万元)</span
  110. >
  111. <div class="disable-input" @change="change(item)">
  112. {{
  113. form.month_plan_investment[index]
  114. ? form.month_plan_investment[index].sum
  115. : ''
  116. }}
  117. </div>
  118. </div>
  119. <div style="width: 20px"></div>
  120. <div class="flex-child-average full-width flex flex-center">
  121. <span style="width: 440px"
  122. >{{
  123. form.month_plan_investment[index].year
  124. }}年度累计纳统投资(万元)</span
  125. >
  126. <div class="disable-input" @change="change(item)">
  127. {{ form.month_investment_amount[index].sum }}
  128. </div>
  129. <div
  130. class="btnSub pointer"
  131. @click="
  132. showMonth(form.month_plan_investment[index].year, 2, index)
  133. "
  134. >
  135. 月填报
  136. </div>
  137. </div>
  138. </div>
  139. </div>
  140. </el-form-item>
  141. </el-form>
  142. </div>
  143. <el-dialog
  144. v-if="current"
  145. v-model="show"
  146. :title="
  147. current.editType === 1
  148. ? current.year + '年度投资情况'
  149. : current.year + '年度纳统情况'
  150. "
  151. width="1260px"
  152. >
  153. <div class="flex flex-center flex-align-start">
  154. <div>
  155. <div class="padding-top"></div>
  156. <div class="padding-top mt-20 mr-10 bold">
  157. {{ current.editType === 1 ? '月计划投资:' : '月计划纳统投资:' }}
  158. </div>
  159. <div class="padding-top mt-10 mr-10 bold">
  160. {{ current.editType === 1 ? '月完成投资:' : '月完成纳统投资:' }}
  161. </div>
  162. </div>
  163. <div>
  164. <div class="mr-5 flex flex-center">
  165. <div v-for="(item, index) in 11" :key="item" class="title">
  166. <div v-if="index === 0">1-2月</div>
  167. <div v-else>{{ item + 1 }}月</div>
  168. </div>
  169. </div>
  170. <div class="mr-5 flex flex-center">
  171. <div v-for="(item, index) in current.planMonths" :key="item.name">
  172. <input
  173. class="input"
  174. v-model="item.data"
  175. @change="changeMonth(item, 1, index)"
  176. />
  177. </div>
  178. </div>
  179. <div class="mr-5 flex flex-center">
  180. <div v-for="(item, index) in current.months" :key="item.name">
  181. <input
  182. class="input"
  183. v-model="item.data"
  184. @change="changeMonth(item, 2, index)"
  185. />
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. <div class="mt-20 full-width flex flex-justify-between">
  191. <span class="red">* 请按月份进行填报,单位:万元</span>
  192. <base-button
  193. class="mr-20"
  194. title="保存"
  195. icon="el-icon-check"
  196. @click="update"
  197. />
  198. </div>
  199. </el-dialog>
  200. </div>
  201. </template>
  202. <script>
  203. import baseButton from '@/components/base-button.vue'
  204. import { deepClone } from '@/utils/tools.js'
  205. export default {
  206. name: 'params3',
  207. components: { baseButton },
  208. props: {
  209. info: {
  210. type: Object,
  211. default: null
  212. },
  213. detail: {
  214. type: Object,
  215. default: null
  216. }
  217. },
  218. watch: {
  219. detail: {
  220. handler(val) {
  221. if (Object.keys(val).length > 1) {
  222. this.init(val)
  223. }
  224. },
  225. immediate: true
  226. },
  227. disabled: {
  228. handler(val) {
  229. if (val) {
  230. this.update(val !== true)
  231. }
  232. },
  233. immediate: false
  234. }
  235. },
  236. data() {
  237. return {
  238. show: false,
  239. disabled: true,
  240. investmentCount: 0,
  241. completeCount: 0,
  242. list1: [],
  243. list2: [],
  244. form: {},
  245. current: null
  246. }
  247. },
  248. methods: {
  249. /**
  250. *
  251. * @param type 1计划投资 2 纳统投资
  252. */
  253. addYear(type) {
  254. this.disabled = false
  255. if (type === 1) {
  256. if (this.form.month_complete_amount.length === 0) {
  257. const nowYear = new Date().getFullYear() - 1
  258. this.form.month_complete_amount.push(this.nextYear(nowYear))
  259. this.form.month_plan_complete_amount.push(this.nextYear(nowYear))
  260. } else {
  261. this.form.month_complete_amount.splice(
  262. 0,
  263. 0,
  264. this.nextYear(
  265. Number.parseInt(this.form.month_complete_amount[0].year)
  266. )
  267. )
  268. this.form.month_plan_complete_amount.splice(
  269. 0,
  270. 0,
  271. this.nextYear(
  272. Number.parseInt(this.form.month_plan_complete_amount[0].year)
  273. )
  274. )
  275. }
  276. this.completeCount = this.completeCount + 1
  277. } else if (type === 2) {
  278. if (this.form.month_investment_amount.length === 0) {
  279. const nowYear = new Date().getFullYear() - 1
  280. this.form.month_investment_amount.push(this.nextYear(nowYear))
  281. this.form.month_plan_investment.push(this.nextYear(nowYear))
  282. } else {
  283. this.form.month_investment_amount.splice(
  284. 0,
  285. 0,
  286. this.nextYear(
  287. Number.parseInt(this.form.month_investment_amount[0].year)
  288. )
  289. )
  290. this.form.month_plan_investment.splice(
  291. 0,
  292. 0,
  293. this.nextYear(
  294. Number.parseInt(this.form.month_plan_investment[0].year)
  295. )
  296. )
  297. }
  298. this.investmentCount = this.investmentCount + 1
  299. }
  300. console.log(this.form)
  301. },
  302. nextYear(year) {
  303. const tmp2 = {}
  304. tmp2.year = (year + 1).toString()
  305. tmp2.sum = ''
  306. tmp2.monthlyData = []
  307. for (let i = 1; i <= 12; i++) {
  308. const item2 = { year: tmp2.year, data: '', month: i.toString() }
  309. tmp2.monthlyData.push(item2)
  310. }
  311. return tmp2
  312. },
  313. init(res) {
  314. if (!Object.keys(res).includes('month_plan_investment')) {
  315. res.month_plan_investment = []
  316. }
  317. if (!Object.keys(res).includes('month_investment_amount')) {
  318. res.month_investment_amount = []
  319. }
  320. if (!Object.keys(res).includes('month_complete_amount')) {
  321. res.month_complete_amount = []
  322. }
  323. if (!Object.keys(res).includes('month_plan_complete_amount')) {
  324. res.month_plan_complete_amount = []
  325. }
  326. this.investmentCount = Math.max(
  327. res.month_plan_investment.length,
  328. res.month_investment_amount.length
  329. )
  330. // 求出差集
  331. const dd = res.month_plan_investment
  332. .filter(sub => {
  333. return (
  334. res.month_investment_amount.findIndex(
  335. ele => sub.year !== ele.year
  336. ) !== -1
  337. )
  338. })
  339. .map(sub => {
  340. // data -》 ''
  341. sub.monthlyData.map(ele => {
  342. ele.data = ele.data ? ele.data : ''
  343. return ele
  344. })
  345. return sub
  346. })
  347. // 复制差集
  348. if (res.month_plan_investment.length === this.completeCount) {
  349. dd.forEach(sub => {
  350. res.month_investment_amount.push(sub)
  351. })
  352. } else {
  353. dd.forEach(sub => {
  354. res.month_plan_investment.push(sub)
  355. })
  356. }
  357. this.completeCount = Math.max(
  358. res.month_complete_amount.length,
  359. res.month_plan_complete_amount.length
  360. )
  361. // 求出差集
  362. const d = res.month_complete_amount
  363. .filter(sub => {
  364. return (
  365. res.month_plan_complete_amount.findIndex(
  366. ele => sub.year !== ele.year
  367. ) !== -1
  368. )
  369. })
  370. .map(sub => {
  371. // data -》 ''
  372. sub.monthlyData.map(ele => {
  373. ele.data = ele.data ? ele.data : ''
  374. return ele
  375. })
  376. return sub
  377. })
  378. // 复制差集
  379. console.log(d)
  380. if (res.month_complete_amount.length === this.completeCount) {
  381. d.forEach(sub => {
  382. if (
  383. res.month_plan_complete_amount.findIndex(
  384. ele => ele.year === sub.year
  385. ) === -1
  386. ) {
  387. res.month_plan_complete_amount.push(sub)
  388. }
  389. })
  390. } else {
  391. d.forEach(sub => {
  392. if (
  393. res.month_complete_amount.findIndex(
  394. ele => ele.year === sub.year
  395. ) === -1
  396. ) {
  397. res.month_complete_amount.push(sub)
  398. }
  399. })
  400. }
  401. this.form = res
  402. },
  403. change(item) {
  404. this.form[item.code] = item.value
  405. this.form[item.code2] = item.value2
  406. },
  407. update(show = Boolean) {
  408. this.$nextTick(() => {
  409. this.form.projectId = this.form.id
  410. if (
  411. this.form.month_plan_complete_amount[this.current.index] !==
  412. undefined &&
  413. this.form.month_plan_complete_amount.length > 0
  414. ) {
  415. this.form.month_plan_complete_amount[this.current.index].sum =
  416. this.getSum(
  417. this.form.month_plan_complete_amount[this.current.index]
  418. .monthlyData
  419. )
  420. }
  421. if (
  422. this.form.month_complete_amount[this.current.index] !== undefined &&
  423. this.form.month_complete_amount.length > 0
  424. ) {
  425. this.form.month_complete_amount[this.current.index].sum = this.getSum(
  426. this.form.month_complete_amount[this.current.index].monthlyData
  427. )
  428. }
  429. if (
  430. this.form.month_plan_investment[this.current.index] !== undefined &&
  431. this.form.month_plan_investment.length > 0
  432. ) {
  433. this.form.month_plan_investment[this.current.index].sum = this.getSum(
  434. this.form.month_plan_investment[this.current.index].monthlyData
  435. )
  436. }
  437. if (
  438. this.form.month_investment_amount[this.current.index] !== undefined &&
  439. this.form.month_investment_amount.length > 0
  440. ) {
  441. this.form.month_investment_amount[this.current.index].sum =
  442. this.getSum(
  443. this.form.month_investment_amount[this.current.index].monthlyData
  444. )
  445. }
  446. // 生成年月字段
  447. this.initYearMonth(
  448. this.form.month_plan_complete_amount,
  449. '_month_plan_complete_amount',
  450. '_yearly_plan_complete_amount'
  451. )
  452. this.initYearMonth(
  453. this.form.month_complete_amount,
  454. '_month_complete_amount',
  455. '_yearly_complete_amount'
  456. )
  457. this.initYearMonth(
  458. this.form.month_plan_investment,
  459. '_month_plan_investment',
  460. '_yearly_plan_investment'
  461. )
  462. this.initYearMonth(
  463. this.form.month_investment_amount,
  464. '_month_investment_amount',
  465. '_yearly_complete_investment'
  466. )
  467. delete this.form._id
  468. this.$api.project.proUpdate(this.detail).then(res => {
  469. if (res.code === 200) {
  470. if (show) {
  471. this.$message.success(res.msg)
  472. this.show = false
  473. }
  474. } else {
  475. this.$message.error(res.msg)
  476. }
  477. })
  478. })
  479. },
  480. /**
  481. * 组合字段
  482. * @param list
  483. * @param key 月度关键词
  484. * @param key1 年度关键词
  485. */
  486. initYearMonth(list, key, key1) {
  487. if (list.length > 0) {
  488. list.forEach(sub => {
  489. let tmp = this.kv(sub.year + key1, sub.sum)
  490. sub.monthlyData.forEach(res => {
  491. const month = this.kv(res.year + '_' + res.month + key, res.data)
  492. tmp = Object.assign(tmp, month)
  493. })
  494. this.form = Object.assign(this.form, tmp)
  495. })
  496. }
  497. },
  498. kv(key, value) {
  499. const keyValue = {}
  500. keyValue[key] = value
  501. return keyValue
  502. },
  503. /**
  504. *
  505. * @param year
  506. * @param type 1 年度投资 2 纳统投资
  507. * @param index 索引
  508. */
  509. showMonth(year, type, index) {
  510. this.$nextTick(() => {
  511. const item = { editType: type, year, index, planMonths: [], months: [] }
  512. if (type === 1) {
  513. this.form.month_plan_complete_amount
  514. .find(sub => sub.year === year)
  515. .monthlyData.forEach(sub => {
  516. item.planMonths.push(deepClone(sub))
  517. })
  518. this.form.month_complete_amount
  519. .find(sub => sub.year === year)
  520. .monthlyData.forEach(sub => {
  521. item.months.push(deepClone(sub))
  522. })
  523. } else if (type === 2) {
  524. this.form.month_plan_investment
  525. .find(sub => sub.year === year)
  526. .monthlyData.forEach(sub => {
  527. item.planMonths.push(deepClone(sub))
  528. })
  529. this.form.month_investment_amount
  530. .find(sub => sub.year === year)
  531. .monthlyData.forEach(sub => {
  532. item.months.push(deepClone(sub))
  533. })
  534. }
  535. this.current = Object.assign({}, item)
  536. for (let i = 1; i <= 11; i++) {
  537. const index = this.current.months.findIndex(
  538. sub => sub.month === i.toString()
  539. )
  540. if (index === -1 && this.current.months.length < 11) {
  541. const ele = { month: i.toString(), data: '', year: '' }
  542. this.current.months.push(ele)
  543. }
  544. const planIndex = this.current.planMonths.findIndex(
  545. sub => sub.month === i.toString()
  546. )
  547. if (planIndex === -1 && this.current.planMonths.length < 11) {
  548. const sub = { month: i.toString(), data: '', year: '' }
  549. this.current.planMonths.push(sub)
  550. }
  551. }
  552. })
  553. this.show = !this.show
  554. },
  555. /**
  556. *
  557. * @param res
  558. * @param type 1 计划 2 累计
  559. * current 1 年度投资 2 纳统投资
  560. */
  561. changeMonth(res, type, index) {
  562. setTimeout(() => {
  563. if (this.current.editType === 1) {
  564. if (type === 1) {
  565. this.form.month_plan_complete_amount[
  566. this.current.index
  567. ].monthlyData[index] = res
  568. } else {
  569. this.form.month_complete_amount[this.current.index].monthlyData[
  570. index
  571. ] = res
  572. }
  573. } else if (this.current.editType === 2) {
  574. if (type === 1) {
  575. this.form.month_plan_investment[this.current.index].monthlyData[
  576. index
  577. ] = res
  578. } else {
  579. this.form.month_investment_amount[this.current.index].monthlyData[
  580. index
  581. ] = res
  582. }
  583. }
  584. }, 1000)
  585. },
  586. getSum(list) {
  587. let sum = 0
  588. list.forEach(sub => {
  589. if (sub.data.length > 0) {
  590. sum = sum + Number.parseInt(sub.data)
  591. }
  592. })
  593. return sum
  594. }
  595. }
  596. }
  597. </script>
  598. <style lang="scss" scoped>
  599. .form-content {
  600. border: 1px solid #eeeeee;
  601. padding: 20px;
  602. :deep(.el-input.is-disabled .el-input__inner) {
  603. color: #343434;
  604. }
  605. :deep(.el-textarea.is-disabled .el-textarea__inner) {
  606. color: #343434;
  607. }
  608. }
  609. .grid {
  610. display: grid;
  611. grid-template-columns: auto auto;
  612. grid-column-gap: 20px;
  613. }
  614. .title {
  615. width: 70px;
  616. padding: 0 11px;
  617. margin-bottom: 10px;
  618. font-weight: bold;
  619. }
  620. .input {
  621. width: 70px;
  622. height: 30px;
  623. border: #e7e7e7 solid 1px;
  624. padding: 0 10px;
  625. border-right: none;
  626. }
  627. .input:last-child {
  628. width: 70px;
  629. height: 40px;
  630. padding: 0 10px;
  631. border-right: #e7e7e7 solid 1px;
  632. }
  633. .disable-input {
  634. height: 30px;
  635. width: 100%;
  636. border-radius: 4px;
  637. background-color: #f5f7fa;
  638. border: #e6e8ed solid 1px;
  639. text-align: left;
  640. padding: 0 10px;
  641. color: #343434;
  642. }
  643. .btnSub {
  644. color: white;
  645. width: 120px;
  646. margin-left: 10px;
  647. height: 30px;
  648. background-color: #edac56;
  649. border-radius: 30px;
  650. padding: 0 10px;
  651. }
  652. </style>