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.

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