bind.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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/admin-shop";
  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. console.log(encodeURIComponent("adminId=18533&shopId=15680"));
  91. const scene = decodeURIComponent(props.scene);
  92. console.log(scene);
  93. var sceneItem = scene.split("&");
  94. var arr, name, value;
  95. var sceneArray = new Array();
  96. for (var i = 0, l = sceneItem.length; i < l; i++) {
  97. arr = sceneItem[i].split("=");
  98. name = arr[0];
  99. value = arr[1];
  100. sceneArray[name] = value;
  101. }
  102. this.form.recommendAdminId = sceneArray.adminId;
  103. this.form.shopId = sceneArray.shopId;
  104. },
  105. methods: {
  106. confirmFn() {
  107. generateAdmin(this.form).then(res => {
  108. this.showBindArea = false
  109. this.showSuccessArea = true
  110. uni.setStorageSync('shopId', res.data.shopId)
  111. //this.$msg("添加成功!");
  112. });
  113. },
  114. // 表单验证
  115. formSubmit(e) {
  116. // 表单规则
  117. let rules = [
  118. {
  119. name: "mobile",
  120. rule: ["required"],
  121. msg: ["请填写手机号"]
  122. },
  123. {
  124. name: "shopId",
  125. rule: ["required"],
  126. msg: ["系统错误(shopId)"]
  127. },
  128. {
  129. name: "recommendAdminId",
  130. rule: ["required"],
  131. msg: ["系统错误(recommendAdminId)"]
  132. },
  133. {
  134. name: "adminId",
  135. rule: ["required"],
  136. msg: ["请填写昵称"]
  137. }
  138. ];
  139. // 进行表单检查
  140. let formData = this.form;
  141. console.log(formData);
  142. let checkRes = form.validation(formData, rules);
  143. // 验证通过!
  144. if (!checkRes) {
  145. this.confirmFn();
  146. } else {
  147. this.$msg(checkRes);
  148. }
  149. },
  150. // 获取微信手机号
  151. getWxMobile(e) {
  152. console.log(e);
  153. if (e.detail.errMsg === "getPhoneNumber:ok") {
  154. getWxPhone({
  155. iv: e.detail.iv,
  156. encryptedData: e.detail.encryptedData
  157. }).then(res => {
  158. this.form.mobile = res.data.mobile;
  159. uni.showToast({
  160. icon: "success"
  161. });
  162. });
  163. } else {
  164. this.$msg("获取信息失败!");
  165. }
  166. },
  167. // 获取微信信息
  168. getWxAvatar() {
  169. uni.getUserInfo({
  170. provider: "weixin",
  171. success: res => {
  172. console.log("res", res);
  173. // this.popupShow = true
  174. getWxInfo({ iv: res.iv, encryptedData: res.encryptedData }).then(
  175. subRes => {
  176. this.form.adminId = subRes.data.id;
  177. this.form.nickname = subRes.data.nickname;
  178. uni.showToast({
  179. icon: "success"
  180. });
  181. }
  182. );
  183. },
  184. fail: () => {
  185. // this.loading = false
  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>