app-phone-binding.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <view class="app-phone-binding">
  3. <view class="app-bound dir-top-nowrap cross-center" v-if="bind">
  4. <image class="app-image" :src="wxapp_img.mall.binding"></image>
  5. <view class="app-phone-text dir-top-nowrap" >
  6. <text>已绑定手机</text>
  7. <text class="app-hone">{{phone}}</text>
  8. </view>
  9. <view class="app-button">
  10. <app-button type="important" round background="#ff4544" height="88" width="700" fontSize="32" @click="clearPhone(false)">更换绑定</app-button>
  11. </view>
  12. </view>
  13. <template v-else>
  14. <view class="app-unbound">
  15. <!-- #ifndef MP-BAIDU -->
  16. <view class="header dir-left-nowrap" v-if="is_manual_mobile_auth == 1">
  17. <view class="box-grow-1" @click="setActive(1)">
  18. <app-form-id>
  19. <text :class="{'active-index': activeIndex === 1}">
  20. 直接授权
  21. </text>
  22. </app-form-id>
  23. </view>
  24. <view class="box-grow-1" @click="setActive(2)">
  25. <app-form-id>
  26. <text :class="{'active-index': activeIndex === 2}">
  27. 手动输入
  28. </text>
  29. </app-form-id>
  30. </view>
  31. </view>
  32. <!-- #endif-->
  33. <view class="content">
  34. <!-- #ifndef MP-BAIDU -->
  35. <view class="input-view dir-left-nowrap cross-center" v-if="activeIndex === 1">
  36. <view class="input" :class="{'input-value': value !== ''}">{{value === '' ? '点击授权获取手机号' : value}}</view>
  37. <view class="line"></view>
  38. <!-- #ifndef MP-ALIPAY -->
  39. <button open-type="getPhoneNumber" class="button" @getphonenumber="getPhoneNumber">点击授权</button>
  40. <!-- #endif -->
  41. <!-- #ifdef MP-ALIPAY -->
  42. <button open-type="getAuthorize"
  43. class="button"
  44. @getAuthorize="onGetAuthorize"
  45. scope='phoneNumber'
  46. >点击授权</button>
  47. <!-- #endif -->
  48. </view>
  49. <!-- #endif -->
  50. <view class="manual-input dir-top-nowrap" v-if="activeIndex === 2">
  51. <view class="top">
  52. <input type="number" v-model="phoneNumber" placeholder="输入手机号">
  53. </view>
  54. <view class="bottom dir-left-nowrap cross-center">
  55. <input type="number" placeholder="输入验证码" v-model="verificationCode">
  56. <view class="line"></view>
  57. <view class="btn" @click="obtain">获取验证码</view>
  58. </view>
  59. </view>
  60. <view class="sure-button" @click="bindPhone(true, activeIndex)">确认</view>
  61. </view>
  62. </view>
  63. </template>
  64. </view>
  65. </template>
  66. <script>
  67. import {mapState, mapGetters} from 'vuex';
  68. export default {
  69. name: 'app-phone-binding',
  70. data() {
  71. return {
  72. code: '',
  73. value: '',
  74. // #ifndef MP-BAIDU
  75. activeIndex: 1,
  76. // #endif
  77. // #ifdef MP-BAIDU
  78. activeIndex: 2,
  79. // #endif
  80. phoneNumber: null,
  81. verificationCode: null,
  82. }
  83. },
  84. props: {
  85. bind: {
  86. type: Boolean,
  87. },
  88. phone: {
  89. type: String,
  90. }
  91. },
  92. computed: {
  93. ...mapState({
  94. wxapp_img: state => state.mallConfig.__wxapp_img,
  95. is_manual_mobile_auth: state => state.mallConfig.mall.setting.is_manual_mobile_auth
  96. }),
  97. },
  98. created() {
  99. // #ifndef MP-ALIPAY
  100. let _this= this;
  101. uni.login({
  102. scopes: 'auth_base',
  103. success(res) {
  104. if (res.errMsg === 'login:ok') {
  105. _this.code = res.code;
  106. }
  107. }
  108. })
  109. // #endif
  110. },
  111. methods: {
  112. // #ifndef MP-ALIPAY
  113. getPhoneNumber(e) {
  114. if (e.detail.errMsg === 'getPhoneNumber:fail user deny' || !this.code) return;
  115. let _this = this;
  116. this.$request({
  117. method: 'post',
  118. url: _this.$api.phone.binding,
  119. data: {
  120. encryptedData: e.detail.encryptedData,
  121. iv: e.detail.iv,
  122. code: _this.code,
  123. }
  124. }).then(response => {
  125. this.value = response.data.mobile;
  126. })
  127. },
  128. // #endif
  129. // #ifdef MP-ALIPAY
  130. onGetAuthorize() {
  131. let _this = this;
  132. my.getPhoneNumber({
  133. success: (res) => {
  134. this.$request({
  135. method: 'post',
  136. url: _this.$api.phone.binding,
  137. data: {
  138. data: JSON.parse(res.response).response,
  139. }
  140. });
  141. this.value = JSON.parse(res.response).response;
  142. },
  143. fail: () => {
  144. }
  145. });
  146. },
  147. // #endif
  148. bindPhone(data, i) {
  149. if (i === 1) {
  150. if (this.value === '') return;
  151. this.$emit('click', data);
  152. } else {
  153. if (this.verificationCode === null) return;
  154. this.$request({
  155. url: this.$api.phone.binding,
  156. method: 'post',
  157. data: {
  158. mobile: this.phoneNumber,
  159. mobile_code: this.verificationCode,
  160. }
  161. }).then(res => {
  162. if (res.code === 0) {
  163. this.$emit('click', data);
  164. } else if (res.code === 1) {
  165. uni.showModal({
  166. title: '提示',
  167. content: res.msg,
  168. })
  169. }
  170. });
  171. }
  172. },
  173. clearPhone(data) {
  174. this.$emit('click', data);
  175. },
  176. obtain() {
  177. if (this.phoneNumber === null) return;
  178. this.$request({
  179. url: this.$api.phone.code,
  180. data: {
  181. mobile: this.phoneNumber,
  182. }
  183. }).then(res => {
  184. if (res.code === 0) {
  185. uni.showModal({
  186. title: '提示',
  187. content: res.msg,
  188. })
  189. } else if (res.code === 1) {
  190. uni.showModal({
  191. title: '提示',
  192. content: res.msg,
  193. })
  194. }
  195. })
  196. },
  197. setActive(data) {
  198. this.activeIndex = data;
  199. }
  200. },
  201. }
  202. </script>
  203. <style scoped lang="scss">
  204. .app-phone-binding {
  205. position: absolute;
  206. height: 100%;
  207. width: 100%;
  208. background-color: #f7f7f7;
  209. .app-unbound {
  210. width: 100%;
  211. background-color: #f7f7f7;
  212. .header {
  213. width: 100%;
  214. height: #{86rpx};
  215. background-color: white;
  216. border-bottom: #{1rpx} solid #e2e2e2;
  217. text-align: center;
  218. margin-bottom: #{8rpx};
  219. .box-grow-1 {
  220. text {
  221. display: inline-block;
  222. height: #{84rpx};
  223. line-height: #{84rpx};
  224. border-bottom-color: transparent;
  225. border-bottom-style: solid;
  226. border-bottom-width: #{2rpx};
  227. color: #353535;
  228. font-size: #{28rpx};
  229. }
  230. .active-index {
  231. border-bottom-color: #ff4544;
  232. color: #ff4544;
  233. }
  234. }
  235. }
  236. .content {
  237. width: 100%;
  238. height: #{110rpx};
  239. background-color: white;
  240. padding: #{10rpx} 0;
  241. box-sizing: border-box;
  242. .input-view {
  243. margin-left: #{24rpx};
  244. background-color: white;
  245. height: #{80rpx};
  246. width: #{750-24rpx};
  247. .input {
  248. height: #{80rpx};
  249. width: #{516rpx};
  250. line-height: #{80rpx};
  251. background-color: #f7f7f7;
  252. padding-left: #{24rpx};
  253. box-sizing: border-box;
  254. font-size: #{28rpx};
  255. color: #999999;
  256. margin-right: #{16rpx};
  257. }
  258. .input-value {
  259. color: #353535;
  260. }
  261. .line {
  262. width: #{1rpx};
  263. height: #{36rpx};
  264. background-color: #e2e2e2;
  265. }
  266. .button {
  267. width: #{194rpx};
  268. height: #{80rpx};
  269. line-height: #{80rpx};
  270. color: #ff4544;
  271. font-size: #{28rpx};
  272. background-color: white;
  273. border: none;
  274. border-radius: 0;
  275. text-align: center;
  276. padding: 0;
  277. box-sizing: border-box;
  278. }
  279. }
  280. .manual-input {
  281. width: 100%;
  282. height: #{200rpx};
  283. background-color: white;
  284. .top {
  285. height: #{100rpx};
  286. font-size: #{28rpx};
  287. border-bottom: #{1rpx} solid #e2e2e2;
  288. >input {
  289. width: #{750rpx};
  290. height: #{60rpx};
  291. margin: #{20rpx} 0;
  292. padding-left: #{40rpx};
  293. box-sizing: border-box;
  294. }
  295. }
  296. .bottom {
  297. height: #{100rpx};
  298. >input {
  299. width: #{750-220-1rpx};
  300. line-height: #{60rpx};
  301. padding-left: #{40rpx};
  302. font-size: #{28rpx};
  303. margin: #{20rpx} 0;
  304. box-sizing: border-box;
  305. }
  306. .line {
  307. width: #{1rpx};
  308. height: #{32rpx};
  309. background-color: #e2e2e2;
  310. }
  311. .btn {
  312. height: #{100rpx};
  313. line-height: #{100rpx};
  314. width: #{220rpx};
  315. font-size: #{28rpx};
  316. text-align: center;
  317. color: #ff4544;
  318. }
  319. }
  320. }
  321. .sure-button {
  322. width: #{702rpx};
  323. height: #{88rpx};
  324. line-height: #{88rpx};
  325. text-align: center;
  326. margin: #{80rpx 20rpx 0 24rpx};
  327. background-color: #ff4544;
  328. color: white;
  329. font-size: #{32rpx};
  330. border-radius: #{44rpx};
  331. }
  332. }
  333. }
  334. .app-bound {
  335. width: #{750rpx};
  336. .app-image {
  337. width: #{288rpx};
  338. height: #{288rpx};
  339. margin: #{64rpx 0rpx 56rpx 0rpx};
  340. }
  341. .app-phone-text {
  342. text-align: center;
  343. color: #666;
  344. font-size: #{30rpx};
  345. margin-bottom: #{60rpx};
  346. .app-hone {
  347. margin-top: #{15rpx};
  348. }
  349. .app-button {
  350. height: 100%;
  351. border: none;
  352. font-size: #{26rpx};
  353. color: #ff4544;
  354. padding: 0 0;
  355. margin-top: #{64rpx};
  356. margin-left: #{24rpx};
  357. margin-right: #{24rpx};
  358. }
  359. .app-button:after {
  360. display: none;
  361. }
  362. }
  363. }
  364. }
  365. </style>