微信小程序
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.

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