|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629 |
- // pages/contract/add/add.js
- import * as UTIL from '../../../utils/util.js';
- import * as API from '../../../utils/API.js';
- const app = getApp();
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- isIPX: app.globalData.isIPX,
- id:null,
- form:{},
- assetTypeindex:'0',
- changeTypeindex:'0',
- depreciationTypeindex:'0',
- changeValueindex:'0',
- // 折旧方式字典
- depreciationTypeOptions:[],
- // 资产类别字典
- assetTypeOptions: [],
- // 变更类型字典
- changeTypeOptions: [
- { 'dictLabel':'数量/面积变更','dictValue':'1'},
- { 'dictLabel':'原值变更','dictValue':'2'},
- { 'dictLabel':'预计使用年数变更','dictValue':'3'},
- { 'dictLabel':'累计折旧变更','dictValue':'4'},
- { 'dictLabel':'已折旧年数变更','dictValue':'5'},
- { 'dictLabel':'残值率变更','dictValue':'6'},
- { 'dictLabel':'折旧方式变更','dictValue':'7'},
- ],
- status:0,
- },
- back:function(){
- wx.navigateBack({
- delta: 1
- })
- },
- openBox(even){
- this.setData({
- [even.currentTarget.dataset.name]:true
- })
- },
- onChange(event){
- this.setData({
- [event.currentTarget.dataset.formname]: event.detail,
- })
- },
- closeBox(even){
- this.setData({
- [even.currentTarget.dataset.name]:false
- })
- },
- onConfirmChangeType (e) {
- let obj = e.detail.value;
- this.setData({
- 'form.changeType':this.data.changeTypeOptions[obj].dictValue,
- 'changeTypeindex':obj
- })
- },
- onConfirmChangeValue(e){
- let obj = e.detail.value;
- this.setData({
- 'form.changeValue':this.data.depreciationTypeOptions[obj].dictValue,
- 'changeValueindex':obj
- })
- },
- onConfirmDepreciationType(e){
- let obj = e.detail.value;
- this.setData({
- 'form.depreciationType':this.data.depreciationTypeOptions[obj].dictValue,
- 'depreciationTypeindex':obj
- })
- },
- onConfirmAssetType (e) {
- let obj = e.detail.value;
- this.setData({
- 'form.assetType':this.data.assetTypeOptions[obj].dictValue,
- 'assetTypeindex':obj
- })
- },
- getNewDate(date){
- //date是传过来的时间戳,注意需为13位,10位需*1000
- //也可以不传,获取的就是当前时间
- var time
- if(date){
- time = new Date(date);
- }else{
- time = new Date();
- }
- var year= time.getFullYear() //年
- var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
- var day = ("0" + time.getDate()).slice(-2); //日
- var mydate = year + "-" + month + "-" + day;
- return mydate
- },
- goSubmit:function(){
- if(this.data.changeTypeindex != 6&&(this.data.form.changeValue===''||this.data.form.changeValue==null)){ //变更后值
- UTIL.showToastNoneIcon('变更后值不能给你为空!');
- return false;
- }else if(this.data.status == '0'){
- let that = this
- this.setData({'status':'1'})
- let data = this.data.form;
- data.method = "POST";
- if(this.data.changeTypeindex == 0){
- data.quantity = data.changeValue
- UTIL.httpRequest(API.URL_POST_UPDATEQUANTITY,data,{
- success: (res) => {
- that.setData({'status':'0'})
- if(res.code == 200){
- UTIL.showToastNoneIcon("变更成功");
- setTimeout(function(){
- wx.navigateBack({
- delta:1
- })
- },2000)
- }else{
- UTIL.showToastNoneIcon("变更失败:"+res.msg);
- }
- },
- fail: function (response) {
- if (typeof fail === FUNCTION_TEXT) {
- fail(handleFail(response));
- } else {
- showToastNoneIcon(API.MSG_FAIL_HTTP);
- }
- that.setData({'status':0})
- },
- complete: function (response) {
- wx.hideNavigationBarLoading();
- }
- })
- }else if(this.data.changeTypeindex == 1){
- data.originalValue = data.changeValue
- UTIL.httpRequest(API.URL_POST_UPDATEORIGINALVALUE,data,{
- success: (res) => {
- that.setData({'status':'0'})
- if(res.code == 200){
- UTIL.showToastNoneIcon("变更成功");
- setTimeout(function(){
- wx.navigateBack({
- delta:1
- })
- },2000)
- }else{
- UTIL.showToastNoneIcon("变更失败:"+res.msg);
- }
- },
- fail: function (response) {
- if (typeof fail === FUNCTION_TEXT) {
- fail(handleFail(response));
- } else {
- showToastNoneIcon(API.MSG_FAIL_HTTP);
- }
- that.setData({'status':0})
- },
- complete: function (response) {
- wx.hideNavigationBarLoading();
- }
- })
- }else if(this.data.changeTypeindex == 2){
- data.expectedYears = data.changeValue
- UTIL.httpRequest(API.URL_POST_UPDATEEXPECTEDYEARS,data,{
- success: (res) => {
- that.setData({'status':'0'})
- if(res.code == 200){
- UTIL.showToastNoneIcon("变更成功");
- setTimeout(function(){
- wx.navigateBack({
- delta:1
- })
- },2000)
- }else{
- UTIL.showToastNoneIcon("变更失败:"+res.msg);
- }
- },
- fail: function (response) {
- if (typeof fail === FUNCTION_TEXT) {
- fail(handleFail(response));
- } else {
- showToastNoneIcon(API.MSG_FAIL_HTTP);
- }
- that.setData({'status':0})
- },
- complete: function (response) {
- wx.hideNavigationBarLoading();
- }
- })
- }else if(this.data.changeTypeindex == 3){
- data.depreciationValue = data.changeValue
- UTIL.httpRequest(API.URL_POST_UPDATEDEPRECIATIONVALUE,data,{
- success: (res) => {
- that.setData({'status':'0'})
- if(res.code == 200){
- UTIL.showToastNoneIcon("变更成功");
- setTimeout(function(){
- wx.navigateBack({
- delta:1
- })
- },2000)
- }else{
- UTIL.showToastNoneIcon("变更失败:"+res.msg);
- }
- },
- fail: function (response) {
- if (typeof fail === FUNCTION_TEXT) {
- fail(handleFail(response));
- } else {
- showToastNoneIcon(API.MSG_FAIL_HTTP);
- }
- that.setData({'status':0})
- },
- complete: function (response) {
- wx.hideNavigationBarLoading();
- }
- })
- }else if(this.data.changeTypeindex == 4){
- data.depreciationYears = data.changeValue
- UTIL.httpRequest(API.URL_POST_UPDATEDEPRECIATIONYEARS,data,{
- success: (res) => {
- that.setData({'status':'0'})
- if(res.code == 200){
- UTIL.showToastNoneIcon("变更成功");
- setTimeout(function(){
- wx.navigateBack({
- delta:1
- })
- },2000)
- }else{
- UTIL.showToastNoneIcon("变更失败:"+res.msg);
- }
- },
- fail: function (response) {
- if (typeof fail === FUNCTION_TEXT) {
- fail(handleFail(response));
- } else {
- showToastNoneIcon(API.MSG_FAIL_HTTP);
- }
- that.setData({'status':0})
- },
- complete: function (response) {
- wx.hideNavigationBarLoading();
- }
- })
- }else if(this.data.changeTypeindex == 5){
- data.residualsRate = data.changeValue
- UTIL.httpRequest(API.URL_POST_UPDATERESIDUALSRATE,data,{
- success: (res) => {
- that.setData({'status':'0'})
- if(res.code == 200){
- UTIL.showToastNoneIcon("变更成功");
- setTimeout(function(){
- wx.navigateBack({
- delta:1
- })
- },2000)
- }else{
- UTIL.showToastNoneIcon("变更失败:"+res.msg);
- }
- },
- fail: function (response) {
- if (typeof fail === FUNCTION_TEXT) {
- fail(handleFail(response));
- } else {
- showToastNoneIcon(API.MSG_FAIL_HTTP);
- }
- that.setData({'status':0})
- },
- complete: function (response) {
- wx.hideNavigationBarLoading();
- }
- })
- }else if(this.data.changeTypeindex == 6){
- data.depreciationType = this.data.depreciationTypeOptions[this.data.changeValueindex].dictValue
- UTIL.httpRequest(API.URL_POST_UPDATEDEPRECIATIONMETHOD,data,{
- success: (res) => {
- that.setData({'status':'0'})
- if(res.code == 200){
- UTIL.showToastNoneIcon("变更成功");
- setTimeout(function(){
- wx.navigateBack({
- delta:1
- })
- },2000)
- }else{
- UTIL.showToastNoneIcon("变更失败:"+res.msg);
- }
- },
- fail: function (response) {
- if (typeof fail === FUNCTION_TEXT) {
- fail(handleFail(response));
- } else {
- showToastNoneIcon(API.MSG_FAIL_HTTP);
- }
- that.setData({'status':0})
- },
- complete: function (response) {
- wx.hideNavigationBarLoading();
- }
- })
- }
-
-
- }
- },
- bindNewInput: function (e) {
- this.setData({
- [e.currentTarget.dataset.name]: e.detail.value
- })
- if(e.currentTarget.dataset.name == 'form.originalValue' ){
- this.setData({
- 'form.netSalvage' : (this.data.form.residualsRate*e.detail.value/100).toFixed(2),
- 'form.perYearDepreciationValue' : ((e.detail.value-(this.data.form.residualsRate*e.detail.value/100))/this.data.form.expectedYears).toFixed(2),
- 'form.netValue':this.data.form.originalValue-this.data.form.depreciationValue
- })
- }
- if(e.currentTarget.dataset.name == 'form.residualsRate' &&e.detail.value<=100){
- this.setData({
- '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,
- })
- this.setData({
- 'form.perYearDepreciationValue' : ((this.data.form.originalValue-this.data.form.netSalvage)/this.data.form.expectedYears).toFixed(2),
- })
- }
- if(e.currentTarget.dataset.name == 'form.residualsRate' &&e.detail.value>100){
- this.setData({
- 'form.residualsRate' : 5,
- })
- }
- if(e.currentTarget.dataset.name == 'form.netSalvage' ){
- this.setData({
- 'form.perYearDepreciationValue' : ((this.data.form.originalValue-e.detail.value)/this.data.form.expectedYears).toFixed(2)
- })
- }
- if(e.currentTarget.dataset.name == 'form.expectedYears' ){
- this.setData({
- 'form.perYearDepreciationValue' : ((this.data.form.originalValue-this.data.form.netSalvage)/e.detail.value).toFixed(2)
- })
- }
- if(e.currentTarget.dataset.name == 'form.depreciationYears' ){
- this.setData({
- '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),
- '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
- })
- }
-
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- if(options.id!=null&&options.id!=""){
- this.setData({id:options.id})
- //获取收入合同状态
- UTIL.httpRequest(API.URL_GET_PERMANENTDETAIL + this.data.id, {method:'GET'}, {
- success: (res) => {
- this.setData({'form':res.data});
- let that = this;
- //获取资产类别
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'asset_type', {method:'GET'}, {
- success: (r) => {
- if(r.data.length>0){
- that.setData({
- assetTypeOptions:r.data,
- })
- r.data.map((rr,ind) => {
- if(rr.dictValue == res.data.assetType){
- that.setData({'assetTypeindex':ind})
- }
- })
- }
- }
- })
- //获取经营属性
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'operation_type', {method:'GET'}, {
- success: (r) => {
- if(r.data.length>0){
- that.setData({
- operationTypeOptions:r.data,
- })
- r.data.map((rr,ind) => {
- if(rr.dictValue == res.data.operationType){
- that.setData({'operationTypeindex':ind})
- }
- })
- }
- }
- })
- //获取增加方式
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'add_type', {method:'GET'}, {
- success: (r) => {
- if(r.data.length>0){
- that.setData({
- addTypeOptions:r.data,
- })
- r.data.map((rr,ind) => {
- if(rr.dictValue == res.data.addType){
- that.setData({'addTypeindex':ind})
- }
- })
- }
- }
- })
- //获取使用情况
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'use_type', {method:'GET'}, {
- success: (r) => {
- if(r.data.length>0){
- that.setData({
- useTypeOptions:r.data,
- })
- r.data.map((rr,ind) => {
- if(rr.dictValue == res.data.useType){
- that.setData({'useTypeindex':ind})
- }
- })
- }
- }
- })
- //获取折旧方式
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'depreciation_type', {method:'GET'}, {
- success: (r) => {
- if(r.data.length>0){
- that.setData({
- depreciationTypeOptions:r.data,
- })
- r.data.map((rr,ind) => {
- if(rr.dictValue == res.data.depreciationType){
- that.setData({'depreciationTypeindex':ind})
- }
- })
- }
- }
- })
- //获取资产状态
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'asset_status', {method:'GET'}, {
- success: (r) => {
- if(r.data.length>0){
- that.setData({
- assetStatusOptions:r.data,
- })
- r.data.map((rr,ind) => {
- if(rr.dictValue == res.data.assetStatus){
- that.setData({'assetStatusindex':ind})
- }
- })
- }
- }
- })
- //获取单位
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'fixed_assets_unit', {method:'GET'}, {
- success: (r) => {
- if(r.data.length>0){
- that.setData({
- unitOptions:r.data,
- })
- r.data.map((rr,ind) => {
- if(rr.dictValue == res.data.unit){
- that.setData({'unitindex':ind})
- }
- })
- }
- }
- })
- //获取系统是否
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'sys_yes_no', {method:'GET'}, {
- success: (r) => {
- if(r.data.length>0){
- that.setData({
- sysYesNoOptions:r.data,
- })
- r.data.map((rr,ind) => {
- if(rr.dictValue == res.data.isMin){
- that.setData({'isMinindex':ind})
- }
- if(rr.dictValue == res.data.isFormAsset){
- that.setData({'isFormAssetindex':ind})
- }
- })
- }
- }
- })
- }
- })
- }else{
- let that = this;
- //获取资产类别
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'asset_type', {method:'GET'}, {
- success: (res) => {
- if(res.data.length>0){
- that.setData({
- assetTypeOptions:res.data,
- 'form.assetType':res.data[0].dictValue
- })
- }
- }
- })
- //获取经营属性
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'operation_type', {method:'GET'}, {
- success: (res) => {
- if(res.data.length>0){
- that.setData({
- operationTypeOptions:res.data,
- 'form.operationType':res.data[0].dictValue
- })
- }
- }
- })
- //获取增加方式
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'add_type', {method:'GET'}, {
- success: (res) => {
- if(res.data.length>0){
- that.setData({
- addTypeOptions:res.data,
- 'form.addType':res.data[0].dictValue
- })
- }
- }
- })
- //获取使用情况
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'use_type', {method:'GET'}, {
- success: (res) => {
- if(res.data.length>0){
- that.setData({
- useTypeOptions:res.data,
- 'form.useType':res.data[0].dictValue
- })
- }
- }
- })
- //获取折旧方式
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'depreciation_type', {method:'GET'}, {
- success: (res) => {
- if(res.data.length>0){
- that.setData({
- depreciationTypeOptions:res.data,
- 'form.depreciationType':res.data[1].dictValue
- })
- }
- }
- })
- //获取资产状态
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'asset_status', {method:'GET'}, {
- success: (res) => {
- if(res.data.length>0){
- that.setData({
- assetStatusOptions:res.data,
- 'form.assetStatus':res.data[0].dictValue
- })
- }
- }
- })
- //获取单位
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'fixed_assets_unit', {method:'GET'}, {
- success: (res) => {
- if(res.data.length>0){
- that.setData({
- unitOptions:res.data,
- 'form.unit':res.data[0].dictValue
- })
- }
- }
- })
- //获取是否
- UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'sys_yes_no', {method:'GET'}, {
- success: (res) => {
- if(res.data.length>0){
- that.setData({
- sysYesNoOptions:res.data,
- 'form.isMin':res.data[0].dictValue,
- 'form.isFormAsset':res.data[0].dictValue
- })
- }
- }
- })
- }
-
- },
-
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- }
- })
|