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.

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