C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

258 rindas
5.6 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, goGive) {
  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. hidePhone: res.data.ownerPhone ? (res.data.ownerPhone.slice(0, 3) + `****` + res.data.ownerPhone.slice(7)) : '',
  127. ownerUserId: res.data.ownerUserId || "",
  128. eCardId: res.data.eCardId || "",
  129. owned: res.data.owned || "",
  130. remainAmount: res.data.remainAmount / 100 || "",
  131. isSHowInfoCard: true // 显示卡详情
  132. })
  133. if (goGive) {
  134. if ((this.data.ownerUserId && this.data.eCardId) || e.detail.value.code) {
  135. if ((this.data.owned && this.data.owned == 1) || e.detail.value.code) {
  136. wx.navigateTo({
  137. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${this.data.eCardId}`,
  138. })
  139. } else {
  140. this.Toast('当前用户不是该卡的持有者,无法转赠!', 'none')
  141. }
  142. } else {
  143. this.Toast('该卡未绑定', 'none')
  144. }
  145. }
  146. })
  147. .catch(err => {
  148. console.log(err);
  149. this.Toast(err.message, 'none')
  150. })
  151. },
  152. getCouponOrderByPassword(password) {
  153. Http.post({
  154. url: config.api.getCouponOrderByPassword,
  155. data: {
  156. password,
  157. }
  158. })
  159. .then(res => {
  160. wx.showModal({
  161. title: '激活成功',
  162. content: '消费卡已发放到"我的卡包"',
  163. showCancel: true,
  164. cancelText: "知道了",
  165. cancelColor: '',
  166. confirmText: "去查看",
  167. confirmColor: '#FD832D',
  168. success: function (res) {
  169. if (res.cancel) {
  170. //点击取消,默认隐藏弹框
  171. } else {
  172. wx.redirectTo({
  173. url: '/pages/cardorder/index/index',
  174. })
  175. }
  176. },
  177. fail: function (res) { },
  178. complete: function (res) { }
  179. })
  180. })
  181. .catch(err => {
  182. wx.showToast({
  183. title: err.message,
  184. icon: 'none',
  185. duration: 2000
  186. })
  187. })
  188. },
  189. setPwdShow() {
  190. const isShowPwd = this.data.isShowPwd
  191. this.setData({
  192. isShowPwd: !isShowPwd
  193. })
  194. },
  195. submit() {
  196. const e = {
  197. detail: { value: { code: this.data.code } }
  198. }
  199. this.searchCard(e)
  200. this.getCouponOrderByPassword(this.data.code)
  201. },
  202. goGive() {
  203. this.getCardDetail(this.data.code, true)
  204. },
  205. // 检查用户登录状态
  206. checkPhoneStatus() {
  207. let that = this;
  208. Http.get({
  209. url: config.api.checkPhoneStatus,
  210. })
  211. .then(res => {
  212. })
  213. .catch(err => {
  214. if (err.code == 11005) {
  215. // 手机号没有授权,将值传到用户手机号授权的页面
  216. wx.redirectTo({
  217. url: "/pages/getphoneInfo/index?path=exchangeCard",
  218. })
  219. } else {
  220. wx.showToast({
  221. title: err.message,
  222. icon: 'none',
  223. duration: 2500
  224. })
  225. }
  226. })
  227. },
  228. Toast(message, icon) {
  229. wx.showToast({
  230. title: message,
  231. icon: icon
  232. })
  233. },
  234. onLoad() {
  235. setTimeout(() => {
  236. this.checkPhoneStatus()
  237. }, 2000);
  238. }
  239. })