finance.vue 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  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-radio-group v-model="radio" @change="switchList" style="margin-left:160px;margin-top:5px;">
  10. <el-radio-button label="全部人员" >全部人员({{allFinanceList.length}})</el-radio-button>
  11. <el-radio-button label="无项目工时人员">无项目工时人员({{noReportUserList.length}})</el-radio-button>
  12. </el-radio-group>
  13. <el-form-item v-if="user.role == 1 || user.role == 2 || user.role == 4" style="margin-left:5px;margin-top:5px;">
  14. <el-link type="primary" :underline="false" @click="showSettingDialog()" >分摊比例设置</el-link>
  15. </el-form-item>
  16. <el-form-item style="float:right;" v-if="user.role == 1 || user.role == 2 || user.role == 4">
  17. <el-link type="primary" :underline="false" @click="getTemplate()" >财务模板下载</el-link>
  18. </el-form-item>
  19. <!-- <el-form-item style="float:right;">
  20. <el-upload ref="upload" action="#" :limit="1" :http-request="importFinance" :show-file-list="false">
  21. <el-link type="primary" :underline="false" >财务数据上传</el-link>
  22. </el-upload>
  23. </el-form-item> -->
  24. <el-form-item style="float:right;" v-if="user.role == 1 || user.role == 2 || user.role == 4">
  25. <el-link type="primary" :underline="false" @click="importDialog = true;isUploading=false;">财务数据上传</el-link>
  26. </el-form-item>
  27. <el-form-item style="float:right;" v-if="user.role == 1 || user.role == 2 || user.role == 4">
  28. <el-link type="primary" :underline="false" @click="showItemDialog">自定义薪资项</el-link>
  29. </el-form-item>
  30. </el-form>
  31. </el-col>
  32. <el-button @click="getCustomColumn()">测试</el-button>
  33. <!--列表-->
  34. <!-- 222 -->
  35. <el-table :data="list" highlight-current-row v-loading="listLoading"
  36. show-summary=true
  37. ref="table"
  38. :height="300" style="width: 100%;">
  39. <el-table-column prop="name" label="姓名" sortable width="150"></el-table-column>
  40. <el-table-column :prop="headerCols[index]" :label="item" sortable show-overflow-tooltip v-for="(item, index) in tblCols"
  41. :key="index">
  42. </el-table-column>
  43. <!-- <el-table-column prop="monthCost" label="customCols.monthCost" width="150"></el-table-column>
  44. <el-table-column prop="bonus" :label="customCols.bonus" ></el-table-column>
  45. <el-table-column prop="allowance" :label="customCols.allowance" ></el-table-column>
  46. <el-table-column prop="insuranceOld" :label="customCols.insuranceOld" ></el-table-column>
  47. <el-table-column prop="insuranceMedical" :label="customCols.insuranceMedical" ></el-table-column>
  48. <el-table-column prop="insuranceLosejob" :label="customCols.insuranceLosejob" ></el-table-column>
  49. <el-table-column prop="insuranceInjury" :label="customCols.insuranceInjury" ></el-table-column>
  50. <el-table-column prop="houseFund" :label="customCols.houseFund" ></el-table-column> -->
  51. <!-- <el-table-column prop="field1" :label="customCols.field1" ></el-table-column>
  52. <el-table-column prop="field2" :label="customCols.field2" ></el-table-column>
  53. <el-table-column prop="field3" :label="customCols.field3" ></el-table-column> -->
  54. <!-- <el-table-column prop="monthCost" :label="customCols.monthCost" width="150"></el-table-column>
  55. <el-table-column prop="bonus" :label="customCols.bonus" ></el-table-column>
  56. <el-table-column prop="allowance" :label="customCols.allowance" ></el-table-column>
  57. <el-table-column prop="insuranceOld" :label="customCols.insuranceOld" ></el-table-column>
  58. <el-table-column prop="insuranceMedical" :label="customCols.insuranceMedical" ></el-table-column>
  59. <el-table-column prop="insuranceLosejob" :label="customCols.insuranceLosejob" ></el-table-column>
  60. <el-table-column prop="insuranceInjury" :label="customCols.insuranceInjury" ></el-table-column>
  61. <el-table-column prop="houseFund" :label="customCols.houseFund" ></el-table-column>
  62. <el-table-column prop="field1" :label="customCols.field1" ></el-table-column>
  63. <el-table-column prop="field2" :label="customCols.field2" ></el-table-column>
  64. <el-table-column prop="field3" :label="customCols.field3" ></el-table-column> -->
  65. <!-- <el-table-column v-for="(item,index) in customFieldList" :prop="item.prop" :label="item.label" :key="index">
  66. </el-table-column> -->
  67. <!-- <el-table-column prop="others" label="其他" ></el-table-column> -->
  68. <!-- <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':''))">
  69. <template slot-scope="scope">
  70. {{index==0?scope.row.customField1:(index==1?scope.row.customField2:(index==2?scope.row.customField3:''))}}
  71. </template>
  72. </el-table-column> -->
  73. <el-table-column prop="totalCost" label="总成本" ></el-table-column>
  74. </el-table>
  75. <el-form :inline="true" >
  76. <el-form-item >
  77. <!-- <el-checkbox style="margin-left:10px;" v-model="assignNoProUser" @click="assignToProject">均摊无项目人员成本</el-checkbox> -->
  78. <!-- <el-button type="primary" :underline="false" size="small" @click="assignNoProUser=false;assignToProject();" style="margin-left:10px;">分摊已填工时人员成本</el-button>
  79. <el-button type="primary" :underline="false" size="small" @click="assignNoProUser=true;assignToProject();" style="margin-left:10px;">分摊全部人员成本</el-button> -->
  80. <el-radio-group v-model="costListRadio" @change="switchCostList" style="margin-left:5px;margin-top:5px;">
  81. <el-radio-button label="1" >分摊已填工时人员成本</el-radio-button>
  82. <el-radio-button label="2">分摊全部人员成本</el-radio-button>
  83. </el-radio-group>
  84. </el-form-item>
  85. <el-form-item style="float:right;">
  86. <el-link type="primary" :underline="false" @click="exportData">导出成本数据</el-link>
  87. </el-form-item>
  88. <!-- <el-form-item style="float:right;margin-right:30px;" v-if="hasNoProjectUsers">
  89. <el-link type="primary" :underline="false" @click="showNoProjectUsers">查看无项目数据</el-link>
  90. </el-form-item> -->
  91. </el-form>
  92. <div id="container" style="height:300px"></div>
  93. <!--新增界面-->
  94. <el-dialog :title="title" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth" width="600px">
  95. <el-form ref="form1" :model="addForm" :rules="rules" label-width="100px">
  96. <el-form-item label="项目编号" >
  97. <el-input v-model="addForm.code" placeholder="请输入项目编号" clearable></el-input>
  98. </el-form-item>
  99. <el-form-item label="项目名称" prop="name">
  100. <el-input v-model="addForm.name" placeholder="请输入项目名称" clearable></el-input>
  101. </el-form-item>
  102. <el-form-item label="全部参与者">
  103. <el-select v-model="addForm.userId" multiple filterable placeholder="请选择参与者" style="width:100%;" @change="changeParticipator">
  104. <el-option v-for="item in users" :key="item.id" :label="item.name" :value="item.id"></el-option>
  105. </el-select>
  106. </el-form-item>
  107. <el-form-item label="主要负责人" >
  108. <el-select v-model="addForm.inchargerId" :disabled="addForm.userId.length==0" filterable placeholder="请选择负责人" style="width:100%;" @change="changeIncharger">
  109. <el-option v-for="item in participator" :key="item.id" :label="item.name" :value="item.id"></el-option>
  110. </el-select>
  111. </el-form-item>
  112. </el-form>
  113. <div slot="footer" class="dialog-footer">
  114. <el-button @click.native="addFormVisible = false">取消</el-button>
  115. <el-button type="primary" @click="submitInsert" :loading="addLoading">提交</el-button>
  116. </div>
  117. </el-dialog>
  118. <!--用户详细信息弹出框-->
  119. <el-dialog title="查看详情" v-if="userDetailVisible" :visible.sync="userDetailVisible" :close-on-click-modal="false" customClass="customWidth" width="400px">
  120. <div class="line"><span>姓名</span><span>{{userDetail.name}}</span></div>
  121. <div class="line"><span>手机号码</span><span>{{userDetail.phone}}</span></div>
  122. <div class="line"><span>部门</span><span>{{userDetail.departmentName}}</span></div>
  123. <div class="line"><span>成本</span><span>{{userDetail.cost}}元/小时</span></div>
  124. <div slot="footer" class="dialog-footer">
  125. <el-button type="primary" @click="userDetailVisible = false" >确定</el-button>
  126. </div>
  127. </el-dialog>
  128. <!--导入时的设置界面 -->
  129. <el-dialog title="财务数据导入" v-if="importDialog" :visible.sync="importDialog" :close-on-click-modal="false" customClass="customWidth" width="500px">
  130. <el-form ref="form3" :model="importParam" >
  131. <el-form-item label="导入月份" >
  132. <!-- <div style="color:orange;">{{date}}</div> -->
  133. <el-date-picker v-model="date" type="month" placeholder="选择月份" format="yyyy-MM" value-format="yyyy-MM"></el-date-picker>
  134. </el-form-item>
  135. <el-form-item prop="syncHistoryReport" >
  136. <el-checkbox label="重新计算该月已填日报成本" v-model="importParam.syncHistoryReport"></el-checkbox>
  137. </el-form-item>
  138. <el-form-item prop="syncUserCost" >
  139. <el-checkbox label="同步到组织架构中员工月薪成本" v-model="importParam.syncUserCost" ></el-checkbox>
  140. </el-form-item>
  141. </el-form>
  142. <div slot="footer" class="dialog-footer">
  143. <el-upload ref="upload" action="#" :limit="1" :http-request="importFinance" :show-file-list="false" >
  144. <el-button type="primary" style="width:100%;" :loading="isUploading" >选择文件并开始导入</el-button>
  145. </el-upload>
  146. </div>
  147. </el-dialog>
  148. <!--无项目人员列表-->
  149. <!-- <el-dialog title="无项目人员列表" v-if="showNPDialog" :visible.sync="showNPDialog" :close-on-click-modal="false" customClass="customWidth" width="1200px">
  150. <el-table :data="npUserList" highlight-current-row v-loading="listLoading"
  151. show-summary=true
  152. ref="table"
  153. :height="400" style="width: 100%;">
  154. <el-table-column prop="name" label="姓名" sortable width="150"></el-table-column>
  155. <el-table-column prop="monthCost" label="工资" width="150"></el-table-column>
  156. <el-table-column prop="bonus" label="奖金" ></el-table-column>
  157. <el-table-column prop="allowance" label="津贴" ></el-table-column>
  158. <el-table-column prop="insuranceOld" label="养老保险" ></el-table-column>
  159. <el-table-column prop="insuranceMedical" label="医疗保险" ></el-table-column>
  160. <el-table-column prop="insuranceLosejob" label="失业保险" ></el-table-column>
  161. <el-table-column prop="insuranceInjury" label="工伤保险" ></el-table-column>
  162. <el-table-column prop="houseFund" label="住房公积金" ></el-table-column>
  163. <el-table-column prop="others" label="其他" ></el-table-column>
  164. <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':''))">
  165. <template slot-scope="scope">
  166. {{index==0?scope.row.customField1:(index==1?scope.row.customField2:(index==2?scope.row.customField3:''))}}
  167. </template>
  168. </el-table-column>
  169. <el-table-column prop="totalCost" label="总成本" ></el-table-column>
  170. </el-table>
  171. <div slot="footer" class="dialog-footer">
  172. <div style="float:left;color:#ff9900;">*以上人员当月尚无投入的项目,请提醒他们填写日报。</div>
  173. <el-button type="primary" @click="showNPDialog = false" >关闭</el-button>
  174. </div>
  175. </el-dialog> -->
  176. <el-dialog title="自定义薪资项" show-header="false" v-if="itemDialog" :visible.sync="itemDialog" :close-on-click-modal="false" customClass="customWidth" width="500px">
  177. <div style="margin-left:30px;">
  178. <!-- 111 -->
  179. <span style="color:#999;">薪资表包含以下数据</span>
  180. <p><el-input v-model="customCols.monthCost" placeholder="请输入自定义薪资项名称" style="width:200px;" maxlength="8"></el-input></p>
  181. <p><el-input v-model="customCols.bonus" placeholder="请输入自定义薪资项名称" style="width:200px;" maxlength="8"></el-input></p>
  182. <p><el-input v-model="customCols.allowance" placeholder="请输入自定义薪资项名称" style="width:200px;" maxlength="8"></el-input></p>
  183. <p><el-input v-model="customCols.insuranceOld" placeholder="请输入自定义薪资项名称" style="width:200px;" maxlength="8"></el-input></p>
  184. <p><el-input v-model="customCols.insuranceMedical" placeholder="请输入自定义薪资项名称" style="width:200px;" maxlength="8"></el-input></p>
  185. <p><el-input v-model="customCols.insuranceLosejob" placeholder="请输入自定义薪资项名称" style="width:200px;" maxlength="8"></el-input></p>
  186. <p><el-input v-model="customCols.insuranceInjury" placeholder="请输入自定义薪资项名称" style="width:200px;" maxlength="8"></el-input></p>
  187. <p><el-input v-model="customCols.houseFund" placeholder="请输入自定义薪资项名称" style="width:200px;" maxlength="8"></el-input></p>
  188. <p><el-input v-model="customCols.field1" placeholder="请输入自定义薪资项1名称" style="width:200px;" maxlength="8"></el-input></p>
  189. <p><el-input v-model="customCols.field2" placeholder="请输入自定义薪资项2名称" style="width:200px;" maxlength="8"></el-input></p>
  190. <p><el-input v-model="customCols.field3" placeholder="请输入自定义薪资项3名称" style="width:200px;" maxlength="8"></el-input></p>
  191. </div>
  192. <div slot="footer" class="dialog-footer">
  193. <el-button type="primary" @click="itemDialog = false" >关闭</el-button>
  194. <el-button type="primary" @click="saveItems()" >保存</el-button>
  195. </div>
  196. </el-dialog>
  197. <el-dialog :title="date+'月 无项目工时人员分摊比例设置'" show-header="false" v-if="settingDialog" :visible.sync="settingDialog"
  198. :close-on-click-modal="false" customClass="customWidth" width="1200px">
  199. <div>
  200. <div>
  201. <el-button :disabled="multipleSelection.length==0" @click="setPercent(true, null)">批量设置比例</el-button>
  202. <el-button :disabled="projectCols.length==0 || userCostSettingList.length == 0" @click="getLastMonthSetting">使用上月比例设置</el-button>
  203. <el-button @click="showSelectProjectDialog">管理待分摊项目</el-button>
  204. </div>
  205. <el-table :data="userCostSettingList" highlight-current-row v-loading="costSettingLoading"
  206. ref="settingTable" @selection-change="handleSelectionChange"
  207. :height="400" style="width: 100%;">
  208. <el-table-column type="selection" width="55"></el-table-column>
  209. <el-table-column prop="name" label="姓名" sortable width="90" fixed="left"></el-table-column>
  210. <el-table-column :label="item.projectName" v-for="(item) in projectCols" width="180" size="small"
  211. :key="item.id" align="center">
  212. <template slot-scope="scope">
  213. <span>{{scope.row[item.projectId]}}</span>%
  214. </template>
  215. </el-table-column>
  216. <el-table-column label="设置比例" width="80" fixed="right">
  217. <template slot-scope="scope">
  218. <el-button size="small" @click="setPercent(false,scope.row)">设置</el-button>
  219. </template>
  220. </el-table-column>
  221. </el-table>
  222. </div>
  223. <div slot="footer" class="dialog-footer">
  224. <el-button type="primary" @click="settingDialog = false" >关闭</el-button>
  225. <el-button type="primary" @click="saveMonthSetting()" >保存</el-button>
  226. </div>
  227. </el-dialog>
  228. <el-dialog title="待分摊项目选择" show-header="false" v-if="projectsDialog" :visible.sync="projectsDialog"
  229. :close-on-click-modal="false" customClass="customWidth" width="1000px">
  230. <el-select v-model="chosenProjects" multiple filterable clearable style="width:100%">
  231. <el-option v-for="item in allProjectList" :label="item.projectName" :key="item.id" :value="item.id"></el-option>
  232. </el-select>
  233. <div slot="footer" class="dialog-footer">
  234. <el-button type="default" @click="projectsDialog = false" >关闭</el-button>
  235. <el-button type="primary" @click="saveProjectSetting()" >确定</el-button>
  236. </div>
  237. </el-dialog>
  238. <el-dialog title="设置员工成本各项目占比" show-header="false" v-if="setPercentDialog" :visible.sync="setPercentDialog"
  239. :close-on-click-modal="false" customClass="customWidth" width="600px" >
  240. <div style="margin:0px 10px 10px 10px;">
  241. <span>选择员工</span>
  242. <el-select v-model="chosenNoReportUserIds" multiple filterable clearable style="width:330px;" collapse-tags>
  243. <el-option v-for="item in noReportUserList" :label="item.name" :key="item.id" :value="item.userId"></el-option>
  244. </el-select>
  245. <el-button @click="averageCost" >自动分摊</el-button>
  246. </div>
  247. <el-divider ></el-divider>
  248. <!--项目列表 -->
  249. <el-form v-model="curPercentVal" label-width="365px" style="margin-top:10px;">
  250. <div class="nameList">
  251. <el-form-item v-for="item in projectCols" :label="item.projectName" :key="item.projectId" >
  252. 占比: <el-input v-model="curPercentVal[item.projectId]" style="width:100px;" @input="updatePercentValue"></el-input>&nbsp;%
  253. </el-form-item>
  254. </div>
  255. <el-form-item >
  256. 总比例: {{totalPercent}}&nbsp;%
  257. </el-form-item>
  258. </el-form>
  259. <div slot="footer" class="dialog-footer">
  260. <el-button type="default" @click="setPercentDialog = false" >关闭</el-button>
  261. <el-button type="primary" @click="setPercentSetting()" >确定</el-button>
  262. </div>
  263. </el-dialog>
  264. </section>
  265. </template>
  266. <style scoped>
  267. .line {
  268. padding:10px;
  269. }
  270. .line span{
  271. font-size:18px;
  272. }
  273. .line span:nth-child(even){
  274. float:right;
  275. }
  276. </style>
  277. <script>
  278. import util from "../../common/js/util";
  279. export default {
  280. data() {
  281. return {
  282. headerCols:['monthCost','bonus', 'allowance', 'insuranceOld', 'insuranceMedical', 'insuranceLosejob', 'insuranceInjury', 'houseFund', 'customField1','customField2','customField3'],
  283. tblCols:[],
  284. costListRadio: 0,
  285. costSettingLoading: false,
  286. chosenNoReportUserIds:[],
  287. curPercentVal:{},
  288. setPercentDialog: false,
  289. chosenProjects:[],
  290. projectsDialog: false,
  291. projectCols:[],
  292. allProjectList:[],
  293. multipleSelection:[],
  294. userCostSettingList: [],
  295. settingDialog: false,
  296. radio:"全部人员",
  297. noReportUserList:[],
  298. allFinanceList:[],
  299. assignNoProUser: false,
  300. customFieldList:[],
  301. itemDialog: false,
  302. customCols:{},
  303. // showNPDialog: false,
  304. npUserList:[],
  305. hasNoProjectUsers: false,
  306. isUploading:false,
  307. importDialog: false,
  308. importParam:{syncUserCost:true, syncHistoryReport:true},
  309. user: JSON.parse(sessionStorage.getItem("user")),
  310. userDetailVisible: false,
  311. userDetail:{},
  312. date: null,
  313. tableHeight: 0,
  314. listLoading: false,
  315. list: [],
  316. addLoading: false,
  317. myChart: null,
  318. params: null,
  319. totalPercent:0,
  320. // 111
  321. aaaaa:[
  322. {label: "工资1"},
  323. {label: "工资2"},
  324. {label: "工资3"},
  325. ]
  326. };
  327. },
  328. methods: {
  329. switchCostList() {
  330. //已填日报的人员成本
  331. if (this.costListRadio == 1) {
  332. this.assignNoProUser=false;
  333. this.assignToProject();
  334. } else if (this.costListRadio == 2) {
  335. //全部人员成本
  336. this.assignNoProUser=true;
  337. this.assignToProject();
  338. }
  339. },
  340. getLastMonthSetting() {
  341. this.costSettingLoading = true;
  342. var dataArr = this.date.split('-');
  343. var year = dataArr[0];
  344. var month = dataArr[1];
  345. if (parseInt(month) == 1) {
  346. year = parseInt(year) -1;
  347. month = 12;
  348. } else {
  349. month = parseInt(month) -1;
  350. if (month < 10) {
  351. month = '0'+month;
  352. }
  353. }
  354. var lastMonth = year + '-' + month;
  355. this.http.post('/project-percentage/getMonthSetting', {ymonth: lastMonth},
  356. res => {
  357. this.costSettingLoading = false;
  358. if (res.code == "ok") {
  359. this.projectCols = res.data.financeProjects;
  360. this.allProjectList = res.data.allProjectList;
  361. this.userCostSettingList = res.data.userCostSetting;
  362. //上次如果没有配置过,需要初始化
  363. for (var i=0;i<this.noReportUserList.length; i++) {
  364. var rUser = this.noReportUserList[i];
  365. //检查当前列表中的无项目人员是否在之前的里面存在,如果不在需要加上去
  366. if (this.userCostSettingList.filter(c=>c.id == rUser.userId).length == 0) {
  367. var item = {name: rUser.name, id: rUser.userId};
  368. this.projectCols.forEach(p=>{
  369. item[p.projectId] = 0;
  370. });
  371. this.userCostSettingList.push(item);
  372. }
  373. }
  374. this.$nextTick(()=>{
  375. this.$refs.settingTable.doLayout();
  376. })
  377. } });
  378. },
  379. //获取当月的无项目工时人员的分配比例设置
  380. getMonthSetting() {
  381. this.costSettingLoading = true;
  382. this.http.post('/project-percentage/getMonthSetting', {ymonth: this.date},
  383. res => {
  384. this.costSettingLoading = false;
  385. if (res.code == "ok") {
  386. this.projectCols = res.data.financeProjects;
  387. this.allProjectList = res.data.allProjectList;
  388. this.userCostSettingList = res.data.userCostSetting;
  389. //上次如果没有配置过,需要初始化
  390. for (var i=0;i<this.noReportUserList.length; i++) {
  391. var rUser = this.noReportUserList[i];
  392. console.log('userId====='+rUser.userId);
  393. //检查当前列表中的无项目人员是否在之前的里面存在,如果不在需要加上去
  394. if (this.userCostSettingList.filter(c=>c.id == rUser.userId).length == 0) {
  395. var item = {name: rUser.name, id: rUser.userId};
  396. this.projectCols.forEach(p=>{
  397. item[p.projectId] = 0;
  398. });
  399. this.userCostSettingList.push(item);
  400. }
  401. }
  402. this.$nextTick(()=>{
  403. this.$refs.settingTable.doLayout();
  404. })
  405. } });
  406. },
  407. //提交无工时人员的分配设置
  408. saveMonthSetting() {
  409. //检查数据是否都分配到100%了,防止由于修改了项目列而导致之前的数据不正确的情况
  410. var errorList = this.userCostSettingList.filter(u=>{
  411. let totalPercent = 0.0;
  412. this.projectCols.forEach(p=>{
  413. totalPercent += parseFloat(u[p.projectId]);
  414. });
  415. totalPercent = totalPercent.toFixed(1);
  416. if (totalPercent != 100) {
  417. return true;
  418. } else {
  419. return false;
  420. }
  421. });
  422. if (errorList.length > 0) {
  423. var nameList = errorList.map(e=>e.name);
  424. this.$message({type:'error', message:'存在人员分配比例非100%: '+nameList});
  425. return;
  426. }
  427. this.http.post('/project-percentage/saveMonthSetting', {projectCols: JSON.stringify(this.projectCols),
  428. ymonth: this.date, userSettings: JSON.stringify(this.userCostSettingList)},
  429. res => {
  430. if (res.code == "ok") {
  431. this.$message({type:'success', message:'保存成功'});
  432. this.settingDialog = false;
  433. } else {
  434. this.$message({type:'error', message:'发生错误:'+res.msg});
  435. }});
  436. },
  437. updatePercentValue() {
  438. var total = 0.0;
  439. this.projectCols.forEach(p=>{
  440. total += parseFloat(this.curPercentVal[p.projectId]);
  441. })
  442. this.totalPercent = total.toFixed(1);
  443. this.$forceUpdate();
  444. },
  445. averageCost() {
  446. var avg = (100/this.projectCols.length).toFixed(1);
  447. //最后一个用100减去前面的总和,保证最终合计为100
  448. for (var i=0;i<this.projectCols.length; i++) {
  449. if (i < this.projectCols.length -1) {
  450. this.curPercentVal[this.projectCols[i].projectId] = avg;
  451. } else {
  452. this.curPercentVal[this.projectCols[i].projectId] = (100-avg*(this.projectCols.length-1)).toFixed(1);
  453. }
  454. }
  455. this.updatePercentValue();
  456. this.$forceUpdate();
  457. },
  458. setPercent(isBatch, row) {
  459. this.setPercentDialog = true;
  460. this.chosenNoReportUserIds = [];
  461. if (!isBatch) {
  462. this.chosenNoReportUserIds.push(row.id);
  463. //获取当前比例
  464. this.projectCols.forEach(p=>{
  465. this.curPercentVal[p.projectId] = row[p.projectId];
  466. });
  467. } else {
  468. //批量处理
  469. this.multipleSelection.forEach(m=>{
  470. this.chosenNoReportUserIds.push(m.id);
  471. })
  472. //批量时获取第一条的比例进行加载
  473. this.projectCols.forEach(p=>{
  474. this.curPercentVal[p.projectId] = this.multipleSelection[0][p.projectId];
  475. });
  476. }
  477. this.updatePercentValue();
  478. },
  479. //确认设置的项目列
  480. saveProjectSetting() {
  481. this.projectsDialog = false;
  482. this.projectCols = [];
  483. this.chosenProjects.forEach(c=>{
  484. var item = this.allProjectList.filter(a=>a.id == c)[0];
  485. this.projectCols.push({projectId: item.id, projectName: item.projectName, projectCode: item.projectCode});
  486. });
  487. this.$nextTick(()=>{
  488. this.$refs.settingTable.doLayout();
  489. })
  490. },
  491. handleProjectSelectionChange(val) {
  492. this.projectSelection = val;
  493. },
  494. showSelectProjectDialog() {
  495. //设置选中状态
  496. this.chosenProjects = [];
  497. this.projectCols.forEach(item=>{
  498. this.chosenProjects.push(item.projectId);
  499. })
  500. this.projectsDialog = true;
  501. },
  502. setPercentSetting() {
  503. //检测是否填写的情况下,是否达到100%
  504. if (this.totalPercent != 100) {
  505. this.$message({
  506. message: '分配比例之和必须是100%',
  507. type: "error"
  508. });
  509. return;
  510. }
  511. this.setPercentDialog = false;
  512. this.chosenNoReportUserIds.forEach(u=>{
  513. var targetU = this.userCostSettingList.filter(a=>a.id == u)[0];
  514. //遍历项目
  515. this.projectCols.forEach(p=>{
  516. targetU[p.projectId] = this.curPercentVal[p.projectId];
  517. })
  518. });
  519. this.userCostSettingList.splice(1,0);
  520. },
  521. showSettingDialog() {
  522. this.settingDialog = true;
  523. this.getMonthSetting();
  524. },
  525. handleSelectionChange(val) {
  526. this.multipleSelection = val;
  527. },
  528. switchList() {
  529. if (this.radio == '全部人员') {
  530. this.list = this.allFinanceList;
  531. } else {
  532. this.list = this.noReportUserList;
  533. }
  534. },
  535. downloadByA(row) {
  536. const a = document.createElement('a'); // 创建a标签
  537. a.setAttribute('download', row.name);// download属性
  538. a.setAttribute('href', row.url);// href链接
  539. a.click();// 自执行点击事件
  540. a.remove();
  541. },
  542. getTemplate() {
  543. this.http.post('/finance/getTemplate', {companyId: this.user.companyId},
  544. res => {
  545. if (res.code == "ok") {
  546. if (res.data.indexOf('xlsx') > 0) {
  547. this.downloadByA({name:'财务成本报表.xlsx', url:res.data});
  548. } else {
  549. this.downloadByA({name:'财务成本报表.xls', url:res.data});
  550. }
  551. }});
  552. },
  553. saveItems() {
  554. let savefields = {
  555. monthCost : this.customCols.monthCost,
  556. bonus : this.customCols.bonus,
  557. allowance : this.customCols.allowance,
  558. insuranceOld : this.customCols.insuranceOld,
  559. insuranceMedical : this.customCols.insuranceMedical,
  560. insuranceLosejob : this.customCols.insuranceLosejob,
  561. insuranceInjury : this.customCols.insuranceInjury,
  562. houseFund : this.customCols.houseFund,
  563. field1 : this.customCols.field1,
  564. field2 : this.customCols.field2,
  565. field3 : this.customCols.field3
  566. }
  567. this.http.post('/finance-tblcuscol/save', savefields,
  568. res => {
  569. if (res.code == "ok") {
  570. this.itemDialog = false;
  571. this.getCustomColumn();
  572. }});
  573. this.$forceUpdate();
  574. },
  575. showItemDialog() {
  576. this.itemDialog = true;
  577. // this.customFieldList = {field1:null,field2:null, field3:null};
  578. // if (this.customCols.field1 !== undefined) {
  579. // this.customFieldList.field1 = this.customCols.field1;
  580. // } else if (this.customCols.field2 !== undefined) {
  581. // this.customFieldList.field2 = this.customCols.field2;
  582. // } else if (this.customCols.field3 !== undefined) {
  583. // this.customFieldList.field3 = this.customCols.field3;
  584. // }
  585. },
  586. //获取自定义的字段
  587. getCustomColumn() {
  588. this.http.post('/finance-tblcuscol/getAll', {companyId: this.user.companyId},
  589. res => {
  590. if (res.code == "ok") {
  591. this.customCols = res.data;
  592. this.tblCols = [];
  593. this.tblCols.push(this.customCols.monthCost);
  594. this.tblCols.push(this.customCols.bonus);
  595. this.tblCols.push(this.customCols.allowance);
  596. this.tblCols.push(this.customCols.insuranceOld);
  597. this.tblCols.push(this.customCols.insuranceMedical);
  598. this.tblCols.push(this.customCols.insuranceLosejob);
  599. this.tblCols.push(this.customCols.insuranceInjury);
  600. if (this.customCols.field1 != null) {
  601. this.tblCols.push(this.customCols.field1);
  602. }
  603. if (this.customCols.field2 != null) {
  604. this.tblCols.push(this.customCols.field2);
  605. }
  606. if (this.customCols.field3 != null) {
  607. this.tblCols.push(this.customCols.field3);
  608. }
  609. }});
  610. },
  611. // 222
  612. // dynamicTable(){
  613. // this.customFieldList = [
  614. // {label : this.customCols.monthCost,prop : "monthCost"},
  615. // {label : this.customCols.bonus,prop:"bonus"},
  616. // {label : this.customCols.allowance,prop:"allowance"},
  617. // {label : this.customCols.insuranceOld,prop:"insuranceOld"},
  618. // {label : this.customCols.insuranceMedical,prop:"insuranceMedical"},
  619. // {label : this.customCols.insuranceLosejob,prop:"insuranceLosejob"},
  620. // {label : this.customCols.insuranceInjury,prop:"insuranceInjury"},
  621. // {label : this.customCols.houseFund,prop:"houseFund"},
  622. // {label : this.customCols.field1,prop:"field1"},
  623. // {label : this.customCols.field2,prop:"field2"},
  624. // {label : this.customCols.field3,prop:"field3"},
  625. // ]
  626. // },
  627. // getProjects() {
  628. // this.http.post('/finance/getProjects', {companyId: this.user.companyId, yearMonth: this.date},
  629. // res => {
  630. // if (res.code == "ok") {
  631. // this.projectCols = res.data.financeProjects;
  632. // this.allProjectList = res.data.allProjectList;
  633. // }});
  634. // },
  635. // showNoProjectUsers() {
  636. // this.showNPDialog = true;
  637. // this.http.post('/finance/getNoProjectUsers', {yearMonth: this.date},
  638. // res => {
  639. // if (res.code == "ok") {
  640. // this.npUserList = res.data;
  641. // }});
  642. // },
  643. assignToProject(){
  644. var _this = this;
  645. this.http.post('/finance/getTimeCost', {yearMonth: this.date, assignNoProUser: this.assignNoProUser},
  646. res => {
  647. if (res.code == "ok") {
  648. var xList = [], yList = [], list = res.data.costList,
  649. totalMoneyCost = res.data.totalMoneyCost;
  650. var nopCost = 0;
  651. if (res.data.noProjectItem.project != null) {
  652. this.hasNoProjectUsers = true;
  653. nopCost = res.data.noProjectItem.cost;
  654. } else {
  655. this.hasNoProjectUsers = false;
  656. }
  657. for(var i in list) {
  658. xList.push(list[i].project);
  659. yList.push({
  660. "value": list[i].cost,
  661. "id": list[i].id,
  662. "time": list[i].workingTime
  663. });
  664. }
  665. var myChart = echarts.init(document.getElementById("container"));
  666. _this.myChart = myChart;
  667. var option = {
  668. title: {
  669. text: this.assignNoProUser?'成本总计 ' + totalMoneyCost + '元'
  670. +(this.hasNoProjectUsers?",含无项目人员成本 " + nopCost+"元 ":"")
  671. :'成本总计 ' + totalMoneyCost + '元',
  672. left:'left',
  673. },
  674. // 工具箱
  675. toolbox: {
  676. show: true,
  677. feature:{
  678. saveAsImage:{
  679. show:true
  680. },
  681. restore:{
  682. show:true
  683. },
  684. magicType:{
  685. type:['line','bar']
  686. },
  687. }
  688. },
  689. tooltip:{
  690. trigger:'axis',
  691. formatter: function (params,ticket,callback) {
  692. var res = params[0].name + "<br/>工作成本"+" : " + params[0].data.value
  693. + "元 <br/>工作时长"+" : " + params[0].data.time + "小时";
  694. _this.params = params;
  695. return res;
  696. }
  697. },
  698. xAxis: {
  699. data: xList,
  700. axisLabel: {
  701. interval:0,rotate:20
  702. }
  703. },
  704. yAxis: [{
  705. type : 'value',
  706. axisLabel: {
  707. formatter:'{value} (元)'
  708. }
  709. }],
  710. series: [{
  711. name: '工作时长(h)',
  712. type: 'bar',
  713. barMaxWidth: 30,
  714. data: yList,
  715. }]
  716. };
  717. option && myChart.setOption(option,{notMerge: true});
  718. // myChart.getZr().on('click', params => {
  719. // const pointInPixel = [params.offsetX, params.offsetY];
  720. // if (myChart.containPixel('grid', pointInPixel)) {
  721. // console.log(_this.params)
  722. // if(_this.radio=='项目') {
  723. // _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name);
  724. // }
  725. // }
  726. // });
  727. } else {
  728. this.$message({
  729. message: res.msg,
  730. type: "error"
  731. });
  732. }
  733. },
  734. error => {
  735. this.$message({
  736. message: error,
  737. type: "error"
  738. });
  739. });
  740. },
  741. //导出财务数据
  742. exportData() {
  743. this.listLoading = true;
  744. this.http.post('/finance/exportData', {
  745. date: this.date, assignNoProUser: this.assignNoProUser
  746. },
  747. res => {
  748. this.listLoading = false;
  749. if (res.code == "ok") {
  750. var aTag = document.createElement('a');
  751. aTag.download = "财务成本统计.xls";
  752. aTag.href = res.data;
  753. aTag.click();
  754. } else {
  755. this.$message({
  756. message: res.msg,
  757. type: "error"
  758. });
  759. }
  760. },
  761. error => {
  762. this.listLoading = false;
  763. this.$message({
  764. message: error,
  765. type: "error"
  766. });
  767. });
  768. },
  769. getSummaries(param) {
  770. const { columns, data } = param;
  771. const sums = [];
  772. columns.forEach((column, index) => {
  773. if (index === 0) {
  774. sums[index] = '总价';
  775. return;
  776. }
  777. const values = data.map(item => Number(item[column.property]));
  778. if (!values.every(value => isNaN(value))) {
  779. sums[index] = values.reduce((prev, curr) => {
  780. const value = Number(curr);
  781. if (!isNaN(value)) {
  782. return prev + curr;
  783. } else {
  784. return prev;
  785. }
  786. }, 0);
  787. sums[index] += ' 元';
  788. } else {
  789. sums[index] = 'N/A';
  790. }
  791. });
  792. return sums;
  793. },
  794. changeMonth() {
  795. //改变月份
  796. this.getList();
  797. this.assignToProject();
  798. },
  799. // 批量导入人员
  800. importFinance(item) {
  801. //首先判断文件类型
  802. let str = item.file.name.split(".");
  803. let format = str[str.length - 1];
  804. if (format != "xls" && format != "xlsx") {
  805. this.$message({
  806. message: "请选择.xls或.xlsx文件",
  807. type: "error"
  808. });
  809. } else {
  810. this.listLoading = true;
  811. let formData = new FormData();
  812. formData.append("file", item.file);
  813. formData.append("companyId", this.user.companyId);
  814. formData.append("yearMonth", this.date);
  815. formData.append("syncUserCost", this.importParam.syncUserCost);
  816. formData.append("syncHistoryReport", this.importParam.syncHistoryReport);
  817. this.isUploading = true;
  818. this.http.uploadFile('/finance/importData', formData,
  819. res => {
  820. this.$refs.upload.clearFiles();
  821. this.listLoading = false;
  822. this.isUploading = false;
  823. if (res.code == "ok") {
  824. this.$message({
  825. message: "导入成功",
  826. type: "success"
  827. });
  828. this.importDialog = false;
  829. //重新读取列表
  830. this.getList();
  831. } else {
  832. this.$message({
  833. message: res.msg,
  834. type: "error"
  835. });
  836. }
  837. },
  838. error => {
  839. this.$refs.upload.clearFiles();
  840. this.listLoading = false;
  841. this.$message({
  842. message: error,
  843. type: "error"
  844. });
  845. });
  846. }
  847. },
  848. //获取项目列表
  849. getList() {
  850. this.listLoading = true;
  851. this.http.post('/finance/getByMonth', {
  852. companyId: this.user.companyId,
  853. yearMonth: this.date
  854. },
  855. res => {
  856. this.listLoading = false;
  857. if (res.code == "ok") {
  858. var list = res.data;
  859. this.allFinanceList = list;
  860. this.list = this.allFinanceList;
  861. this.noReportUserList = list.filter(r=>r.hasReport == 0);
  862. } else {
  863. this.$message({
  864. message: res.msg,
  865. type: "error"
  866. });
  867. }
  868. },
  869. error => {
  870. this.listLoading = false;
  871. this.$message({
  872. message: error,
  873. type: "error"
  874. });
  875. });
  876. },
  877. },
  878. created() {
  879. var d = new Date();
  880. this.date = d.getFullYear() +'-'+ ((d.getMonth()+1) < 10? '0'+(d.getMonth()+1):d.getMonth()+1);
  881. },
  882. mounted() {
  883. let height = window.innerHeight;
  884. this.tableHeight = height - 245;
  885. const that = this;
  886. window.onresize = function temp() {
  887. that.tableHeight = window.innerHeight - 245;
  888. };
  889. this.getCustomColumn();
  890. this.getList();
  891. // this.getProjects();
  892. },
  893. updated() {
  894. this.$nextTick(() => {
  895. this.$refs['table'].doLayout();
  896. })
  897. }
  898. };
  899. </script>
  900. <style lang="scss" scoped>
  901. .nameList {
  902. height: 400px;
  903. overflow: auto;
  904. }
  905. </style>