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.

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