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.

331 rivejä
8.2 KiB

  1. const config = require('../../config/config.js')
  2. const Http = require('../../utils/HttpBasics.js')
  3. const app = getApp();
  4. Page({
  5. data: {
  6. recentlyList: [],
  7. Switch: true,
  8. todayTimer: '',
  9. todayMoney: '',
  10. money: '',
  11. loading: false,
  12. flag: true,
  13. submitText: '应收0元',
  14. submitDisabled: false,
  15. timeCount: 0,
  16. showDetailIf: false,
  17. discount: null,
  18. message: null,
  19. val: '',
  20. haveData: '',
  21. },
  22. hideKey() {
  23. this.setData({
  24. flag: false
  25. })
  26. },
  27. search() {
  28. this.setData({
  29. flag: true
  30. })
  31. },
  32. countChange(e) {
  33. console.log(e)
  34. let a = [];
  35. a = e.detail.value.split('.');
  36. if (a.length > 1) {
  37. a[1] = a[1].substring(0, 2)
  38. }
  39. this.setData({
  40. val: a.join('.')
  41. })
  42. if (this.data.val.split('.')[0] && Number(this.data.val) > 0.01) {
  43. if (this.data.discountRate != '暂无折扣') {
  44. let submitText = (this.data.val * this.data.discountRate / 10).toFixed(2)
  45. this.setData({
  46. submitText: "应收" + submitText + '元',
  47. money: submitText
  48. })
  49. console.log(this.data.submitText)
  50. } else {
  51. this.setData({
  52. submitText: "应收" + this.data.val + '元',
  53. money: this.data.val
  54. })
  55. }
  56. }
  57. if (this.data.val == 0 || this.data.val == '') {
  58. this.setData({
  59. submitText: "应收0元",
  60. submitDisabled: false
  61. })
  62. }
  63. },
  64. searchDetail() {
  65. wx.redirectTo({
  66. url: '../record/list/index',
  67. })
  68. },
  69. //扫码支付
  70. submit(e) {
  71. let _this = this;
  72. if (_this.data.val.split('.')[0] && Number(_this.data.val) > 0.01 && Number(_this.data.val) <= 10000000) {
  73. wx.scanCode({
  74. onlyFromCamera: true,
  75. success(res) {
  76. let postData = {
  77. authCode: res.result,
  78. totalFee: _this.data.money
  79. }
  80. wx.showLoading({
  81. title: '收款中',
  82. })
  83. if (res.result) {
  84. _this.orderCreate(_this, postData)
  85. } else {
  86. console.log(333)
  87. }
  88. }
  89. })
  90. } else {
  91. wx.showToast({
  92. title: '请输入有效金额',
  93. icon: "none"
  94. })
  95. }
  96. },
  97. // 刷卡支付订单
  98. orderCreate(_this, postData) {
  99. Http.post({
  100. url: config.api.orderCreate,
  101. data: postData
  102. })
  103. .then(res => {
  104. let postData = {
  105. payOrderId: res.data.payOrderId,
  106. orderId: res.data.orderId
  107. }
  108. _this.orderQuery(_this, postData)
  109. })
  110. .catch(err => {
  111. console.log(err);
  112. let postData = {
  113. payOrderId: err.data.payOrderId,
  114. orderId: err.data.orderId
  115. }
  116. if (err.data.err_code == 'USERPAYING') {
  117. console.log(err.data.err_code)
  118. setTimeout(function () {
  119. _this.orderQuery(_this, postData);
  120. // 调用超过三次
  121. _this.setData({
  122. timeCount: _this.data.timeCount + 1
  123. })
  124. }, 3000);
  125. } else if (err.data.err_code == 'SYSTEMERROR' || err.data.err_code == 'BANKERROR') {
  126. setTimeout(function () {
  127. _this.orderQuery(_this, postData);
  128. // 调用超过三次
  129. _this.setData({
  130. timeCount: _this.data.timeCount + 1
  131. })
  132. }, 1000);
  133. } else {
  134. _this.orderReverse(_this, postData)
  135. wx.showModal({
  136. title: '提示',
  137. content: err.message,
  138. showCancel: false
  139. })
  140. }
  141. });
  142. },
  143. // 查询刷卡支付订单
  144. orderQuery(_this, postData) {
  145. Http.post({
  146. url: config.api.orderQuery,
  147. data: postData
  148. })
  149. .then(res => {
  150. console.log(666)
  151. wx.showModal({
  152. title: '支付信息',
  153. content: '付款成功',
  154. showCancel: false,
  155. success: function (res) {
  156. if (res.confirm) {
  157. wx.reLaunch({
  158. url: '/pages/main/main',
  159. })
  160. }
  161. }
  162. })
  163. })
  164. .catch(err => {
  165. console.log(err)
  166. if (err.data.trade_state == 'USERPAYING') {
  167. if (_this.data.timeCount < 10) {
  168. setTimeout(function () {
  169. _this.orderQuery(_this, postData);
  170. // USERPAYING状态下, 且不超过30秒时继续调用查询
  171. _this.setData({
  172. timeCount: _this.data.timeCount + 1
  173. })
  174. }, 3000);
  175. } else {
  176. _this.orderReverse(_this, postData)
  177. }
  178. } else if (err.data.trade_state == 'BANKERROR') {
  179. setTimeout(function () {
  180. _this.orderQuery(_this, postData);
  181. }, 5000)
  182. } else if (err.data.trade_state == 'SYSTEMERROR') {
  183. setTimeout(function () {
  184. _this.orderQuery(_this, postData);
  185. }, 3000);
  186. } else {
  187. _this.orderReverse(_this, postData)
  188. wx.showModal({
  189. title: '提示',
  190. content: err.message,
  191. showCancel: false
  192. })
  193. }
  194. });
  195. },
  196. // 撤销刷卡支付订单
  197. orderReverse(_this, postData) {
  198. wx.hideLoading()
  199. Http.post({
  200. url: config.api.orderReverse,
  201. data: postData
  202. })
  203. .then(res => {
  204. console.log(666)
  205. wx.showModal({
  206. title: '提示',
  207. content: err.message,
  208. showCancel: false,
  209. success: function (res) {
  210. console.log(res);
  211. if (res.cancel) {
  212. console.log("cancle")
  213. //点击取消,默认隐藏弹框
  214. } else {
  215. console.log("yes")
  216. this.setData({
  217. submitText: '扫码收款',
  218. submitDisabled: false,
  219. timeCount: 0,
  220. // loading:true
  221. })
  222. }
  223. },
  224. fail: function (res) {
  225. console.log("fail")
  226. }, //接口调用失败的回调函数
  227. complete: function (res) { }, //接口调用结束的回调函数(调用成功、失败都会执行)
  228. })
  229. })
  230. .catch(err => { });
  231. },
  232. /**
  233. * 生命周期函数--监听页面加载
  234. */
  235. onLoad: function (options) {
  236. console.log(options, 'options')
  237. this.setData({
  238. message: options,
  239. discountRate: options.discountRate
  240. })
  241. },
  242. /**
  243. * 生命周期函数--监听页面显示
  244. */
  245. onShow: function (options) {
  246. let that = this;
  247. app.globalData.userInfo().then(res => {
  248. console.log(res)
  249. that.setData({
  250. userInfo: res
  251. })
  252. if (res && res.merchant_id) {
  253. that.findAccountById(res);
  254. that.findJurisdiction()
  255. }
  256. })
  257. },
  258. /**
  259. * 查询是否有修改账户权限
  260. */
  261. findJurisdiction() {
  262. Http.get({
  263. url: config.api.permitModifiy,
  264. }).then(res => {
  265. console.log(res)
  266. /**
  267. * data:true
  268. * 如有:显示
  269. * 没有;不显示
  270. */
  271. if (res && res.data == true) {
  272. this.setData({
  273. haveData: true,
  274. })
  275. } else {
  276. this.setData({
  277. haveData: false,
  278. })
  279. }
  280. }).catch(error => {
  281. console.log(error)
  282. })
  283. },
  284. /**
  285. * 查询收款账户状态
  286. */
  287. findAccountById(response) {
  288. let that = this;
  289. Http.get({
  290. url: config.api.findAccountById,
  291. data: {
  292. id: response.merchant_id
  293. }
  294. }).then(res => {
  295. /**
  296. * receiverAccount
  297. * 如有:已设置收款账户
  298. * 没有;未设置收款账户
  299. */
  300. if (res && res.data && res.data.receiver) {
  301. that.setData({
  302. receiverAccount: res.data.receiver.receiverAccount
  303. })
  304. } else {
  305. wx.showModal({
  306. title: '提醒',
  307. content: '您暂未配置收款账户,请配置',
  308. showCancel: false,
  309. success: function (res) {
  310. if (res.confirm) {
  311. if (that.data.haveData == true) {
  312. wx.navigateTo({
  313. url: `/pages/accountManagement/index?merchant_id=${response.merchant_id}&merchant_name=${response.merchant_name}`,
  314. })
  315. } else {
  316. wx.switchTab({
  317. url: '/pages/main/main',
  318. })
  319. }
  320. }
  321. }
  322. })
  323. }
  324. }).catch(error => {
  325. console.log(error)
  326. })
  327. }
  328. })