technician-month-avg-sales.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <basic-container>
  3. <avue-crud
  4. ref="crud"
  5. v-bind="bindVal"
  6. v-on="onEvent"
  7. v-model="form"
  8. :page.sync="page"
  9. :before-open="handleBeforeOpen"
  10. :permission="permissionList"
  11. >
  12. <template slot="menuLeft">
  13. <el-button
  14. type="danger"
  15. size="small"
  16. icon="el-icon-delete"
  17. plain
  18. @click="handleDelete"
  19. >
  20. 清除工资数据
  21. </el-button>
  22. <el-button
  23. type="success"
  24. size="small"
  25. plain
  26. icon="el-icon-upload2"
  27. @click="handleImport"
  28. >
  29. 导入
  30. </el-button>
  31. <el-button
  32. type="warning"
  33. size="small"
  34. plain
  35. icon="el-icon-download"
  36. @click="handleExport"
  37. >
  38. 导出
  39. </el-button>
  40. <el-button
  41. type="primary"
  42. size="small"
  43. plain
  44. @click="handleReadyLastMonData"
  45. >
  46. 读取上年度工资明细
  47. </el-button>
  48. <print-table-btn @click="printTable" />
  49. <div>
  50. <year-month-select v-model="params.yearAndMonth" :showMonth="false"></year-month-select>
  51. </div>
  52. </template>
  53. <div v-for="key of watchUpdateKey" :slot="key" slot-scope="scope" :key="key">
  54. <updated-text v-if="scope.row[key+'Edit'] === 1" :text="scope.row[key]"></updated-text>
  55. <span v-else>{{ scope.row[key] }}</span>
  56. </div>
  57. </avue-crud>
  58. <upload-excel-dialog ref="uploadExcelDialog" :uploadAfter="uploadAfter"/>
  59. <WideTablePrinter
  60. ref="printWideTable"
  61. :columns="wideTableColumns"
  62. :data="data"
  63. :print-title="printTitle"
  64. :rows-per-page="30"
  65. :default-landscape="true"
  66. />
  67. </basic-container>
  68. </template>
  69. <script>
  70. import { getLastMonthData } from "@/api/basicResource/technicianMonthAvgSales";
  71. import {exportBloByPost} from "@/api/common";
  72. import YearMonthSelect from "@/components/year-month-select";
  73. import UpdatedText from "@/components/updated-text";
  74. import UploadExcelDialog from "@/components/upload-excel-dialog";
  75. import moment from "moment";
  76. import {getToken} from "@/util/auth";
  77. import {downloadXls} from "@/util/util";
  78. import Decimal from "decimal.js";
  79. import PrintTableBtn from "@/components/print-table-btn";
  80. import WideTablePrinter from '@/components/print-wide-table'
  81. export default window.$crudCommon({
  82. components: {
  83. YearMonthSelect,
  84. UpdatedText,
  85. UploadExcelDialog,
  86. WideTablePrinter,
  87. PrintTableBtn
  88. },
  89. data() {
  90. return {
  91. params: {
  92. yearAndMonth: moment(new Date()).format('YYYY'),
  93. },
  94. operateType: '',
  95. watchUpdateKey: ["averageMonthlySalary", "pensionInsurance", "medicalInsurance", "unemploymentInsurance", "injuryInsurance", "maternityInsurance", "providentFund"],
  96. beforeUpdatedData: {},
  97. updatedFormData: {},
  98. wideTableColumns: [],
  99. printTitle: "",
  100. };
  101. },
  102. watch: {
  103. 'params.yearAndMonth'(newVal) {
  104. this.page.currentPage = 1;
  105. this.getList(this.page);
  106. }
  107. },
  108. created() {
  109. let newOption = { ...this.option };
  110. // 姓名下拉框,设置监听事件
  111. newOption.column.forEach(item => {
  112. if (item.prop == "name") {
  113. item.change = ({ item }) => {
  114. if (!!item) {
  115. this.form = {
  116. ...this.form,
  117. name: item.name,
  118. number: item.number,
  119. idCard: item.idCard,
  120. department: item.department,
  121. personnelType: item.personnelType,
  122. };
  123. }
  124. }
  125. }
  126. });
  127. this.option = { ...newOption };
  128. },
  129. methods: {
  130. handleBeforeOpen(done, type) {
  131. this.operateType = type;
  132. this.beforeUpdatedData = { ...this.form };
  133. this.option.column.forEach(item => {
  134. if (item.prop == "name") {
  135. item.dicUrl = '/api/kd-scientific/technician/page';
  136. item.dicQuery.yearAndMonth = this.params.yearAndMonth;
  137. }
  138. });
  139. done();
  140. },
  141. getFormData() {
  142. if (this.operateType === 'edit') {
  143. return this.updatedFormData
  144. }
  145. return this.form;
  146. },
  147. updateBefore(loading, callback) {
  148. let updatedData = {};
  149. this.watchUpdateKey.forEach(key => {
  150. if (Number(this.form[key]) != Number(this.beforeUpdatedData[key])) {
  151. updatedData[key] = this.form[key];
  152. }
  153. });
  154. this.updatedFormData = {
  155. technicianId: this.form.technicianId,
  156. yearAndMonth: this.params.yearAndMonth,
  157. ...updatedData
  158. };
  159. callback && callback();
  160. },
  161. getDelParams(row) {
  162. return [{ yearAndMonth: this.params.yearAndMonth, technicianId: row.technicianId }]
  163. },
  164. getBatchDelParams() {
  165. let delArr = [];
  166. this.data.forEach(item => {
  167. if (this.ids.indexOf(item.id) > -1) {
  168. delArr.push({ yearAndMonth: this.params.yearAndMonth, technicianId: item.technicianId });
  169. }
  170. });
  171. return delArr;
  172. },
  173. handleImport() {
  174. let excelParams = { yearAndMonth: this.params.yearAndMonth };
  175. this.$refs.uploadExcelDialog.open('/api/kd-scientific/salary/import', excelParams);
  176. },
  177. uploadAfter() {
  178. this.page.currentPage = 1;
  179. this.getList(this.page);
  180. },
  181. handleExport() {
  182. exportBloByPost(`/api/kd-scientific/salary/export-salary?${this.website.tokenHeader}=${getToken()}`, this.params).then(res => {
  183. downloadXls(res.data, `技术人员${this.params.yearAndMonth}年度平均工资.xlsx`);
  184. });
  185. },
  186. handleReadyLastMonData() {
  187. this.$confirm("确认读取上年度工资明细吗?", "提示", {
  188. confirmButtonText: "确定",
  189. cancelButtonText: "取消",
  190. type: "warning"
  191. }).then(() => {
  192. getLastMonthData({ yearAndMonth: this.params.yearAndMonth}).then(res => {
  193. let data = res.data;
  194. if (data.success) {
  195. this.$message.success('读取成功!');
  196. this.page.currentPage = 1;
  197. this.getList(this.page);
  198. }
  199. });
  200. });
  201. },
  202. printTable(isLandscape) {
  203. this.wideTableColumns = this.$refs.crud.columnOption;
  204. this.printTitle = `技术人员${this.params.yearAndMonth}年度平均工资`;
  205. this.$nextTick(() => {
  206. this.$refs.printWideTable.printTable(isLandscape);
  207. });
  208. },
  209. },
  210. }, {
  211. // 模块路径
  212. name: 'basicResource/technicianMonthAvgSales',
  213. res: ({ data }) => {
  214. data.records = data.records.map(item => {
  215. // 处理id为空的时候,批量清除数据无法获取数据的问题
  216. item.id = !item.id ? (item.number || item.idCard) : item.id;
  217. item.averageMonthlySalary = item.averageMonthlySalary === -1 ? "0.00" : item.averageMonthlySalary;
  218. item.pensionInsurance = item.pensionInsurance === -1 ? "0.00" : item.pensionInsurance;
  219. item.medicalInsurance = item.medicalInsurance === -1 ? "0.00" : item.medicalInsurance;
  220. item.unemploymentInsurance = item.unemploymentInsurance === -1 ? "0.00" : item.unemploymentInsurance;
  221. item.injuryInsurance = item.injuryInsurance === -1 ? "0.00" : item.injuryInsurance;
  222. item.maternityInsurance = item.maternityInsurance === -1 ? "0.00" : item.maternityInsurance;
  223. item.providentFund = item.providentFund === -1 ? "0.00" : item.providentFund;
  224. let pensionInsurance = new Decimal(item.pensionInsurance);
  225. let medicalInsurance = new Decimal(item.medicalInsurance);
  226. let unemploymentInsurance = new Decimal(item.unemploymentInsurance);
  227. let injuryInsurance = new Decimal(item.injuryInsurance);
  228. let maternityInsurance = new Decimal(item.maternityInsurance);
  229. let providentFund = new Decimal(item.providentFund);
  230. // 社保合计
  231. let socialInsurance = pensionInsurance.add(medicalInsurance).add(unemploymentInsurance).add(injuryInsurance).add(maternityInsurance);
  232. // 总计
  233. let total = socialInsurance.add(providentFund);
  234. item.socialInsurance = socialInsurance.toFixed(2);
  235. item.total = total.toFixed(2);
  236. return item;
  237. });
  238. return data;
  239. },
  240. });
  241. </script>