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.

261 rivejä
6.4 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: ["fingerPrint"],
  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. }else{
  82. that.gotoPay();
  83. }
  84. }
  85. })
  86. }
  87. const checkIsEnrolled = () => {
  88. wx.checkIsSoterEnrolledInDevice({
  89. checkAuthMode: AUTH_MODE,
  90. success: (res) => {
  91. console.log(res)
  92. if (res.isEnrolled) {
  93. startSoterAuthentication();
  94. } else {
  95. that.gotoPay();
  96. }
  97. },
  98. fail: (err) => {
  99. console.error(err)
  100. }
  101. })
  102. }
  103. wx.checkIsSupportSoterAuthentication({
  104. success: (res) => {
  105. console.log(res)
  106. if (res.supportMode == []) {
  107. that.gotoPay();
  108. } else if (res.supportMode == ['fingerPrint']) {
  109. checkIsEnrolled();
  110. } else if (res.supportMode == ['fingerPrint', 'facial']) {
  111. checkIsEnrolled();
  112. }else{
  113. that.gotoPay();
  114. }
  115. },
  116. fail: (err) => {
  117. console.error(err);
  118. that.gotoPay();
  119. }
  120. })
  121. },
  122. gotoPay: function() {
  123. let that = this;
  124. console.log(that.data.cardid)
  125. Http.post({
  126. url: config.api.cardPayOrder,
  127. data: {
  128. cardId: that.data.cardid,
  129. merchantId: that.data.merChant.id,
  130. totalFee: that.data.inputValue
  131. }
  132. })
  133. .then(res => {
  134. if (res.code == 200) {
  135. wx.hideLoading();
  136. that.setData({
  137. showModel: false,
  138. showInput: false
  139. })
  140. wx.navigateTo({
  141. url: `/pages/paySuccess/paySuccess?data=${JSON.stringify(res.data)}`,
  142. })
  143. }
  144. })
  145. .catch(err => {
  146. wx.hideLoading()
  147. wx.showModal({
  148. title: "抱歉",
  149. content: err.message,
  150. showCancel: false
  151. })
  152. that.setData({
  153. cardid: that.data.cardids,
  154. ids: "",
  155. remainingAmount: that.data.remainingAmounts
  156. })
  157. })
  158. },
  159. check: function(e) {
  160. let that = this;
  161. console.log(e.currentTarget.dataset.id)
  162. if (e) {
  163. if (e.currentTarget.dataset.flags == 'check') {
  164. that.setData({
  165. ids: e.currentTarget.dataset.id,
  166. cardid: e.currentTarget.dataset.id,
  167. remainingAmount: e.currentTarget.dataset.remainingamount,
  168. checked: true
  169. })
  170. }
  171. }
  172. },
  173. startAuth(e) {
  174. let that = this;
  175. if (that.data.inputValue == "" || that.data.inputValue == 0) {
  176. wx.showModal({
  177. title: '抱歉',
  178. content: '请输入金额',
  179. showCancel: false
  180. })
  181. } else if (that.data.inputValue != "" && Number(that.data.remainingAmount) < Number(that.data.inputValue)) {
  182. that.setData({
  183. showModel: true,
  184. showInput:'disabled'
  185. })
  186. that.getList();
  187. console.log("1111")
  188. } else if (that.data.inputValue != "" && Number(that.data.remainingAmount) >= Number(that.data.inputValue)) {
  189. wx.showLoading({
  190. title: '加载中',
  191. })
  192. console.log("222")
  193. setTimeout(function() {
  194. wx.hideLoading();
  195. }, 1500)
  196. that.gotoPayMoney();
  197. }
  198. },
  199. gotonewcard: function() {
  200. wx.navigateTo({
  201. url: '/pages/discountCardList/discountCardList'
  202. })
  203. this.setData({
  204. showModel: false,
  205. showInput: false
  206. })
  207. },
  208. getList() {
  209. var that = this;
  210. var data = {
  211. pageNum: 1,
  212. pageSize: 100,
  213. couponType: "7",
  214. couponOrderStatus: 4
  215. }
  216. Http.get({
  217. url: config.api.cardorderList,
  218. data: data
  219. })
  220. .then(res => {
  221. console.log(res)
  222. if (res.code == 200) {
  223. let arrays = [];
  224. res.data.list.map(file => {
  225. if (file.remainingAmount / 100 >= that.data.inputValue) {
  226. file.merchantVoList.map(files => {
  227. if (files.id == that.data.merChant.id) {
  228. file.flag = true;
  229. arrays.push(file);
  230. }
  231. })
  232. }
  233. })
  234. console.log(arrays)
  235. that.setData({
  236. showPage: true,
  237. cardList: res.data.list,
  238. arrays: arrays
  239. })
  240. }
  241. })
  242. .catch(err => {
  243. wx.showModal({
  244. title: '提示',
  245. content: err.errMsg,
  246. showCancel: false
  247. })
  248. })
  249. },
  250. showModel: function() {
  251. this.setData({
  252. showModel: false,
  253. showInput: false,
  254. cardid: this.data.cardids,
  255. ids: "",
  256. remainingAmount: this.data.remainingAmounts
  257. })
  258. console.log(this.data.cardid)
  259. },
  260. })