特易招,招聘小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
6.0 KiB

  1. <template>
  2. <view class="page">
  3. <navbar title="工种选择组件示例" leftClick @leftClick="$utils.navigateBack" />
  4. <view class="content">
  5. <view class="demo-section">
  6. <view class="section-title">单选模式</view>
  7. <view class="demo-item">
  8. <uv-cell
  9. title="选择工种(单选)"
  10. rightIconStyle="fontSize: 30rpx;"
  11. :value="singleResult.fullJobType || '请选择工种'"
  12. @click="openSinglePicker"
  13. isLink
  14. ></uv-cell>
  15. <view v-if="singleResult.selectedId" class="result-info">
  16. <text>选中ID: {{ singleResult.selectedId }}</text>
  17. <text>选中工种: {{ singleResult.selectedJobType?.name }}</text>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="demo-section">
  22. <view class="section-title">多选模式</view>
  23. <view class="demo-item">
  24. <uv-cell
  25. title="选择工种(多选)"
  26. rightIconStyle="fontSize: 30rpx;"
  27. :value="multipleResult.fullJobType || '请选择工种'"
  28. @click="openMultiplePicker"
  29. isLink
  30. ></uv-cell>
  31. <view v-if="multipleResult.selectedIds && multipleResult.selectedIds.length > 0" class="result-info">
  32. <text>选中ID数组: {{ multipleResult.selectedIds.join(',') }}</text>
  33. <text>选中数量: {{ multipleResult.selectedIds.length }}</text>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="demo-section">
  38. <view class="section-title">只选择到二级工种</view>
  39. <view class="demo-item">
  40. <uv-cell
  41. title="选择工种(二级)"
  42. rightIconStyle="fontSize: 30rpx;"
  43. :value="subTypeResult.fullJobType || '请选择工种'"
  44. @click="openSubTypePicker"
  45. isLink
  46. ></uv-cell>
  47. <view v-if="subTypeResult.selectedId" class="result-info">
  48. <text>选中ID: {{ subTypeResult.selectedId }}</text>
  49. <text>选中工种: {{ subTypeResult.selectedJobType?.name }}</text>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="demo-section">
  54. <view class="section-title">"选择整个工种"选项</view>
  55. <view class="demo-item">
  56. <uv-cell
  57. title="选择工种(整个工种)"
  58. rightIconStyle="fontSize: 30rpx;"
  59. :value="wholeTypeResult.fullJobType || '请选择工种'"
  60. @click="openWholeTypePicker"
  61. isLink
  62. ></uv-cell>
  63. <view v-if="wholeTypeResult.selectedId" class="result-info">
  64. <text>选中ID: {{ wholeTypeResult.selectedId }}</text>
  65. <text>选中工种: {{ wholeTypeResult.selectedJobType?.name }}</text>
  66. </view>
  67. </view>
  68. </view>
  69. <view class="demo-section">
  70. <view class="section-title">使用说明</view>
  71. <view class="usage-info">
  72. <text class="usage-title">组件属性</text>
  73. <text> multiple: 是否支持多选</text>
  74. <text> onlySubType: 是否只选择到二级工种</text>
  75. <text> showSelectWholeType: 是否显示"选择整个工种"选项</text>
  76. <text class="usage-title">返回数据</text>
  77. <text> selectedId: 单选时的工种ID</text>
  78. <text> selectedIds: 多选时的工种ID数组</text>
  79. <text> fullJobType: 完整的工种名称文本</text>
  80. <text> selectedJobType: 选中的工种对象</text>
  81. </view>
  82. </view>
  83. </view>
  84. <!-- 工种选择组件 -->
  85. <JobTypePicker
  86. ref="singlePicker"
  87. @confirm="onSingleConfirm"
  88. />
  89. <JobTypePicker
  90. ref="multiplePicker"
  91. :multiple="true"
  92. @confirm="onMultipleConfirm"
  93. />
  94. <JobTypePicker
  95. ref="subTypePicker"
  96. :onlySubType="true"
  97. @confirm="onSubTypeConfirm"
  98. />
  99. <JobTypePicker
  100. ref="wholeTypePicker"
  101. :showSelectWholeType="true"
  102. @confirm="onWholeTypeConfirm"
  103. />
  104. </view>
  105. </template>
  106. <script>
  107. import JobTypePicker from '@/components/JobTypePicker.vue'
  108. export default {
  109. components: {
  110. JobTypePicker
  111. },
  112. data() {
  113. return {
  114. singleResult: {}, // 单选结果
  115. multipleResult: {}, // 多选结果
  116. subTypeResult: {}, // 二级工种结果
  117. wholeTypeResult: {} // 整个工种结果
  118. }
  119. },
  120. onLoad() {
  121. // 确保工种数据已加载
  122. this.$store.commit('getJobTypeList')
  123. },
  124. methods: {
  125. // 打开单选工种选择器
  126. openSinglePicker() {
  127. this.$refs.singlePicker.open()
  128. },
  129. // 打开多选工种选择器
  130. openMultiplePicker() {
  131. this.$refs.multiplePicker.open()
  132. },
  133. // 打开二级工种选择器
  134. openSubTypePicker() {
  135. this.$refs.subTypePicker.open()
  136. },
  137. // 打开整个工种选择器
  138. openWholeTypePicker() {
  139. this.$refs.wholeTypePicker.open()
  140. },
  141. // 单选确认回调
  142. onSingleConfirm(result) {
  143. console.log('单选结果:', result)
  144. this.singleResult = result
  145. },
  146. // 多选确认回调
  147. onMultipleConfirm(result) {
  148. console.log('多选结果:', result)
  149. this.multipleResult = result
  150. },
  151. // 二级工种确认回调
  152. onSubTypeConfirm(result) {
  153. console.log('二级工种结果:', result)
  154. this.subTypeResult = result
  155. },
  156. // 整个工种确认回调
  157. onWholeTypeConfirm(result) {
  158. console.log('整个工种结果:', result)
  159. this.wholeTypeResult = result
  160. }
  161. }
  162. }
  163. </script>
  164. <style scoped lang="scss">
  165. .page {
  166. background: #f5f5f5;
  167. min-height: 100vh;
  168. }
  169. .content {
  170. padding: 20rpx;
  171. }
  172. .demo-section {
  173. margin-bottom: 40rpx;
  174. background: #fff;
  175. border-radius: 20rpx;
  176. overflow: hidden;
  177. .section-title {
  178. padding: 30rpx 30rpx 20rpx;
  179. font-size: 32rpx;
  180. font-weight: bold;
  181. color: #333;
  182. border-bottom: 1px solid #f0f0f0;
  183. }
  184. .demo-item {
  185. padding: 0;
  186. .result-info {
  187. padding: 20rpx 30rpx;
  188. background: #f8f9fa;
  189. border-top: 1px solid #f0f0f0;
  190. text {
  191. display: block;
  192. font-size: 26rpx;
  193. color: #666;
  194. margin-bottom: 10rpx;
  195. &:last-child {
  196. margin-bottom: 0;
  197. }
  198. }
  199. }
  200. }
  201. .usage-info {
  202. padding: 30rpx;
  203. text {
  204. display: block;
  205. font-size: 26rpx;
  206. color: #666;
  207. line-height: 1.6;
  208. margin-bottom: 10rpx;
  209. &.usage-title {
  210. font-weight: bold;
  211. color: #333;
  212. margin-top: 20rpx;
  213. margin-bottom: 15rpx;
  214. &:first-child {
  215. margin-top: 0;
  216. }
  217. }
  218. &:last-child {
  219. margin-bottom: 0;
  220. }
  221. }
  222. }
  223. }
  224. </style>