C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

242 rader
5.9 KiB

  1. const util = require("../../utils/util.js");
  2. const config = require("../../config/config.js");
  3. const Http = require("../../utils/HttpBasics");
  4. const AUTH_MODE = 'fingerPrint';
  5. let app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. merChant: {},
  12. focus: true,
  13. inputValue: '',
  14. cardList: [],
  15. arrays: [],
  16. showModel: false,
  17. ids: ""
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function(options) {
  23. let that = this;
  24. that.setData({
  25. merChant: JSON.parse(options.merChant),
  26. cardid: options.cardid,
  27. cardids: options.cardid,
  28. remainingAmount: options.remainingAmount,
  29. remainingAmounts: options.remainingAmount,
  30. })
  31. },
  32. bindKeyInput(e) {
  33. console.log(e)
  34. this.setData({
  35. inputValue: e.detail.value
  36. })
  37. },
  38. suretoPay: function(e) {
  39. let that = this;
  40. if (e.currentTarget.dataset.sure == 'sure' && that.data.checked) {
  41. wx.showLoading({
  42. title: '加载中...',
  43. })
  44. that.gotoPayMoney();
  45. } else {
  46. wx.showModal({
  47. title: '提醒',
  48. content: '请选择消费卡',
  49. showCancel: false
  50. })
  51. }
  52. },
  53. gotoPayMoney: function() {
  54. let that = this;
  55. const startSoterAuthentication = () => {
  56. wx.startSoterAuthentication({
  57. requestAuthModes: [AUTH_MODE],
  58. challenge: 'test',
  59. authContent: '请验证已有的指纹以继续',
  60. success: (res) => {
  61. that.gotoPay()
  62. },
  63. fail: (err) => {
  64. wx.hideLoading();
  65. that.setData({
  66. showModel: false,
  67. cardid: that.data.cardids,
  68. ids: "",
  69. remainingAmount: that.data.remainingAmounts
  70. })
  71. }
  72. })
  73. }
  74. const checkIsEnrolled = () => {
  75. wx.checkIsSoterEnrolledInDevice({
  76. checkAuthMode: AUTH_MODE,
  77. success: (res) => {
  78. console.log(res)
  79. if (res.isEnrolled) {
  80. startSoterAuthentication();
  81. } else {
  82. that.gotoPay();
  83. }
  84. },
  85. fail: (err) => {
  86. console.error(err)
  87. }
  88. })
  89. }
  90. wx.checkIsSupportSoterAuthentication({
  91. success: (res) => {
  92. console.log(res)
  93. if (res.supportMode == []) {
  94. that.gotoPay();
  95. } else if (res.supportMode == ['fingerPrint']) {
  96. checkIsEnrolled()
  97. } else if (res.supportMode = ['fingerPrint', 'facial']) {
  98. checkIsEnrolled()
  99. }
  100. },
  101. fail: (err) => {
  102. console.error(err);
  103. that.gotoPay();
  104. }
  105. })
  106. },
  107. gotoPay: function() {
  108. let that = this;
  109. console.log(that.data.cardid)
  110. Http.post({
  111. url: config.api.cardPayOrder,
  112. data: {
  113. cardId: that.data.cardid,
  114. merchantId: that.data.merChant.id,
  115. totalFee: that.data.inputValue
  116. }
  117. })
  118. .then(res => {
  119. if (res.code == 200) {
  120. wx.hideLoading();
  121. that.setData({
  122. showModel: false
  123. })
  124. wx.navigateTo({
  125. url: `/pages/paySuccess/paySuccess?data=${JSON.stringify(res.data)}`,
  126. })
  127. }
  128. })
  129. .catch(err => {
  130. wx.hideLoading()
  131. wx.showModal({
  132. title: "抱歉",
  133. content: err.message,
  134. showCancel: false
  135. })
  136. that.setData({
  137. cardid: that.data.cardids,
  138. ids: "",
  139. remainingAmount: that.data.remainingAmounts
  140. })
  141. })
  142. },
  143. check: function(e) {
  144. let that = this;
  145. console.log(e.currentTarget.dataset.id)
  146. if (e) {
  147. if (e.currentTarget.dataset.flags == 'check') {
  148. that.setData({
  149. ids: e.currentTarget.dataset.id,
  150. cardid: e.currentTarget.dataset.id,
  151. remainingAmount: e.currentTarget.dataset.remainingamount,
  152. checked: true
  153. })
  154. }
  155. }
  156. },
  157. startAuth(e) {
  158. let that = this;
  159. if (that.data.inputValue == "" || that.data.inputValue == 0) {
  160. wx.showModal({
  161. title: '抱歉',
  162. content: '请输入金额',
  163. showCancel: false
  164. })
  165. } else if (that.data.inputValue != "" && Number(that.data.remainingAmount) < Number(that.data.inputValue)) {
  166. that.setData({
  167. showModel: true
  168. })
  169. that.getList();
  170. console.log("1111")
  171. } else if (that.data.inputValue != "" && Number(that.data.remainingAmount) >= Number(that.data.inputValue)) {
  172. wx.showLoading({
  173. title: '加载中',
  174. })
  175. console.log("222")
  176. setTimeout(function() {
  177. wx.hideLoading();
  178. }, 1500)
  179. that.gotoPayMoney();
  180. }
  181. },
  182. gotonewcard: function() {
  183. wx.navigateTo({
  184. url: '/pages/discountCardList/discountCardList'
  185. })
  186. this.setData({
  187. showModel: false
  188. })
  189. },
  190. getList() {
  191. var that = this;
  192. var data = {
  193. pageNum: 1,
  194. pageSize: 100,
  195. couponType: "7",
  196. couponOrderStatus: 4
  197. }
  198. Http.get({
  199. url: config.api.cardorderList,
  200. data: data
  201. })
  202. .then(res => {
  203. console.log(res)
  204. if (res.code == 200) {
  205. let arrays = [];
  206. res.data.list.map(file => {
  207. if (file.remainingAmount / 100 >= that.data.inputValue) {
  208. file.merchantVoList.map(files => {
  209. if (files.id == that.data.merChant.id) {
  210. file.flag = true;
  211. arrays.push(file);
  212. }
  213. })
  214. }
  215. })
  216. console.log(arrays)
  217. that.setData({
  218. showPage: true,
  219. cardList: res.data.list,
  220. arrays: arrays
  221. })
  222. }
  223. })
  224. .catch(err => {
  225. wx.showModal({
  226. title: '提示',
  227. content: err.errMsg,
  228. showCancel: false
  229. })
  230. })
  231. },
  232. showModel: function() {
  233. this.setData({
  234. showModel: false,
  235. cardid: this.data.cardids,
  236. ids: "",
  237. remainingAmount: this.data.remainingAmounts
  238. })
  239. console.log(this.data.cardid)
  240. },
  241. })