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.

271 lines
6.9 KiB

  1. const config = require('../../../../config/config.js')
  2. const Http = require('../../../../utils/http.js')
  3. const until = require('../../../../utils/util')
  4. const app = getApp();
  5. Page({
  6. data: {
  7. Switch: true,
  8. todayTimer: '',
  9. tradeAmt: '',
  10. money: '',
  11. flag: false,
  12. val: '',
  13. disabled: false,
  14. dateMark: 'day',
  15. dateType: 1
  16. },
  17. search() {
  18. this.setData({
  19. flag: true
  20. })
  21. },
  22. // 选择时间
  23. bindDateChange(e) {
  24. let that = this;
  25. that.setData({
  26. date: e.detail.value,
  27. reportDateX: e.detail.value
  28. })
  29. const timeArr = this.data.reportDateX.split('-')
  30. // 按日解单
  31. if (this.data.dateMark == 'day' && timeArr.length == 3) {
  32. const reportDate = timeArr[0] + "-" + timeArr[1] + "-" + timeArr[2]
  33. this.setData({
  34. reportDate: reportDate,
  35. dateType: 1
  36. })
  37. // 按月解单
  38. } else if (this.data.dateMark == 'month') {
  39. const reportDate = timeArr[0] + "-" + timeArr[1]
  40. this.setData({
  41. reportDate: reportDate,
  42. dateType: 2
  43. })
  44. } else if (this.data.dateMark == 'day' && timeArr.length == 2) {
  45. this.setData({
  46. reportDate: '',
  47. dateType: 1
  48. })
  49. }
  50. that.getList(e.detail.value)
  51. },
  52. //获取今日解单
  53. getList(reportDate) {
  54. Http.getRequest(config.api.getVolume, app.globalData.token, '获取解单', {
  55. reportDate: reportDate
  56. }, (res) => {
  57. if (res.code == 200) {
  58. //提交的情况
  59. this.setData({
  60. Switch: false,
  61. flag: true
  62. })
  63. } else {
  64. this.setData({
  65. Switch: true,
  66. flag: true
  67. })
  68. }
  69. })
  70. },
  71. subList(e) {
  72. this.setData({
  73. disabled: true
  74. })
  75. let reg = /(^[1-9]\d*(\.\d{1,2})?$)|(^0(\.\d{1,2})?$)/;
  76. let tradeAmt = e.detail.value.tradeAmt ? e.detail.value.tradeAmt : "";
  77. if (reg.test(tradeAmt) && tradeAmt <= 1000000) {
  78. let flag = this.data.flag;
  79. let parmers;
  80. let url
  81. if (flag) {
  82. url = config.api.reportDailyVolume
  83. parmers = {
  84. reportDate: this.data.reportDate,
  85. tradeAmt: tradeAmt * 100,
  86. dateType: this.data.dateType,
  87. tradeCount: e.detail.value.tradeCount ? parseInt(e.detail.value.tradeCount) : null,
  88. proof: this.data.receiptUrl ? this.data.receiptUrl : null,
  89. }
  90. if (!parmers.reportDate) {
  91. wx.showToast({
  92. title: '请选择时间',
  93. icon: "none"
  94. })
  95. this.setData({
  96. disabled: false
  97. })
  98. return;
  99. }
  100. } else {
  101. url = config.api.updateDailyVolume
  102. parmers = {
  103. id: this.data.id,
  104. tradeAmt: tradeAmt * 100,
  105. tradeCount: e.detail.value.tradeCount ? parseInt(e.detail.value.tradeCount) : null,
  106. reportDate: this.data.reportDate,
  107. dateType: this.data.dateType,
  108. proof: this.data.receiptUrl ? this.data.receiptUrl : null,
  109. }
  110. }
  111. Http.postRequest(url, app.globalData.token, '解单中', parmers, (res) => {
  112. this.setData({
  113. disabled: false
  114. })
  115. if (res.code == 200) {
  116. wx.redirectTo({
  117. url: `/pages/main/solution/success/success?money=${tradeAmt * 100}`,
  118. })
  119. } else {
  120. // wx.redirectTo({
  121. // url: '/pages/main/solution/fail/fail',
  122. // })
  123. wx.showToast({
  124. title: res.message,
  125. icon: 'none',
  126. duration: 5000
  127. })
  128. return
  129. }
  130. })
  131. } else {
  132. this.setData({
  133. disabled: false
  134. })
  135. if (tradeAmt > 1000000) {
  136. wx.showToast({
  137. title: '您输入的解单金额不能大于100万元',
  138. icon: "none"
  139. })
  140. } else {
  141. wx.showToast({
  142. title: '金额限制为最多两位小数',
  143. icon: "none"
  144. })
  145. }
  146. }
  147. },
  148. changeDateType(e) {
  149. console.log(e.currentTarget.dataset.id);
  150. this.setData({
  151. dateMark: e.currentTarget.dataset.id
  152. })
  153. if (!this.data.reportDateX) return
  154. const timeArr = this.data.reportDateX.split('-')
  155. console.log(timeArr, 'timeArr');
  156. // 按日解单
  157. if (this.data.dateMark == 'day' && timeArr.length == 3) {
  158. const reportDate = timeArr[0] + "-" + timeArr[1] + "-" + timeArr[2]
  159. this.setData({
  160. reportDate: reportDate,
  161. dateType: 1
  162. })
  163. // 按月解单
  164. } else if (this.data.dateMark == 'month') {
  165. const reportDate = timeArr[0] + "-" + timeArr[1]
  166. this.setData({
  167. reportDate: reportDate,
  168. dateType: 2
  169. })
  170. } else if (this.data.dateMark == 'day' && timeArr.length == 2) {
  171. this.setData({
  172. reportDate: '',
  173. dateType: 1
  174. })
  175. }
  176. console.log(this.data.reportDate, 'reportDate');
  177. },
  178. onShow() {
  179. let myDate = new Date();
  180. var year = myDate.getFullYear();
  181. var month = myDate.getMonth() + 1;
  182. let day = myDate.getDate();
  183. let zero = month >= 10 ? '' : 0;
  184. this.setData({
  185. nowDateTime: year + '-' + zero + month + '-' + day
  186. })
  187. },
  188. uploadImg() {
  189. let that = this;
  190. wx.chooseImage({
  191. success(res) {
  192. const tempFilePaths = res.tempFilePaths
  193. wx.uploadFile({
  194. url: config.api.imgUpload,
  195. filePath: tempFilePaths[0],
  196. name: 'file',
  197. header: {
  198. 'token': app.globalData.token
  199. },
  200. success(res) {
  201. if (res.statusCode == 200) {
  202. that.setData({
  203. receiptUrl: JSON.parse(res.data).data.url
  204. })
  205. } else if (res.statusCode == 413) {
  206. wx.showToast({
  207. title: '上传的图片太大,请重新上传',
  208. icon: "none"
  209. })
  210. } else {
  211. wx.showToast({
  212. title: '请上传正确的图片',
  213. icon: "none"
  214. })
  215. }
  216. },
  217. fail(error) {
  218. console.log(error);
  219. }
  220. })
  221. }
  222. })
  223. },
  224. onLoad(options) {
  225. let that = this;
  226. console.log(options, 'options');
  227. if (options && options.reportDate) {
  228. that.setData({
  229. reportDate: options.reportDate,
  230. reportDateX: options.reportDate
  231. })
  232. }
  233. if (options && options.id) {
  234. that.setData({
  235. id: options.id
  236. })
  237. that.wxMerchantTradeDailyfindById(options.id);
  238. }
  239. if (options && options.flag) {
  240. that.setData({
  241. flag: options.flag
  242. })
  243. wx.setNavigationBarTitle({
  244. title: '补单'
  245. })
  246. } else {
  247. wx.setNavigationBarTitle({
  248. title: '编辑'
  249. })
  250. }
  251. },
  252. // //解单详情
  253. wxMerchantTradeDailyfindById(id) {
  254. Http.getRequest(config.api.wxMerchantTradeDailyfindById, app.globalData.token, '解单中', {
  255. id: id
  256. }, (res) => {
  257. if (res && res.data) {
  258. this.setData({
  259. detail: res.data,
  260. tradeAmt: res.data.tradeAmt,
  261. tradeCount: res.data.tradeCount,
  262. })
  263. }
  264. })
  265. }
  266. })