change-form.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <template>
  2. <div>
  3. <div class="tool-btn" style="width: 800px; margin: 0 auto; text-align: right;">
  4. <el-button size="small" type="primary" icon="el-icon-printer" v-print="'#changeDoc'" :disabled="!disabled">打印</el-button>
  5. </div>
  6. <div id="changeDoc" class="doc-page">
  7. <h3 class="page-title">项目变更申请表</h3>
  8. <table>
  9. <tbody>
  10. <tr>
  11. <td class="doc-label">研发项目名称</td>
  12. <td class="doc-input">
  13. <project-select v-model="currProjectId" @change="handleProjectChange" :disabled="disabled"></project-select>
  14. </td>
  15. <td class="doc-label">研发项目编号</td>
  16. <td class="doc-input">{{ selProject.xmbh }}</td>
  17. </tr>
  18. <tr>
  19. <td class="doc-label">项目负责人</td>
  20. <td class="doc-input">{{ selProject.xmfzrxm }} </td>
  21. <td class="doc-label">项目申请单位</td>
  22. <td class="doc-input">{{ selProject.xmsqdw }}</td>
  23. </tr>
  24. <tr>
  25. <td class="doc-label">变更类型</td>
  26. <td class="doc-input" colspan="3">
  27. <avue-select
  28. v-model="formData.zdmc"
  29. placeholder="请选择"
  30. :dic="changeTypeList"
  31. style="width: 100%"
  32. :disabled="disabled || !selProject.id"
  33. ></avue-select>
  34. </td>
  35. </tr>
  36. <tr>
  37. <td class="doc-label">变更前</td>
  38. <td class="doc-input" style="padding: 0;">
  39. <!-- 项目预算 -->
  40. <template v-if="formData.zdmc === 'xmyszemx'">
  41. <div style="height: 31px; line-height: 31px; border-bottom: 1px solid #000;">总计:{{ selProject.xmysze }}万元</div>
  42. <div class="year-list">
  43. <div class="year-list-item" v-for="item of oldXmyszemxList" :key="item.year">
  44. <div class="year" >{{ item.year }}</div>
  45. <div class="year-input"> {{ item.amount }} </div>
  46. </div>
  47. </div>
  48. </template>
  49. <span v-else>{{ getChangeBeforeVal }}</span>
  50. </td>
  51. <td class="doc-label">变更后</td>
  52. <td class="doc-input">
  53. <el-input v-if="formData.zdmc === 'xmmc'" placeholder="请输入项目名称" v-model="formData.bghdz" :disabled="disabled" />
  54. <!-- 项目结束时间 -->
  55. <el-date-picker
  56. v-if="'xmjssj'.indexOf(formData.zdmc) > -1"
  57. v-model="formData.bghdz"
  58. format="yyyy年MM月dd日"
  59. value-format="yyyy-MM-dd"
  60. placeholder="请选择日期"
  61. style="width: 100%"
  62. :disabled="disabled"
  63. @change="handleEndDateChange"
  64. ></el-date-picker>
  65. <!-- 项目负责人 -->
  66. <template v-if="formData.zdmc === 'xmfzr'">
  67. <person-select
  68. v-if="!disabled"
  69. v-model="formData.bghdz"
  70. :yearAndMonth="projectStartMonth"
  71. valueKey="id"
  72. :disabled="disabled"
  73. style="width: 100%"
  74. />
  75. <span v-else>{{ formData.bghdz }}</span>
  76. </template>
  77. <!-- 项目状态 -->
  78. <avue-select
  79. v-if="formData.zdmc === 'status'"
  80. v-model="formData.bghdz"
  81. placeholder="请选择"
  82. :dic="projectStateList"
  83. style="width: 100%"
  84. :disabled="disabled"
  85. ></avue-select>
  86. <!-- 所属二级单位 -->
  87. <template v-if="formData.zdmc === 'xmsqdwid'">
  88. <second-unit-cascader
  89. v-if="!disabled"
  90. v-model="formData.bghdz"
  91. :disabled="disabled"
  92. :yearAndMonth="currProjectYear"
  93. style="width: 100%;"
  94. />
  95. <span v-else>{{ formData.bghdz }}</span>
  96. </template>
  97. <!-- 项目预算明细 -->
  98. <div v-if="formData.zdmc === 'xmyszemx'" class="year-list">
  99. <div style="height: 31px; line-height: 31px; border-bottom: 1px solid #000;">总计:{{ newXmysTotal }}万元</div>
  100. <div class="year-list-item" v-for="item of newXmyszemxList" :key="item.year">
  101. <div class="year" >{{ item.year }}</div>
  102. <div class="year-input">
  103. <input v-model="item.amount" type="number" style="padding: 0 6px;" :disabled="disabled" />
  104. </div>
  105. </div>
  106. </div>
  107. </td>
  108. </tr>
  109. <!-- 变更结束时间,同时增加预算变更 -->
  110. <tr v-if="formData.zdmc === 'xmjssj' && !disabled"><td colspan="4" align="center" style="height: 46px; font-weight: 600;">预算变更</td></tr>
  111. <tr v-if="formData.zdmc === 'xmjssj' && !disabled">
  112. <td class="doc-label">变更前</td>
  113. <td class="doc-input" style="padding: 0;">
  114. <div style="height: 31px; line-height: 31px; border-bottom: 1px solid #000;">总计:{{ selProject.xmysze }}万元</div>
  115. <div class="year-list">
  116. <div class="year-list-item" v-for="item of oldXmyszemxList" :key="item.year">
  117. <div class="year">{{ item.year }}</div>
  118. <div class="year-input"> {{ item.amount }} </div>
  119. </div>
  120. </div>
  121. </td>
  122. <td class="doc-label">变更后</td>
  123. <td class="doc-input" style="padding: 0;">
  124. <div class="year-list">
  125. <div style="height: 31px; line-height: 31px; border-bottom: 1px solid #000;">总计:{{ newXmysTotal }}万元</div>
  126. <div class="year-list-item" v-for="item of newXmyszemxList" :key="item.year">
  127. <div class="year">{{ item.year }}</div>
  128. <div class="year-input">
  129. <input v-model="item.amount" type="number" style="padding: 0 6px;" :disabled="disabled" />
  130. </div>
  131. </div>
  132. </div>
  133. </td>
  134. </tr>
  135. <tr>
  136. <td class="doc-label">变更原因说明</td>
  137. <td class="doc-input" colspan="3">
  138. <el-input v-model="formData.bgyy" type="textarea" :rows="3" :disabled="disabled" />
  139. </td>
  140. </tr>
  141. <tr>
  142. <td class="doc-label">变更生效时间</td>
  143. <td class="doc-input" colspan="3">
  144. <el-date-picker
  145. v-model="formData.bgsxsj"
  146. format="yyyy年MM月dd日"
  147. value-format="yyyy-MM-dd"
  148. placeholder="请选择日期"
  149. style="width: 100%"
  150. :disabled="disabled"
  151. ></el-date-picker>
  152. </td>
  153. </tr>
  154. <tr>
  155. <td class="doc-label">附件上传</td>
  156. <td class="doc-input" colspan="3" style="text-align: left;">
  157. <avue-upload
  158. v-if="!disabled"
  159. action="/api/kd-resource/oss/endpoint/put-file"
  160. dataType="object"
  161. :props-http="{
  162. url: 'link',
  163. name: 'originalName',
  164. res: 'data',
  165. }"
  166. type="upload"
  167. v-model="formData.attachment"
  168. style="margin: 14px 0 14px 12px;"
  169. :disabled="disabled"
  170. :uploadPreview="handleUploadPreview"
  171. ></avue-upload>
  172. <div v-else>
  173. <div v-for="(item, index) of formData.attachment" :key="index" style="line-height: 26px; padding: 6px;">
  174. <el-link type="primary" @click="handleDownFile(item)">{{ item.label }}</el-link>
  175. </div>
  176. </div>
  177. </td>
  178. </tr>
  179. </tbody>
  180. </table>
  181. <div v-if="!disabled" class="btn-wrap" style="text-align: center; margin-top: 30px;">
  182. <el-button type="primary" style="width: 160px;" @click="handleSaveBtn">保存</el-button>
  183. </div>
  184. </div>
  185. </div>
  186. </template>
  187. <script>
  188. import { getDictionary } from "@/api/system/dict";
  189. import { getList as getTechnicanRosterList } from "@/api/basicResource/technicianRoster";
  190. import { save } from "@/api/projectManage/change";
  191. import moment from "moment";
  192. import projectSelect from "@/components/project-select";
  193. import secondUnitCascader from "@/components/second-unit-cascader";
  194. import personSelect from "@/components/person-select";
  195. import Decimal from "decimal.js";
  196. import { downloadFileByUrl } from "@/util/util";
  197. export default {
  198. props: {
  199. projectId: [String, Number],
  200. data: Object,
  201. disabled: {
  202. type: Boolean,
  203. type: false
  204. }
  205. },
  206. components: {
  207. projectSelect,
  208. secondUnitCascader,
  209. personSelect
  210. },
  211. data() {
  212. return {
  213. currProjectId: '',
  214. formData: {
  215. attachment: []
  216. },
  217. // 变更类型
  218. changeTypeList: [],
  219. // 项目状态
  220. projectStateList: [],
  221. loading: false,
  222. selProject: {},
  223. // 项目负责人列表
  224. fzrList: [],
  225. // 变更前预算明细
  226. oldXmyszemxList: [],
  227. // 变更后预算明细
  228. newXmyszemxList: [],
  229. // 项目开始月份
  230. projectStartMonth: ""
  231. };
  232. },
  233. watch: {
  234. "formData.zdmc"(newVal) {
  235. if (newVal == 'xmfzr') {
  236. this.getTechnicanRosterListFunc(moment(this.selProject.xmkssj).format('yyyyMM'));
  237. }
  238. // else if (newVal == 'xmyszemx' || newVal == 'xmjssj') {
  239. // this.oldXmyszemxList = JSON.parse(this.selProject.xmyszemx);
  240. // this.newXmyszemxList = JSON.parse(this.selProject.xmyszemx);
  241. // }
  242. },
  243. },
  244. computed: {
  245. // 当前项目所属年份
  246. currProjectYear() {
  247. return this.selProject.xmkssj ? moment(this.selProject.xmkssj).format('YYYY') : '';
  248. },
  249. // 获取变更前的值
  250. getChangeBeforeVal() {
  251. if (this.disabled) {
  252. return this.formData.bgqdz;
  253. }
  254. if (this.formData.zdmc === 'xmfzr') {
  255. return this.selProject.xmfzrxm;
  256. } else if (this.formData.zdmc === 'xmsqdwid') {
  257. return this.selProject.xmsqdw;
  258. } else if (this.formData.zdmc === 'status') {
  259. let _currStatusObj = this.projectStateList.find(item => item.value == this.selProject.status);
  260. return _currStatusObj ? _currStatusObj.label: '';
  261. } else {
  262. return this.selProject[this.formData.zdmc];
  263. }
  264. },
  265. // 变更后的预算总值
  266. newXmysTotal() {
  267. let total = new Decimal(0);
  268. this.newXmyszemxList.forEach(item => {
  269. total = total.add(new Decimal(item.amount || 0));
  270. });
  271. return total;
  272. },
  273. },
  274. mounted() {
  275. this.getDictList("xm_biangeng_field", "changeTypeList");
  276. this.getDictList("project_state", "projectStateList");
  277. this.currProjectId = this.projectId;
  278. if (Object.keys(this.data).length) {
  279. this.formData = { ...this.data, zdmc: this.data.zdmc.toLowerCase() };
  280. if (this.formData.zdmc === 'xmyszemx') {
  281. this.oldXmyszemxList = this.formData.bgqdzJSON;
  282. this.newXmyszemxList = this.formData.bghdzJSON;
  283. }
  284. this.currProjectId = this.data.xmId;
  285. }
  286. },
  287. methods: {
  288. handleEndDateChange(e) {
  289. let startYear = moment(this.selProject.xmkssj).format('YYYY');
  290. let endYear = moment(e).format('YYYY');
  291. let newYearList = [];
  292. for (let i=startYear; i<=endYear; i++) {
  293. let _obj = this.oldXmyszemxList.find(item => item.year == i);
  294. newYearList.push({ year: i, amount: _obj ? _obj.amount : '' });
  295. }
  296. this.newXmyszemxList = newYearList;
  297. },
  298. /**
  299. * 获取人员花名册
  300. */
  301. getTechnicanRosterListFunc(yearAndMonth) {
  302. getTechnicanRosterList(1, 99999, { yearAndMonth }).then(res => {
  303. if (res.data.success) {
  304. this.fzrList = res.data.data.records.map(item => {
  305. return { label: item.name, value: item.id };
  306. });
  307. }
  308. });
  309. },
  310. getDictList(code, toListKey) {
  311. getDictionary({ code }).then((res) => {
  312. this[toListKey] = res.data.data.map((item) => {
  313. return { label: item.dictValue, value: item.dictKey.toLowerCase() };
  314. });
  315. });
  316. },
  317. handleProjectChange(data) {
  318. this.selProject = data;
  319. this.projectStartMonth = moment(data.xmkssj).format("yyyyMM");
  320. if (!this.disabled) {
  321. this.oldXmyszemxList = JSON.parse(data.xmyszemx);
  322. this.newXmyszemxList = JSON.parse(data.xmyszemx);
  323. }
  324. },
  325. validForm() {
  326. let errorText = '';
  327. if (!this.currProjectId) {
  328. errorText = '请选择变更的项目';
  329. } else if (!this.formData.zdmc) {
  330. errorText = '请选择变更类型';
  331. } else if (!this.formData.bgyy) {
  332. errorText = '请输入变更原因';
  333. } else if (!this.formData.bgsxsj) {
  334. errorText = '请选择变更生效时间';
  335. }
  336. if ('xmyszemx,xmjssj'.indexOf(this.formData.zdmc) > -1) {
  337. for (let i=0; i<this.newXmyszemxList.length; i++) {
  338. let _item = this.newXmyszemxList[i];
  339. if (_item.amount === null || _item.amount === undefined || _item.amount === '') {
  340. errorText = `请填写${_item.year}年的预算`;
  341. break;
  342. }
  343. }
  344. if (this.formData.zdmc === 'xmjssj' && !this.formData.bghdz) {
  345. errorText = '变更后的值不能为空!';
  346. }
  347. } else {
  348. if (!this.formData.bghdz || (this.formData.bghdz instanceof Array && !this.formData.bghdz.length)) {
  349. errorText = '变更后的值不能为空!';
  350. }
  351. }
  352. return errorText;
  353. },
  354. /**
  355. * 获取提交的参数
  356. * @param changeType 变更类型
  357. */
  358. getFormData(changeType) {
  359. const params = {
  360. ...this.formData,
  361. bgqdz: this.selProject[changeType],
  362. attachment: JSON.stringify(this.formData.attachment),
  363. xmId: this.currProjectId,
  364. zdmc: changeType.toUpperCase()
  365. };
  366. if (changeType === 'xmyszemx') {
  367. params.bghdz = JSON.stringify(this.newXmyszemxList);
  368. } else if (changeType === 'xmsqdwid') {
  369. params.bghdz = params.bghdz[params.bghdz.length - 1];
  370. }
  371. return params;
  372. },
  373. handleSaveBtn() {
  374. let errorText = this.validForm();
  375. if (errorText) {
  376. this.$message.error(errorText+'!');
  377. return;
  378. }
  379. if (this.formData.zdmc === 'xmjssj' && JSON.stringify(this.newXmyszemxList) != JSON.stringify(this.oldXmyszemxList)) {
  380. this.$confirm('检测到预算发生变化,点击确定,将同时发起一个预算变更,确认要操作吗?', '提示').then(() => {
  381. const params1 = this.getFormData(this.formData.zdmc);
  382. const params2 = this.getFormData('xmyszemx');
  383. params2.bgqdz = JSON.stringify(this.oldXmyszemxList);
  384. Promise.all([this.saveData(params1), this.saveData(params2)]).then(([res1, res2]) => {
  385. if (res1.data.success) {
  386. this.$message.success("保存成功!");
  387. this.$emit("success");
  388. }
  389. });
  390. });
  391. return;
  392. }
  393. const params = this.getFormData(this.formData.zdmc);
  394. this.saveData(params).then(({ data }) => {
  395. if (data.code == 200) {
  396. this.$message.success("保存成功!");
  397. this.$emit("success");
  398. }
  399. });
  400. },
  401. saveData(params) {
  402. return save(params)
  403. },
  404. handleDownFile(file) {
  405. downloadFileByUrl(file.value, file.label);
  406. },
  407. handleUploadPreview (file, column, done) {
  408. downloadFileByUrl(file.url, file.name);
  409. return;
  410. },
  411. },
  412. };
  413. </script>
  414. <style lang="scss" scoped>
  415. .page-title {
  416. text-align: center;
  417. font-size: 24px;
  418. padding: 24px 0 16px;
  419. margin: 0;
  420. }
  421. .doc-page {
  422. width: 800px;
  423. margin: 0 auto;
  424. }
  425. table {
  426. width: 100%;
  427. border: 1px solid #333;
  428. }
  429. .doc-label {
  430. text-align: center;
  431. padding: 6px;
  432. color: #777;
  433. font-size: 14px;
  434. width: 15%;
  435. }
  436. .doc-input {
  437. text-align: center;
  438. color: #333;
  439. width: 35%;
  440. height: 40px;
  441. }
  442. .el-input__inner {
  443. border: none;
  444. }
  445. tr td {
  446. border: 1px solid #333;
  447. }
  448. .year-list {
  449. &-item {
  450. display: flex;
  451. height: 32px;
  452. line-height: 32px;
  453. border-bottom: 1px solid #333;
  454. &:last-child {
  455. border-bottom: 0;
  456. }
  457. .year {
  458. width: 65px;
  459. border-right: 1px solid #333;
  460. }
  461. .year-input {
  462. padding-left: 12px;
  463. input {
  464. border: none;
  465. }
  466. }
  467. }
  468. }
  469. </style>