remark-input.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <view>
  3. <!-- 触发区域 -->
  4. <view class="remark-action" @click="openRemarkModal">
  5. <text :class="{ placeholder: !value }">{{ value || placeholder }}</text>
  6. <text class="iconfont iconxiangyou icon-arrow-right"></text>
  7. </view>
  8. <!-- 备注输入弹窗 -->
  9. <view class="remark-modal" v-if="showRemarkModal" @click="closeRemarkModal">
  10. <view class="modal-content" @click.stop>
  11. <view class="modal-header">
  12. <text class="modal-title">{{ modalTitle }}</text>
  13. </view>
  14. <view class="modal-body">
  15. <textarea
  16. v-model="tempRemark"
  17. :placeholder="placeholder"
  18. :maxlength="maxLength"
  19. :auto-height="true"
  20. class="remark-textarea"
  21. />
  22. <view class="char-count">{{ tempRemark.length }}/{{ maxLength }}</view>
  23. </view>
  24. <view class="modal-footer">
  25. <button class="modal-btn cancel-btn" @click="closeRemarkModal">取消</button>
  26. <button class="modal-btn confirm-btn" @click="confirmRemark">确认</button>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. name: 'DeliveryInput',
  35. props: {
  36. value: {
  37. type: String,
  38. default: ''
  39. },
  40. placeholder: {
  41. type: String,
  42. default: '请填写配送备注'
  43. },
  44. modalTitle: {
  45. type: String,
  46. default: '填写备注信息'
  47. },
  48. maxLength: {
  49. type: Number,
  50. default: 200
  51. }
  52. },
  53. data() {
  54. return {
  55. showRemarkModal: false,
  56. tempRemark: ''
  57. };
  58. },
  59. methods: {
  60. openRemarkModal() {
  61. // 打开弹窗时,将当前备注内容赋值给临时变量
  62. this.tempRemark = this.value;
  63. this.showRemarkModal = true;
  64. },
  65. closeRemarkModal() {
  66. this.showRemarkModal = false;
  67. this.tempRemark = '';
  68. },
  69. confirmRemark() {
  70. // 更新备注
  71. this.$emit('input', this.tempRemark);
  72. // 关闭弹窗
  73. this.showRemarkModal = false;
  74. this.tempRemark = '';
  75. }
  76. }
  77. };
  78. </script>
  79. <style lang="scss" scoped>
  80. .remark-action {
  81. color: #3385FF;
  82. display: flex;
  83. align-items: center;
  84. font-size: 13upx;
  85. flex: 1;
  86. justify-content: flex-end;
  87. text {
  88. color: #333333;
  89. margin-right: 4upx;
  90. line-height: 1;
  91. display: flex;
  92. align-items: center;
  93. &.placeholder {
  94. color: #999999;
  95. }
  96. &.icon-arrow-right {
  97. color: #ccc;
  98. font-size: 10upx;
  99. display: inline-flex;
  100. justify-content: center;
  101. width: 12upx;
  102. height: 14upx;
  103. margin-left: 2upx;
  104. margin-right: 0;
  105. }
  106. }
  107. }
  108. /* 备注输入弹窗 */
  109. .remark-modal {
  110. position: fixed;
  111. top: 0;
  112. left: 0;
  113. right: 0;
  114. bottom: 0;
  115. background-color: rgba(0, 0, 0, 0.5);
  116. display: flex;
  117. align-items: center;
  118. justify-content: center;
  119. z-index: 9999;
  120. .modal-content {
  121. width: 400upx;
  122. background-color: white;
  123. border-radius: 16upx;
  124. overflow: hidden;
  125. }
  126. .modal-header {
  127. padding: 20upx 20upx 12upx;
  128. border-bottom: 1upx solid #f0f0f0;
  129. .modal-title {
  130. font-size: 18upx;
  131. font-weight: bold;
  132. color: #333333;
  133. }
  134. }
  135. .modal-body {
  136. padding: 15upx;
  137. .remark-textarea {
  138. width: 100%;
  139. min-height: 120upx;
  140. padding: 10upx;
  141. font-size: 14upx;
  142. color: #333333;
  143. background-color: #f9f9f9;
  144. border-radius: 8upx;
  145. border: 1upx solid #e0e0e0;
  146. box-sizing: border-box;
  147. }
  148. .char-count {
  149. margin-top: 5upx;
  150. font-size: 12upx;
  151. color: #999999;
  152. text-align: right;
  153. }
  154. }
  155. .modal-footer {
  156. display: flex;
  157. border-top: 1upx solid #f0f0f0;
  158. .modal-btn {
  159. flex: 1;
  160. height: 60upx;
  161. line-height: 60upx;
  162. font-size: 16upx;
  163. border: none;
  164. background-color: transparent;
  165. margin: 0;
  166. padding: 0;
  167. &.cancel-btn {
  168. color: #666666;
  169. border-right: 1upx solid #f0f0f0;
  170. }
  171. &.confirm-btn {
  172. color: #3385FF;
  173. font-weight: 400;
  174. }
  175. }
  176. }
  177. }
  178. </style>