wx-points-commit.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <template>
  2. <view class="box" v-if="show" @touchmove.stop.prevent>
  3. <view class="boxIn">
  4. <view class="content">
  5. <image class="commit-star" src="https://cnsh-kerry-crm-prod.oss-cn-shanghai.aliyuncs.com/images/wx-points/points-commit.png"> </image>
  6. <image v-if="custTypeId === 0" class="commit-logo-default" src="https://cnsh-kerry-crm-prod.oss-cn-shanghai.aliyuncs.com/images/wx-points/kerry.png"> </image>
  7. <image v-else class="commit-logo-ko" src="https://cnsh-kerry-crm-prod.oss-cn-shanghai.aliyuncs.com/images/wx-points/ko.png"> </image>
  8. <view class="logo"> </view>
  9. <view class="title"> 您有消费积分未领取 </view>
  10. <view class="text"> 如您的微信支付积分未到账,请于消费当日申请领取 </view>
  11. <view @click="toWxPointsAuth" class="commit-btn" :class="{ 'commit-btn--blue': custTypeId === 1, 'commit-btn--green': custTypeId === 2 }"> 去领取 </view>
  12. <image @click="close" class="commit-cancel" src="https://cnsh-kerry-crm-prod.oss-cn-shanghai.aliyuncs.com/images/wx-points/close.svg"> </image>
  13. </view>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import { mapState } from 'vuex';
  19. import { kipGetPointsConfig } from '@/utils/api-kip.js';
  20. // const app = getApp();
  21. const app = {};
  22. export default {
  23. props: {},
  24. created() {
  25. // this.handleGetPointsConfig()
  26. },
  27. watch: {},
  28. data() {
  29. return {
  30. pointsConfig: null,
  31. show: false,
  32. clickToWxPointsAuth: false,
  33. };
  34. },
  35. computed: {
  36. // custTypeId: 0 默认版本,1 上海静安 2 上海浦东
  37. ...mapState({
  38. // custTypeId: 0
  39. custTypeId: (state) => state.custTypeId,
  40. }),
  41. },
  42. methods: {
  43. checkoutLogin() {
  44. const pages = getCurrentPages();
  45. let url = '/' + pages[pages.length - 1].route;
  46. pages[pages.length - 1].$vm.$refs.child.login(url, () => {
  47. this.toWxPointsAuth();
  48. });
  49. },
  50. handleGetPointsConfig() {
  51. kipGetPointsConfig()
  52. .then((resp) => {
  53. const result = resp.data;
  54. // codes,wxAuth,aliAuth
  55. this.pointsConfig = result;
  56. if (result) {
  57. if (result && result.codes) {
  58. // codes,wxAuth,aliAuth
  59. this.pointsConfig = result;
  60. this.checkoutLogin();
  61. } else {
  62. if (result.code && result.code === '300000') {
  63. this.checkoutLogin();
  64. } else {
  65. uni.showToast({
  66. icon: 'none',
  67. mask: true,
  68. duration: 2000,
  69. title: result.errorMessage || result.message || '出错了,请稍后再试',
  70. });
  71. }
  72. }
  73. } else {
  74. if (resp.code && resp.code === '300000') {
  75. this.checkoutLogin();
  76. } else {
  77. uni.showToast({
  78. icon: 'none',
  79. mask: true,
  80. duration: 2000,
  81. title: resp.message,
  82. });
  83. }
  84. }
  85. })
  86. .catch((e) => {
  87. uni.showToast({
  88. icon: 'none',
  89. mask: true,
  90. title: '请求错误',
  91. });
  92. });
  93. },
  94. async toWxPointsAuth() {
  95. console.log('授权微信无感积分');
  96. if (this.clickToWxPointsAuth) {
  97. console.log('授权微信无感积分重复点击');
  98. return;
  99. }
  100. await this.handleGetPointsConfig();
  101. this.clickToWxPointsAuth = true;
  102. var myPluginInterface = requirePlugin('myPlugin');
  103. uni.showLoading();
  104. const _this = this;
  105. await myPluginInterface.getLocation(app.globalData.openId).then((res) => {
  106. const that = _this;
  107. if (res.return_code === 0) {
  108. uni.navigateTo({
  109. url: `plugin://myPlugin/index?openid=${app.globalData.openId}&mch_id=${that.pointsConfig.mchId}&member_status=${that.pointsConfig.wxAuth ? 1 : 0}`,
  110. success: function () {
  111. that.close();
  112. uni.hideLoading();
  113. that.clickToWxPointsAuth = false;
  114. },
  115. });
  116. } else if (res.return_code === '102') {
  117. uni.showModal({
  118. title: '提示',
  119. content: '请您在”定位服务“中允许”微信”使用位置信息, 并允许该小程序使用定位功能',
  120. showCancel: false,
  121. confirmText: '确认',
  122. success: function (res) {
  123. that.close();
  124. that.clickToWxPointsAuth = false;
  125. },
  126. });
  127. uni.hideLoading();
  128. } else {
  129. that.clickToWxPointsAuth = false;
  130. }
  131. });
  132. },
  133. open() {
  134. this.show = true;
  135. },
  136. close() {
  137. this.show = false;
  138. },
  139. },
  140. };
  141. </script>
  142. <style scoped lang="less">
  143. .box {
  144. position: fixed;
  145. z-index: 10000;
  146. width: 100vw;
  147. height: 100vh;
  148. background: rgba(0, 0, 0, 0.7);
  149. }
  150. .boxIn {
  151. position: relative;
  152. width: 100%;
  153. height: 100%;
  154. }
  155. .content {
  156. position: relative;
  157. width: calc(100% - 110px);
  158. height: 232px;
  159. background: #ffffff;
  160. border-radius: 8px;
  161. margin: 0 auto;
  162. margin-top: 280px;
  163. }
  164. .commit-star {
  165. position: absolute;
  166. width: calc(100vw - 40px);
  167. height: calc(48.1vw - 23.6px);
  168. top: calc(11.8px - 24.05vw);
  169. left: -33px;
  170. }
  171. .commit-logo-default {
  172. width: 84px;
  173. height: 20px;
  174. position: relative;
  175. display: block;
  176. top: 15px;
  177. left: 30px;
  178. }
  179. .commit-logo-ko {
  180. width: 80px;
  181. height: 20px;
  182. position: relative;
  183. display: block;
  184. top: 15px;
  185. left: 35px;
  186. }
  187. .logo {
  188. height: 35px;
  189. border-bottom: 1rpx solid rgba(151, 151, 151, 0.1);
  190. }
  191. .title {
  192. font-size: 16px;
  193. font-weight: 600;
  194. color: #333;
  195. text-align: center;
  196. margin-top: 22px;
  197. }
  198. .text {
  199. width: 180px;
  200. margin: 0 auto;
  201. margin-top: 8px;
  202. color: #999;
  203. font-size: 12px;
  204. text-align: center;
  205. }
  206. .commit-btn {
  207. width: calc(100vw - 180px);
  208. height: 40px;
  209. margin: 0 auto;
  210. margin-top: 17px;
  211. line-height: 40px;
  212. text-align: center;
  213. font-size: 15px;
  214. color: #fff;
  215. background: #644a79;
  216. border-radius: 25px;
  217. box-shadow: 3px 3px 12px 0px #644a79;
  218. }
  219. .commit-btn--blue {
  220. box-shadow: 3px 3px 12px 0px #13358e;
  221. background: #13358e;
  222. }
  223. .commit-btn--green {
  224. box-shadow: 3px 3px 12px 0px #25673c;
  225. background: #25673c;
  226. }
  227. .commit-cancel {
  228. position: relative;
  229. display: block;
  230. margin: 0 auto;
  231. margin-top: 56px;
  232. width: 32px;
  233. height: 32px;
  234. }
  235. </style>