PromoCodeCreate.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <div class="promo_code_create clear">
  3. <!-- 正常 -->
  4. <!-- <el-button
  5. v-show="canSms"
  6. class="create_code"
  7. type="primary"
  8. plain
  9. @click="genPromoCode"
  10. >
  11. {{ title }}
  12. </el-button> -->
  13. <!-- 倒计时 -->
  14. <!-- <el-button
  15. v-show="!canSms"
  16. class="create_code el_gray"
  17. type="primary"
  18. plain
  19. >
  20. {{ createText }}
  21. </el-button> -->
  22. <div class="clear code">
  23. <div class="promo_code text_overflow">{{ link }}</div>
  24. <el-tooltip class="item" effect="dark" content="点击复制" placement="top">
  25. <div
  26. class="copy"
  27. data-clipboard-action="copy"
  28. :data-clipboard-text="link"
  29. id="clipboard_promo_code"
  30. >
  31. <i class="el-icon-document-copy"></i>
  32. </div>
  33. </el-tooltip>
  34. <span>({{ tips }})</span>
  35. </div>
  36. </div>
  37. </template>
  38. <script>
  39. export default {
  40. name: "PromoCodeCreate",
  41. components: {},
  42. inject: ["checkCode"],
  43. data() {
  44. return {
  45. promoCode: "", // 推广码链接
  46. clipboard: null, // 复制
  47. createText: "", // 生成推广码
  48. canSms: true, // 是否可以点击生成推广码
  49. };
  50. },
  51. props: {
  52. // 按钮名
  53. title: {
  54. type: String,
  55. default: "",
  56. },
  57. // 链接
  58. link: {
  59. type: String,
  60. default: "",
  61. },
  62. tips: {
  63. type: String,
  64. default: "",
  65. },
  66. },
  67. computed: {},
  68. watch: {},
  69. created() {},
  70. mounted() {
  71. this.initClipboard();
  72. },
  73. beforeDestroy() {
  74. this.clipboard.destroy();
  75. },
  76. methods: {
  77. /**
  78. * 初始化 clipboard插件
  79. */
  80. initClipboard() {
  81. this.clipboard = new this.$clipboard("#clipboard_promo_code");
  82. this.clipboard.on("success", () => {
  83. this.$notify({
  84. message: "复制成功!",
  85. type: "success",
  86. });
  87. });
  88. this.clipboard.on("error", () => {
  89. this.$notify.error({
  90. message: "复制失败!",
  91. });
  92. });
  93. },
  94. // 生成推广码
  95. genPromoCode() {
  96. if (!this.canSms) {
  97. return;
  98. }
  99. this.countDown();
  100. this.$api.genPromoCode().then((res) => {
  101. this.promoCode = "";
  102. this.checkCode(res);
  103. const { code, data, msg } = res.data;
  104. if (code) {
  105. return;
  106. }
  107. // 成功 通知父组件请求推广码列表数据
  108. this.$emit("onGetpromoCodeList", 1, 15);
  109. this.promoCode = `${this.link}?promoCode=${data.promoCode}`;
  110. });
  111. },
  112. // 倒计时
  113. countDown() {
  114. this.canSms = false;
  115. let count = 60;
  116. this.createText = count + "s";
  117. this.countDownTimer = setInterval(() => {
  118. count--;
  119. this.createText = count + "s";
  120. // 倒计时结束
  121. if (count === 0) {
  122. this.createText = "获取验证码";
  123. this.canSms = true;
  124. clearInterval(this.countDownTimer);
  125. }
  126. }, 1000);
  127. },
  128. },
  129. };
  130. </script>
  131. <style lang='less' scoped>
  132. .promo_code_create {
  133. .create_code,
  134. .code {
  135. float: left;
  136. }
  137. .create_code {
  138. width: 140px;
  139. }
  140. .el_gray {
  141. background-color: #dee1e6 !important;
  142. }
  143. .code {
  144. width: 100%;
  145. margin: 0 10px;
  146. span {
  147. line-height: 40px;
  148. float: left;
  149. margin-left: 10px;
  150. font-weight: bold;
  151. font-size: 20px;
  152. }
  153. .promo_code {
  154. width: 70%;
  155. height: 40px;
  156. padding-left: 10px;
  157. line-height: 40px;
  158. float: left;
  159. cursor: pointer;
  160. border: 1px solid #e6e6e6;
  161. border-radius: 5px 0 0 5px;
  162. background-color: #fff;
  163. color: #9a999f;
  164. }
  165. .copy {
  166. width: 40px;
  167. height: 40px;
  168. line-height: 40px;
  169. float: left;
  170. border: 1px solid #e6e6e6;
  171. border-left: 0;
  172. border-radius: 0 5px 5px 0;
  173. cursor: pointer;
  174. background-color: #fff;
  175. }
  176. }
  177. }
  178. </style>