C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

248 рядки
6.1 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: ["fingerPrint"],
  58. challenge: 'test',
  59. authContent: '请验证已有的指纹以继续',
  60. success: (res) => {
  61. console.log(res)
  62. that.gotoPay()
  63. },
  64. fail: (err) => {
  65. console.log(err);
  66. wx.hideLoading();
  67. that.setData({
  68. showModel: false,
  69. cardid: that.data.cardids,
  70. ids: "",
  71. remainingAmount: that.data.remainingAmounts
  72. })
  73. if(err.errCode==90008||err.errCode == 90009){
  74. }else{
  75. that.gotoPay();
  76. }
  77. }
  78. })
  79. }
  80. const checkIsEnrolled = () => {
  81. wx.checkIsSoterEnrolledInDevice({
  82. checkAuthMode: AUTH_MODE,
  83. success: (res) => {
  84. console.log(res)
  85. if (res.isEnrolled) {
  86. startSoterAuthentication();
  87. } else {
  88. that.gotoPay();
  89. }
  90. },
  91. fail: (err) => {
  92. console.error(err)
  93. }
  94. })
  95. }
  96. wx.checkIsSupportSoterAuthentication({
  97. success: (res) => {
  98. console.log(res)
  99. if (res.supportMode == []) {
  100. that.gotoPay();
  101. } else if (res.supportMode == ['fingerPrint']) {
  102. checkIsEnrolled();
  103. } else if (res.supportMode = ['fingerPrint', 'facial']) {
  104. checkIsEnrolled();
  105. }
  106. },
  107. fail: (err) => {
  108. console.error(err);
  109. that.gotoPay();
  110. }
  111. })
  112. },
  113. gotoPay: function() {
  114. let that = this;
  115. console.log(that.data.cardid)
  116. Http.post({
  117. url: config.api.cardPayOrder,
  118. data: {
  119. cardId: that.data.cardid,
  120. merchantId: that.data.merChant.id,
  121. totalFee: that.data.inputValue
  122. }
  123. })
  124. .then(res => {
  125. if (res.code == 200) {
  126. wx.hideLoading();
  127. that.setData({
  128. showModel: false
  129. })
  130. wx.navigateTo({
  131. url: `/pages/paySuccess/paySuccess?data=${JSON.stringify(res.data)}`,
  132. })
  133. }
  134. })
  135. .catch(err => {
  136. wx.hideLoading()
  137. wx.showModal({
  138. title: "抱歉",
  139. content: err.message,
  140. showCancel: false
  141. })
  142. that.setData({
  143. cardid: that.data.cardids,
  144. ids: "",
  145. remainingAmount: that.data.remainingAmounts
  146. })
  147. })
  148. },
  149. check: function(e) {
  150. let that = this;
  151. console.log(e.currentTarget.dataset.id)
  152. if (e) {
  153. if (e.currentTarget.dataset.flags == 'check') {
  154. that.setData({
  155. ids: e.currentTarget.dataset.id,
  156. cardid: e.currentTarget.dataset.id,
  157. remainingAmount: e.currentTarget.dataset.remainingamount,
  158. checked: true
  159. })
  160. }
  161. }
  162. },
  163. startAuth(e) {
  164. let that = this;
  165. if (that.data.inputValue == "" || that.data.inputValue == 0) {
  166. wx.showModal({
  167. title: '抱歉',
  168. content: '请输入金额',
  169. showCancel: false
  170. })
  171. } else if (that.data.inputValue != "" && Number(that.data.remainingAmount) < Number(that.data.inputValue)) {
  172. that.setData({
  173. showModel: true
  174. })
  175. that.getList();
  176. console.log("1111")
  177. } else if (that.data.inputValue != "" && Number(that.data.remainingAmount) >= Number(that.data.inputValue)) {
  178. wx.showLoading({
  179. title: '加载中',
  180. })
  181. console.log("222")
  182. setTimeout(function() {
  183. wx.hideLoading();
  184. }, 1500)
  185. that.gotoPayMoney();
  186. }
  187. },
  188. gotonewcard: function() {
  189. wx.navigateTo({
  190. url: '/pages/discountCardList/discountCardList'
  191. })
  192. this.setData({
  193. showModel: false
  194. })
  195. },
  196. getList() {
  197. var that = this;
  198. var data = {
  199. pageNum: 1,
  200. pageSize: 100,
  201. couponType: "7",
  202. couponOrderStatus: 4
  203. }
  204. Http.get({
  205. url: config.api.cardorderList,
  206. data: data
  207. })
  208. .then(res => {
  209. console.log(res)
  210. if (res.code == 200) {
  211. let arrays = [];
  212. res.data.list.map(file => {
  213. if (file.remainingAmount / 100 >= that.data.inputValue) {
  214. file.merchantVoList.map(files => {
  215. if (files.id == that.data.merChant.id) {
  216. file.flag = true;
  217. arrays.push(file);
  218. }
  219. })
  220. }
  221. })
  222. console.log(arrays)
  223. that.setData({
  224. showPage: true,
  225. cardList: res.data.list,
  226. arrays: arrays
  227. })
  228. }
  229. })
  230. .catch(err => {
  231. wx.showModal({
  232. title: '提示',
  233. content: err.errMsg,
  234. showCancel: false
  235. })
  236. })
  237. },
  238. showModel: function() {
  239. this.setData({
  240. showModel: false,
  241. cardid: this.data.cardids,
  242. ids: "",
  243. remainingAmount: this.data.remainingAmounts
  244. })
  245. console.log(this.data.cardid)
  246. },
  247. })