微信小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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