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

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