C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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