upload-num.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <view class="upload_num_container">
  3. <!-- <picker :value="sexIndex" :range="sexList" range-key="name" @change="pickerSexChange">
  4. <view class="sex_select">
  5. <view class="select_main">{{ sexList[sexIndex].name || '选款式' }}</view>
  6. <view class="select_arrow"></view>
  7. </view>
  8. </picker>
  9. <picker :value="sizeIndex" :range="sizeList" range-key="name" @change="pickerSizeChange">
  10. <view class="sex_select">
  11. <view class="select_main">{{ sizeList[sizeIndex].name || '选尺码' }}</view>
  12. <view class="select_arrow"></view>
  13. </view>
  14. </picker> -->
  15. <view class="upload_input_counter">
  16. <view class="counter_delete" @click="changeCounter(0)"></view>
  17. <input v-model="sarr[2]" type="number" class="counter_input" :class="sarr[2] === 0 ? 'counter_input_had' : ''" @input="inputCounter">
  18. <view class="counter_add" @click="changeCounter(1)"></view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. props: {
  25. sarr: {
  26. type: Array,
  27. default: () => ['', '', 0]
  28. },
  29. skey: {
  30. type: String,
  31. default: ''
  32. },
  33. sindex: {
  34. type: Number,
  35. default: 0
  36. }
  37. },
  38. data() {
  39. return {
  40. sexList: [
  41. {
  42. id: 0,
  43. name: '女'
  44. },
  45. {
  46. id: 1,
  47. name: '男'
  48. }
  49. ],
  50. sizeList: [
  51. {
  52. id: 0,
  53. name: 'M'
  54. },
  55. {
  56. id: 1,
  57. name: 'L'
  58. },
  59. {
  60. id: 2,
  61. name: 'XL'
  62. },
  63. {
  64. id: 3,
  65. name: '2XL'
  66. },
  67. {
  68. id: 4,
  69. name: '3XL'
  70. },
  71. {
  72. id: 5,
  73. name: '5XL'
  74. }
  75. ],
  76. sexIndex: -1,
  77. sizeIndex: -1
  78. }
  79. },
  80. watch: {
  81. sarr: {
  82. handler(a) {
  83. this.sexIndex = this.sexList.findIndex(({ id }) => +id === a[0])
  84. this.sizeIndex = this.sizeList.findIndex(({ id }) => +id === a[1])
  85. },
  86. deep: true,
  87. immediate: true
  88. }
  89. },
  90. methods: {
  91. pickerSexChange(e) {
  92. this.sexIndex = Number(e.detail.value)
  93. if(this.sexIndex === -1) return false
  94. let id = this.sexList[this.sexIndex].id
  95. this.$emit('inputCounter', this.skey, this.sindex, 0, id)
  96. },
  97. pickerSizeChange(e) {
  98. this.sizeIndex = Number(e.detail.value)
  99. if(this.sizeIndex === -1) return false
  100. let id = this.sizeList[this.sizeIndex].id
  101. this.$emit('inputCounter', this.skey, this.sindex, 1, id)
  102. },
  103. changeCounter(type) {
  104. let n = this.sarr[2]
  105. type ? ++ n : (n > 0 ? --n : n)
  106. this.$emit('inputCounter', this.skey, this.sindex, 2, n)
  107. },
  108. inputCounter(e) {
  109. let n = e.detail.value
  110. this.$emit('inputCounter', this.skey, this.sindex, 2, n)
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss" scoped>
  116. .upload_num_container {
  117. width: 100%;
  118. display: flex;
  119. align-items: center;
  120. justify-content: space-between;
  121. .select_arrow {
  122. &::after {
  123. content: "";
  124. display: block;
  125. width: 28rpx;
  126. height: 28rpx;
  127. background-image: url(../static/icon/arrow.png);
  128. background-size: 100% 100%;
  129. background-repeat: no-repeat;
  130. transform: rotate(90deg);
  131. }
  132. }
  133. .select_main {
  134. flex: 1;
  135. text-align: center;
  136. overflow: hidden;
  137. }
  138. .sex_select {
  139. width: 160rpx;
  140. height: 64rpx;
  141. line-height: 64rpx;
  142. display: flex;
  143. justify-content: center;
  144. align-items: center;
  145. color: #FB6342;
  146. font-size: 32rpx;
  147. background-color: #F5F5F5;
  148. border-radius: 8rpx;
  149. padding: 0 16rpx;
  150. box-sizing: border-box;
  151. }
  152. .upload_input_counter {
  153. width: 300rpx;
  154. color: #FB6342;
  155. font-size: 32rpx;
  156. height: 64rpx;
  157. border-radius: 64rpx;
  158. border: 1px solid #FB6342;
  159. display: flex;
  160. align-items: center;
  161. justify-content: space-between;
  162. .counter_input_had {
  163. color: #000 !important;
  164. }
  165. .counter_input {
  166. flex: 1;
  167. overflow: hidden;
  168. height: 64rpx;
  169. line-height: 64rpx;
  170. text-align: center;
  171. border-left: 1px solid #FB6342;
  172. border-right: 1px solid #FB6342;
  173. }
  174. .counter_add {
  175. width: 54rpx;
  176. position: relative;
  177. height: 100%;
  178. &::before {
  179. content: "";
  180. display: block;
  181. width: 4rpx;
  182. height: 16rpx;
  183. background-color: #FB6342;
  184. position: absolute;
  185. top: 50%;
  186. left: 50%;
  187. margin-top: -8rpx;
  188. margin-left: -2rpx;
  189. }
  190. &::after {
  191. content: "";
  192. display: block;
  193. width: 16rpx;
  194. height: 2rpx;
  195. background-color: #FB6342;
  196. position: absolute;
  197. top: 50%;
  198. left: 50%;
  199. margin-top: -2rpx;
  200. margin-left: -8rpx;
  201. }
  202. }
  203. .counter_delete {
  204. width: 54rpx;
  205. height: 100%;
  206. position: relative;
  207. &::before {
  208. content: "";
  209. display: block;
  210. width: 16rpx;
  211. height: 2rpx;
  212. background-color: #FB6342;
  213. position: absolute;
  214. top: 50%;
  215. left: 50%;
  216. margin-top: -2rpx;
  217. margin-left: -8rpx;
  218. }
  219. }
  220. }
  221. }
  222. </style>