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.

scanPay.js 7.7 KiB

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