C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

248 行
5.2 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. wx.showToast({
  57. title: '请输入正确的手机号!',
  58. icon: 'none'
  59. })
  60. return
  61. }
  62. this.setData({
  63. isChangePhone: false,
  64. })
  65. },
  66. // 取消更改
  67. cancelChangePhone() {
  68. this.setData({
  69. isChangePhone: false,
  70. phone: this.data.tempPhone
  71. })
  72. },
  73. // 更改tab栏
  74. changeTabs(e) {
  75. console.log(e, 'changeTabs');
  76. this.setData({
  77. tabIndex: e.target.id,
  78. code: '',
  79. password: '',
  80. isSHowInfoCard: false
  81. })
  82. },
  83. // 支付安全设置
  84. securityChange(e) {
  85. this.setData({
  86. pdwSwitch: e.detail.value * 1
  87. })
  88. },
  89. // 扫描二维码
  90. goScanCode() {
  91. console.log('scan!!!');
  92. const that = this
  93. wx.scanCode({
  94. success: (res) => {
  95. console.log(res, 'res');
  96. const num = res.result
  97. that.setData({
  98. code: num
  99. })
  100. const e = {
  101. detail: { value: { code: num } }
  102. }
  103. that.searchCard(e)
  104. },
  105. fail: (res) => {
  106. console.log(res, 'fail');
  107. }
  108. })
  109. },
  110. /** 根据卡id查询卡详情*/
  111. getCardDetail(cardId) {
  112. const that = this
  113. Http.get({
  114. url: config.api.getCardDetail,
  115. data: { cardId }
  116. })
  117. .then(res => {
  118. console.log(res, 'res');
  119. that.setData({
  120. title: res.data.title,
  121. phone: res.data.ownerPhone,
  122. ownerUserId: res.data.ownerUserId,
  123. eCardId: res.data.eCardId,
  124. owned: res.data.owned,
  125. remainAmount: res.data.remainAmount / 100,
  126. isSHowInfoCard: true // 显示卡详情
  127. })
  128. })
  129. .catch(err => {
  130. console.log(err);
  131. wx.showToast({
  132. title: err.message,
  133. icon: "none"
  134. })
  135. })
  136. },
  137. getCouponOrderByPassword(password) {
  138. Http.post({
  139. url: config.api.getCouponOrderByPassword,
  140. data: {
  141. password,
  142. }
  143. })
  144. .then(res => {
  145. wx.showModal({
  146. title: '激活成功',
  147. content: '消费卡已发放到"我的卡包"',
  148. showCancel: true,
  149. cancelText: "知道了",
  150. cancelColor: '',
  151. confirmText: "去查看",
  152. confirmColor: '#FD832D',
  153. success: function (res) {
  154. if (res.cancel) {
  155. //点击取消,默认隐藏弹框
  156. } else {
  157. wx.redirectTo({
  158. url: '/pages/cardorder/index/index',
  159. })
  160. }
  161. },
  162. fail: function (res) { },
  163. complete: function (res) { }
  164. })
  165. })
  166. .catch(err => {
  167. wx.showToast({
  168. title: err.message,
  169. icon: 'none',
  170. duration: 2000
  171. })
  172. })
  173. },
  174. setPwdShow() {
  175. const isShowPwd = this.data.isShowPwd
  176. this.setData({
  177. isShowPwd: !isShowPwd
  178. })
  179. },
  180. submit() {
  181. const data = this.data
  182. this.getCouponOrderByPassword(data.code)
  183. },
  184. goGive() {
  185. if (this.data.ownerUserId && this.data.eCardId) {
  186. if (this.data.owned && this.data.owned == 1) {
  187. wx.navigateTo({
  188. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${this.data.eCardId}`,
  189. })
  190. } else {
  191. wx.showToast({
  192. title: '当前用户不是该卡的持有者,无法转赠!',
  193. icon: 'none'
  194. })
  195. }
  196. } else {
  197. wx.showToast({
  198. title: '该卡未绑定',
  199. icon: 'error'
  200. })
  201. }
  202. },
  203. // 检查用户登录状态
  204. checkPhoneStatus() {
  205. let that = this;
  206. Http.get({
  207. url: config.api.checkPhoneStatus,
  208. })
  209. .then(res => {
  210. })
  211. .catch(err => {
  212. if (err.code == 11005) {
  213. // 手机号没有授权,将值传到用户手机号授权的页面
  214. wx.redirectTo({
  215. url: "/pages/getphoneInfo/index?path=exchangeCard",
  216. })
  217. } else {
  218. wx.showToast({
  219. title: err.message,
  220. icon: 'none',
  221. duration: 2500
  222. })
  223. }
  224. })
  225. },
  226. onLoad() {
  227. setTimeout(() => {
  228. this.checkPhoneStatus()
  229. }, 2000);
  230. }
  231. })