微信小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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