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.

select-data-list.vue 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <next-indexed-xlist
  3. :dataList="state.dataList"
  4. :showAvatar="false"
  5. @itemclick="itemclick">
  6. </next-indexed-xlist>
  7. </template>
  8. <script setup lang="ts">
  9. import { reactive, ref, computed, onMounted } from "vue";
  10. import { onLoad, onShow } from "@dcloudio/uni-app";
  11. import { getDicWithType } from '@/datas/queryKey.js'
  12. import { commonStore } from '@/stores/common.js'
  13. const { setSelectIndex } = commonStore()
  14. // 地址数据形式
  15. const state = reactive({
  16. selectType: '1',
  17. keyObj: {
  18. type: '',
  19. key: '',
  20. title: '',
  21. storeKey: ''
  22. },
  23. dataList: []
  24. })
  25. const selectTypeMap = [
  26. {type: '1', key: 'PROVINCE_TYPE', title: '省份选择', storeKey: 'province'},
  27. {type: '2', key: 'BANK_TYPE', title: '银行选择', storeKey: 'bank'},
  28. ]
  29. // selectType 1:选择省份 2:选择银行
  30. onLoad(({selectType}) => {
  31. if (selectType) state.selectType = selectType
  32. setSelectData()
  33. })
  34. onMounted(() => {
  35. })
  36. const setSelectData = () => {
  37. let keyObj = selectTypeMap.find(item => item.type === state.selectType)
  38. if (!keyObj) return
  39. state.keyObj = keyObj
  40. uni.setNavigationBarTitle({
  41. title: keyObj.title
  42. })
  43. let list = getDicWithType(keyObj.key)
  44. console.log(list)
  45. state.dataList = list.map(item => {
  46. return {
  47. id: item.code,
  48. name: item.name,
  49. code: item.code,
  50. abbr: item.code
  51. }
  52. })
  53. }
  54. const itemclick = (e) => {
  55. console.log('点击列表回调:', e)
  56. setSelectIndex(state.keyObj.storeKey, { name: e.name, code: e.id })
  57. uni.navigateBack()
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .content-block {
  62. display: flex;
  63. flex-direction: row;
  64. justify-content: flex-start;
  65. background-color: #fff;
  66. .title {
  67. color: #333;
  68. padding: 20rpx;
  69. margin-right: 20rpx;
  70. display: flex;
  71. flex-direction: column;
  72. justify-content: center;
  73. }
  74. .btn {
  75. color: #ccc;
  76. padding: 10rpx;
  77. border: 1rpx solid #ccc;
  78. border-radius: 10rpx;
  79. margin: 20rpx 10rpx;
  80. font-size: 28rpx;
  81. display: flex;
  82. flex-direction: column;
  83. justify-content: center;
  84. }
  85. }
  86. </style>