bind.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <div class="app-content">
  3. <div v-if="showBindArea">
  4. <form @submit="formSubmit">
  5. <div class="module-com input-line-wrap">
  6. <div
  7. class="prompt-text"
  8. style="padding-top:20rpx;margin-bottom:20rpx;font-size:30rpx;"
  9. >请按以下操作完成绑定:</div>
  10. <tui-list-cell class="line-cell" :hover="false">
  11. <div class="tui-title required" style="width:120rpx;">手机号</div>
  12. <view style="width:400rpx;">{{form.mobile}}</view>
  13. <button
  14. class="admin-button-com blue mini-btn"
  15. open-type="getPhoneNumber"
  16. @getphonenumber="getWxMobile"
  17. >帮我填</button>
  18. </tui-list-cell>
  19. <tui-list-cell class="line-cell" :hover="false">
  20. <div class="tui-title required" style="width:120rpx;">昵称</div>
  21. <view style="width:400rpx;">{{form.name}}</view>
  22. <button
  23. class="admin-button-com blue mini-btn"
  24. @click="getWxAvatar"
  25. >帮我填</button>
  26. </tui-list-cell>
  27. <div
  28. class="prompt-text"
  29. style="margin-top:20rpx;margin-bottom:20rpx;font-size:30rpx;"
  30. >关注公众号,第一时间接收门店动态:</div>
  31. <tui-list-cell>
  32. <block>
  33. <official-account></official-account>
  34. </block>
  35. </tui-list-cell>
  36. <div class="btn-wrap">
  37. <button class="admin-button-com blue big" formType="submit">完成</button>
  38. </div>
  39. </div>
  40. </form>
  41. </div>
  42. <div v-if="showSuccessArea">
  43. <view style="text-align:center;padding-top:50rpx;">
  44. <img
  45. :src="`${constant.imgUrl}/retail/callback/success.png`"
  46. alt
  47. mode="widthFix"
  48. style="width:30vh;margin:0 auto;"
  49. />
  50. </view>
  51. <view style="text-align:center;font-size:40rpx;margin-top:30rpx;">绑定成功</view>
  52. <view style="text-align:center;margin-top:5vh">
  53. <button
  54. class="admin-button-com blue big"
  55. style="width:260rpx;"
  56. @click="redirectToCenter"
  57. >管理中心</button>
  58. </view>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import { mapGetters } from "vuex";
  64. import TuiListCell from "@/components/plugin/list-cell";
  65. const form = require("@/utils/formValidation.js");
  66. import { generateAdmin } from "@/api/shop-admin";
  67. import { getWxInfo, getWxPhone } from "@/api/mini";
  68. export default {
  69. name: "bind",
  70. components: {
  71. TuiListCell
  72. },
  73. data() {
  74. return {
  75. form: {
  76. mobile: "",
  77. recommendAdminId: "",
  78. shopId: "",
  79. adminId: "",
  80. name: ""
  81. },
  82. levelSelData: {},
  83. showBindArea:true,
  84. showSuccessArea:false
  85. };
  86. },
  87. computed: {},
  88. onLoad(props) {
  89. console.log(props)
  90. const scene = decodeURIComponent(props.scene);
  91. var sceneItem = scene.split("&");
  92. var arr, name, value;
  93. var sceneArray = new Array();
  94. for (var i = 0, l = sceneItem.length; i < l; i++) {
  95. arr = sceneItem[i].split("=");
  96. name = arr[0];
  97. value = arr[1];
  98. sceneArray[name] = value;
  99. }
  100. this.form.recommendAdminId = sceneArray.adminId;
  101. this.form.shopId = sceneArray.shopId;
  102. },
  103. methods: {
  104. confirmFn() {
  105. generateAdmin(this.form).then(res => {
  106. this.showBindArea = false
  107. this.showSuccessArea = true
  108. uni.clearStorageSync();
  109. });
  110. },
  111. // 表单验证
  112. formSubmit(e) {
  113. // 表单规则
  114. let rules = [
  115. {
  116. name: "mobile",
  117. rule: ["required"],
  118. msg: ["请填写手机号"]
  119. },
  120. {
  121. name: "shopId",
  122. rule: ["required"],
  123. msg: ["系统错误(shopId)"]
  124. },
  125. {
  126. name: "recommendAdminId",
  127. rule: ["required"],
  128. msg: ["系统错误(recommendAdminId)"]
  129. },
  130. {
  131. name: "adminId",
  132. rule: ["required"],
  133. msg: ["请填写昵称"]
  134. }
  135. ];
  136. // 进行表单检查
  137. let formData = this.form;
  138. let checkRes = form.validation(formData, rules);
  139. // 验证通过!
  140. if (!checkRes) {
  141. this.confirmFn();
  142. } else {
  143. this.$msg(checkRes);
  144. }
  145. },
  146. // 获取微信手机号
  147. getWxMobile(e) {
  148. if (e.detail.errMsg === "getPhoneNumber:ok") {
  149. getWxPhone({
  150. iv: e.detail.iv,
  151. encryptedData: e.detail.encryptedData
  152. }).then(res => {
  153. this.form.mobile = res.data.mobile;
  154. uni.showToast({
  155. icon: "success"
  156. });
  157. });
  158. } else {
  159. this.$msg("获取信息失败!");
  160. }
  161. },
  162. // 获取微信信息
  163. getWxAvatar() {
  164. // uni.getUserInfo({
  165. // provider: "weixin",
  166. // success: res => {
  167. // },
  168. // fail: () => {
  169. // // this.loading = false
  170. // }
  171. // });
  172. uni.getUserProfile({
  173. desc:'登录',
  174. success:(res)=>{
  175. getWxInfo({ iv: res.iv, encryptedData: res.encryptedData }).then(
  176. subRes => {
  177. this.form.adminId = subRes.data.id;
  178. this.form.name = subRes.data.name;
  179. uni.showToast({
  180. icon: "success"
  181. });
  182. }
  183. );
  184. },
  185. fail:(res)=>{
  186. }
  187. });
  188. },
  189. redirectToCenter() {
  190. this.$util.pageTo({
  191. url: "/admin/home/workbench",
  192. type: 3
  193. });
  194. }
  195. }
  196. };
  197. </script>
  198. <style lang="scss" scoped>
  199. </style>