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.

257 lines
6.3 KiB

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