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.

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