C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

272 行
6.7 KiB

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