C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

267 řádky
6.0 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) || e.detail.value.code) {
  137. if ((this.data.owned && this.data.owned == 1) || e.detail.value.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. Http.post({
  163. url: config.api.getCouponOrderByPassword,
  164. data: {
  165. password,
  166. }
  167. })
  168. .then(res => {
  169. wx.showModal({
  170. title: '激活成功',
  171. content: '消费卡已发放到"我的卡包"',
  172. showCancel: true,
  173. cancelText: "知道了",
  174. cancelColor: '',
  175. confirmText: "去查看",
  176. confirmColor: '#FD832D',
  177. success: function (res) {
  178. if (res.cancel) {
  179. //点击取消,默认隐藏弹框
  180. } else {
  181. wx.redirectTo({
  182. url: '/pages/cardorder/index/index',
  183. })
  184. }
  185. },
  186. fail: function (res) { },
  187. complete: function (res) { }
  188. })
  189. })
  190. .catch(err => {
  191. wx.showToast({
  192. title: err.message,
  193. icon: 'none',
  194. duration: 2000
  195. })
  196. })
  197. },
  198. setPwdShow() {
  199. const isShowPwd = this.data.isShowPwd
  200. this.setData({
  201. isShowPwd: !isShowPwd
  202. })
  203. },
  204. submit() {
  205. const e = {
  206. detail: { value: { code: this.data.code } }
  207. }
  208. this.searchCard(e)
  209. this.getCouponOrderByPassword(this.data.code)
  210. },
  211. goGive() {
  212. this.getCardDetailOrGoGive(this.data.code, true)
  213. },
  214. // 检查用户登录状态
  215. checkPhoneStatus() {
  216. let that = this;
  217. Http.get({
  218. url: config.api.checkPhoneStatus,
  219. })
  220. .then(res => {
  221. })
  222. .catch(err => {
  223. if (err.code == 11005) {
  224. // 手机号没有授权,将值传到用户手机号授权的页面
  225. wx.redirectTo({
  226. url: "/pages/getphoneInfo/index?path=exchangeCard",
  227. })
  228. } else {
  229. wx.showToast({
  230. title: err.message,
  231. icon: 'none',
  232. duration: 2500
  233. })
  234. }
  235. })
  236. },
  237. Toast(message, icon) {
  238. wx.showToast({
  239. title: message,
  240. icon: icon
  241. })
  242. },
  243. onLoad() {
  244. setTimeout(() => {
  245. this.checkPhoneStatus()
  246. }, 2000);
  247. }
  248. })