PromoCodeCreatePlayer.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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_player"
  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. // 备注
  63. tips: {
  64. type: String,
  65. default: "",
  66. },
  67. },
  68. computed: {},
  69. watch: {},
  70. created() {},
  71. mounted() {
  72. this.initClipboard();
  73. },
  74. beforeDestroy() {
  75. this.clipboard.destroy();
  76. },
  77. methods: {
  78. /**
  79. * 初始化 clipboard插件
  80. */
  81. initClipboard() {
  82. this.clipboard = new this.$clipboard("#clipboard_promo_code_player");
  83. this.clipboard.on("success", () => {
  84. this.$notify({
  85. message: "复制成功!",
  86. type: "success",
  87. });
  88. });
  89. this.clipboard.on("error", () => {
  90. this.$notify.error({
  91. message: "复制失败!",
  92. });
  93. });
  94. },
  95. // 生成推广码
  96. genPromoCode() {
  97. if (!this.canSms) {
  98. return;
  99. }
  100. this.countDown();
  101. this.$api.genPromoCode().then((res) => {
  102. this.promoCode = "";
  103. this.checkCode(res);
  104. const { code, data, msg } = res.data;
  105. if (code) {
  106. return;
  107. }
  108. // 成功 通知父组件请求推广码列表数据
  109. this.$emit("onGetpromoCodeList", 1, 15);
  110. this.promoCode = `${this.link}?promoCode=${data.promoCode}`;
  111. });
  112. },
  113. // 倒计时
  114. countDown() {
  115. this.canSms = false;
  116. let count = 60;
  117. this.createText = count + "s";
  118. this.countDownTimer = setInterval(() => {
  119. count--;
  120. this.createText = count + "s";
  121. // 倒计时结束
  122. if (count === 0) {
  123. this.createText = "获取验证码";
  124. this.canSms = true;
  125. clearInterval(this.countDownTimer);
  126. }
  127. }, 1000);
  128. },
  129. },
  130. };
  131. </script>
  132. <style lang='less' scoped>
  133. .promo_code_create {
  134. .create_code,
  135. .code {
  136. float: left;
  137. }
  138. .create_code {
  139. width: 140px;
  140. }
  141. .el_gray {
  142. background-color: #dee1e6 !important;
  143. }
  144. .code {
  145. width: 100%;
  146. margin: 0 10px;
  147. span {
  148. line-height: 40px;
  149. float: left;
  150. margin-left: 10px;
  151. font-weight: bold;
  152. font-size: 20px;
  153. }
  154. .promo_code {
  155. width: 70%;
  156. height: 40px;
  157. padding-left: 10px;
  158. line-height: 40px;
  159. float: left;
  160. cursor: pointer;
  161. border: 1px solid #e6e6e6;
  162. border-radius: 5px 0 0 5px;
  163. background-color: #fff;
  164. color: #9a999f;
  165. }
  166. .copy {
  167. width: 40px;
  168. height: 40px;
  169. line-height: 40px;
  170. float: left;
  171. border: 1px solid #e6e6e6;
  172. border-left: 0;
  173. border-radius: 0 5px 5px 0;
  174. cursor: pointer;
  175. background-color: #fff;
  176. }
  177. }
  178. }
  179. </style>