shopSelect.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view class="select-bg_bx">
  3. <view v-if="isShowTit" @click="switchCut" :class="['select-title',dropdownShow?'select_corlor':'']">
  4. <text>{{showShopName!=''?showShopName:getMyShopInfo.shopName}}</text>
  5. <text v-if="placeholder" style="color: #ccc;">{{placeholder}}</text>
  6. <i v-if="isShowMore" class="iconfont iconsanjiao_xia"></i>
  7. </view>
  8. <view v-else @click="switchCut" :class="['select-title',dropdownShow?'select_corlor':'']">
  9. <text v-if="placeholder" style="color: #ccc;">{{placeholder}}</text>
  10. </view>
  11. <view class="select-mark-view" v-show="dropdownShow" @click="switchCut"></view>
  12. <view v-if="dropdownShow" :style="{top}" class="select-fixed_bx">
  13. <slot>
  14. <view class="select-item-box">
  15. <view class="title">请选择门店</view>
  16. <view class="item-child_box">
  17. <button v-for="(item,index) in shopList" :key="index" @click="changeItem(item)"
  18. :class="['admin-button-com','mini-btn','default']"> {{item.name}} </button>
  19. </view>
  20. </view>
  21. </slot>
  22. </view>
  23. </view>
  24. </template>
  25. <script>
  26. import DropdownList from "@/components/plugin/dropdown-list"
  27. import {mapGetters,mapState} from "vuex"
  28. import { shopAll } from '@/api/common'
  29. export default {
  30. name:'DorpdownSelect',
  31. components:{
  32. DropdownList
  33. },
  34. props:{
  35. top:{
  36. type: String,
  37. default: 'auto'
  38. },
  39. isShowTit:{
  40. type: Boolean,
  41. default: true
  42. },
  43. typeTime:{
  44. type: Boolean,
  45. default: false
  46. },
  47. isShowMore:{
  48. type: Boolean,
  49. default: true
  50. },
  51. placeholder: {
  52. type: String,
  53. default: ''
  54. }
  55. },
  56. data(){
  57. return {
  58. dropdownShow: false,
  59. selectItem:'',
  60. showShopName:'',
  61. shopList:[]
  62. }
  63. },
  64. watch:{
  65. dropdownShow: {
  66. deep: true, // 深度监听
  67. handler(newVal, oldVal) {
  68. if(newVal == true && oldVal == false) { // 开启门店弹窗,请求最新门店数据
  69. this.shopList = []
  70. shopAll().then(res=>{
  71. if(res.code == 1){
  72. if (!this.$util.isEmpty(res.data)){
  73. res.data.forEach((i) => {
  74. this.shopList.push({id:i.id,name:i.shopName})
  75. })
  76. }
  77. }
  78. })
  79. }
  80. }
  81. }
  82. },
  83. computed:{
  84. ...mapGetters(["getMyShopInfo"])
  85. },
  86. mounted(){
  87. this.shopList = []
  88. shopAll().then(res=>{
  89. if(res.code == 1){
  90. if (!this.$util.isEmpty(res.data)){
  91. res.data.forEach((i) => {
  92. this.shopList.push({id:i.id,name:i.shopName})
  93. })
  94. }
  95. }
  96. })
  97. },
  98. methods:{
  99. switchCut(){
  100. this.dropdownShow = !this.dropdownShow
  101. },
  102. changeItem(val){
  103. this.dropdownShow = false;
  104. this.showShopName = val.name;
  105. this.$emit('selectShopFn',val)
  106. }
  107. }
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. .select-bg_bx {
  112. .select-title {
  113. color: #666666;
  114. font-size: 26upx;
  115. & .iconsanjiao_xia {
  116. margin-left: 10upx;
  117. }
  118. &.select_corlor {
  119. color: #3385FF;
  120. & .iconsanjiao_xia {
  121. transform: rotate(180deg);
  122. }
  123. }
  124. }
  125. .select-mark-view {
  126. height: 100vh;
  127. height: 100%;
  128. position: fixed;
  129. width: 100%;
  130. background-color: rgba(0, 0, 0, 0.5);
  131. left: 0;
  132. top: 0upx;
  133. z-index: 20;
  134. }
  135. & .select-fixed_bx {
  136. position: fixed;
  137. width: 100%;
  138. background-color: #FFFFFF;
  139. left: 0upx;
  140. top:0upx;
  141. z-index: 29;
  142. padding:110upx 30upx 40upx;
  143. border-radius: 0upx 0upx 20upx 20upx;
  144. transition: all 0.5s ease-in-out;
  145. & .select-item-box {
  146. & .title {
  147. font-size: 24upx;
  148. color: #333333;
  149. font-weight: 600;
  150. text-align: left;
  151. }
  152. & .item-child_box {
  153. padding: 20upx 0 0;
  154. align-items: center;
  155. & .admin-button-com {
  156. margin-bottom: 20upx;
  157. padding: 18upx 50upx;
  158. margin-right: 20upx;
  159. &.custom {
  160. width: 100%;
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. </style>