C端小程序
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.

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