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

264 lines
6.9 KiB

  1. // pages/project/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. showStartTime:false,
  12. showEndTime:false,
  13. ynProjcetStatusOptions:[],
  14. form:{
  15. },
  16. id:"",
  17. ynProjcetStatusindex:0,
  18. status:0,
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad(options) {
  24. if(options.id!=null&&options.id!=""){
  25. let that = this
  26. this.setData({id:options.id})
  27. UTIL.httpRequest(API.URL_GET_PROJECTGET + this.data.id, {method:'GET'}, {
  28. success: (res) => {
  29. this.setData({'form':res.data})
  30. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'yn_projcet_status', {method:'GET'}, {
  31. success: (r) => {
  32. if(r.data.length>0){
  33. that.setData({
  34. ynProjcetStatusOptions:r.data,
  35. })
  36. r.data.map((rr,ind) => {
  37. if(rr.dictValue == res.data.ynProjcetStatus){
  38. console.log(rr);
  39. that.setData({'form.ynProjcetStatusText':rr.dictLabel})
  40. }
  41. })
  42. }
  43. }
  44. })
  45. }
  46. })
  47. }else{
  48. let that = this
  49. this.setData({
  50. 'form.startTime':this.getNewDate(new Date()),
  51. 'form.endTime':this.getNewDate(new Date())
  52. });
  53. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'yn_projcet_status', {method:'GET'}, {
  54. success: (r) => {
  55. if(r.data.length>0){
  56. that.setData({
  57. ynProjcetStatusOptions:r.data,
  58. 'form.ynProjcetStatus':r.data[0].dictValue
  59. })
  60. }
  61. }
  62. })
  63. }
  64. },
  65. onConfirmStartTime(e){
  66. let data = this.getNewDate(new Date(e.detail.value));
  67. this.setData({'form.startTime':data});
  68. },
  69. onConfirmEndTime(e){
  70. let data = this.getNewDate(new Date(e.detail.value));
  71. this.setData({'form.endTime':data});
  72. },
  73. onConfirmynProjcetStatus (e) {
  74. let obj = e.detail.value;
  75. this.setData({
  76. 'form.ynProjcetStatus':this.data.ynProjcetStatusOptions[obj].dictValue,
  77. 'ynProjcetStatusindex':obj
  78. })
  79. },
  80. getNewDate(date){
  81. //date是传过来的时间戳,注意需为13位,10位需*1000
  82. //也可以不传,获取的就是当前时间
  83. var time
  84. if(date){
  85. time = new Date(date);
  86. }else{
  87. time = new Date();
  88. }
  89. var year= time.getFullYear() //年
  90. var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
  91. var day = ("0" + time.getDate()).slice(-2); //日
  92. var mydate = year + "-" + month + "-" + day;
  93. return mydate
  94. },
  95. back:function(){
  96. wx.navigateBack({
  97. delta: 1
  98. })
  99. },
  100. closeBox(even){
  101. this.setData({
  102. [even.currentTarget.dataset.name]:false
  103. })
  104. },
  105. openBox(even){
  106. this.setData({
  107. [even.currentTarget.dataset.name]:true
  108. })
  109. },
  110. onConfirmTime(event){
  111. this.setData({
  112. [event.currentTarget.dataset.name]: false,
  113. [event.currentTarget.dataset.value]: UTIL.formatDate(event.detail),
  114. });
  115. },
  116. onConfirmYn(event) {
  117. this.setData({
  118. [event.currentTarget.dataset.name]: false,
  119. [event.currentTarget.dataset.value]: event.detail.value.dictValue,
  120. [event.currentTarget.dataset.value+'Text']: event.detail.value.dictLabel,
  121. });
  122. },
  123. goSubmit(){
  124. if(this.data.form.projectName===''||this.data.form.projectName==null){ //项目名称
  125. UTIL.showToastNoneIcon('请填写项目名称!');
  126. return false;
  127. }else if(this.data.form.projectContractor===''||this.data.form.projectContractor==null){ //合同承建方
  128. UTIL.showToastNoneIcon('请输入合同承建方!');
  129. return false;
  130. }else if(this.data.form.startTime===''||this.data.form.startTime==null){ //开工日期
  131. UTIL.showToastNoneIcon('请选择开工日期!');
  132. return false;
  133. }else if(this.data.form.endTime===''||this.data.form.endTime==null){ //竣工日期
  134. UTIL.showToastNoneIcon('请输入竣工日期!');
  135. return false;
  136. }else if(this.data.form.projectAmount === ''||this.data.form.projectAmount==null){//合共价款
  137. UTIL.showToastNoneIcon('请输入合共价款!');
  138. return false;
  139. }else if(this.data.form.ynProjcetStatus === ''||this.data.form.ynProjcetStatus==null){//工程状态
  140. UTIL.showToastNoneIcon('工程状态不能为空!');
  141. return false;
  142. }else if(this.data.status=='0'){
  143. this.setData({'status':1})
  144. var that = this ;
  145. let data = that.data.form;
  146. data.method = 'POST';
  147. if(that.data.form.id==""||that.data.form.id==null){
  148. UTIL.httpRequest(API.URL_GET_PROJECTADD, data, {
  149. success: (res) => {
  150. this.setData({'status':0})
  151. if(res.code == 200){
  152. UTIL.showToastNoneIcon('新增成功');
  153. setTimeout(function(){
  154. wx.navigateBack({
  155. delta:1
  156. })
  157. },2000)
  158. }else{
  159. UTIL.showToastNoneIcon('新增失败:'+res.msg);
  160. }
  161. },
  162. fail: function (response) {
  163. if (typeof fail === FUNCTION_TEXT) {
  164. fail(handleFail(response));
  165. } else {
  166. showToastNoneIcon(API.MSG_FAIL_HTTP);
  167. }
  168. that.setData({'status':0})
  169. },
  170. complete: function (response) {
  171. wx.hideNavigationBarLoading();
  172. }
  173. })
  174. }else{
  175. UTIL.httpRequest(API.URL_POST_PROJECTUPDATE, data, {
  176. success: (res) => {
  177. this.setData({'status':0})
  178. if(res.code == 200){
  179. UTIL.showToastNoneIcon('修改成功');
  180. setTimeout(function(){
  181. wx.navigateBack({
  182. delta:1
  183. })
  184. },2000)
  185. }else{
  186. UTIL.showToastNoneIcon('修改失败:'+res.msg);
  187. }
  188. },
  189. fail: function (response) {
  190. if (typeof fail === FUNCTION_TEXT) {
  191. fail(handleFail(response));
  192. } else {
  193. showToastNoneIcon(API.MSG_FAIL_HTTP);
  194. }
  195. this.setData({'status':0})
  196. },
  197. complete: function (response) {
  198. wx.hideNavigationBarLoading();
  199. }
  200. })
  201. }
  202. }
  203. },
  204. onChange(event){
  205. this.setData({
  206. [event.currentTarget.dataset.value]: event.detail,
  207. })
  208. },
  209. /**
  210. * 生命周期函数--监听页面初次渲染完成
  211. */
  212. onReady() {
  213. },
  214. /**
  215. * 生命周期函数--监听页面显示
  216. */
  217. onShow() {
  218. },
  219. /**
  220. * 生命周期函数--监听页面隐藏
  221. */
  222. onHide() {
  223. },
  224. /**
  225. * 生命周期函数--监听页面卸载
  226. */
  227. onUnload() {
  228. },
  229. /**
  230. * 页面相关事件处理函数--监听用户下拉动作
  231. */
  232. onPullDownRefresh() {
  233. },
  234. /**
  235. * 页面上拉触底事件的处理函数
  236. */
  237. onReachBottom() {
  238. },
  239. /**
  240. * 用户点击右上角分享
  241. */
  242. onShareAppMessage() {
  243. }
  244. })