RedPkgAdd.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div>
  3. <el-dialog
  4. title="添加微信红包奖品"
  5. :visible.sync="dialogVisible"
  6. :before-close="close"
  7. width="500px"
  8. >
  9. <el-form
  10. :model="packetForm"
  11. :rules="packetRules"
  12. ref="packetForm"
  13. label-width="100px"
  14. >
  15. <el-form-item label="金额" prop="quantity">
  16. <el-input
  17. v-model="packetForm.quantity"
  18. size="small"
  19. placeholder="请输入微信红包金额"
  20. style="width: 200px"
  21. />
  22. </el-form-item>
  23. </el-form>
  24. <div class="dialog-btn">
  25. <el-button size="small" @click="close"> 取 消 </el-button>
  26. <div class="ge"></div>
  27. <el-button type="primary" size="small" @click="confirmRedPkg">
  28. 确 认
  29. </el-button>
  30. </div>
  31. </el-dialog>
  32. </div>
  33. </template>
  34. <script>
  35. import { publicFileGetUrl } from "@/api/common";
  36. import { accMul, accDiv } from "@/utils/util";
  37. export default{
  38. name: "RedPkgAdd",
  39. props: {
  40. dialogVisible: {
  41. type: Boolean,
  42. default: false,
  43. },
  44. },
  45. data() {
  46. return {
  47. packetForm: { quantity: "" },
  48. packetRules: {
  49. quantity: [
  50. { required: true, message: "请输入金额", trigger: "blur" },
  51. {
  52. pattern:
  53. /^([1-9]\d*(\.\d{1,2})?|([0](\.([0][1-9]|[1-9]\d{0,1}))))$/,
  54. message: "请输入合法的金额数字,最多两位小数",
  55. trigger: ["blur", "change"],
  56. },
  57. ],
  58. },
  59. };
  60. },
  61. methods: {
  62. // 确认输入金额
  63. confirmRedPkg() {
  64. let redPacket = {
  65. prizeType: "red_pkg",
  66. quantity: 1,
  67. title: `微信红包 ${this.packetForm.quantity} 元`,
  68. picUrl: publicFileGetUrl + "static/redPkg.png",
  69. value: accMul(this.packetForm.quantity, 100),
  70. sortWeight: 100
  71. };
  72. this.$refs["packetForm"].validate((valid) => {
  73. if (valid) {
  74. this.$emit("confirmRedPkg", redPacket);
  75. } else {
  76. return false;
  77. }
  78. });
  79. },
  80. close() {
  81. this.$emit("close");
  82. },
  83. },
  84. };
  85. </script>
  86. <style lang="scss" scoped>
  87. .dialog-btn {
  88. display: flex;
  89. align-content: center;
  90. justify-content: flex-end;
  91. padding: 40px 0 0;
  92. .ge {
  93. width: 40px;
  94. }
  95. }
  96. </style>