params7.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <template>
  2. <div class="flex flex-center flex-col">
  3. <!-- title and btn -->
  4. <div class="flex flex-center full-width flex-justify-between mt-10 mb-10">
  5. <span class="full-width text-left bold">{{ info.dictValue }}</span>
  6. <el-button
  7. v-if="detail.can_update"
  8. type="primary"
  9. @click="disabled = !disabled"
  10. >{{ disabled ? '编 辑' : '保 存' }}
  11. </el-button>
  12. </div>
  13. <!-- content list -->
  14. <div style="width: 93%" class="mt-20">
  15. <div class="flex flex-justify-start ml-20">
  16. <el-select v-model="selectYear">
  17. <el-option
  18. v-for="item in years"
  19. :key="item.value"
  20. :label="item.label"
  21. :value="item.value"
  22. />
  23. </el-select>
  24. <el-button
  25. type="primary"
  26. icon="el-icon-plus"
  27. class="ml-20"
  28. @click="addYear(1)"
  29. >新增年度
  30. </el-button>
  31. </div>
  32. </div>
  33. <div style="width: 90%" class="mt-20">
  34. <div class="flex flex-justify-start flex-col border padding">
  35. <div
  36. v-for="(item, index) in amount"
  37. :key="item"
  38. class="flex flex-center full-width mb-10 mt-10"
  39. >
  40. <div
  41. class="flex flex-justify-start flex-align-center full-width flex-child-average"
  42. >
  43. <div class="value flex flex-justify-end">
  44. {{ item.year }}年度计划投资(万元)
  45. </div>
  46. <el-input
  47. v-model="item.planSum"
  48. type="number"
  49. :disabled="disabled"
  50. ></el-input>
  51. </div>
  52. <div
  53. class="flex flex-justify-start flex-align-center full-width flex-child-average"
  54. >
  55. <div class="value flex flex-justify-end">年度累计投资(万元)</div>
  56. <div class="ml-20 value-box flex flex-justify-start">
  57. {{ item.actualSum }}
  58. </div>
  59. </div>
  60. <div>
  61. <el-button
  62. type="primary"
  63. size="mini"
  64. icon="el-icon-edit"
  65. round
  66. class="ml-10"
  67. @click="updateMonth(item, 1, index)"
  68. >月填报
  69. </el-button>
  70. </div>
  71. </div>
  72. </div>
  73. </div>
  74. <!-- 纳统投资 -->
  75. <div style="width: 93%" class="mt-20">
  76. <div class="flex flex-justify-start ml-20">
  77. <el-select v-model="selectYear2">
  78. <el-option
  79. v-for="item in years"
  80. :key="item.value"
  81. :label="item.label"
  82. :value="item.value"
  83. />
  84. </el-select>
  85. <el-button
  86. type="primary"
  87. icon="el-icon-plus"
  88. class="ml-20"
  89. @click="addYear(2)"
  90. >新增年度
  91. </el-button>
  92. </div>
  93. </div>
  94. <div style="width: 90%" class="mt-20">
  95. <div class="flex flex-justify-start border padding flex-col mb-10 mt-10">
  96. <div
  97. v-for="(item, index) in investment"
  98. :key="item"
  99. class="flex flex-center full-width mb-10 mt-10"
  100. >
  101. <div
  102. class="flex flex-justify-start flex-align-center full-width flex-child-average"
  103. >
  104. <div class="value flex flex-justify-end">
  105. {{ item.year }}年度计划纳统投资(万元)
  106. </div>
  107. <el-input
  108. type="number"
  109. v-model="item.planSum"
  110. :disabled="disabled"
  111. ></el-input>
  112. </div>
  113. <div
  114. class="flex flex-justify-start flex-align-center full-width flex-child-average"
  115. >
  116. <div class="value flex flex-justify-end">
  117. 年度累计纳统投资(万元)
  118. </div>
  119. <div class="ml-20 value-box flex flex-justify-start">
  120. {{ item.actualSum }}
  121. </div>
  122. </div>
  123. <div>
  124. <el-button
  125. type="primary"
  126. size="mini"
  127. icon="el-icon-edit"
  128. round
  129. class="ml-10"
  130. @click="updateMonth(item, 2, index)"
  131. >月填报
  132. </el-button>
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. <!-- dialog -->
  138. <el-dialog
  139. v-model="show"
  140. title="投资情况"
  141. v-if="currentMonth"
  142. width="1250px"
  143. >
  144. <div>
  145. <div>
  146. <div class="flex flex-center mb-20">
  147. <div>
  148. <div class="title-box bold" style="background-color: white"></div>
  149. <div class="title-box bold flex flex-center">计划投资:</div>
  150. <div class="title-box bold mt-10 flex flex-center">
  151. 实际投资:
  152. </div>
  153. </div>
  154. <div>
  155. <div class="flex flex-center">
  156. <div
  157. v-for="i in currentMonth.monthData"
  158. :key="i"
  159. class="month-box bold flex flex-center"
  160. @focus="focusin"
  161. >
  162. {{ i.month }}月
  163. </div>
  164. </div>
  165. <div class="flex flex-center">
  166. <div
  167. v-for="i in currentMonth.monthData"
  168. :key="i"
  169. class="month-box flex flex-center"
  170. >
  171. <el-input type="number" v-model="i.planData"></el-input>
  172. </div>
  173. </div>
  174. <div class="flex flex-center mt-5">
  175. <div
  176. v-for="i in currentMonth.monthData"
  177. :key="i"
  178. class="month-box flex flex-center"
  179. >
  180. <el-input type="number" v-model="i.actualData"></el-input>
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185. <div>
  186. <el-button
  187. type="primary"
  188. icon="el-icon-check"
  189. class="full-width flex flex-center flex-justify-end light-blue-bg"
  190. @click="save"
  191. >保存
  192. </el-button>
  193. </div>
  194. </div>
  195. </div>
  196. </el-dialog>
  197. </div>
  198. </template>
  199. <script>
  200. export default {
  201. props: {
  202. info: {
  203. type: Object,
  204. default: null
  205. },
  206. detail: {
  207. type: Object,
  208. default: null
  209. }
  210. },
  211. watch: {
  212. detail: {
  213. immediate: true,
  214. deep: true,
  215. handler(val) {
  216. this.form = val
  217. if (val.amount && val.amount.data) {
  218. this.amount = val.amount.data
  219. }
  220. if (val.investment && val.investment.data) {
  221. this.investment = val.investment.data
  222. }
  223. this.initYear()
  224. }
  225. },
  226. disabled: {
  227. handler(val) {
  228. if (val) {
  229. this.save()
  230. }
  231. }
  232. }
  233. },
  234. data() {
  235. return {
  236. form: null,
  237. disabled: true,
  238. amount: [],
  239. investment: [],
  240. currentMonth: null,
  241. show: false,
  242. years: [],
  243. selectYear: '',
  244. selectYear2: ''
  245. }
  246. },
  247. methods: {
  248. initYear() {
  249. this.years.length = 0
  250. let localYears = []
  251. if (this.detail && this.detail.investment) {
  252. localYears = this.detail.investment.data.map(ele => ele.year)
  253. }
  254. const year = new Date().getFullYear()
  255. for (let i = 2017; i <= year + 1; i++) {
  256. const item = { label: i, value: i }
  257. if (localYears.findIndex(sub => sub === i) === -1) {
  258. this.years.push(item)
  259. }
  260. }
  261. this.years.reverse()
  262. },
  263. /**
  264. * 新增年度
  265. * @param {*} type 1,新增年度投资 2 新增纳统投资
  266. */
  267. addYear(type) {
  268. if (
  269. (type === 1 && this.selectYear.length === 0) ||
  270. (type === 2 && this.selectYear2.length === 0)
  271. ) {
  272. this.$message.error('请选择新增年度')
  273. return
  274. }
  275. const newMonthData = []
  276. for (let i = 1; i <= 11; i++) {
  277. const sub = {
  278. actualData: 0,
  279. planData: 0,
  280. month: i === 1 ? '1-2' : (i + 1).toString(),
  281. year: type === 1 ? this.selectYear : this.selectYear2
  282. }
  283. newMonthData.push(sub)
  284. }
  285. const newYearObj = {
  286. year: type === 1 ? this.selectYear : this.selectYear2,
  287. actualSum: 0,
  288. planSum: 0,
  289. monthData: newMonthData
  290. }
  291. if (type === 1) {
  292. this.amount.splice(0, 0, newYearObj)
  293. } else if (type === 2) {
  294. this.investment.splice(0, 0, newYearObj)
  295. }
  296. },
  297. /**
  298. * 更新数据
  299. * @param type 1 计划 2 纳统 index
  300. */
  301. updateMonth(item, type, index) {
  302. this.currentMonth = item
  303. this.currentMonth.updateIndex = index
  304. this.currentMonth.updateType = type
  305. this.show = !this.show
  306. },
  307. save() {
  308. if (this.currentMonth && this.currentMonth.updateType === 1) {
  309. this.form.amount.data[this.currentMonth.updateIndex].monthData =
  310. this.currentMonth.monthData.map(sub => {
  311. sub.planData = Number.parseInt(sub.planData)
  312. sub.actualData = Number.parseInt(sub.actualData)
  313. return sub
  314. })
  315. this.form.amount.data[this.currentMonth.updateIndex].actualSum =
  316. this.getSum(
  317. this.form.amount.data[this.currentMonth.updateIndex].monthData.map(
  318. sub => sub.actualData
  319. )
  320. )
  321. } else if (this.currentMonth && this.currentMonth.updateType === 2) {
  322. this.form.investment.data[this.currentMonth.updateIndex].monthData =
  323. this.currentMonth.monthData.map(sub => {
  324. sub.planData = Number.parseInt(sub.planData)
  325. sub.actualData = Number.parseInt(sub.actualData)
  326. return sub
  327. })
  328. this.form.investment.data[this.currentMonth.updateIndex].actualSum =
  329. this.getSum(
  330. this.form.investment.data[
  331. this.currentMonth.updateIndex
  332. ].monthData.map(sub => sub.actualData)
  333. )
  334. }
  335. delete this.form._id
  336. this.$api.project.proUpdate(this.detail).then(res => {
  337. if (res.code === 200) {
  338. this.$message.success(res.msg)
  339. } else {
  340. this.$message.error(res.msg)
  341. }
  342. this.show = false
  343. })
  344. },
  345. getSum(list) {
  346. let sum = 0
  347. console.log(list)
  348. list.forEach(sub => {
  349. if (sub) {
  350. sum = sum + Number.parseInt(sub)
  351. }
  352. })
  353. return sum
  354. }
  355. }
  356. }
  357. </script>
  358. <style lang="scss" scoped>
  359. .value {
  360. width: 300px;
  361. }
  362. :deep(.el-input.is-disabled .el-input__inner) {
  363. color: #343434;
  364. }
  365. .value-box {
  366. width: 100%;
  367. background-color: #f5f7fa;
  368. border-radius: 4px;
  369. padding: 10px 10px;
  370. border: #e5e7ec solid 1px;
  371. }
  372. .month-box {
  373. width: 90px;
  374. background-color: #f5f7fa;
  375. margin: 5px;
  376. height: 35px;
  377. }
  378. .title-box {
  379. width: 80px;
  380. height: 42px;
  381. }
  382. </style>