v-phone.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view>
  3. <uni-popup ref="popup" type="center" @change="maskClick">
  4. <view class="get-phone-pop">
  5. <view class="content-block">
  6. <view class="content flex flex-y-center flex-x-center">完善资料享有更多优惠,是否完善</view>
  7. </view>
  8. <form @submit="getbang">
  9. <view class="flex-y-center content-tel">
  10. <text style="min-width: 130rpx;">手机号码</text>
  11. <view class="flex-y-center content-tel-bor">
  12. <input type="number" maxlength="11" @input="getphone" name='tel'
  13. placeholder-class="content-tel-bor-input" placeholder="请输入手机号码" />
  14. </view>
  15. </view>
  16. <view class="flex-y-center content-tel">
  17. <view class="flex-y-center content-tel-bor" style="border: none;">
  18. <input type="number" placeholder-class="content-tel-bor-input" name='code'
  19. placeholder="请输入验证码" />
  20. <view class="code-btn" @click="getCode" :style="{'background-color':setColor}">
  21. {{codeConfig.type == 1?'获取验证码':'重试('+codeConfig.time+'s)'}}
  22. </view>
  23. </view>
  24. </view>
  25. <view class="btm-block flex flex-nowarp flex-x-between">
  26. <button class="btn" @click="showGetPhone">取消</button>
  27. <button form-type="submit" class="btn sub-btn" :style="{color:setColor}">马上完善</button>
  28. </view>
  29. </form>
  30. </view>
  31. </uni-popup>
  32. </view>
  33. </template>
  34. <script>
  35. // #ifdef MP-ALIPAY
  36. // const {
  37. // requestSubscribeMessage
  38. // } = requirePlugin('subscribeMsg');
  39. // #endif
  40. export default {
  41. props: {
  42. getPhonePop: {
  43. type: Boolean,
  44. default: false
  45. },
  46. },
  47. watch: {
  48. getPhonePop: {
  49. handler(newVal) {
  50. console.log(newVal,"newVal")
  51. if (newVal) {
  52. this.$refs.popup.open();
  53. }
  54. },
  55. }
  56. },
  57. data() {
  58. return {
  59. phone: null,
  60. codeConfig: {
  61. type: 1,
  62. time: 60
  63. }
  64. }
  65. },
  66. methods: {
  67. maskClick(e) {
  68. if (!e.show) {
  69. this.$emit('close', false);
  70. }
  71. },
  72. getphone(e) {
  73. this.phone = e.detail.value;
  74. },
  75. showGetPhone() {
  76. this.$refs.popup.close();
  77. },
  78. // 获取验证码
  79. getCode() {
  80. if (this.codeConfig.type != 1) {
  81. return
  82. }
  83. if (!/^1[0-9]{10}/.test(this.phone)) {
  84. uni.showToast({
  85. title: "请正确输入手机号",
  86. icon: 'none'
  87. })
  88. return false
  89. }
  90. this.$http.request('xcx/sendcode', {
  91. tel: this.phone,
  92. store_id:this.$store.state.store_id,
  93. }, "", "", true).then(res => {
  94. if (res.code == "200") {
  95. this.codeConfig.type = 2
  96. this._timer = setInterval(() => {
  97. if (this.codeConfig.time == 1) {
  98. this.codeConfig = {
  99. type: 1,
  100. time: 30
  101. }
  102. clearInterval(this._timer)
  103. }
  104. this.codeConfig.time--
  105. }, 1000)
  106. }
  107. }).catch((res) => {
  108. uni.showToast({
  109. title: res.message,
  110. icon: 'none'
  111. })
  112. });
  113. },
  114. // 支付宝成为会员
  115. getbang(e) {
  116. let subscribe = uni.getStorageSync('balance_subscribe');
  117. let data = {},
  118. url;
  119. if (!/^1[0-9]{10}/.test(e.detail.value.tel)) {
  120. uni.showToast({
  121. title: "请正确输入手机号",
  122. icon: 'none'
  123. })
  124. return false
  125. }
  126. if (!e.detail.value.code) {
  127. uni.showToast({
  128. title: "请输入验证码",
  129. icon: 'none'
  130. })
  131. return false
  132. }
  133. data.tel = e.detail.value.tel;
  134. data.store_id = this.$store.state.store_id,
  135. data.id = this.$store.state.userInfo.id,
  136. data.code = e.detail.value.code;
  137. // console.log(this.$store.state.store_id, this.$store.state.userInfo.id, this.$store.state.systemInfo
  138. // .alipay_appid)
  139. this.$http.request('xcx/alipaytel', data, "", "", true).then(res => {
  140. if (res.code == "200") {
  141. this.phoneNumber = res.data.phoneNumber;
  142. uni.setStorageSync('phone', res.data.phoneNumber);
  143. uni.showModal({
  144. title: '恭喜完成!',
  145. content: '享受更多优惠!',
  146. showCancel: false,
  147. cancelText: '',
  148. confirmText: '确定',
  149. success: res => {
  150. this.$refs.popup.close();
  151. let that = this;
  152. // 调用方法,唤起订阅组件
  153. my.requestSubscribeMessage({
  154. thirdTypeAppId: this.$store.state.systemInfo
  155. .alipay_appid, // 可选,isv接入场景下必填
  156. entityIds: [subscribe.alipay_user], // 模板id列表,最多3个
  157. // 接收结果的回调方法
  158. complete:(r)=> {
  159. console.log('订阅回调', r);
  160. },
  161. });
  162. that.menber_info();
  163. },
  164. fail: () => {},
  165. complete: () => {}
  166. });
  167. }
  168. }).catch((res) => {
  169. uni.showToast({
  170. title: res.message,
  171. icon: 'none'
  172. })
  173. });
  174. },
  175. menber_info() {
  176. let userInfo = this.$store.state.userInfo;
  177. let pages = getCurrentPages();
  178. let { route, options } = pages[pages.length-1];
  179. this.$http.request('xcx/userinfo', {
  180. id: userInfo.id,
  181. }, "", "", true).then(res => {
  182. if (res.code == "200") {
  183. this.$store.commit('SET_USER_INFO', res.data)
  184. if (route =="pages/creatOrder/creatOrder") {
  185. uni.redirectTo({
  186. url: `/pages/creatOrder/creatOrder?teen_index=${options.teen_index}&eat_people=${options.eat_people}`
  187. })
  188. }
  189. }
  190. }).catch((res) => {
  191. uni.showToast({
  192. title: res.message,
  193. icon: 'none'
  194. })
  195. });
  196. },
  197. }
  198. }
  199. </script>
  200. <style>
  201. /* 成为会员 */
  202. .get-phone-pop {
  203. width: 660rpx;
  204. background-color: #fff;
  205. border-radius: 14rpx;
  206. overflow: hidden;
  207. }
  208. .code-btn {
  209. flex: none;
  210. width: 170rpx;
  211. height: 60rpx;
  212. border-radius: 30rpx;
  213. background-color: #3387FF;
  214. text-align: center;
  215. line-height: 60rpx;
  216. color: #fff;
  217. font-size: 24rpx;
  218. }
  219. .get-phone-pop .content {
  220. // height: 180rpx;
  221. text-align: center;
  222. font-size: 35rpx;
  223. color: #000;
  224. // line-height: 60rpx;
  225. padding: 30rpx 0;
  226. }
  227. .get-phone-pop .btm-block {
  228. width: 100%;
  229. height: 115rpx;
  230. border-top: 1rpx solid #eef0ef;
  231. }
  232. .get-phone-pop .btm-block .btn {
  233. flex: none;
  234. width: 50%;
  235. height: 115rpx;
  236. box-sizing: border-box;
  237. text-align: center;
  238. line-height: 115rpx;
  239. color: #010101;
  240. font-weight: bold;
  241. padding: 0;
  242. margin: 0;
  243. border: none;
  244. border-radius: 0;
  245. background-color: #fff;
  246. font-size: 35rpx;
  247. }
  248. .get-phone-pop .btm-block .btn::after {
  249. padding: 0;
  250. border: none;
  251. border-radius: 0;
  252. }
  253. .get-phone-pop .btm-block .sub-btn {
  254. color: #626c90;
  255. border-left: 1px solid #eef0fe;
  256. }
  257. .content-tel {
  258. padding: 20rpx 40rpx;
  259. }
  260. .content-tel-bor {
  261. border-bottom: 1rpx solid #F1F1F1;
  262. margin-left: 10rpx;
  263. }
  264. .content-tel-bor-input {
  265. font-size: 26rpx;
  266. }
  267. </style>