membershipCode.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <uv-popup ref="popupRef" mode="center" bgColor="none">
  3. <view>
  4. <view class="membership-code">
  5. <view class="membership-code-view">
  6. <view class="membership-code-title">
  7. <HeadlineDecorate />
  8. <text class="text">{{
  9. props.type == 1 ? "会员码" : "店铺收款码"
  10. }}</text>
  11. <HeadlineDecorate reversal />
  12. </view>
  13. <view class="code-content" v-if="props.type == 1">
  14. <text class="code-text">{{ info.code || "--" }}</text>
  15. <text class="iconfont" v-if="info.code" @click.stop="handleCopy"
  16. >&#xe64f;</text
  17. >
  18. </view>
  19. <view class="QR-code">
  20. <image
  21. v-if="info.qrUrl || info.qrCode"
  22. class="QR-code-img"
  23. :src="info.qrUrl || info.qrCode"
  24. alt=""
  25. />
  26. </view>
  27. <view class="membership-code-prompt u-flex-center">
  28. <text v-if="props.type == 1"> 动态会员码,仅限单次核销使用 </text>
  29. <template v-else>
  30. <image class="shop-img" :src="info.image" mode="aspectFit"></image>
  31. <text class="text">由药品商城提供技术支持</text>
  32. </template>
  33. </view>
  34. <view
  35. class="u-btn-two membership-code-btn"
  36. @click.stop="getInfo(2)"
  37. v-if="props.type == 1"
  38. >
  39. 重新获取二维码
  40. </view>
  41. <view
  42. class="u-btn-two membership-code-btn"
  43. @click.stop="downloadQrCode()"
  44. v-if="props.type == 2 && info.qrCode"
  45. >
  46. 下载店铺收款码
  47. </view>
  48. </view>
  49. </view>
  50. <view class="close" @click="popupRef.close()">
  51. <uv-icon name="close-circle" color="#c4c4c4" size="50rpx"></uv-icon>
  52. </view>
  53. </view>
  54. </uv-popup>
  55. </template>
  56. <script setup name="membershipCode">
  57. import { ref } from "vue";
  58. import { getMemberCode_Api, refreshQrCode_Api } from "@/api/userInfo";
  59. const props = defineProps({
  60. type: {
  61. type: Number,
  62. default: 1, // 1: 会员码使用, 2: 店铺码使用
  63. },
  64. });
  65. const popupRef = ref(null);
  66. const info = ref({});
  67. const handleCopy = () => {
  68. uni.setClipboardData({
  69. data: info.value.code || "",
  70. success: () => {
  71. uni.$uv.toast("复制成功");
  72. },
  73. });
  74. };
  75. const getInfo = async (type = 1) => {
  76. let url = type == 1 ? getMemberCode_Api : refreshQrCode_Api;
  77. uni.showLoading({ title: "加载中...", mask: true });
  78. await url()
  79. .then((res) => {
  80. uni.hideLoading();
  81. if (res && res.code == 200) {
  82. info.value = res.data || {};
  83. }
  84. })
  85. .catch((err) => {
  86. console.log(err);
  87. // uni.hideLoading();
  88. });
  89. };
  90. const open = async (form = {}) => {
  91. if (props.type == 1) {
  92. await getInfo(1);
  93. } else {
  94. info.value = form || {};
  95. }
  96. popupRef.value.open();
  97. };
  98. const downloadQrCode = () => {
  99. if (!info.value.qrCode) {
  100. uni.$uv.toast("未获取到店铺码");
  101. return
  102. }
  103. uni.showLoading({
  104. title: '下载中...',
  105. mask: true,
  106. });
  107. uni.downloadFile({
  108. url: info.value.qrCode,
  109. success: (res) => {
  110. if (res.statusCode === 200) {
  111. uni.saveImageToPhotosAlbum({
  112. filePath: res.tempFilePath,
  113. success: () => {
  114. uni.hideLoading();
  115. uni.$uv.toast("下载成功");
  116. },
  117. fail: () => {
  118. uni.hideLoading();
  119. uni.$uv.toast("保存失败");
  120. },
  121. });
  122. } else {
  123. uni.hideLoading();
  124. uni.$uv.toast("下载失败");
  125. }
  126. },
  127. fail: () => {
  128. uni.hideLoading();
  129. uni.$uv.toast("下载失败");
  130. },
  131. });
  132. };
  133. defineExpose({
  134. open,
  135. });
  136. </script>
  137. <style lang="scss" scoped>
  138. .membership-code {
  139. width: 507rpx;
  140. // min-height: 744rpx;
  141. background: linear-gradient(180deg, #fcfdfd, #fdd8d3);
  142. border-radius: 20rpx;
  143. padding: 14rpx;
  144. box-sizing: border-box;
  145. .membership-code-view {
  146. width: 100%;
  147. // min-height: 716rpx;
  148. border: 1rpx solid #dbd2d1;
  149. border-radius: 20rpx;
  150. padding: 50rpx 0 43rpx 0;
  151. .membership-code-title {
  152. text-align: center;
  153. .text {
  154. font-size: 36rpx;
  155. font-weight: 600;
  156. color: #1a1a1a;
  157. margin: 0 10rpx;
  158. }
  159. }
  160. .code-content {
  161. margin: 10rpx 0 0 0;
  162. text-align: center;
  163. color: #fb2914;
  164. .code-text {
  165. font-size: 28rpx;
  166. font-weight: 400;
  167. }
  168. .iconfont {
  169. font-size: 36rpx;
  170. margin-left: 5rpx;
  171. }
  172. }
  173. .QR-code {
  174. width: 326rpx;
  175. height: 326rpx;
  176. border: 1rpx solid #dcbcb8;
  177. border-radius: 20rpx;
  178. padding: 25rpx;
  179. box-sizing: border-box;
  180. margin: auto;
  181. margin-top: 40rpx;
  182. .QR-code-img {
  183. width: 100%;
  184. height: 100%;
  185. }
  186. }
  187. .membership-code-prompt {
  188. font-size: 26rpx;
  189. font-weight: 400;
  190. text-align: center;
  191. color: #1a1a1a;
  192. margin: 30rpx 0 36rpx 0;
  193. justify-content: center;
  194. .shop-img {
  195. width: 41rpx;
  196. height: 41rpx;
  197. border-radius: 6rpx;
  198. flex-shrink: 0;
  199. margin-right: 10rpx;
  200. }
  201. }
  202. .membership-code-btn.u-btn-two {
  203. width: 345rpx;
  204. margin: 0 auto;
  205. font-size: 28rpx;
  206. }
  207. }
  208. }
  209. .close {
  210. width: 100%;
  211. margin-top: 44rpx;
  212. display: flex;
  213. justify-content: center;
  214. }
  215. </style>