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

add.js 16 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  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. },
  19. assetTypeindex:'0',
  20. settleTypeindex:'0',
  21. collectionPayindex:'0',
  22. contractionSourceindex:'0',
  23. contractionStatusindex:'0',
  24. biddingWayindex:'0',
  25. biddingTypeindex:'0',
  26. showBiddingDate:false,
  27. minDate: new Date(2008, 5, 1).getTime(),
  28. maxDate: new Date(2040, 0, 31).getTime(),
  29. // 合同类型字典
  30. assetTypeOptions: [],
  31. // 结款方式字典
  32. settleTypeOptions: [],
  33. // 收付款类型字典
  34. collectionPayOptions: [],
  35. // 合同来源字典
  36. contractionSourceOptions: [],
  37. // 合同状态字典
  38. contractionStatusOptions: [],
  39. // 招标方式字典
  40. biddingWayOptions: [],
  41. // 招标类型字典
  42. biddingTypeOptions: [],
  43. status:0,
  44. },
  45. back:function(){
  46. wx.navigateBack({
  47. delta: 1
  48. })
  49. },
  50. openBox(even){
  51. this.setData({
  52. [even.currentTarget.dataset.name]:true
  53. })
  54. },
  55. onChange(event){
  56. this.setData({
  57. [event.currentTarget.dataset.formname]: event.detail,
  58. })
  59. },
  60. closeBox(even){
  61. this.setData({
  62. [even.currentTarget.dataset.name]:false
  63. })
  64. },
  65. onConfirmBiddingDate(e){
  66. let data = this.getNewDate(new Date(e.detail.value));
  67. this.setData({'form.biddingDate':data});
  68. },
  69. onConfirmReviewTime(e){
  70. let data = this.getNewDate(new Date(e.detail.value));
  71. this.setData({'form.reviewTime':data});
  72. },
  73. onConfirmBuildingTime(e){
  74. let data = this.getNewDate(new Date(e.detail.value));
  75. this.setData({'form.buildingTime':data});
  76. },
  77. onConfirmStartTime(e){
  78. let data = this.getNewDate(new Date(e.detail.value));
  79. this.setData({'form.startTime':data});
  80. },
  81. onConfirmEndTime(e){
  82. let data = this.getNewDate(new Date(e.detail.value));
  83. this.setData({'form.endTime':data});
  84. },
  85. onConfirmbiddingType (e) {
  86. let obj = e.detail.value;
  87. this.setData({
  88. 'form.biddingType':this.data.biddingTypeOptions[obj].dictValue,
  89. 'biddingTypeindex':obj
  90. })
  91. },
  92. onConfirmShowBiddingWay (e) {
  93. let obj = e.detail.value;
  94. this.setData({
  95. 'form.biddingWay':this.data.biddingWayOptions[obj].dictValue,
  96. 'biddingWayindex':obj
  97. })
  98. },
  99. onConfirmSettleType (e) {
  100. let obj = e.detail.value;
  101. this.setData({
  102. 'form.settleType':this.data.settleTypeOptions[obj].dictValue,
  103. 'settleTypeindex':obj
  104. })
  105. },
  106. onConfirmCollectionPay (e) {
  107. let obj = e.detail.value;
  108. this.setData({
  109. 'form.collectionPay':this.data.collectionPayOptions[obj].dictValue,
  110. 'collectionPayindex':obj
  111. })
  112. },
  113. onConfirmContractionSource (e) {
  114. let obj = e.detail.value;
  115. this.setData({
  116. 'form.contractionSource':this.data.contractionSourceOptions[obj].dictValue,
  117. 'contractionSourceindex':obj
  118. })
  119. },
  120. onConfirmAssetType (e) {
  121. let obj = e.detail.value;
  122. this.setData({
  123. 'form.assetType':this.data.assetTypeOptions[obj].dictValue,
  124. 'assetTypeindex':obj
  125. })
  126. },
  127. onConfirmContractionStatus (e) {
  128. let obj = e.detail.value;
  129. this.setData({
  130. 'form.contractionStatus':this.data.contractionStatusOptions[obj].dictValue,
  131. 'contractionStatusindex':obj
  132. })
  133. },
  134. onConfirmBiddingWay (e) {
  135. let obj = e.detail.value;
  136. this.setData({
  137. 'form.biddingWay':this.data.biddingWayOptions[obj].dictValue,
  138. 'biddingWayindex':obj
  139. })
  140. },
  141. getNewDate(date){
  142. //date是传过来的时间戳,注意需为13位,10位需*1000
  143. //也可以不传,获取的就是当前时间
  144. var time
  145. if(date){
  146. time = new Date(date);
  147. }else{
  148. time = new Date();
  149. }
  150. var year= time.getFullYear() //年
  151. var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
  152. var day = ("0" + time.getDate()).slice(-2); //日
  153. var mydate = year + "-" + month + "-" + day;
  154. return mydate
  155. },
  156. goSubmit:function(){
  157. if(this.data.form.code===''||this.data.form.code==null){ //合同编码
  158. UTIL.showToastNoneIcon('请填写合同编码!');
  159. return false;
  160. }else if(this.data.form.name===''||this.data.form.name==null){ //合同名称
  161. UTIL.showToastNoneIcon('请输入合同名称!');
  162. return false;
  163. }else if(this.data.form.firstParty===''||this.data.form.firstParty==null){ //甲方
  164. UTIL.showToastNoneIcon('请输入单据编码!');
  165. return false;
  166. }else if(this.data.form.secondParty===''||this.data.form.secondParty==null){ //乙方
  167. UTIL.showToastNoneIcon('请输入备注说明!');
  168. return false;
  169. }else if(this.data.form.collectionPay === ''||this.data.form.collectionPay==null){//收付款类型
  170. UTIL.showToastNoneIcon('收付款类型不能为空!');
  171. return false;
  172. }else if(this.data.form.contractionSource === ''||this.data.form.contractionSource==null){//合同来源
  173. UTIL.showToastNoneIcon('合同来源不能为空!');
  174. return false;
  175. }else if(this.data.form.totalAmount === ''||this.data.form.totalAmount==null){//合同金额
  176. UTIL.showToastNoneIcon('合同金额不能为空!');
  177. return false;
  178. }else if(this.data.form.buildingTime === ''||this.data.form.buildingTime==null){//签订日期
  179. UTIL.showToastNoneIcon('合同金额不能为空!');
  180. return false;
  181. }else if(this.data.form.startTime === ''||this.data.form.startTime==null){//开始日期
  182. UTIL.showToastNoneIcon('开始日期不能为空!');
  183. return false;
  184. }else if(this.data.form.endTime === ''||this.data.form.endTime==null){//结束日期
  185. UTIL.showToastNoneIcon('结束日期不能为空!');
  186. return false;
  187. }else if(this.data.form.price === ''||this.data.form.price==null){//单价
  188. UTIL.showToastNoneIcon('单价不能为空!');
  189. return false;
  190. }else if(this.data.form.receivedAmount === ''||this.data.form.receivedAmount==null){//已结款
  191. UTIL.showToastNoneIcon('已结款不能为空!');
  192. return false;
  193. }else if(this.data.form.contractionStatus === ''||this.data.form.contractionStatus==null){//合同状态
  194. UTIL.showToastNoneIcon('单价不能为空!');
  195. return false;
  196. }else if(this.data.status=='0'){
  197. this.setData({'status':1})
  198. if(this.data.form.id!=null&&this.data.form.id!=""){
  199. let data = this.data.form;
  200. data.method = "POST";
  201. UTIL.httpRequest(API.URL_POST_CONTRACTUPDATE,data,{
  202. success: (res) => {
  203. if(res.code == 200){
  204. UTIL.showToastNoneIcon('修改成功');
  205. setTimeout(function(){
  206. wx.navigateBack({
  207. delta:1
  208. })
  209. },2000)
  210. }else{
  211. UTIL.showToastNoneIcon('修改失败');
  212. }
  213. },
  214. fail: function (response) {
  215. if (typeof fail === FUNCTION_TEXT) {
  216. fail(handleFail(response));
  217. } else {
  218. showToastNoneIcon(API.MSG_FAIL_HTTP);
  219. }
  220. this.setData({'status':0})
  221. },
  222. complete: function (response) {
  223. this.setData({'status':0})
  224. wx.hideNavigationBarLoading();
  225. }
  226. })
  227. }else{
  228. let data = this.data.form;
  229. data.method = "POST";
  230. UTIL.httpRequest(API.URL_POST_CONTRACTADD,data,{
  231. success: (res) => {
  232. if(res.code == 200){
  233. UTIL.showToastNoneIcon('新增成功');
  234. setTimeout(function(){
  235. wx.navigateBack({
  236. delta:1
  237. })
  238. },2000)
  239. }else{
  240. UTIL.showToastNoneIcon('新增失败');
  241. }
  242. },
  243. fail: function (response) {
  244. if (typeof fail === FUNCTION_TEXT) {
  245. fail(handleFail(response));
  246. } else {
  247. showToastNoneIcon(API.MSG_FAIL_HTTP);
  248. }
  249. this.setData({'status':0})
  250. },
  251. complete: function (response) {
  252. this.setData({'status':0})
  253. wx.hideNavigationBarLoading();
  254. }
  255. })
  256. }
  257. }
  258. },
  259. bindNewInput: function (e) {
  260. this.setData({
  261. [e.currentTarget.dataset.name]: e.detail.value
  262. })
  263. },
  264. /**
  265. * 生命周期函数--监听页面加载
  266. */
  267. onLoad(options) {
  268. if(options.id!=null&&options.id!=""){
  269. this.setData({id:options.id})
  270. //获取收入合同状态
  271. UTIL.httpRequest(API.URL_GET_CONTRACTDETAIL + this.data.id, {method:'GET'}, {
  272. success: (res) => {
  273. this.setData({'form':res.data});
  274. let that = this;
  275. //获取收入合同状态
  276. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'type_of_contract', {method:'GET'}, {
  277. success: (r) => {
  278. if(r.data.length>0){
  279. that.setData({
  280. assetTypeOptions:r.data,
  281. })
  282. r.data.map((rr,ind) => {
  283. if(rr.dictValue == res.data.assetType){
  284. that.setData({'assetTypeindex':ind})
  285. }
  286. })
  287. }
  288. }
  289. })
  290. //获取收入合同来源
  291. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'contraction_source', {method:'GET'}, {
  292. success: (r) => {
  293. if(r.data.length>0){
  294. that.setData({
  295. contractionSourceOptions:r.data,
  296. })
  297. r.data.map((rr,ind) => {
  298. if(rr.dictValue == res.data.contractionSource){
  299. that.setData({'contractionSourceindex':ind})
  300. }
  301. })
  302. }
  303. }
  304. })
  305. //获取收入收付款类型
  306. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'collection_pay', {method:'GET'}, {
  307. success: (r) => {
  308. if(r.data.length>0){
  309. that.setData({
  310. collectionPayOptions:r.data,
  311. })
  312. r.data.map((rr,ind) => {
  313. if(rr.dictValue == res.data.collectionPay){
  314. that.setData({'collectionPayindex':ind})
  315. }
  316. })
  317. }
  318. }
  319. })
  320. //获取收入结款方式
  321. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'settle_type', {method:'GET'}, {
  322. success: (r) => {
  323. if(r.data.length>0){
  324. that.setData({
  325. settleTypeOptions:r.data,
  326. })
  327. r.data.map((rr,ind) => {
  328. if(rr.dictValue == res.data.settleType){
  329. that.setData({'settleTypeindex':ind})
  330. }
  331. })
  332. }
  333. }
  334. })
  335. //获取收入合同状态
  336. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'contraction_status', {method:'GET'}, {
  337. success: (r) => {
  338. if(r.data.length>0){
  339. that.setData({
  340. contractionStatusOptions:r.data,
  341. })
  342. r.data.map((rr,ind) => {
  343. if(rr.dictValue == res.data.contractionStatus){
  344. that.setData({'contractionStatusindex':ind})
  345. }
  346. })
  347. }
  348. }
  349. })
  350. //获取收入招标方式
  351. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'bidding_way', {method:'GET'}, {
  352. success: (r) => {
  353. if(r.data.length>0){
  354. that.setData({
  355. biddingWayOptions:r.data,
  356. })
  357. r.data.map((rr,ind) => {
  358. if(rr.dictValue == res.data.biddingWay){
  359. that.setData({'biddingWayindex':ind})
  360. }
  361. })
  362. }
  363. }
  364. })
  365. //获取收入招标类型
  366. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'bidding_types', {method:'GET'}, {
  367. success: (r) => {
  368. if(r.data.length>0){
  369. that.setData({
  370. biddingTypeOptions:r.data,
  371. })
  372. r.data.map((rr,ind) => {
  373. if(rr.dictValue == res.data.biddingType){
  374. that.setData({'biddingTypeindex':ind})
  375. }
  376. })
  377. }
  378. }
  379. })
  380. }
  381. })
  382. }else{
  383. let that = this;
  384. this.setData({
  385. 'form.reviewTime':this.getNewDate(),
  386. 'form.buildingTime':this.getNewDate(),
  387. 'form.startTime':this.getNewDate(),
  388. 'form.endTime':this.getNewDate(),
  389. 'form.biddingDate':this.getNewDate(),
  390. })
  391. //获取收入合同状态
  392. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'type_of_contract', {method:'GET'}, {
  393. success: (res) => {
  394. if(res.data.length>0){
  395. that.setData({
  396. assetTypeOptions:res.data,
  397. 'form.assetType':res.data[0].dictValue
  398. })
  399. }
  400. }
  401. })
  402. //获取收入合同来源
  403. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'contraction_source', {method:'GET'}, {
  404. success: (res) => {
  405. if(res.data.length>0){
  406. that.setData({
  407. contractionSourceOptions:res.data,
  408. 'form.contractionSource':res.data[0].dictValue
  409. })
  410. }
  411. }
  412. })
  413. //获取收入收付款类型
  414. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'collection_pay', {method:'GET'}, {
  415. success: (res) => {
  416. if(res.data.length>0){
  417. that.setData({
  418. collectionPayOptions:res.data,
  419. 'form.collectionPay':res.data[0].dictValue
  420. })
  421. }
  422. }
  423. })
  424. //获取收入结款方式
  425. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'settle_type', {method:'GET'}, {
  426. success: (res) => {
  427. if(res.data.length>0){
  428. that.setData({
  429. settleTypeOptions:res.data,
  430. 'form.settleType':res.data[0].dictValue
  431. })
  432. }
  433. }
  434. })
  435. //获取收入合同状态
  436. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'contraction_status', {method:'GET'}, {
  437. success: (res) => {
  438. if(res.data.length>0){
  439. that.setData({
  440. contractionStatusOptions:res.data,
  441. 'form.contractionStatus':res.data[0].dictValue
  442. })
  443. }
  444. }
  445. })
  446. //获取收入招标方式
  447. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'bidding_way', {method:'GET'}, {
  448. success: (res) => {
  449. if(res.data.length>0){
  450. that.setData({
  451. biddingWayOptions:res.data,
  452. 'form.biddingWay':res.data[0].dictValue
  453. })
  454. }
  455. }
  456. })
  457. //获取收入招标类型
  458. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'bidding_types', {method:'GET'}, {
  459. success: (res) => {
  460. if(res.data.length>0){
  461. that.setData({
  462. biddingTypeOptions:res.data,
  463. 'form.biddingType':res.data[0].dictValue
  464. })
  465. }
  466. }
  467. })
  468. }
  469. },
  470. /**
  471. * 生命周期函数--监听页面初次渲染完成
  472. */
  473. onReady() {
  474. },
  475. /**
  476. * 生命周期函数--监听页面显示
  477. */
  478. onShow() {
  479. },
  480. /**
  481. * 生命周期函数--监听页面隐藏
  482. */
  483. onHide() {
  484. },
  485. /**
  486. * 生命周期函数--监听页面卸载
  487. */
  488. onUnload() {
  489. },
  490. /**
  491. * 页面相关事件处理函数--监听用户下拉动作
  492. */
  493. onPullDownRefresh() {
  494. },
  495. /**
  496. * 页面上拉触底事件的处理函数
  497. */
  498. onReachBottom() {
  499. },
  500. /**
  501. * 用户点击右上角分享
  502. */
  503. onShareAppMessage() {
  504. }
  505. })