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

275 line
7.6 KiB

  1. // pages/bankDraft/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. showOrderType:false,
  12. showOrderStatus:false,
  13. form:{
  14. orderNum: "", //汇票号码 必填
  15. orderType: "", //汇票类型 必填
  16. orderAmount: "",//汇票金额 必填
  17. billPayUnit: "", //付票单位 必填
  18. billReceiveUnit: "", // 收票单位 必填
  19. startTime: "2020-01-01", //开票日期 必填
  20. endTime: "2020-01-01", //到期日期 必填
  21. orderStatus: "", //汇票状态 必填 1在库 2转付中 3转付 4承兑
  22. remark: "",
  23. },
  24. orderStatusOptions:[],
  25. orderTypeOptions:[],
  26. showBtn:true,
  27. showStartTime:false,
  28. showEndTime:false,
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad(options) {
  34. if(options.id!=null&&options.id!=""){
  35. let that = this
  36. this.setData({id:options.id})
  37. UTIL.httpRequest(API.URL_GET_MONEYORDERDETAIL + this.data.id, {method:'GET'}, {
  38. success: (res) => {
  39. if(res.data.orderStatus!='1'){
  40. this.setData({'showBtn':false});
  41. }
  42. //汇票类型
  43. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'order_type', {method:'GET'}, {
  44. success: (rr) => {
  45. this.setData({
  46. orderTypeOptions:rr.data
  47. });
  48. this.data.orderTypeOptions.map(r => {
  49. if(r.dictValue == res.data.orderType){
  50. res.data.orderTypeText = r.dictLabel
  51. that.setData({'form':res.data});
  52. }
  53. })
  54. }
  55. })
  56. //汇票状态
  57. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'order_status', {method:'GET'}, {
  58. success: (rr) => {
  59. this.setData({
  60. orderStatusOptions:rr.data
  61. });
  62. this.data.orderStatusOptions.map(r => {
  63. if(r.dictValue == res.data.orderStatus){
  64. res.data.orderStatusText = r.dictLabel
  65. that.setData({'form':res.data});
  66. }
  67. })
  68. }
  69. })
  70. }
  71. })
  72. }else{
  73. this.onShow()
  74. }
  75. },
  76. onConfirmStartTime(e){
  77. let data = this.getNewDate(new Date(e.detail.value));
  78. this.setData({'form.startTime':data});
  79. },
  80. onConfirmEndTime(e){
  81. let data = this.getNewDate(new Date(e.detail.value));
  82. this.setData({'form.endTime':data});
  83. },
  84. getNewDate(date){
  85. //date是传过来的时间戳,注意需为13位,10位需*1000
  86. //也可以不传,获取的就是当前时间
  87. var time
  88. if(date){
  89. time = new Date(date);
  90. }else{
  91. time = new Date();
  92. }
  93. var year= time.getFullYear() //年
  94. var month = ("0" + (time.getMonth() + 1)).slice(-2); //月
  95. var day = ("0" + time.getDate()).slice(-2); //日
  96. var mydate = year + "-" + month + "-" + day;
  97. return mydate
  98. },
  99. /**
  100. * 生命周期函数--监听页面初次渲染完成
  101. */
  102. onReady() {
  103. },
  104. /**
  105. * 生命周期函数--监听页面显示
  106. */
  107. onShow() {
  108. //汇票类型
  109. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'order_type', {method:'GET'}, {
  110. success: (res) => {
  111. this.setData({
  112. orderTypeOptions:res.data
  113. });
  114. }
  115. })
  116. //汇票状态
  117. UTIL.httpRequest(API.URL_GET_GETDICTTYPE + 'order_status', {method:'GET'}, {
  118. success: (res) => {
  119. this.setData({
  120. orderStatusOptions:res.data
  121. });
  122. }
  123. })
  124. },
  125. openBox(even){
  126. console.log(even.currentTarget.dataset.name);
  127. this.setData({
  128. [even.currentTarget.dataset.name]:true
  129. })
  130. },
  131. onChange(event){
  132. console.log(event);
  133. this.setData({
  134. [event.currentTarget.dataset.value]: event.detail,
  135. })
  136. },
  137. closeBox(even){
  138. console.log(even.currentTarget.dataset.name);
  139. this.setData({
  140. [even.currentTarget.dataset.name]:false
  141. })
  142. },
  143. onConfirmOrderType(event) {
  144. this.setData({
  145. [event.currentTarget.dataset.name]: false,
  146. [event.currentTarget.dataset.value]: event.detail.value.dictValue,
  147. [event.currentTarget.dataset.value+'Text']: event.detail.value.dictLabel,
  148. });
  149. },
  150. goSubmit(){
  151. if(this.data.form.orderNum===''||this.data.form.orderNum==null){ //汇票号码
  152. UTIL.showToastNoneIcon('请填写汇票号码!');
  153. return false;
  154. }else if(this.data.form.orderType===''||this.data.form.orderType==null){ //汇票类型
  155. UTIL.showToastNoneIcon('汇票类型不能为空!');
  156. return false;
  157. }else if(this.data.form.orderAmount===''||this.data.form.orderAmount==null){ //出票金额
  158. UTIL.showToastNoneIcon('请输入出票金额!');
  159. return false;
  160. }else if(this.data.form.billPayUnit===''||this.data.form.billPayUnit==null){ //付飘单位
  161. UTIL.showToastNoneIcon('请输入付飘单位!');
  162. return false;
  163. }else if(this.data.form.billReceiveUnit === ''||this.data.form.billReceiveUnit==null){//收票单位
  164. UTIL.showToastNoneIcon('请输入收票单位!');
  165. return false;
  166. }else if(this.data.form.startTime === ''||this.data.form.startTime==null){//开票日期
  167. UTIL.showToastNoneIcon('请输入开票日期!');
  168. return false;
  169. }else if(this.data.form.endTime === ''||this.data.form.endTime==null){//到期日期
  170. UTIL.showToastNoneIcon('请输入到期日期!');
  171. return false;
  172. }else if(this.data.form.orderStatus === ''||this.data.form.orderStatus==null){//联行号
  173. UTIL.showToastNoneIcon('汇票状态不能为空!');
  174. return false;
  175. }else if(this.data.form.orderStatus === ''||this.data.form.orderStatus==null){//联行号
  176. UTIL.showToastNoneIcon('汇票状态不能为空!');
  177. return false;
  178. }else{
  179. var that = this;
  180. that.data.form.method = 'POST';
  181. if(that.data.form.id==""||that.data.form.id==null){
  182. UTIL.httpRequest(API.URL_POST_MONEYORDERADD, that.data.form , {
  183. success: (res) => {
  184. wx.showToast({
  185. title: '新增成功',
  186. icon: 'success',
  187. duration: 2000,
  188. complete(){
  189. setTimeout(function(){
  190. that.back();
  191. },2000)
  192. }
  193. })
  194. }
  195. })
  196. }else{
  197. UTIL.httpRequest(API.URL_POST_MONEYORDERUPDATE, that.data.form , {
  198. success: (res) => {
  199. wx.showToast({
  200. title: '修改成功',
  201. icon: 'success',
  202. duration: 2000,
  203. complete(){
  204. setTimeout(function(){
  205. that.back();
  206. },2000)
  207. }
  208. })
  209. }
  210. })
  211. }
  212. }
  213. },
  214. onConfirmTime(event){
  215. this.setData({
  216. [event.currentTarget.dataset.name]: false,
  217. [event.currentTarget.dataset.value]: UTIL.formatDate(event.detail),
  218. });
  219. },
  220. openBox(even){
  221. console.log(even.currentTarget.dataset.name);
  222. this.setData({
  223. [even.currentTarget.dataset.name]:true
  224. })
  225. },
  226. closeBox(even){
  227. console.log(even.currentTarget.dataset.name);
  228. this.setData({
  229. [even.currentTarget.dataset.name]:false
  230. })
  231. },
  232. back:function(){
  233. wx.navigateBack({
  234. delta: 1
  235. })
  236. },
  237. /**
  238. * 生命周期函数--监听页面隐藏
  239. */
  240. onHide() {
  241. },
  242. /**
  243. * 生命周期函数--监听页面卸载
  244. */
  245. onUnload() {
  246. },
  247. /**
  248. * 页面相关事件处理函数--监听用户下拉动作
  249. */
  250. onPullDownRefresh() {
  251. },
  252. /**
  253. * 页面上拉触底事件的处理函数
  254. */
  255. onReachBottom() {
  256. },
  257. /**
  258. * 用户点击右上角分享
  259. */
  260. onShareAppMessage() {
  261. }
  262. })