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.

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