warehouse.vue 2.9 KB

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