multiSelector.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view>
  3. <picker mode="multiSelector" :range="list" @columnchange="columnchange" @change="change">
  4. <input :placeholder="placeholder" v-model="title" :disabled="true" placeholder-class="pc" />
  5. <view class="icon more" v-if="icon">&#xe8f2;</view>
  6. </picker>
  7. </view>
  8. </template>
  9. <script>
  10. export default {
  11. name: 'multiSelector',
  12. props: {
  13. range: {
  14. type: Array
  15. },
  16. name: {
  17. type: String,
  18. default: '时间段'
  19. },
  20. icon: {
  21. type: Boolean,
  22. default: true
  23. },
  24. placeholder: {
  25. type: String,
  26. default: '请选择'
  27. },
  28. value: {
  29. type: String
  30. }
  31. },
  32. data() {
  33. return {
  34. title: this.value,
  35. list: this.range,
  36. multiIndex: [0, 0]
  37. };
  38. },
  39. watch: {
  40. value(newValue) {
  41. this.title = newValue;
  42. }
  43. },
  44. mounted() {
  45. let year = parseInt(this.util.getDate('year'));
  46. let month = parseInt(this.util.getDate('month'));
  47. if (this.name == '出生年月') {
  48. for (let i = 1970; i <= year - 16; i++) {
  49. this.list[0].unshift(i + '年');
  50. }
  51. for (let i = 1; i <= 12; i++) {
  52. this.list[1].push((i < 10 ? '0' + i : i) + '月');
  53. }
  54. }
  55. if (this.name == '薪资') {
  56. for (let i = 1; i <= 250; i++) {
  57. this.list[0].push(i + 'k');
  58. }
  59. }
  60. if (this.name == '时间段') {
  61. for (let i = 1990; i <= year; i++) {
  62. this.list[0].unshift(i);
  63. }
  64. for (let i = year + 1; i <= year + 8; i++) {
  65. this.list[1].push(i);
  66. }
  67. }
  68. if (this.name == '开始时间') {
  69. for (let i = 1990; i <= year; i++) {
  70. this.list[0].unshift(i + '年');
  71. }
  72. for (let i = 1; i <= month; i++) {
  73. this.list[1].push((i < 10 ? '0' + i : i) + '月');
  74. }
  75. }
  76. if (this.name == '结束时间') {
  77. for (let i = 1990; i <= year; i++) {
  78. this.list[0].unshift(i + '年');
  79. }
  80. this.list[0].unshift('至今');
  81. }
  82. },
  83. methods: {
  84. columnchange(e) {
  85. this.multiIndex[e.detail.column] = e.detail.value;
  86. if (e.detail.column == 0) {
  87. this.list[0].forEach((item, index) => {
  88. if (this.multiIndex[0] == index) {
  89. let array = [];
  90. let year = this.util.getDate('year') + '年';
  91. let month = parseInt(this.util.getDate('month'));
  92. //选择教育经历时间段
  93. if (this.name == '时间段') {
  94. for (let i = parseInt(this.list[0][this.multiIndex[0]]) + 1; i <= parseInt(this.list[0][this.multiIndex[0]]) + 8; i++) {
  95. if (this.list[0][this.multiIndex[0]] == '1990以前') {
  96. array = ['1990以前'];
  97. } else {
  98. array.push(i);
  99. }
  100. }
  101. this.list[1] = array;
  102. }
  103. //选择薪资要求
  104. if (this.name == '薪资') {
  105. for (let i = parseInt(e.detail.value) + 1; i <= parseInt(e.detail.value) + 5; i++) {
  106. if (e.detail.value > 0) {
  107. array.push(i + 'k');
  108. }
  109. }
  110. this.list[1] = array;
  111. }
  112. //选择时间范围
  113. if (this.name == '开始时间' || this.name == '结束时间') {
  114. //如果是今年只取当前月以前月份
  115. month = this.list[0][this.multiIndex[0]] == year ? month : 12;
  116. for (let i = 1; i <= month; i++) {
  117. if (this.list[0][this.multiIndex[0]] != '1990以前' && this.list[0][this.multiIndex[0]] != '至今') {
  118. array.push((i < 10 ? '0' + i : i) + '月');
  119. }
  120. }
  121. this.list[1] = array;
  122. }
  123. //选择出生年月
  124. if (this.name == '出生年月') {
  125. for (let i = 1; i <= 12; i++) {
  126. array.push((i < 10 ? '0' + i : i) + '月');
  127. }
  128. this.list[1] = array;
  129. }
  130. }
  131. });
  132. }
  133. this.$forceUpdate();
  134. },
  135. change(e) {
  136. if (this.list[0][this.multiIndex[0]]) {
  137. this.title = this.list[0][this.multiIndex[0]];
  138. }
  139. if (this.list[1][this.multiIndex[1]]) {
  140. this.title = this.list[0][this.multiIndex[0]] + '-' + this.list[1][this.multiIndex[1]];
  141. }
  142. this.title = this.title.replace('年', '').replace('月', '');
  143. this.$emit('input', this.title);
  144. this.$forceUpdate();
  145. }
  146. }
  147. };
  148. </script>
  149. <style lang="scss"></style>