微信小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

600 line
19 KiB

  1. // pages/contract/add/add.js
  2. import * as UTIL from '../../../utils/util.js';
  3. import * as API from '../../../utils/API.js';
  4. const app = getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. isIPX: app.globalData.isIPX,
  11. id:null,
  12. form:{
  13. reviewTime:'2022-01-01',
  14. buildTime:'2022-01-01',
  15. startTime:'2022-01-01',
  16. endTime:'2022-01-01',
  17. biddingDate:'2022-01-01',
  18. fixedValue:'',
  19. fixedSubject:'153:固定资产清理',
  20. depreciationSubject:'152:累计折旧',
  21. depreciationFeeSubject:'541005:管理费用-折旧及修理费',
  22. originalValue:0.00,
  23. quantity:0.00,
  24. netValue:0.00,
  25. residualsRate:1,
  26. netSalvage:0.00,
  27. expectedYears:1,
  28. depreciationYears:0,
  29. depreciationValue:0,
  30. perYearDepreciationValue:0,
  31. },
  32. assetTypeindex:'0',
  33. operationTypendex:'0',
  34. addTypeindex:'0',
  35. useTypeindex:'0',
  36. depreciationTypeindex:'0',
  37. assetStatusindex:'0',
  38. isFormAssetindex:'0',
  39. isMinindex:'0',
  40. unitindex:'0',
  41. showBiddingDate:false,
  42. minDate: new Date(2008, 5, 1).getTime(),
  43. maxDate: new Date(2040, 0, 31).getTime(),
  44. // 资产类别字典
  45. assetTypeOptions: [],
  46. // 经营属性字典
  47. operationTypeOptions: [],
  48. // 增加方式字典
  49. addTypeOptions: [],
  50. // 使用情况字典
  51. useTypeOptions: [],
  52. // 折旧方式字典
  53. depreciationTypeOptions: [],
  54. // 资产状态字典
  55. assetStatusOptions: [],
  56. // 系统是否字典
  57. sysYesNoOptions: [],
  58. //单位字段
  59. unitOptions:[],
  60. status:0,
  61. },
  62. back:function(){
  63. wx.navigateBack({
  64. delta: 1
  65. })
  66. },
  67. openBox(even){
  68. this.setData({
  69. [even.currentTarget.dataset.name]:true
  70. })
  71. },
  72. onChange(event){
  73. this.setData({
  74. [event.currentTarget.dataset.formname]: event.detail,
  75. })
  76. },
  77. closeBox(even){
  78. this.setData({
  79. [even.currentTarget.dataset.name]:false
  80. })
  81. },
  82. onConfirmBuildTime(e){
  83. let data = this.getNewDate(new Date(e.detail.value));
  84. this.setData({'form.buildTime':data});
  85. },
  86. onConfirmOperationType (e) {
  87. let obj = e.detail.value;
  88. this.setData({
  89. 'form.operationType':this.data.operationTypeOptions[obj].dictValue,
  90. 'operationTypeindex':obj
  91. })
  92. },
  93. onConfirmAddType (e) {
  94. let obj = e.detail.value;
  95. this.setData({
  96. 'form.addType':this.data.addTypeOptions[obj].dictValue,
  97. 'addTypeindex':obj
  98. })
  99. },
  100. onConfirmUseType (e) {
  101. let obj = e.detail.value;
  102. this.setData({
  103. 'form.useType':this.data.useTypeOptions[obj].dictValue,
  104. 'useTypeindex':obj
  105. })
  106. },
  107. onConfirmAssetStatus (e) {
  108. let obj = e.detail.value;
  109. this.setData({
  110. 'form.assetStatus':this.data.assetStatusOptions[obj].dictValue,
  111. 'assetStatusindex':obj
  112. })
  113. },
  114. onConfirmIsMin (e) {
  115. console.log(e);
  116. let obj = e.detail.value;
  117. this.setData({
  118. 'form.isMin':this.data.sysYesNoOptions[obj].dictValue,
  119. 'isMinindex':obj
  120. })
  121. },
  122. onConfirmAssetType (e) {
  123. let obj = e.detail.value;
  124. this.setData({
  125. 'form.assetType':this.data.assetTypeOptions[obj].dictValue,
  126. 'assetTypeindex':obj
  127. })
  128. },
  129. onConfirmIsFormAsset (e) {
  130. let obj = e.detail.value;
  131. this.setData({
  132. 'form.isFormAsset':this.data.sysYesNoOptions[obj].dictValue,
  133. 'isFormAssetindex':obj
  134. })
  135. },
  136. onConfirmUnit (e) {
  137. let obj = e.detail.value;
  138. this.setData({
  139. 'form.unit':this.data.unitOptions[obj].dictValue,
  140. 'unitindex':obj
  141. })
  142. },
  143. onConfirmDepreciationType (e) {
  144. let obj = e.detail.value;
  145. this.setData({
  146. 'form.depreciationType':this.data.depreciationTypeOptions[obj].dictValue,
  147. 'depreciationTypeindex':obj
  148. })
  149. },
  150. getNewDate(date){
  151. //date是传过来的时间戳,注意需为13位,10位需*1000
  152. //也可以不传,获取的就是当前时间
  153. var time
  154. if(date){
  155. time = new Date(date);
  156. }else{
  157. time = new Date();
  158. }
  159. var year= time.getFullYear() //年
  160. var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
  161. var day = ("0" + time.getDate()).slice(-2); //日
  162. var mydate = year + "-" + month + "-" + day;
  163. return mydate
  164. },
  165. goSubmit:function(){
  166. if(this.data.form.code===''||this.data.form.code==null){ //合同编码
  167. UTIL.showToastNoneIcon('请填写资产编码!');
  168. return false;
  169. }else if(this.data.form.name===''||this.data.form.name==null){ //合同名称
  170. UTIL.showToastNoneIcon('请输入资产名称!');
  171. return false;
  172. }else if(this.data.form.assetType===''||this.data.form.assetType==null){ //甲方
  173. UTIL.showToastNoneIcon('资产类别不能为空!');
  174. return false;
  175. }else if(this.data.form.operationType===''||this.data.form.operationType==null){ //乙方
  176. UTIL.showToastNoneIcon('经营属性不能为空!');
  177. return false;
  178. }else if(this.data.form.addType === ''||this.data.form.addType==null){//收付款类型
  179. UTIL.showToastNoneIcon('增加方式能为空!');
  180. return false;
  181. }else if(this.data.form.buildTime === ''||this.data.form.buildTime==null){//合同来源
  182. UTIL.showToastNoneIcon('构建时间不能为空!');
  183. return false;
  184. }else if(this.data.form.useType === ''||this.data.form.useType==null){//合同金额
  185. UTIL.showToastNoneIcon('使用情况不能为空!');
  186. return false;
  187. }else if(this.data.form.assetStatus === ''||this.data.form.assetStatus==null){//签订日期
  188. UTIL.showToastNoneIcon('资产状态不能为空!');
  189. return false;
  190. }else if(this.data.form.quantity === ''||this.data.form.quantity==null){//开始日期
  191. UTIL.showToastNoneIcon('请输入数量、面积!');
  192. return false;
  193. }else if(this.data.form.unit === ''||this.data.form.unit==null){//结束日期
  194. UTIL.showToastNoneIcon('计量单位不能为空!');
  195. return false;
  196. }else if(this.data.form.originalValue === ''||this.data.form.originalValue==null){//单价
  197. UTIL.showToastNoneIcon('原值不能为空!');
  198. return false;
  199. }else if(this.data.form.depreciationType === ''||this.data.form.depreciationType==null){//已结款
  200. UTIL.showToastNoneIcon('折旧方式不能为空!');
  201. return false;
  202. }else if(this.data.status == '0'){
  203. let that = this
  204. this.setData({'status':'1'})
  205. if(this.data.form.id!=null&&this.data.form.id!=""){
  206. let data = this.data.form;
  207. data.method = "POST";
  208. UTIL.httpRequest(API.URL_POST_PERMANENTUPDATE,data,{
  209. success: (res) => {
  210. if(res.code == 200){
  211. UTIL.showToastNoneIcon('修改成功');
  212. setTimeout(function(){
  213. wx.navigateBack({
  214. delta:1
  215. })
  216. },2000)
  217. }else{
  218. UTIL.showToastNoneIcon('修改失败');
  219. that.setData({'status':'0'})
  220. }
  221. },
  222. fail: function (response) {
  223. if (typeof fail === FUNCTION_TEXT) {
  224. fail(handleFail(response));
  225. } else {
  226. showToastNoneIcon(API.MSG_FAIL_HTTP);
  227. }
  228. that.setData({'status':0})
  229. },
  230. complete: function (response) {
  231. that.setData({'status':0})
  232. wx.hideNavigationBarLoading();
  233. }
  234. })
  235. }else{
  236. let data = this.data.form;
  237. data.method = "POST";
  238. UTIL.httpRequest(API.URL_POST_PERMANENTADD,data,{
  239. success: (res) => {
  240. if(res.code == 200){
  241. UTIL.showToastNoneIcon(res.msg);
  242. setTimeout(function(){
  243. wx.navigateBack({
  244. delta:1
  245. })
  246. },2000)
  247. }else{
  248. UTIL.showToastNoneIcon(res.msg);
  249. that.setData({'status':'0'})
  250. }
  251. },
  252. fail: function (response) {
  253. if (typeof fail === FUNCTION_TEXT) {
  254. fail(handleFail(response));
  255. } else {
  256. showToastNoneIcon(API.MSG_FAIL_HTTP);
  257. }
  258. that.setData({'status':0})
  259. },
  260. complete: function (response) {
  261. that.setData({'status':0})
  262. wx.hideNavigationBarLoading();
  263. }
  264. })
  265. }
  266. }
  267. },
  268. bindNewInput: function (e) {
  269. this.setData({
  270. [e.currentTarget.dataset.name]: e.detail.value
  271. })
  272. if(e.currentTarget.dataset.name == 'form.originalValue' ){
  273. this.setData({
  274. 'form.netSalvage' : this.data.form.residualsRate*e.detail.value/100,
  275. 'form.perYearDepreciationValue' : ((e.detail.value-(this.data.form.residualsRate*e.detail.value/100))/this.data.form.expectedYears).toFixed(2)
  276. })
  277. }
  278. if(e.currentTarget.dataset.name == 'form.residualsRate' &&e.detail.value<=100){
  279. this.setData({
  280. 'form.netSalvage' : (this.data.form.originalValue*e.detail.value/100)<this.data.form.originalValue?(this.data.form.originalValue*e.detail.value/100).toFixed(2):this.data.form.originalValue,
  281. })
  282. this.setData({
  283. 'form.perYearDepreciationValue' : ((this.data.form.originalValue-this.data.form.netSalvage)/this.data.form.expectedYears).toFixed(2),
  284. })
  285. }
  286. if(e.currentTarget.dataset.name == 'form.residualsRate' &&e.detail.value>100){
  287. this.setData({
  288. 'form.residualsRate' : 5,
  289. })
  290. }
  291. if(e.currentTarget.dataset.name == 'form.netSalvage' ){
  292. this.setData({
  293. 'form.perYearDepreciationValue' : ((this.data.form.originalValue-e.detail.value)/this.data.form.expectedYears).toFixed(2)
  294. })
  295. }
  296. if(e.currentTarget.dataset.name == 'form.expectedYears' ){
  297. this.setData({
  298. 'form.perYearDepreciationValue' : ((this.data.form.originalValue-this.data.form.netSalvage)/e.detail.value).toFixed(2)
  299. })
  300. }
  301. if(e.currentTarget.dataset.name == 'form.depreciationYears' ){
  302. this.setData({
  303. 'form.depreciationValue' : (this.data.form.perYearDepreciationValue*e.detail.value)>this.data.form.originalValue?this.data.form.originalValue:(this.data.form.perYearDepreciationValue*e.detail.value).toFixed(2),
  304. 'form.netValue' : (this.data.form.originalValue-(this.data.form.perYearDepreciationValue*e.detail.value))>=0?(this.data.form.originalValue-(this.data.form.perYearDepreciationValue*e.detail.value).toFixed(2)):0
  305. })
  306. }
  307. },
  308. /**
  309. * 生命周期函数--监听页面加载
  310. */
  311. onLoad(options) {
  312. if(options.id!=null&&options.id!=""){
  313. this.setData({id:options.id})
  314. //获取收入合同状态
  315. UTIL.httpRequest(API.URL_GET_PERMANENTDETAIL + this.data.id, {method:'GET'}, {
  316. success: (res) => {
  317. this.setData({'form':res.data});
  318. let that = this;
  319. //获取资产类别
  320. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'asset_type', {method:'GET'}, {
  321. success: (r) => {
  322. if(r.data.length>0){
  323. that.setData({
  324. assetTypeOptions:r.data,
  325. })
  326. r.data.map((rr,ind) => {
  327. if(rr.dictValue == res.data.assetType){
  328. that.setData({'assetTypeindex':ind})
  329. }
  330. })
  331. }
  332. }
  333. })
  334. //获取经营属性
  335. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'operation_type', {method:'GET'}, {
  336. success: (r) => {
  337. if(r.data.length>0){
  338. that.setData({
  339. operationTypeOptions:r.data,
  340. })
  341. r.data.map((rr,ind) => {
  342. if(rr.dictValue == res.data.operationType){
  343. that.setData({'operationTypeindex':ind})
  344. }
  345. })
  346. }
  347. }
  348. })
  349. //获取增加方式
  350. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'add_type', {method:'GET'}, {
  351. success: (r) => {
  352. if(r.data.length>0){
  353. that.setData({
  354. addTypeOptions:r.data,
  355. })
  356. r.data.map((rr,ind) => {
  357. if(rr.dictValue == res.data.addType){
  358. that.setData({'addTypeindex':ind})
  359. }
  360. })
  361. }
  362. }
  363. })
  364. //获取使用情况
  365. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'use_type', {method:'GET'}, {
  366. success: (r) => {
  367. if(r.data.length>0){
  368. that.setData({
  369. useTypeOptions:r.data,
  370. })
  371. r.data.map((rr,ind) => {
  372. if(rr.dictValue == res.data.useType){
  373. that.setData({'useTypeindex':ind})
  374. }
  375. })
  376. }
  377. }
  378. })
  379. //获取折旧方式
  380. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'depreciation_type', {method:'GET'}, {
  381. success: (r) => {
  382. if(r.data.length>0){
  383. that.setData({
  384. depreciationTypeOptions:r.data,
  385. })
  386. r.data.map((rr,ind) => {
  387. if(rr.dictValue == res.data.depreciationType){
  388. that.setData({'depreciationTypeindex':ind})
  389. }
  390. })
  391. }
  392. }
  393. })
  394. //获取资产状态
  395. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'asset_status', {method:'GET'}, {
  396. success: (r) => {
  397. if(r.data.length>0){
  398. that.setData({
  399. assetStatusOptions:r.data,
  400. })
  401. r.data.map((rr,ind) => {
  402. if(rr.dictValue == res.data.assetStatus){
  403. that.setData({'assetStatusindex':ind})
  404. }
  405. })
  406. }
  407. }
  408. })
  409. //获取单位
  410. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'fixed_assets_unit', {method:'GET'}, {
  411. success: (r) => {
  412. if(r.data.length>0){
  413. that.setData({
  414. unitOptions:r.data,
  415. })
  416. r.data.map((rr,ind) => {
  417. if(rr.dictValue == res.data.unit){
  418. that.setData({'unitindex':ind})
  419. }
  420. })
  421. }
  422. }
  423. })
  424. //获取系统是否
  425. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'sys_yes_no', {method:'GET'}, {
  426. success: (r) => {
  427. if(r.data.length>0){
  428. that.setData({
  429. sysYesNoOptions:r.data,
  430. })
  431. r.data.map((rr,ind) => {
  432. if(rr.dictValue == res.data.isMin){
  433. that.setData({'isMinindex':ind})
  434. }
  435. if(rr.dictValue == res.data.isFormAsset){
  436. that.setData({'isFormAssetindex':ind})
  437. }
  438. })
  439. }
  440. }
  441. })
  442. }
  443. })
  444. }else{
  445. let that = this;
  446. this.setData({
  447. 'form.reviewTime':this.getNewDate(),
  448. 'form.buildTime':this.getNewDate(),
  449. 'form.startTime':this.getNewDate(),
  450. 'form.endTime':this.getNewDate(),
  451. 'form.biddingDate':this.getNewDate(),
  452. })
  453. //获取资产类别
  454. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'asset_type', {method:'GET'}, {
  455. success: (res) => {
  456. if(res.data.length>0){
  457. that.setData({
  458. assetTypeOptions:res.data,
  459. 'form.assetType':res.data[0].dictValue
  460. })
  461. }
  462. }
  463. })
  464. //获取经营属性
  465. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'operation_type', {method:'GET'}, {
  466. success: (res) => {
  467. if(res.data.length>0){
  468. that.setData({
  469. operationTypeOptions:res.data,
  470. 'form.operationType':res.data[0].dictValue
  471. })
  472. }
  473. }
  474. })
  475. //获取增加方式
  476. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'add_type', {method:'GET'}, {
  477. success: (res) => {
  478. if(res.data.length>0){
  479. that.setData({
  480. addTypeOptions:res.data,
  481. 'form.addType':res.data[0].dictValue
  482. })
  483. }
  484. }
  485. })
  486. //获取使用情况
  487. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'use_type', {method:'GET'}, {
  488. success: (res) => {
  489. if(res.data.length>0){
  490. that.setData({
  491. useTypeOptions:res.data,
  492. 'form.useType':res.data[0].dictValue
  493. })
  494. }
  495. }
  496. })
  497. //获取折旧方式
  498. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'depreciation_type', {method:'GET'}, {
  499. success: (res) => {
  500. if(res.data.length>0){
  501. that.setData({
  502. depreciationTypeOptions:res.data,
  503. 'form.depreciationType':res.data[1].dictValue
  504. })
  505. }
  506. }
  507. })
  508. //获取资产状态
  509. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'asset_status', {method:'GET'}, {
  510. success: (res) => {
  511. if(res.data.length>0){
  512. that.setData({
  513. assetStatusOptions:res.data,
  514. 'form.assetStatus':res.data[0].dictValue
  515. })
  516. }
  517. }
  518. })
  519. //获取单位
  520. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'fixed_assets_unit', {method:'GET'}, {
  521. success: (res) => {
  522. if(res.data.length>0){
  523. that.setData({
  524. unitOptions:res.data,
  525. 'form.unit':res.data[0].dictValue
  526. })
  527. }
  528. }
  529. })
  530. //获取是否
  531. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'sys_yes_no', {method:'GET'}, {
  532. success: (res) => {
  533. if(res.data.length>0){
  534. that.setData({
  535. sysYesNoOptions:res.data,
  536. 'form.isMin':res.data[0].dictValue,
  537. 'form.isFormAsset':res.data[0].dictValue
  538. })
  539. }
  540. }
  541. })
  542. }
  543. },
  544. /**
  545. * 生命周期函数--监听页面初次渲染完成
  546. */
  547. onReady() {
  548. },
  549. /**
  550. * 生命周期函数--监听页面显示
  551. */
  552. onShow() {
  553. },
  554. /**
  555. * 生命周期函数--监听页面隐藏
  556. */
  557. onHide() {
  558. },
  559. /**
  560. * 生命周期函数--监听页面卸载
  561. */
  562. onUnload() {
  563. },
  564. /**
  565. * 页面相关事件处理函数--监听用户下拉动作
  566. */
  567. onPullDownRefresh() {
  568. },
  569. /**
  570. * 页面上拉触底事件的处理函数
  571. */
  572. onReachBottom() {
  573. },
  574. /**
  575. * 用户点击右上角分享
  576. */
  577. onShareAppMessage() {
  578. }
  579. })