productBrand.vue 4.1 KB

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