wxzctx-cost.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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="zcbm" slot-scope="scope">
  54. <span>{{ scope.row.zcmc }}</span>
  55. </template>
  56. <template slot="zcbmForm">
  57. <asset-select
  58. v-model="form.zcbm"
  59. :params="{ yearAndMonth: projectStartMonth, zclb: '软件,专利权,非专利技术,其他' }"
  60. @change="handleAssetChange"
  61. ></asset-select>
  62. </template>
  63. </avue-crud>
  64. <upload-excel-dialog ref="uploadExcelDialog" :showTempBtn="false" templateKey="预算-无形资产摊销费用" templateName="预算-无形资产摊销费用-导入模板" :uploadAfter="uploadAfter"/>
  65. </div>
  66. </template>
  67. <script>
  68. import {exportBloByPost} from "@/api/common";
  69. import UploadExcelDialog from "@/components/upload-excel-dialog";
  70. import projectSelect from "@/components/project-select";
  71. import {getToken} from "@/util/auth";
  72. import {downloadXls} from "@/util/util";
  73. import moment from "moment";
  74. import Decimal from "decimal.js";
  75. import assetSelect from "@/components/asset-select";
  76. export default window.$crudCommon({
  77. props: {
  78. projectId: [String, Number],
  79. projectData: Object,
  80. projectStartMonth: [String, Number]
  81. },
  82. components: {
  83. UploadExcelDialog,
  84. projectSelect,
  85. assetSelect
  86. },
  87. data() {
  88. return {
  89. params: {
  90. xmId: ''
  91. },
  92. selProject: {},
  93. currZcObj: {},
  94. };
  95. },
  96. created() {
  97. this.params.xmId = this.projectId;
  98. this.option.height = window.innerHeight - 340;
  99. },
  100. watch: {
  101. projectId(newVal, oldVal) {
  102. this.params.xmId = newVal;
  103. if (oldVal) {
  104. this.selProject = this.projectData;
  105. }
  106. },
  107. "params.xmId"() {
  108. this.page.currentPage = 1;
  109. this.getList(this.page);
  110. },
  111. },
  112. computed: {
  113. pageTitle() {
  114. return `${this.selProject.xmmc}无形资产摊销费用`;
  115. }
  116. },
  117. methods: {
  118. validCustom() {
  119. const { sysm, ysysm } = this.currZcObj;
  120. const { xmkssj, xmjssj } = this.selProject
  121. let sm = sysm - ysysm;
  122. if (this.form.zzsc > sm) {
  123. this.$message.warning(`设备剩余寿命为${sm}月,在项目的工作时长不能大于设备寿命!`);
  124. return false;
  125. }
  126. if (xmkssj && xmjssj) {
  127. let monthDiff = moment(xmjssj).diff(moment(xmkssj), 'months', true).toFixed(0);
  128. if (this.form.zzsc > monthDiff) {
  129. this.$message.warning(`项目周期为${monthDiff}月,在项目的工作时长不能大于项目周期!`);
  130. return false;
  131. }
  132. }
  133. return true;
  134. },
  135. addBefore(loading, callback) {
  136. if (!this.validCustom()) {
  137. loading();
  138. return;
  139. }
  140. callback && callback();
  141. },
  142. updateBefore(loading, callback) {
  143. if (!this.validCustom()) {
  144. loading();
  145. return false;
  146. }
  147. callback && callback();
  148. },
  149. handleBeforeOpen(done) {
  150. if (!this.projectStartMonth) {
  151. this.$message.warning("请选择项目!");
  152. return;
  153. }
  154. this.currZcObj = {};
  155. done();
  156. },
  157. getList() {
  158. if (!this.params.xmId) {
  159. return;
  160. }
  161. this.loadData();
  162. },
  163. getFormData() {
  164. return { assetId: this.currZcObj.id, ...this.form, xmId: this.params.xmId, }
  165. },
  166. handleProjectChange(data) {
  167. this.selProject = data;
  168. this.$emit("change", data);
  169. },
  170. handleAssetChange(data) {
  171. this.currZcObj = data;
  172. },
  173. handleImport() {
  174. if (!this.params.xmId) {
  175. this.$message.warning("请选择项目!");
  176. return;
  177. }
  178. let excelParams = { xmId: this.params.xmId };
  179. this.$refs.uploadExcelDialog.open('/api/kd-scientific/ys-wxzctxfy/import', excelParams);
  180. },
  181. uploadAfter() {
  182. this.page.currentPage = 1;
  183. this.getList(this.page);
  184. },
  185. handleExport() {
  186. exportBloByPost(`/api/kd-scientific/ys-wxzctxfy/export?${this.website.tokenHeader}=${getToken()}`, this.params).then(res => {
  187. downloadXls(res.data, `${this.pageTitle}.xlsx`);
  188. });
  189. },
  190. /**
  191. * 打印表格
  192. * @param isLandscape 是否横向打印
  193. */
  194. printTable(isLandscape) {
  195. this.$emit("printClick", {
  196. column: this.printOption.column,
  197. data: this.data,
  198. pageTitle: this.pageTitle,
  199. zoom: 95
  200. });
  201. },
  202. },
  203. }, {
  204. // 模块路径
  205. name: 'projectManage/wxzctxCost',
  206. res: ({ data }) => {
  207. data.records = data.records.map(item => {
  208. item.zcmc = item.zcEntity ? item.zcEntity.zcmc : '';
  209. item.zcbm = item.zcEntity ? item.zcEntity.zcbm : '';
  210. item.ytxe = Number(item.zcEntity ? item.zcEntity.yzje : 0).toFixed(2);
  211. let zzscD = new Decimal(item.zzsc || 0); // 工作时长
  212. let yzjeD = new Decimal(item.ytxe || 0); // 摊销额
  213. item.yshj = zzscD.mul(yzjeD).toFixed(2);
  214. return item;
  215. });
  216. return data;
  217. },
  218. });
  219. </script>