wx-points-commit.vue 6.2 KB

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