Owner.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <van-dialog v-model:show="ownerTrueFalseBy"
  3. title="货主列表"
  4. :show-confirm-button="false"
  5. close-on-click-overlay
  6. >
  7. <van-search v-model="value" @input="onClickButton" @search="onClickButton" show-action placeholder="请输入搜索货主" >
  8. <template #action>
  9. <div @click="onClickButton">搜索</div>
  10. </template>
  11. </van-search>
  12. <div style="width:100%;max-height:65vh;overflow:auto">
  13. <van-radio-group v-model="owner">
  14. <van-cell-group inset>
  15. <van-cell v-for="(item,i) in ownerFilterList" :title="item.name" clickable @click="onOwner(item)" :key="i" >
  16. <template #right-icon>
  17. <van-radio :name="item.code" />
  18. </template>
  19. </van-cell>
  20. </van-cell-group>
  21. </van-radio-group>
  22. </div>
  23. </van-dialog>
  24. </template>
  25. <script setup>
  26. import { ref } from 'vue'
  27. import { getOwner, getPrinter } from '@/api/basic/index'
  28. import { closeLoading, showLoading } from '@/utils/loading'
  29. import pinyin from 'pinyin'
  30. const value=ref('')
  31. const ownerTrueFalseBy=ref(false)
  32. const owner=ref('')
  33. const ownerList=ref([])
  34. const ownerFilterList=ref([])
  35. const onClickButton=()=>{
  36. ownerFilterList.value=ownerList.value.filter((item) => {
  37. return item.pinyin.includes(value.value) || item.name.includes(value.value)
  38. });
  39. }
  40. const convertToPinyin = (text) => {
  41. return pinyin(text, { style: pinyin.STYLE_NORMAL }).join('');
  42. };
  43. const modeType=ref('')
  44. const show=(type)=>{
  45. modeType.value=type
  46. owner.value=''
  47. value.value=''
  48. if(localStorage.getItem('OWNER:KEY')){
  49. const list=JSON.parse(localStorage.getItem('OWNER:KEY'))
  50. ownerList.value=list
  51. ownerFilterList.value=list
  52. ownerTrueFalseBy.value=true
  53. return
  54. }
  55. showLoading()
  56. getOwner().then(res => {
  57. res.data.forEach(item=>{
  58. item.pinyin=convertToPinyin(item.name)
  59. })
  60. ownerList.value=res.data
  61. ownerFilterList.value=res.data
  62. localStorage.setItem('OWNER:KEY',JSON.stringify(res.data))
  63. ownerTrueFalseBy.value=true
  64. }).finally(() => {
  65. closeLoading()
  66. })
  67. }
  68. const emit = defineEmits()
  69. const onOwner=(item)=>{
  70. owner.value = item.code
  71. ownerTrueFalseBy.value=false
  72. emit('onOwner', item,modeType.value)
  73. }
  74. defineExpose({show})
  75. </script>
  76. <style scoped lang="sass">
  77. </style>