finance.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true">
  6. <el-form-item label="财务核算成本 | 月份选择" style="margin-top:5px;">
  7. <el-date-picker size="small" v-model="date" :editable="false" format="yyyy-MM" value-format="yyyy-MM" @change="changeMonth" :clearable="false" type="month" placeholder="选择月份"></el-date-picker>
  8. </el-form-item>
  9. <el-form-item style="float:right;" v-if="user.role == 1 || user.role == 2 || user.role == 4">
  10. <el-link type="primary" :underline="false" @click="getTemplate()" >财务模板下载</el-link>
  11. </el-form-item>
  12. <!-- <el-form-item style="float:right;">
  13. <el-upload ref="upload" action="#" :limit="1" :http-request="importFinance" :show-file-list="false">
  14. <el-link type="primary" :underline="false" >财务数据上传</el-link>
  15. </el-upload>
  16. </el-form-item> -->
  17. <el-form-item style="float:right;" v-if="user.role == 1 || user.role == 2 || user.role == 4">
  18. <el-link type="primary" :underline="false" @click="importDialog = true;isUploading=false;">财务数据上传</el-link>
  19. </el-form-item>
  20. <el-form-item style="float:right;" v-if="user.role == 1 || user.role == 2 || user.role == 4">
  21. <el-link type="primary" :underline="false" @click="showItemDialog">自定义薪资项</el-link>
  22. </el-form-item>
  23. </el-form>
  24. </el-col>
  25. <!--列表-->
  26. <el-table :data="list" highlight-current-row v-loading="listLoading"
  27. show-summary=true
  28. ref="table"
  29. :height="300" style="width: 100%;">
  30. <el-table-column prop="name" label="姓名" sortable width="150"></el-table-column>
  31. <el-table-column prop="monthCost" label="工资" width="150"></el-table-column>
  32. <el-table-column prop="bonus" label="奖金" ></el-table-column>
  33. <el-table-column prop="allowance" label="津贴" ></el-table-column>
  34. <el-table-column prop="insuranceOld" label="养老保险" ></el-table-column>
  35. <el-table-column prop="insuranceMedical" label="医疗保险" ></el-table-column>
  36. <el-table-column prop="insuranceLosejob" label="失业保险" ></el-table-column>
  37. <el-table-column prop="insuranceInjury" label="工伤保险" ></el-table-column>
  38. <el-table-column prop="houseFund" label="住房公积金" ></el-table-column>
  39. <!-- <el-table-column prop="others" label="其他" ></el-table-column> -->
  40. <el-table-column :label="item.fieldName" v-for="(item, index) in customCols" :key="item.id" :prop="index==0?'customField1':(index==1?'customField2':(index==2?'customField3':''))">
  41. <template slot-scope="scope">
  42. {{index==0?scope.row.customField1:(index==1?scope.row.customField2:(index==2?scope.row.customField3:''))}}
  43. </template>
  44. </el-table-column>
  45. <el-table-column prop="totalCost" label="总成本" ></el-table-column>
  46. </el-table>
  47. <el-form :inline="true" >
  48. <el-form-item >
  49. <el-link type="primary" :underline="false" @click="assignToProject" style="margin-left:5px;">查看项目成本分配</el-link>
  50. </el-form-item>
  51. <el-form-item style="float:right;">
  52. <el-link type="primary" :underline="false" @click="exportData">导出项目成本数据</el-link>
  53. </el-form-item>
  54. <el-form-item style="float:right;margin-right:30px;" v-if="hasNoProjectUsers">
  55. <el-link type="primary" :underline="false" @click="showNoProjectUsers">查看无项目数据</el-link>
  56. </el-form-item>
  57. </el-form>
  58. <div id="container" style="height:300px"></div>
  59. <!--新增界面-->
  60. <el-dialog :title="title" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth" width="600px">
  61. <el-form ref="form1" :model="addForm" :rules="rules" label-width="100px">
  62. <el-form-item label="项目编号" >
  63. <el-input v-model="addForm.code" placeholder="请输入项目编号" clearable></el-input>
  64. </el-form-item>
  65. <el-form-item label="项目名称" prop="name">
  66. <el-input v-model="addForm.name" placeholder="请输入项目名称" clearable></el-input>
  67. </el-form-item>
  68. <el-form-item label="全部参与者">
  69. <el-select v-model="addForm.userId" multiple filterable placeholder="请选择参与者" style="width:100%;" @change="changeParticipator">
  70. <el-option v-for="item in users" :key="item.id" :label="item.name" :value="item.id"></el-option>
  71. </el-select>
  72. </el-form-item>
  73. <el-form-item label="主要负责人" >
  74. <el-select v-model="addForm.inchargerId" :disabled="addForm.userId.length==0" filterable placeholder="请选择负责人" style="width:100%;" @change="changeIncharger">
  75. <el-option v-for="item in participator" :key="item.id" :label="item.name" :value="item.id"></el-option>
  76. </el-select>
  77. </el-form-item>
  78. </el-form>
  79. <div slot="footer" class="dialog-footer">
  80. <el-button @click.native="addFormVisible = false">取消</el-button>
  81. <el-button type="primary" @click="submitInsert" :loading="addLoading">提交</el-button>
  82. </div>
  83. </el-dialog>
  84. <!--用户详细信息弹出框-->
  85. <el-dialog title="查看详情" v-if="userDetailVisible" :visible.sync="userDetailVisible" :close-on-click-modal="false" customClass="customWidth" width="400px">
  86. <div class="line"><span>姓名</span><span>{{userDetail.name}}</span></div>
  87. <div class="line"><span>手机号码</span><span>{{userDetail.phone}}</span></div>
  88. <div class="line"><span>部门</span><span>{{userDetail.departmentName}}</span></div>
  89. <div class="line"><span>成本</span><span>{{userDetail.cost}}元/小时</span></div>
  90. <div slot="footer" class="dialog-footer">
  91. <el-button type="primary" @click="userDetailVisible = false" >确定</el-button>
  92. </div>
  93. </el-dialog>
  94. <!--导入时的设置界面 -->
  95. <el-dialog title="财务数据导入" v-if="importDialog" :visible.sync="importDialog" :close-on-click-modal="false" customClass="customWidth" width="500px">
  96. <el-form ref="form3" :model="importParam" >
  97. <el-form-item label="导入月份" >
  98. <div style="color:orange;">{{date}}</div>
  99. </el-form-item>
  100. <el-form-item prop="syncHistoryReport" >
  101. <el-checkbox label="重新计算该月已填日报成本" v-model="importParam.syncHistoryReport"></el-checkbox>
  102. </el-form-item>
  103. <el-form-item prop="syncUserCost" >
  104. <el-checkbox label="同步到组织架构中员工月薪成本" v-model="importParam.syncUserCost" ></el-checkbox>
  105. </el-form-item>
  106. </el-form>
  107. <div slot="footer" class="dialog-footer">
  108. <el-upload ref="upload" action="#" :limit="1" :http-request="importFinance" :show-file-list="false" >
  109. <el-button type="primary" style="width:100%;" :loading="isUploading" >选择文件并开始导入</el-button>
  110. </el-upload>
  111. </div>
  112. </el-dialog>
  113. <!--无项目人员列表-->
  114. <el-dialog title="无项目人员列表" v-if="showNPDialog" :visible.sync="showNPDialog" :close-on-click-modal="false" customClass="customWidth" width="1200px">
  115. <el-table :data="npUserList" highlight-current-row v-loading="listLoading"
  116. show-summary=true
  117. ref="table"
  118. :height="400" style="width: 100%;">
  119. <el-table-column prop="name" label="姓名" sortable width="150"></el-table-column>
  120. <el-table-column prop="monthCost" label="工资" width="150"></el-table-column>
  121. <el-table-column prop="bonus" label="奖金" ></el-table-column>
  122. <el-table-column prop="allowance" label="津贴" ></el-table-column>
  123. <el-table-column prop="insuranceOld" label="养老保险" ></el-table-column>
  124. <el-table-column prop="insuranceMedical" label="医疗保险" ></el-table-column>
  125. <el-table-column prop="insuranceLosejob" label="失业保险" ></el-table-column>
  126. <el-table-column prop="insuranceInjury" label="工伤保险" ></el-table-column>
  127. <el-table-column prop="houseFund" label="住房公积金" ></el-table-column>
  128. <!-- <el-table-column prop="others" label="其他" ></el-table-column> -->
  129. <el-table-column :label="item.fieldName" v-for="(item, index) in customCols" :key="item.id" :prop="index==0?'customField1':(index==1?'customField2':(index==2?'customField3':''))">
  130. <template slot-scope="scope">
  131. {{index==0?scope.row.customField1:(index==1?scope.row.customField2:(index==2?scope.row.customField3:''))}}
  132. </template>
  133. </el-table-column>
  134. <el-table-column prop="totalCost" label="总成本" ></el-table-column>
  135. </el-table>
  136. <div slot="footer" class="dialog-footer">
  137. <div style="float:left;color:#ff9900;">*以上人员当月尚无投入的项目,请提醒他们填写日报。</div>
  138. <el-button type="primary" @click="showNPDialog = false" >关闭</el-button>
  139. </div>
  140. </el-dialog>
  141. <el-dialog title="自定义薪资项" show-header="false" v-if="itemDialog" :visible.sync="itemDialog" :close-on-click-modal="false" customClass="customWidth" width="500px">
  142. <div style="margin-left:30px;">
  143. <span style="color:#999;">薪资表包含以下数据</span>
  144. <p>工资</p>
  145. <p>奖金</p>
  146. <p>津贴</p>
  147. <p>养老保险</p>
  148. <p>医疗保险</p>
  149. <p>失业保险</p>
  150. <p>工伤保险</p>
  151. <p>住房公积金</p>
  152. <p><el-input v-model="customFieldList.field1" placeholder="请输入自定义薪资项1名称" style="width:200px;" maxlength="8"></el-input></p>
  153. <p><el-input v-model="customFieldList.field2" placeholder="请输入自定义薪资项2名称" style="width:200px;" maxlength="8"></el-input></p>
  154. <p><el-input v-model="customFieldList.field3" placeholder="请输入自定义薪资项3名称" style="width:200px;" maxlength="8"></el-input></p>
  155. </div>
  156. <div slot="footer" class="dialog-footer">
  157. <el-button type="primary" @click="itemDialog = false" >关闭</el-button>
  158. <el-button type="primary" @click="saveItems()" >保存</el-button>
  159. </div>
  160. </el-dialog>
  161. </section>
  162. </template>
  163. <style scoped>
  164. .line {
  165. padding:10px;
  166. }
  167. .line span{
  168. font-size:18px;
  169. }
  170. .line span:nth-child(even){
  171. float:right;
  172. }
  173. </style>
  174. <script>
  175. import util from "../../common/js/util";
  176. export default {
  177. data() {
  178. return {
  179. customFieldList:{field1:null, field2: null, field3: null},
  180. itemDialog: false,
  181. customCols:[],
  182. showNPDialog: false,
  183. npUserList:[],
  184. hasNoProjectUsers: false,
  185. isUploading:false,
  186. importDialog: false,
  187. importParam:{syncUserCost:true, syncHistoryReport:true},
  188. user: JSON.parse(sessionStorage.getItem("user")),
  189. userDetailVisible: false,
  190. userDetail:{},
  191. date: null,
  192. tableHeight: 0,
  193. listLoading: false,
  194. list: [],
  195. addLoading: false,
  196. myChart: null,
  197. params: null,
  198. };
  199. },
  200. methods: {
  201. downloadByA(row) {
  202. const a = document.createElement('a'); // 创建a标签
  203. a.setAttribute('download', row.name);// download属性
  204. a.setAttribute('href', row.url);// href链接
  205. a.click();// 自执行点击事件
  206. a.remove();
  207. },
  208. getTemplate() {
  209. this.http.post('/finance/getTemplate', {companyId: this.user.companyId},
  210. res => {
  211. if (res.code == "ok") {
  212. if (res.data.indexOf('xlsx') > 0) {
  213. this.downloadByA({name:'财务成本报表.xlsx', url:res.data});
  214. } else {
  215. this.downloadByA({name:'财务成本报表.xls', url:res.data});
  216. }
  217. }});
  218. },
  219. saveItems() {
  220. this.http.post('/finance-tblcuscol/save', this.customFieldList,
  221. res => {
  222. if (res.code == "ok") {
  223. this.itemDialog = false;
  224. this.getCustomColumn();
  225. }});
  226. },
  227. showItemDialog() {
  228. this.itemDialog = true;
  229. this.customFieldList = {field1:null,field2:null, field3:null};
  230. for (var i=0;i<this.customCols.length; i++) {
  231. if (i == 0) {
  232. this.customFieldList.field1 = this.customCols[i].fieldName;
  233. } else if (i == 1) {
  234. this.customFieldList.field2 = this.customCols[i].fieldName;
  235. } else if (i == 2) {
  236. this.customFieldList.field3 = this.customCols[i].fieldName;
  237. }
  238. }
  239. },
  240. //获取自定义的字段
  241. getCustomColumn() {
  242. this.http.post('/finance-tblcuscol/get', {companyId: this.user.companyId},
  243. res => {
  244. if (res.code == "ok") {
  245. this.customCols = res.data;
  246. }});
  247. },
  248. showNoProjectUsers() {
  249. this.showNPDialog = true;
  250. this.http.post('/finance/getNoProjectUsers', {yearMonth: this.date},
  251. res => {
  252. if (res.code == "ok") {
  253. this.npUserList = res.data;
  254. }});
  255. },
  256. assignToProject(){
  257. var _this = this;
  258. this.http.post('/finance/getTimeCost', {yearMonth: this.date},
  259. res => {
  260. if (res.code == "ok") {
  261. var xList = [], yList = [], list = res.data.costList,
  262. totalMoneyCost = res.data.totalMoneyCost;
  263. var nopCost = 0;
  264. if (res.data.noProjectItem.project != null) {
  265. this.hasNoProjectUsers = true;
  266. nopCost = res.data.noProjectItem.cost;
  267. } else {
  268. this.hasNoProjectUsers = false;
  269. }
  270. for(var i in list) {
  271. xList.push(list[i].project);
  272. yList.push({
  273. "value": list[i].cost,
  274. "id": list[i].id,
  275. "time": list[i].workingTime
  276. });
  277. }
  278. var myChart = echarts.init(document.getElementById("container"));
  279. _this.myChart = myChart;
  280. var option = {
  281. title: {
  282. text: '项目成本总计 ' + totalMoneyCost + '元'
  283. +(this.hasNoProjectUsers?",无项目人员成本总计 " + nopCost+"元, 共: "+(totalMoneyCost+nopCost)+"元":""),
  284. left:'left',
  285. },
  286. // 工具箱
  287. toolbox: {
  288. show: true,
  289. feature:{
  290. saveAsImage:{
  291. show:true
  292. },
  293. restore:{
  294. show:true
  295. },
  296. magicType:{
  297. type:['line','bar']
  298. },
  299. }
  300. },
  301. tooltip:{
  302. trigger:'axis',
  303. formatter: function (params,ticket,callback) {
  304. var res = params[0].name + "<br/>工作成本"+" : " + params[0].data.value
  305. + "元 <br/>工作时长"+" : " + params[0].data.time + "小时";
  306. _this.params = params;
  307. return res;
  308. }
  309. },
  310. xAxis: {
  311. data: xList,
  312. axisLabel: {
  313. interval:0,rotate:20
  314. }
  315. },
  316. yAxis: [{
  317. type : 'value',
  318. axisLabel: {
  319. formatter:'{value} (元)'
  320. }
  321. }],
  322. series: [{
  323. name: '工作时长(h)',
  324. type: 'bar',
  325. barMaxWidth: 30,
  326. data: yList,
  327. }]
  328. };
  329. option && myChart.setOption(option);
  330. // myChart.getZr().on('click', params => {
  331. // const pointInPixel = [params.offsetX, params.offsetY];
  332. // if (myChart.containPixel('grid', pointInPixel)) {
  333. // console.log(_this.params)
  334. // if(_this.radio=='项目') {
  335. // _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name);
  336. // }
  337. // }
  338. // });
  339. } else {
  340. this.$message({
  341. message: res.msg,
  342. type: "error"
  343. });
  344. }
  345. },
  346. error => {
  347. this.$message({
  348. message: error,
  349. type: "error"
  350. });
  351. });
  352. },
  353. //导出财务数据
  354. exportData() {
  355. this.listLoading = true;
  356. this.http.post('/finance/exportData', {
  357. date: this.date
  358. },
  359. res => {
  360. this.listLoading = false;
  361. if (res.code == "ok") {
  362. var aTag = document.createElement('a');
  363. aTag.download = "财务成本统计.xls";
  364. aTag.href = res.data;
  365. aTag.click();
  366. } else {
  367. this.$message({
  368. message: res.msg,
  369. type: "error"
  370. });
  371. }
  372. },
  373. error => {
  374. this.listLoading = false;
  375. this.$message({
  376. message: error,
  377. type: "error"
  378. });
  379. });
  380. },
  381. getSummaries(param) {
  382. const { columns, data } = param;
  383. const sums = [];
  384. columns.forEach((column, index) => {
  385. if (index === 0) {
  386. sums[index] = '总价';
  387. return;
  388. }
  389. const values = data.map(item => Number(item[column.property]));
  390. if (!values.every(value => isNaN(value))) {
  391. sums[index] = values.reduce((prev, curr) => {
  392. const value = Number(curr);
  393. if (!isNaN(value)) {
  394. return prev + curr;
  395. } else {
  396. return prev;
  397. }
  398. }, 0);
  399. sums[index] += ' 元';
  400. } else {
  401. sums[index] = 'N/A';
  402. }
  403. });
  404. return sums;
  405. },
  406. changeMonth() {
  407. //改变月份
  408. this.getList();
  409. this.assignToProject();
  410. },
  411. // 批量导入人员
  412. importFinance(item) {
  413. //首先判断文件类型
  414. let str = item.file.name.split(".");
  415. let format = str[str.length - 1];
  416. if (format != "xls" && format != "xlsx") {
  417. this.$message({
  418. message: "请选择.xls或.xlsx文件",
  419. type: "error"
  420. });
  421. } else {
  422. this.listLoading = true;
  423. let formData = new FormData();
  424. formData.append("file", item.file);
  425. formData.append("companyId", this.user.companyId);
  426. console.log('date====='+this.date);
  427. formData.append("yearMonth", this.date);
  428. formData.append("syncUserCost", this.importParam.syncUserCost);
  429. formData.append("syncHistoryReport", this.importParam.syncHistoryReport);
  430. this.isUploading = true;
  431. this.http.uploadFile('/finance/importData', formData,
  432. res => {
  433. this.$refs.upload.clearFiles();
  434. this.listLoading = false;
  435. this.isUploading = false;
  436. if (res.code == "ok") {
  437. this.$message({
  438. message: "导入成功",
  439. type: "success"
  440. });
  441. this.importDialog = false;
  442. //重新读取列表
  443. this.getList();
  444. } else {
  445. this.$message({
  446. message: res.msg,
  447. type: "error"
  448. });
  449. }
  450. },
  451. error => {
  452. this.$refs.upload.clearFiles();
  453. this.listLoading = false;
  454. this.$message({
  455. message: error,
  456. type: "error"
  457. });
  458. });
  459. }
  460. },
  461. //获取项目列表
  462. getList() {
  463. this.listLoading = true;
  464. this.http.post('/finance/getByMonth', {
  465. companyId: this.user.companyId,
  466. yearMonth: this.date
  467. },
  468. res => {
  469. this.listLoading = false;
  470. if (res.code == "ok") {
  471. var list = res.data;
  472. this.list = list;
  473. } else {
  474. this.$message({
  475. message: res.msg,
  476. type: "error"
  477. });
  478. }
  479. },
  480. error => {
  481. this.listLoading = false;
  482. this.$message({
  483. message: error,
  484. type: "error"
  485. });
  486. });
  487. },
  488. },
  489. created() {
  490. var d = new Date();
  491. this.date = d.getFullYear() +'-'+ ((d.getMonth()+1) < 10? '0'+(d.getMonth()+1):d.getMonth()+1);
  492. },
  493. mounted() {
  494. let height = window.innerHeight;
  495. this.tableHeight = height - 245;
  496. const that = this;
  497. window.onresize = function temp() {
  498. that.tableHeight = window.innerHeight - 245;
  499. };
  500. this.getList();
  501. this.getCustomColumn();
  502. },
  503. updated() {
  504. this.$nextTick(() => {
  505. this.$refs['table'].doLayout();
  506. })
  507. }
  508. };
  509. </script>
  510. <style lang="scss" scoped>
  511. </style>