CostBaseline.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <template>
  2. <div :style="'padding:10px;background:#f7f7f7;min-height:'+tableHeight+'px;'">
  3. <div style="margin: 0 auto;width:1120px;">
  4. <el-row :gutter="24">
  5. <el-col :span="12">
  6. <div class="box" style="min-height:180px">
  7. <div >
  8. <!-- <div class="lableTxt">总成本基线</div> -->
  9. <label class="lableTxt">总成本基线<el-link v-if="permissions.projectCorrection" @click="correctBase" style="float:right;"><i class="el-icon-edit" ></i></el-link></label>
  10. <div class="lableCon" v-for="item in projectBaseCostData" :key="item.id">
  11. <div><span class="gray_label">{{item.baseName}}:</span></div>
  12. <div><span style="padding-right:20px;float:right;">¥{{item.baseAmount==null?'-':item.baseAmount | numberToCurrency}}</span></div>
  13. </div>
  14. <div style="height:24px">
  15. <el-link style="float:right;margin-right:10px" @click="addCostAdd" size="small" v-if="permissions.projectAllocate" type="primary">下拨成本预算</el-link>
  16. </div>
  17. </div>
  18. </div>
  19. </el-col>
  20. <el-col :span="12">
  21. <div class="box" style="min-height:180px;">
  22. <label class="lableTxt">当前成本基线</label>
  23. <div class="lableCon" v-for="item in nowBaseList" :key="item.id">
  24. <div><span class="gray_label">{{item.baseName}}:</span></div>
  25. <div><span style="padding-right:20px;float:right;">¥{{item.baseAmount==null?'-':item.baseAmount | numberToCurrency}}</span></div>
  26. </div>
  27. <div style="height:24px">
  28. <!-- <el-link style="float:right;margin-right:10px" @click="addCostAdd" size="small" v-if="permissions.projectAllocate" type="primary">下拨成本预算</el-link> -->
  29. </div>
  30. </div>
  31. </el-col>
  32. <el-col :span="24"></el-col>
  33. </el-row>
  34. <el-row :gutter="24">
  35. <el-col :span="24">
  36. <div class="box">
  37. <el-table :data="addList" :loading="ListLoading" :default-sort="{prop:'indate',order:'descending'}">
  38. <el-table-column v-for="item in addListColumns" :key="item.id" :label="item.name" align="right" header-align="center">
  39. <template slot-scope="scope">
  40. <span>¥{{itemListFilter(scope.row.addItemList,item.id) | numberToCurrency}}</span>
  41. <!-- <span style="margin-right:30px">{{itemListFilter(scope.row.addItemList,item.id) == false ? '¥' + (itemListFilter(scope.row.addItemList,item.id) | numberToCurrency) : '-'}}</span> -->
  42. <!-- <span style="margin-right:30px">{{itemListFilter(scope.row.addItemList,item.id) == false ? '-' : '¥' + itemListFilter(scope.row.addItemList,item.id) | numberToCurrency}}</span> -->
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="下拨时间" prop="indate" align="center"></el-table-column>
  46. <el-table-column label="操作人员" prop="userName" align="center"></el-table-column>
  47. <el-table-column label="备注" prop="remark" align="left" header-align="center" show-overflow-tooltip></el-table-column>
  48. <el-table-column label="" align="center">
  49. <template slot-scope="scope">
  50. <el-button size="small" @click="revert(scope.row.id)" v-if="scope.$index == 0">撤销</el-button>
  51. </template>
  52. </el-table-column>
  53. </el-table>
  54. </div>
  55. </el-col>
  56. </el-row>
  57. </div>
  58. <el-dialog title="下拨成本预算" v-if="addCostAddDialog" :visible.sync="addCostAddDialog" :close-on-click-modal="false" width="600px">
  59. <el-form>
  60. <el-form-item v-for="item in modBaseCostData" :key="item.id" :label="item.baseName" label-width="200px">
  61. <el-input :id="'nowBaseCost'+index" v-model="item.baseAmount" placeholder="请输入" clearable @keyup.native="restrictNumber('nowBaseCost'+index)"></el-input>
  62. </el-form-item>
  63. <el-form-item label="备注" label-width="200px">
  64. <el-input v-model="remark" placeholder="请输入下拨备注" ></el-input>
  65. </el-form-item>
  66. </el-form>
  67. <div slot="footer" class="dialog-footer">
  68. <!-- <el-button @click="test">test</el-button> -->
  69. <el-button @click.native="addCostAddDialog = false">取消</el-button>
  70. <el-button type="primary" @click="addCostAddSure" :loading="addLoading">提交</el-button>
  71. </div>
  72. </el-dialog>
  73. <el-dialog title="校正成本基线" v-if="correctBaseDialog" :visible.sync="correctBaseDialog" :close-on-click-modal="false" width="600px">
  74. <el-form>
  75. <el-form-item v-for="item in correctBaseCostData" :key="item.id" :label="item.baseName" label-width="200px">
  76. <el-input :id="'baseCost'+index" v-model="item.baseAmount" placeholder="请输入" clearable @keyup.native="restrictNumber('baseCost'+index)"></el-input>
  77. </el-form-item>
  78. <el-form-item label="备注" label-width="200px">
  79. <el-input v-model="remark" placeholder="请输入校正原因" ></el-input>
  80. </el-form-item>
  81. </el-form>
  82. <div slot="footer" class="dialog-footer">
  83. <!-- <el-button @click="test">test</el-button> -->
  84. <el-button @click.native="correctBaseDialog = false">取消</el-button>
  85. <el-button type="primary" @click="correctBaseSure" :loading="addLoading">提交</el-button>
  86. </div>
  87. </el-dialog>
  88. </div>
  89. </template>
  90. <script>
  91. import util from "../../common/js/util";
  92. export default {
  93. data() {
  94. return {
  95. user: JSON.parse(sessionStorage.getItem('user')),
  96. permissions: JSON.parse(sessionStorage.getItem("permissions")),
  97. curProjectId: null,
  98. addLoading: false,
  99. projectBaseCostData: [],
  100. modBaseCostData: [],
  101. correctBaseCostData: [],
  102. remark: '',
  103. addCostAddDialog: false,
  104. addListColumns:[],
  105. ListLoading: false,
  106. nowBaseList: [],
  107. correctBaseDialog: false,
  108. projectContractAmount: null
  109. };
  110. },
  111. filters: {
  112. numberToCurrency(value) {
  113. console.log('info numberToCurrency='+value);
  114. if (!value || value=='-') return '0.00'
  115. value = value.toFixed(2)
  116. const intPart = Math.trunc(value)
  117. const intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
  118. let floatPart = '.00'
  119. const valueArray = value.toString().split('.')
  120. if (valueArray.length === 2) { // 有小数部分
  121. floatPart = valueArray[1].toString() // 取得小数部分
  122. return intPartFormat + '.' + floatPart
  123. }
  124. return intPartFormat + floatPart
  125. }
  126. },
  127. methods: {
  128. restrictNumber(targetId) {
  129. let inpu = document.getElementById(targetId);
  130. inpu.value = inpu.value.replace(/[^\d.]/g, ""); //仅保留数字和"."
  131. inpu.value = inpu.value.replace(/\.{2,}/g, "."); //两个连续的"."仅保留第一个"."
  132. inpu.value = inpu.value.replace(".", "$#*").replace(/\./g,'').replace('$#*','.');//去除其他"."
  133. inpu.value = inpu.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2');;//限制只能输入两个小数
  134. if (inpu.value.indexOf(".") < 0 && inpu.value != "") { //首位是0的话去掉
  135. inpu.value = parseFloat(inpu.value);
  136. }
  137. },
  138. test(item){
  139. // let list = [
  140. // {id: 5, name: 'zs'},
  141. // {id: 6, name: 'ls'},
  142. // {id: 7, name: 'ww'}
  143. // ]
  144. // let lid = 5
  145. // let item = this.itemListFilter(list,lid)
  146. console.log('test',this.addListColumns);
  147. },
  148. itemListFilter(emList,eId){
  149. let emItem = emList.filter((em)=>{
  150. return em.baseId == eId
  151. })
  152. if(emItem.length == 0){
  153. return 0
  154. }else{
  155. return emItem[0].baseAmount
  156. }
  157. },
  158. getProjectBaseData(projectId) {
  159. this.http.post('/project-basecost/get',{
  160. projectId: projectId
  161. },res => {
  162. if (res.code == "ok") {
  163. this.projectBaseCostData = res.data;
  164. } else {
  165. this.$message({
  166. message: res.msg,
  167. type: "error"
  168. });
  169. }
  170. },error => {
  171. this.$message({
  172. message: error,
  173. type: "error"
  174. });
  175. });
  176. },
  177. // 撤销操作
  178. revert(eId){
  179. this.http.post('/project-addcost-record/revert',{
  180. id: eId
  181. },res => {
  182. if(res.code == 'ok'){
  183. this.$message({
  184. message: '撤销成功',
  185. type: 'success'
  186. })
  187. this.getAddList()
  188. this.getNowBase()
  189. }else {
  190. this.$message({
  191. message: res.msg,
  192. type: 'error'
  193. })
  194. }
  195. },err => {
  196. this.$message({
  197. message: err,
  198. type: 'error'
  199. })
  200. })
  201. },
  202. correctBase(){
  203. // 校正成本基线
  204. this.correctBaseCostData = JSON.parse(JSON.stringify(this.projectBaseCostData))
  205. this.correctBaseDialog = true
  206. },
  207. addCostAdd(){
  208. this.modBaseCostData = JSON.parse(JSON.stringify(this.projectBaseCostData))
  209. for (let i = 0; i < this.modBaseCostData.length; i++) {
  210. this.modBaseCostData[i].baseAmount = 0
  211. }
  212. this.addCostAddDialog = true
  213. },
  214. addCostAddSure(){
  215. this.addLoading = true
  216. let itemList = []
  217. for(let i=0; i<this.modBaseCostData.length; i++){
  218. // let itemListItem = {
  219. // baseId: this.modBaseCostData[i].baseId,
  220. // baseName: this.modBaseCostData[i].baseName,
  221. // baseAmount: this.modBaseCostData[i].baseAmount
  222. // }
  223. itemList.push({
  224. baseId: this.modBaseCostData[i].baseId,
  225. baseName: this.modBaseCostData[i].baseName,
  226. baseAmount: this.modBaseCostData[i].baseAmount
  227. })
  228. }
  229. this.http.post('/project-addcost-record/add',{
  230. projectId: this.curProjectId,
  231. userId: this.user.id,
  232. userName: this.user.name,
  233. itemList: JSON.stringify(itemList),
  234. remark: this.remark
  235. },res => {
  236. if(res.code == 'ok'){
  237. this.addLoading = false
  238. this.addCostAddDialog = false
  239. this.$message({
  240. message: '下拨成功',
  241. type: 'success'
  242. })
  243. this.remark = ''
  244. this.getAddList()
  245. this.getNowBase()
  246. }else {
  247. this.addLoading = false
  248. this.$message({
  249. message: res.msg,
  250. type: 'error'
  251. })
  252. }
  253. },err => {
  254. this.addLoading = false
  255. this.$message({
  256. message: err,
  257. type: 'error'
  258. })
  259. })
  260. },
  261. correctBaseSure(){
  262. //如果没有做修改,不提交数据
  263. var hasChangeData = false;
  264. for (var i=0;i<this.correctBaseCostData.length; i++) {
  265. var item = this.correctBaseCostData[i];
  266. var oldAmount = this.projectBaseCostData.filter(p=>p.id == item.id)[0].baseAmount;
  267. if (item.baseAmount != oldAmount) {
  268. hasChangeData = true;
  269. break;
  270. }
  271. }
  272. if (!hasChangeData) {
  273. this.correctBaseDialog = false;
  274. return;
  275. }
  276. this.http.post('/project/adjustBase', {
  277. id: this.curProjectId,
  278. contractAmount: this.projectContractAmount,
  279. baseCostData:JSON.stringify(this.correctBaseCostData),
  280. remark: this.remark
  281. },
  282. res => {
  283. if (res.code == "ok") {
  284. this.correctBaseDialog = false;
  285. this.$message({
  286. message: '校正成功',
  287. type: "success"
  288. });
  289. this.remark = ''
  290. this.getProjectBaseData(this.curProjectId)
  291. } else {
  292. this.$message({
  293. message: res.msg,
  294. type: "error"
  295. });
  296. }
  297. },
  298. error => {
  299. this.$message({
  300. message: error,
  301. type: "error"
  302. });
  303. });
  304. },
  305. getNowBase(){
  306. this.http.post('/project-currentcost/get',{
  307. companyId: this.user.companyId,
  308. projectId: this.curProjectId
  309. },res => {
  310. if(res.code == 'ok'){
  311. this.nowBaseList = res.data
  312. }else {
  313. this.$message({
  314. message: res.msg,
  315. type: 'error'
  316. })
  317. }
  318. },err => {
  319. this.$message({
  320. message: err,
  321. type: 'error'
  322. })
  323. })
  324. },
  325. getAddList(){
  326. this.ListLoading = true
  327. this.http.post('/project-addcost-record/getAddList',{
  328. companyId: this.user.companyId,
  329. projectId: this.curProjectId
  330. },res => {
  331. if(res.code == 'ok'){
  332. this.ListLoading = false
  333. this.addList = res.data.recordList
  334. this.addListColumns = res.data.columns
  335. console.log('getaddlist',res.data);
  336. }else {
  337. this.ListLoading = false
  338. this.$message({
  339. message: res.msg,
  340. type: 'error'
  341. })
  342. }
  343. },err => {
  344. this.ListLoading = false
  345. this.$message({
  346. message: err,
  347. type: 'error'
  348. })
  349. })
  350. },
  351. getProjectInfo() {
  352. this.http.post('/project/detail', {
  353. id: this.curProjectId
  354. },
  355. res => {
  356. if (res.code == "ok") {
  357. this.projectContractAmount = res.data.contractAmount;
  358. console.log('res.data',res.data);
  359. } else {
  360. this.$message({
  361. message: res.msg,
  362. type: "error"
  363. });
  364. }
  365. },
  366. error => {
  367. this.$message({
  368. message: error,
  369. type: "error"
  370. });
  371. });
  372. },
  373. },
  374. created() {
  375. let height = window.innerHeight;
  376. this.tableHeight = height - 160;
  377. const that = this;
  378. window.onresize = function temp() {
  379. that.tableHeight = window.innerHeight - 160;
  380. };
  381. },
  382. mounted() {
  383. this.curProjectId = parseInt(this.$route.params.id);
  384. // var _this = this;
  385. // var that = this
  386. console.log("mounted",this.$route.params)
  387. // window.addEventListener("resize", function() {
  388. // // _this.profitChart.resize();
  389. // // that.profitChart.resize();
  390. // });
  391. this.getProjectBaseData(this.curProjectId)
  392. this.getAddList()
  393. this.getNowBase()
  394. this.getProjectInfo()
  395. }
  396. };
  397. </script>
  398. <style scoped>
  399. .box {
  400. background:#fff;
  401. border: 1px solid #eeeeee;
  402. border-radius:5px;
  403. padding:10px;
  404. margin-top:10px;
  405. overflow-x: auto;
  406. }
  407. .el-row {
  408. margin-top:10px;
  409. }
  410. .lableTxt {
  411. color:#666;
  412. }
  413. .lableCon{
  414. margin: 20px 10px;
  415. }
  416. .lableCon div:nth-child(1){
  417. width: 50%;
  418. float: left;
  419. }
  420. .lableCon div:nth-child(2){
  421. width: 25%;
  422. display: inline-block;
  423. }
  424. .gray_label {
  425. color: #999;
  426. }
  427. </style>