main.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div class="digitalInput">
  3. <el-input-number
  4. v-model="num"
  5. :name="name"
  6. class="fl"
  7. :class="{ appendInput: append }"
  8. @change="handleChange"
  9. @blur="handleChange"
  10. :precision="precision"
  11. :step="step"
  12. :min="min"
  13. :max="max"
  14. :disabled="disabled"
  15. :size="size || 'medium'"
  16. :placeholder="placeholder"
  17. :controls-position="position"
  18. />
  19. <!-- step-strictly -->
  20. <div
  21. class="my-append fl"
  22. :class="{
  23. 'my-append-mini': size === 'mini',
  24. 'my-append-small': size === 'small',
  25. }"
  26. v-if="append"
  27. >
  28. {{ append }}
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. export default {
  34. name: "digitalInput",
  35. props: [
  36. "values",
  37. "min",
  38. "max",
  39. "step",
  40. "precision",
  41. "size",
  42. "append",
  43. "name",
  44. "disabled",
  45. "controls",
  46. "newTime",
  47. "placeholder",
  48. "position",
  49. ],
  50. watch: {
  51. values: function (val) {
  52. // console.log(this.name + "=" + val);
  53. this.num = val;
  54. },
  55. newTime: function (val) {
  56. // console.log(this.name + "=" + this.values);
  57. this.num = this.values;
  58. this.$emit("reschange", this.num);
  59. },
  60. min: function (val) {
  61. let a = this.accMul(val, "1");
  62. let b = this.accMul(this.num, "1");
  63. console.log(a, b);
  64. if (a >= b) {
  65. this.num = a + "";
  66. this.$emit("reschange", this.num);
  67. }
  68. },
  69. max: function (val) {
  70. let a = this.accMul(val, "1");
  71. let b = this.accMul(this.num, "1");
  72. console.log(a, b);
  73. if (a <= b) {
  74. this.num = a + "";
  75. this.$emit("reschange", this.num);
  76. }
  77. },
  78. },
  79. data() {
  80. return {
  81. num: 0,
  82. loading: false,
  83. };
  84. },
  85. methods: {
  86. handleChange(value) {
  87. this.$emit("reschange", this.num);
  88. // console.log(value);
  89. },
  90. accMul(arg1, arg2) {
  91. var m = 0,
  92. s1 = arg1.toString(),
  93. s2 = arg2.toString();
  94. try {
  95. m += s1.split(".")[1].length;
  96. } catch (e) {}
  97. try {
  98. m += s2.split(".")[1].length;
  99. } catch (e) {}
  100. return (
  101. (Number(s1.replace(".", "")) * Number(s2.replace(".", ""))) /
  102. Math.pow(10, m)
  103. );
  104. },
  105. },
  106. };
  107. </script>
  108. <style lang="scss" scoped>
  109. .digitalInput {
  110. width: 100%;
  111. /deep/ .el-input-number.is-controls-right .el-input__inner {
  112. padding-right: 15px !important;
  113. text-align: left !important;
  114. }
  115. /deep/.el-input-number.is-controls-right .el-input-number__decrease {
  116. display: none !important;
  117. }
  118. /deep/.el-input-number.is-controls-right .el-input-number__increase {
  119. display: none !important;
  120. }
  121. /deep/.el-input-number {
  122. width: 100% !important;
  123. &.appendInput {
  124. width: calc(100% - 40px) !important;
  125. .el-input__inner {
  126. border-top-right-radius: 0px !important;
  127. border-bottom-right-radius: 0px !important;
  128. }
  129. }
  130. }
  131. .my-append {
  132. width: 40px;
  133. height: 40px;
  134. line-height: 40px;
  135. box-sizing: border-box;
  136. text-align: center;
  137. background-color: #f5f7fa;
  138. color: #909399;
  139. position: relative;
  140. border: 1px solid #dcdfe6;
  141. border-left: 0;
  142. border-top-right-radius: 4px;
  143. border-bottom-right-radius: 4px;
  144. &.my-append-small {
  145. height: 32px !important;
  146. line-height: 32px !important;
  147. }
  148. &.my-append-mini {
  149. height: 28px !important;
  150. line-height: 28px !important;
  151. }
  152. }
  153. }
  154. </style>