zjfyycqdtfy-cost.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <div>
  3. <div style="margin-top: 6px;">
  4. <el-form :inline="true">
  5. <el-form-item label="研发项目名称">
  6. <project-select v-model="params.xmId" @change="handleProjectChange"></project-select>
  7. </el-form-item>
  8. <el-form-item label="研发项目编号">
  9. {{ selProject.xmbh }}
  10. </el-form-item>
  11. </el-form>
  12. </div>
  13. <avue-crud
  14. ref="crud"
  15. v-bind="bindVal"
  16. v-on="onEvent"
  17. v-model="form"
  18. :page.sync="page"
  19. :before-open="handleBeforeOpen"
  20. >
  21. <template slot="menuLeft">
  22. <el-button
  23. v-if="!isSelAnnual"
  24. type="danger"
  25. size="small"
  26. icon="el-icon-delete"
  27. plain
  28. @click="handleDelete"
  29. >
  30. 删 除
  31. </el-button>
  32. <el-button
  33. v-if="!isSelAnnual"
  34. type="success"
  35. size="small"
  36. plain
  37. icon="el-icon-upload2"
  38. @click="handleImport"
  39. >
  40. 导入
  41. </el-button>
  42. <el-button
  43. type="warning"
  44. size="small"
  45. plain
  46. icon="el-icon-download"
  47. @click="handleExport"
  48. >
  49. 导出
  50. </el-button>
  51. <print-table-btn @click="printTable" />
  52. </template>
  53. <template slot="assetId" slot-scope="scope">
  54. <span>{{ scope.row.zcmc }}</span>
  55. </template>
  56. </avue-crud>
  57. <upload-excel-dialog ref="uploadExcelDialog" templateKey="预算-折旧费用与长期待摊费用" templateName="预算-折旧费用与长期待摊费用-导入模板" :uploadAfter="uploadAfter"/>
  58. </div>
  59. </template>
  60. <script>
  61. import {exportBloByPost} from "@/api/common";
  62. import UploadExcelDialog from "@/components/upload-excel-dialog";
  63. import projectSelect from "@/components/project-select";
  64. import {getToken} from "@/util/auth";
  65. import {downloadXls} from "@/util/util";
  66. import moment from "moment";
  67. import Decimal from "decimal.js";
  68. export default window.$crudCommon({
  69. props: {
  70. projectId: [String, Number]
  71. },
  72. components: {
  73. UploadExcelDialog,
  74. projectSelect,
  75. },
  76. data() {
  77. return {
  78. params: {
  79. xmId: ''
  80. },
  81. selProject: {},
  82. currZcObj: {},
  83. };
  84. },
  85. watch: {
  86. "params.xmId"() {
  87. this.page.currentPage = 1;
  88. this.getList(this.page);
  89. },
  90. },
  91. computed: {
  92. pageTitle() {
  93. return `${this.selProject.xmmc}折旧费用与长期待摊费用`;
  94. }
  95. },
  96. created() {
  97. this.params.xmId = this.projectId;
  98. this.option.height = window.innerHeight - 340;
  99. let newOption = { ...this.option };
  100. // 姓名下拉框,设置监听事件
  101. newOption.column.forEach(item => {
  102. if (item.prop == "assetId") {
  103. item.change = ({ item }) => {
  104. if (!!item) {
  105. this.currZcObj = item;
  106. }
  107. }
  108. }
  109. });
  110. this.option = { ...newOption };
  111. },
  112. methods: {
  113. validCustom() {
  114. const { sysm, ysysm } = this.currZcObj;
  115. const { xmkssj, xmjssj } = this.selProject
  116. let sm = sysm - ysysm;
  117. if (this.form.zzsc > sm) {
  118. this.$message.warning(`设备剩余寿命为${sm}月,在项目的工作时长不能大于设备寿命!`);
  119. return false;
  120. }
  121. if (xmkssj && xmjssj) {
  122. let monthDiff = moment(xmjssj).diff(moment(xmkssj), 'months', true).toFixed(0);
  123. if (this.form.zzsc > monthDiff) {
  124. this.$message.warning(`项目周期为${monthDiff}月,在项目的工作时长不能大于项目周期!`);
  125. return false;
  126. }
  127. }
  128. return true;
  129. },
  130. addBefore(loading, callback) {
  131. if (!this.validCustom()) {
  132. loading();
  133. return;
  134. }
  135. callback && callback();
  136. },
  137. updateBefore(loading, callback) {
  138. if (!this.validCustom()) {
  139. loading();
  140. return false;
  141. }
  142. callback && callback();
  143. },
  144. handleBeforeOpen(done) {
  145. if (!this.params.xmId) {
  146. this.$message.warning("请选择项目!");
  147. return;
  148. }
  149. this.currZcObj = {};
  150. // this.option.column.forEach(item => {
  151. // let yearAndMonth = this.selProject.xmkssj || new Date();
  152. // if (item.prop == "zcbm") {
  153. // item.dicUrl = '/api/kd-scientific/asset/simple/list';
  154. // item.dicQuery.yearAndMonth = moment(yearAndMonth).format("yyyyMM");
  155. // }
  156. // });
  157. done();
  158. },
  159. getList() {
  160. if (!this.params.xmId) {
  161. return;
  162. }
  163. this.loadData();
  164. },
  165. getFormData() {
  166. return { ...this.form, xmId: this.params.xmId }
  167. },
  168. handleProjectChange(data) {
  169. this.selProject = data;
  170. },
  171. handleImport() {
  172. if (!this.params.xmId) {
  173. this.$message.warning("请选择项目!");
  174. return;
  175. }
  176. let excelParams = { xmId: this.params.xmId };
  177. this.$refs.uploadExcelDialog.open('/api/kd-scientific/ys-zjfyycqdtfy/import', excelParams);
  178. },
  179. uploadAfter() {
  180. this.page.currentPage = 1;
  181. this.getList(this.page);
  182. },
  183. handleExport() {
  184. exportBloByPost(`/api/kd-scientific/ys-zjfyycqdtfy/export?${this.website.tokenHeader}=${getToken()}`, this.params).then(res => {
  185. downloadXls(res.data, `${this.pageTitle}.xlsx`);
  186. });
  187. },
  188. /**
  189. * 打印表格
  190. * @param isLandscape 是否横向打印
  191. */
  192. printTable(isLandscape) {
  193. this.$emit("printClick", {
  194. column: this.printOption.column,
  195. data: this.data,
  196. pageTitle: this.pageTitle,
  197. zoom: 95
  198. });
  199. },
  200. },
  201. }, {
  202. // 模块路径
  203. name: 'projectManage/zjfyycqdtfyCost',
  204. res: ({ data }) => {
  205. data.records = data.records.map(item => {
  206. // item.zcmc = item.zcmc;
  207. // item.zcbm = item.zcbm;
  208. item.yzje = Number((item.yzje || 0)).toFixed(2);
  209. item.cqdtfyysje = Number((item.cqdtfyysje || 0)).toFixed(2);
  210. let zzscD = new Decimal(item.zzsc || 0); // 工作时长
  211. let yzjeD = new Decimal(item.yzje || 0);
  212. item.yshj = zzscD.mul(yzjeD).toFixed(2);
  213. return item;
  214. });
  215. return data;
  216. },
  217. });
  218. </script>