index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. "use strict";
  2. var _component = require("../common/component");
  3. var _props = require("./props");
  4. var _my = require("../../__antmove/api/index.js")(my);
  5. var wx = _my;
  6. (0, _component.VantComponent)({
  7. field: true,
  8. classes: ["input-class", "right-icon-class", "label-class"],
  9. props: Object.assign(Object.assign(Object.assign(Object.assign({}, _props.commonProps), _props.inputProps), _props.textareaProps), {
  10. size: String,
  11. icon: String,
  12. label: String,
  13. error: Boolean,
  14. center: Boolean,
  15. isLink: Boolean,
  16. leftIcon: String,
  17. rightIcon: String,
  18. autosize: [Boolean, Object],
  19. required: Boolean,
  20. iconClass: String,
  21. clickable: Boolean,
  22. inputAlign: String,
  23. customStyle: String,
  24. errorMessage: String,
  25. arrowDirection: String,
  26. showWordLimit: Boolean,
  27. errorMessageAlign: String,
  28. readonly: {
  29. type: Boolean,
  30. observer: "setShowClear"
  31. },
  32. clearable: {
  33. type: Boolean,
  34. observer: "setShowClear"
  35. },
  36. border: {
  37. type: Boolean,
  38. value: true
  39. },
  40. titleWidth: {
  41. type: String,
  42. value: "6.2em"
  43. }
  44. }),
  45. data: {
  46. focused: false,
  47. innerValue: "",
  48. showClear: false
  49. },
  50. created: function created() {
  51. this.value = this.data.value;
  52. this.setData({
  53. innerValue: this.value
  54. });
  55. },
  56. methods: {
  57. onInput: function onInput(event) {
  58. var _ref = event.detail || {},
  59. _ref$value = _ref.value,
  60. value = _ref$value === void 0 ? "" : _ref$value;
  61. this.value = value;
  62. this.setData({
  63. innerValue: value
  64. });
  65. this.setShowClear();
  66. this.emitChange();
  67. },
  68. onFocus: function onFocus(event) {
  69. this.focused = true;
  70. this.setShowClear();
  71. this.$emit("focus", event.detail);
  72. },
  73. onBlur: function onBlur(event) {
  74. this.focused = false;
  75. this.setShowClear();
  76. this.$emit("blur", event.detail);
  77. },
  78. onClickIcon: function onClickIcon() {
  79. this.$emit("click-icon");
  80. },
  81. onClear: function onClear() {
  82. var _this = this;
  83. this.setData({
  84. innerValue: ""
  85. });
  86. this.value = "";
  87. this.setShowClear();
  88. wx.nextTick(function () {
  89. _this.emitChange();
  90. _this.$emit("clear", "");
  91. });
  92. },
  93. onConfirm: function onConfirm(event) {
  94. var _ref2 = event.detail || {},
  95. _ref2$value = _ref2.value,
  96. value = _ref2$value === void 0 ? "" : _ref2$value;
  97. this.value = value;
  98. this.setShowClear();
  99. this.$emit("confirm", value);
  100. },
  101. setValue: function setValue(value) {
  102. this.value = value;
  103. this.setShowClear();
  104. if (value === "") {
  105. this.setData({
  106. innerValue: ""
  107. });
  108. }
  109. this.emitChange();
  110. },
  111. onLineChange: function onLineChange(event) {
  112. this.$emit("linechange", event.detail);
  113. },
  114. onKeyboardHeightChange: function onKeyboardHeightChange(event) {
  115. this.$emit("keyboardheightchange", event.detail);
  116. },
  117. emitChange: function emitChange() {
  118. var _this2 = this;
  119. //this.setData({ value: this.value });
  120. wx.nextTick(function () {
  121. _this2.$emit("input", _this2.value);
  122. _this2.$emit("change", _this2.value);
  123. });
  124. },
  125. setShowClear: function setShowClear() {
  126. var _this$data = this.data,
  127. clearable = _this$data.clearable,
  128. readonly = _this$data.readonly;
  129. var focused = this.focused,
  130. value = this.value;
  131. this.setData({
  132. showClear: !!clearable && !!focused && !!value && !readonly
  133. });
  134. },
  135. noop: function noop() {}
  136. }
  137. });