bind.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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.nickName}}</view>
  22. <button
  23. class="admin-button-com blue mini-btn"
  24. open-type="getUserInfo"
  25. @getuserinfo="getWxAvatar"
  26. >帮我填</button>
  27. </tui-list-cell>
  28. <div
  29. class="prompt-text"
  30. style="margin-top:20rpx;margin-bottom:20rpx;font-size:30rpx;"
  31. >关注公众号,第一时间接收门店动态:</div>
  32. <tui-list-cell>
  33. <block>
  34. <official-account></official-account>
  35. </block>
  36. </tui-list-cell>
  37. <div class="btn-wrap">
  38. <button class="admin-button-com blue big" formType="submit">完成</button>
  39. </div>
  40. </div>
  41. </form>
  42. </div>
  43. <div v-if="showSuccessArea">
  44. <view style="text-align:center;padding-top:50rpx;">
  45. <img
  46. :src="`${constant.imgUrl}/retail/callback/success.png`"
  47. alt
  48. mode="widthFix"
  49. style="width:30vh;margin:0 auto;"
  50. />
  51. </view>
  52. <view style="text-align:center;font-size:40rpx;margin-top:30rpx;">绑定成功</view>
  53. <view style="text-align:center;margin-top:5vh">
  54. <button
  55. class="admin-button-com blue big"
  56. style="width:260rpx;"
  57. @click="redirectToCenter"
  58. >管理中心</button>
  59. </view>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import { mapGetters } from "vuex";
  65. import TuiListCell from "@/components/plugin/list-cell";
  66. const form = require("@/utils/formValidation.js");
  67. import { generateAdmin } from "@/api/shop-admin";
  68. import { getWxInfo, getWxPhone } from "@/api/mini";
  69. export default {
  70. name: "bind",
  71. components: {
  72. TuiListCell
  73. },
  74. data() {
  75. return {
  76. form: {
  77. mobile: "",
  78. recommendAdminId: "",
  79. shopId: "",
  80. adminId: "",
  81. nickName: ""
  82. },
  83. levelSelData: {},
  84. showBindArea:true,
  85. showSuccessArea:false
  86. };
  87. },
  88. computed: {},
  89. onLoad(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. getWxInfo({ iv: res.iv, encryptedData: res.encryptedData }).then(
  168. subRes => {
  169. this.form.adminId = subRes.data.id;
  170. this.form.nickName = subRes.data.nickName;
  171. uni.showToast({
  172. icon: "success"
  173. });
  174. }
  175. );
  176. },
  177. fail: () => {
  178. // this.loading = false
  179. }
  180. });
  181. },
  182. redirectToCenter() {
  183. this.$util.pageTo({
  184. url: "/admin/home/workbench",
  185. type: 3
  186. });
  187. }
  188. }
  189. };
  190. </script>
  191. <style lang="scss" scoped>
  192. </style>