warehouse.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view class="warehouse-select">
  3. <view class="select-wrap" @click="showPicker = true">
  4. <text class="required-label">*</text>
  5. <text class="label">默认仓库</text>
  6. <view class="picker-value">
  7. <text :class="['value-text', !selectedWarehouse && 'placeholder']">
  8. {{ selectedWarehouse || '请选择仓库' }}
  9. </text>
  10. <u-icon name="arrow-right" color="#999" size="16"></u-icon>
  11. </view>
  12. </view>
  13. <!-- 仓库选择器 -->
  14. <u-picker :show="showPicker" :columns="[warehouseList]" @confirm="onConfirm" @cancel="showPicker = false"
  15. @close="showPicker = false" title="选择仓库" confirmText="确定" cancelText="取消"></u-picker>
  16. </view>
  17. </template>
  18. <script setup>
  19. import {
  20. ref
  21. } from 'vue'
  22. // 选择器显示状态
  23. const showPicker = ref(false)
  24. // 选中的仓库
  25. const selectedWarehouse = ref('')
  26. // 仓库列表
  27. const warehouseList = ref([])
  28. // 获取仓库列表
  29. const getWarehouseList = () => {
  30. uni.$u.http.post('/app/appUser/searchGodown?name=').then(res => {
  31. if (res.code == 200) {
  32. warehouseList.value = res.data.filter(v => v.useStatus == 1).map(v => ({
  33. text: v.godownName,
  34. value: v.id
  35. }))
  36. }
  37. })
  38. }
  39. getWarehouseList()
  40. //获取默认仓库
  41. const getWarehouse = () => {
  42. uni.$u.http.get('/app/appUser/getUserBindGodown').then(res => {
  43. if (res.code == 200) {
  44. selectedWarehouse.value = res.data?.godownName
  45. }
  46. })
  47. }
  48. getWarehouse()
  49. //保存
  50. const saveWarehouse = (godownId) => {
  51. uni.$u.http.post('/app/appUser/bingowGodown?godownId=' + godownId).then(res => {
  52. if (res.code == 200) {
  53. uni.showToast({
  54. title: '设置默认仓库成功',
  55. icon: 'success'
  56. })
  57. }
  58. })
  59. }
  60. // 确认选择
  61. const onConfirm = (e) => {
  62. const [{
  63. value,
  64. text
  65. }] = e.value
  66. selectedWarehouse.value = text
  67. showPicker.value = false
  68. console.log(e,'xxxxxx')
  69. saveWarehouse(value)
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. .warehouse-select {
  74. padding: 20rpx;
  75. .select-wrap {
  76. display: flex;
  77. align-items: center;
  78. background: #FFFFFF;
  79. min-height: 88rpx;
  80. padding: 0 20rpx;
  81. position: relative;
  82. .required-label {
  83. color: #FF4D4F;
  84. font-size: 28rpx;
  85. margin-right: 4rpx;
  86. }
  87. .label {
  88. font-size: 28rpx;
  89. color: #333333;
  90. margin-right: 20rpx;
  91. white-space: nowrap;
  92. }
  93. .picker-value {
  94. flex: 1;
  95. display: flex;
  96. align-items: center;
  97. justify-content: space-between;
  98. .value-text {
  99. font-size: 28rpx;
  100. color: #333333;
  101. &.placeholder {
  102. color: #999999;
  103. }
  104. }
  105. .count {
  106. font-size: 24rpx;
  107. color: #999999;
  108. margin-right: 10rpx;
  109. }
  110. }
  111. &::after {
  112. content: '';
  113. position: absolute;
  114. left: 20rpx;
  115. right: 20rpx;
  116. bottom: 0;
  117. height: 1px;
  118. background: #EEEEEE;
  119. transform: scaleY(0.5);
  120. }
  121. &:active {
  122. background: #F5F5F5;
  123. }
  124. }
  125. }
  126. </style>