productBrand.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <u-popup v-model="isShow" class="brand-picker" @close="isShow=false" mode="bottom">
  3. <view class="brand-header flex justify_between align_center">
  4. <text class="brand-picker-btn" @click="onClean">清空</text>
  5. <text>产品品牌</text>
  6. <text class="brand-picker-btn color-blue" @click="isShow=false">X</text>
  7. </view>
  8. <view class="search-box">
  9. <u-search
  10. placeholder="请输入品牌名称搜索"
  11. v-model="queryWord"
  12. :show-action="isGobleSearch"
  13. @focus="isGobleSearch=true"
  14. @blur="isGobleSearch=false"
  15. @custom="searchBrand"
  16. @search="searchBrand"
  17. @clear="clearSearch"
  18. :action-style="{'color': '#fff', 'font-size': '24upx', 'background-color': $config('primaryColor'), 'border-radius': '6upx', 'padding': '12upx 0'}">
  19. </u-search>
  20. </view>
  21. <scroll-view class="picker-content" scroll-y>
  22. <view class="picker-main">
  23. <view class="picker-main-item" v-for="(item, index) in listData" :key="item.brandSn" @click="chooseItem(index)">
  24. <view class="item-name">{{item.brandName}}</view>
  25. <u-icon v-show="item.brandSn==brandSn" class="item-icon" name="checkbox-mark" :color="$config('primaryColor')" size="28"></u-icon>
  26. </view>
  27. <view v-if="listData && listData.length == 0">
  28. <u-empty text="数据为空" mode="list" :img-width="200" :margin-top="-60"></u-empty>
  29. </view>
  30. </view>
  31. </scroll-view>
  32. </u-popup>
  33. </template>
  34. <script>
  35. import { dealerProductBrandQuery } from '@/api/dealerProductBrand'
  36. export default {
  37. props: {
  38. openModal: { // 弹框显示状态
  39. type: Boolean,
  40. default: false
  41. },
  42. itemSn: {
  43. type: String,
  44. default: ''
  45. }
  46. },
  47. data() {
  48. return {
  49. isShow: this.openModal, // 是否打开弹框
  50. listData: [],
  51. queryWord: '',
  52. isGobleSearch: false,
  53. brandList: [],
  54. brandSn: this.itemSn || null
  55. }
  56. },
  57. mounted() {
  58. this.clearSearch()
  59. },
  60. methods: {
  61. // 搜索品牌
  62. searchBrand(){
  63. if(this.queryWord != ''){
  64. this.getBrandList()
  65. }
  66. },
  67. clearSearch(){
  68. this.queryWord = ''
  69. this.listData = []
  70. this.getBrandList()
  71. },
  72. getBrandList(){
  73. dealerProductBrandQuery({ brandName: this.queryWord }).then(res => {
  74. if(res.status == 200 && res.data){
  75. this.listData = res.data
  76. }else{
  77. this.listData = []
  78. }
  79. })
  80. },
  81. // 选择
  82. chooseItem(ind){
  83. this.brandSn = this.listData[ind].brandSn
  84. this.$emit('choose', this.listData[ind])
  85. this.isShow = false
  86. },
  87. // 清空
  88. onClean(){
  89. this.brandSn = null
  90. this.$emit('clean')
  91. this.isShow = false
  92. }
  93. },
  94. watch: {
  95. // 父页面传过来的弹框状态
  96. openModal (newValue, oldValue) {
  97. this.isShow = newValue
  98. },
  99. // 重定义的弹框状态
  100. isShow (newValue, oldValue) {
  101. if (!newValue) {
  102. this.$emit('close')
  103. }
  104. }
  105. }
  106. }
  107. </script>
  108. <style lang="scss" scoped>
  109. .brand-picker{
  110. .brand-header{
  111. padding: 20upx 30upx;
  112. position: relative;
  113. .brand-picker-btn{
  114. color: rgb(96, 98, 102);
  115. }
  116. }
  117. .brand-header:after{
  118. content: "";
  119. position: absolute;
  120. border-bottom: 1px solid #eaeef1;
  121. -webkit-transform: scaleY(.5);
  122. transform: scaleY(.5);
  123. bottom: 0;
  124. right: 0;
  125. left: 0;
  126. }
  127. .search-box{
  128. padding: 10upx 20upx;
  129. }
  130. .picker-content{
  131. height: 300upx;
  132. padding: 6upx 0 20upx;
  133. position: relative;
  134. .picker-main{
  135. position: absolute;
  136. top: 50%;
  137. left: 50%;
  138. transform: translate(-50%,-50%);
  139. width: 100%;
  140. max-height: 300upx;
  141. .picker-main-item{
  142. position: relative;
  143. padding: 0 30upx;
  144. .item-name{
  145. padding: 14upx 0;
  146. text-align: center;
  147. // border-bottom: 1upx dashed #efefef;
  148. }
  149. .item-icon{
  150. position: absolute;
  151. right: 100upx;
  152. top: 19upx;
  153. }
  154. }
  155. }
  156. }
  157. }
  158. </style>