C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

243 lignes
5.1 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 60) + 'px'
  2. const util = require("../../utils/util.js");
  3. const Http = require("../../utils/HttpBasics");
  4. const config = require("../../config/config");
  5. const imgurl = require("../../utils/imgurl");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. navigationBarHeight,
  12. tabIndex: 0,
  13. pdwSwitch: 0,
  14. isShowPwd: false,
  15. isChangePhone: false,
  16. isSHowInfoCard: false,
  17. code: "",
  18. title: "",
  19. name: "",
  20. phone: "",
  21. tempPhone: "",
  22. password: ""
  23. },
  24. // 查询
  25. searchCard(e) {
  26. let code = e.detail.value.code;
  27. this.setData({
  28. code: e.detail.value.code
  29. })
  30. this.getCardDetail(code)
  31. },
  32. // 更改手机号
  33. changePhone() {
  34. this.setData({
  35. isChangePhone: true,
  36. tempPhone: this.data.phone
  37. })
  38. },
  39. // 输入手机号
  40. phoneInput(e) {
  41. this.setData({
  42. phone: e.detail.value
  43. })
  44. },
  45. // 输入密码
  46. pwdInput(e) {
  47. this.setData({
  48. password: e.detail.value,
  49. })
  50. },
  51. // 确认手机号更改
  52. confirmPhone() {
  53. const phoneReg = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/
  54. const phoneValid = phoneReg.test(this.data.phone)
  55. if (!phoneValid) {
  56. this.Toast('请输入正确的手机号!', 'none')
  57. return
  58. }
  59. this.setData({
  60. isChangePhone: false,
  61. })
  62. },
  63. // 取消更改
  64. cancelChangePhone() {
  65. this.setData({
  66. isChangePhone: false,
  67. phone: this.data.tempPhone
  68. })
  69. },
  70. // 更改tab栏
  71. changeTabs(e) {
  72. console.log(e, 'changeTabs');
  73. this.setData({
  74. tabIndex: e.target.id,
  75. code: '',
  76. password: '',
  77. isSHowInfoCard: false
  78. })
  79. },
  80. // 支付安全设置
  81. securityChange(e) {
  82. this.setData({
  83. pdwSwitch: e.detail.value * 1
  84. })
  85. },
  86. // 扫描二维码
  87. goScanCode() {
  88. console.log('scan!!!');
  89. const that = this
  90. wx.scanCode({
  91. success: (res) => {
  92. console.log(res, 'res');
  93. const num = res.result
  94. that.setData({
  95. code: num
  96. })
  97. const e = {
  98. detail: { value: { code: num } }
  99. }
  100. that.searchCard(e)
  101. },
  102. fail: (res) => {
  103. console.log(res, 'fail');
  104. }
  105. })
  106. },
  107. /** 根据卡id查询卡详情*/
  108. getCardDetail(cardId) {
  109. const that = this
  110. Http.get({
  111. url: config.api.getCardDetail,
  112. data: { cardId }
  113. })
  114. .then(res => {
  115. console.log(res, 'res');
  116. that.setData({
  117. title: res.data.title,
  118. phone: res.data.ownerPhone,
  119. ownerUserId: res.data.ownerUserId,
  120. eCardId: res.data.eCardId,
  121. owned: res.data.owned,
  122. remainAmount: res.data.remainAmount / 100,
  123. isSHowInfoCard: true // 显示卡详情
  124. })
  125. })
  126. .catch(err => {
  127. console.log(err);
  128. this.Toast(err.message, 'none')
  129. })
  130. },
  131. getCouponOrderByPassword(password) {
  132. Http.post({
  133. url: config.api.getCouponOrderByPassword,
  134. data: {
  135. password,
  136. }
  137. })
  138. .then(res => {
  139. wx.showModal({
  140. title: '激活成功',
  141. content: '消费卡已发放到"我的卡包"',
  142. showCancel: true,
  143. cancelText: "知道了",
  144. cancelColor: '',
  145. confirmText: "去查看",
  146. confirmColor: '#FD832D',
  147. success: function (res) {
  148. if (res.cancel) {
  149. //点击取消,默认隐藏弹框
  150. } else {
  151. wx.redirectTo({
  152. url: '/pages/cardorder/index/index',
  153. })
  154. }
  155. },
  156. fail: function (res) { },
  157. complete: function (res) { }
  158. })
  159. })
  160. .catch(err => {
  161. wx.showToast({
  162. title: err.message,
  163. icon: 'none',
  164. duration: 2000
  165. })
  166. })
  167. },
  168. setPwdShow() {
  169. const isShowPwd = this.data.isShowPwd
  170. this.setData({
  171. isShowPwd: !isShowPwd
  172. })
  173. },
  174. submit() {
  175. const data = this.data
  176. this.getCouponOrderByPassword(data.code)
  177. },
  178. goGive() {
  179. if (this.data.ownerUserId && this.data.eCardId) {
  180. if (this.data.owned && this.data.owned == 1) {
  181. wx.navigateTo({
  182. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${this.data.eCardId}`,
  183. })
  184. } else {
  185. this.Toast('当前用户不是该卡的持有者,无法转赠!', 'none')
  186. }
  187. } else {
  188. this.Toast('该卡未绑定', 'none')
  189. }
  190. },
  191. // 检查用户登录状态
  192. checkPhoneStatus() {
  193. let that = this;
  194. Http.get({
  195. url: config.api.checkPhoneStatus,
  196. })
  197. .then(res => {
  198. })
  199. .catch(err => {
  200. if (err.code == 11005) {
  201. // 手机号没有授权,将值传到用户手机号授权的页面
  202. wx.redirectTo({
  203. url: "/pages/getphoneInfo/index?path=exchangeCard",
  204. })
  205. } else {
  206. wx.showToast({
  207. title: err.message,
  208. icon: 'none',
  209. duration: 2500
  210. })
  211. }
  212. })
  213. },
  214. Toast(message, icon) {
  215. wx.showToast({
  216. title: message,
  217. icon: icon
  218. })
  219. },
  220. onLoad() {
  221. setTimeout(() => {
  222. this.checkPhoneStatus()
  223. }, 2000);
  224. }
  225. })