productBrand.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. brandSn: this.itemSn || null
  54. }
  55. },
  56. mounted() {
  57. this.clearSearch()
  58. },
  59. methods: {
  60. // 搜索品牌
  61. searchBrand(){
  62. if(this.queryWord != ''){
  63. this.getBrandList()
  64. }
  65. },
  66. clearSearch(){
  67. this.queryWord = ''
  68. this.listData = []
  69. this.getBrandList()
  70. },
  71. getBrandList(){
  72. dealerProductBrandQuery({ brandName: this.queryWord }).then(res => {
  73. if(res.status == 200 && res.data){
  74. this.listData = res.data
  75. }else{
  76. this.listData = []
  77. }
  78. })
  79. },
  80. // 选择
  81. chooseItem(ind){
  82. this.brandSn = this.listData[ind].brandSn
  83. this.$emit('choose', this.listData[ind])
  84. this.isShow = false
  85. },
  86. // 清空
  87. onClean(){
  88. this.brandSn = null
  89. this.$emit('clean')
  90. this.isShow = false
  91. }
  92. },
  93. watch: {
  94. // 父页面传过来的弹框状态
  95. openModal (newValue, oldValue) {
  96. this.isShow = newValue
  97. },
  98. // 重定义的弹框状态
  99. isShow (newValue, oldValue) {
  100. if (!newValue) {
  101. this.$emit('close')
  102. }
  103. }
  104. }
  105. }
  106. </script>
  107. <style lang="scss" scoped>
  108. .brand-picker{
  109. .brand-header{
  110. padding: 20upx 30upx;
  111. position: relative;
  112. .brand-picker-btn{
  113. color: rgb(96, 98, 102);
  114. }
  115. }
  116. .brand-header:after{
  117. content: "";
  118. position: absolute;
  119. border-bottom: 1px solid #eaeef1;
  120. -webkit-transform: scaleY(.5);
  121. transform: scaleY(.5);
  122. bottom: 0;
  123. right: 0;
  124. left: 0;
  125. }
  126. .search-box{
  127. padding: 10upx 20upx;
  128. }
  129. .picker-content{
  130. height: 300upx;
  131. padding: 6upx 0 20upx;
  132. position: relative;
  133. .picker-main{
  134. position: absolute;
  135. top: 50%;
  136. left: 50%;
  137. transform: translate(-50%,-50%);
  138. width: 100%;
  139. max-height: 300upx;
  140. .picker-main-item{
  141. position: relative;
  142. padding: 0 30upx;
  143. .item-name{
  144. padding: 14upx 0;
  145. text-align: center;
  146. }
  147. .item-icon{
  148. position: absolute;
  149. right: 100upx;
  150. top: 19upx;
  151. }
  152. }
  153. }
  154. }
  155. }
  156. </style>