dorpdownSelect.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view class="select-bg_bx">
  3. <view v-if="isShowTit" @click="switchCut" :class="['select-title',dropdownShow?'select_corlor':'']">
  4. <!--{{menuObjActive?menuObjActive:getMyShopInfo.shopName}}-->
  5. <!--{{selectItemId?menuObjActive:''}}-->
  6. <text v-if="typeTime">{{selectItemId?menuObjActive:menuObj.title}}</text>
  7. <text v-else>{{menuObjActive?menuObjActive:getMyShopInfo.shopName}}</text>
  8. <text v-if="placeholder" style="color: #ccc;">{{placeholder}}</text>
  9. <!-- {{getMyShopInfo?getMyShopInfo.shopName:menuObj.title}}-->
  10. <i v-if="isShowMore" class="iconfont iconsanjiao_xia"></i>
  11. </view>
  12. <view v-else @click="switchCut" :class="['select-title',dropdownShow?'select_corlor':'']">
  13. <text v-if="placeholder" style="color: #ccc;">{{placeholder}}</text>
  14. </view>
  15. <view
  16. class="select-mark-view" v-show="dropdownShow" @click="switchCut"></view>
  17. <view
  18. v-if="dropdownShow"
  19. :style="{
  20. top
  21. }"
  22. class="select-fixed_bx">
  23. <slot>
  24. <view class="select-item-box">
  25. <view class="title">{{menuObj.titleChild}}</view>
  26. <view class="item-child_box">
  27. <button
  28. v-for="(item,index) in menuObj.list"
  29. :key="index"
  30. @click="changeItem(item)"
  31. :class="['admin-button-com','mini-btn',selectItemId === item.id?'blue':'default']">
  32. {{item.name}}
  33. </button>
  34. </view>
  35. </view>
  36. <view
  37. v-if="typeSelect === 1"
  38. class="select-item-box">
  39. <view class="title">其他时间选择</view>
  40. <view class="item-child_box" >
  41. <view class="admin-button-com mini-btn default custom" @tap="changeItem({name:'自定义',id:'custom'})">自定义</view>
  42. <!-- <picker-->
  43. <!-- class="admin-button-com mini-btn default custom"-->
  44. <!-- mode="date" :value="selectItemId" @change="endTimeFn">-->
  45. <!-- <div v-if="selectItemId&&formatSelect">{{ selectItemId }}</div>-->
  46. <!-- <div class="tui-placeholder" v-else>自定义时间</div>-->
  47. <!-- </picker>-->
  48. </view>
  49. </view>
  50. </slot>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import DropdownList from "@/components/plugin/dropdown-list";
  56. import AppDatePicker from "@/components/app-date-picker";
  57. import rangeDatePick from '@/components/pyh-rdtpicker/pyh-rdtpicker.vue';
  58. import {mapGetters} from "vuex";
  59. export default {
  60. name:'DorpdownSelect',
  61. components:{
  62. DropdownList,AppDatePicker,rangeDatePick
  63. },
  64. props:{
  65. menuObj:{
  66. type: Object,
  67. default: ()=>({
  68. title:'时间',
  69. titleChild:'时间',
  70. list: [{name:'昨天',id:'0'},{name:'今天',id:'1'},{name:'本月',id:'2'},{name:'上月',id:'3'},{name:'今年',id:'4'}]
  71. })
  72. },
  73. // 1 是时间 2是其他
  74. typeSelect:{
  75. type:Number,
  76. default: 2
  77. },
  78. top:{
  79. type: String,
  80. default: 'auto'
  81. },
  82. selectItemId:{
  83. type:[String,Number],
  84. default:''
  85. },
  86. isShowTit:{
  87. type: Boolean,
  88. default: true
  89. },
  90. typeTime:{
  91. type: Boolean,
  92. default: false
  93. },
  94. isShowMore:{
  95. type: Boolean,
  96. default: true
  97. },
  98. placeholder: {
  99. type: String,
  100. default: ''
  101. }
  102. },
  103. data(){
  104. return {
  105. dropdownShow: false,
  106. selectItem:'',
  107. menuObjActive:'',
  108. }
  109. },
  110. computed:{
  111. ...mapGetters(["getMyShopInfo"]),
  112. formatSelect(){
  113. if(!this.$util.isEmpty(this.selectItemId)&&
  114. this.$util.isString(this.selectItemId)&&
  115. this.selectItemId.split('-').length>1){
  116. return true
  117. }else{
  118. return false
  119. }
  120. },
  121. },
  122. mounted(){
  123. },
  124. onLoad(){
  125. },
  126. methods:{
  127. switchCut(){
  128. this.dropdownShow = !this.dropdownShow
  129. },
  130. changeItem(val){
  131. if(val.id== this.selectItemId&&val.name!='自定义'){
  132. return false
  133. }
  134. this.$emit('update:selectItemId',val.id)
  135. this.dropdownShow = false;
  136. this.$emit('update:menuObj',{
  137. ...this.menuObj,
  138. title:val.name
  139. })
  140. this.menuObjActive = val.name;
  141. this.$emit('selectSussess',{
  142. select: this.$util.isString(val)?val:val.name,
  143. selectItem: val
  144. })
  145. },
  146. endTimeFn(e){
  147. this.selectItemId = e.detail.value;
  148. this.dropdownShow = false;
  149. this.$emit('update:selectItemId',val.id)
  150. this.$emit('update:menuObj',{
  151. ...this.menuObj,
  152. title:e.detail.value
  153. })
  154. this.$emit('selectSussess',{
  155. select: e.detail.value,
  156. selectItem: val
  157. })
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scoped>
  163. .select-bg_bx {
  164. .select-title {
  165. color: #666666;
  166. font-size: 26px;
  167. & .iconsanjiao_xia {
  168. margin-left: 10px;
  169. }
  170. &.select_corlor {
  171. color: #3385FF;
  172. & .iconsanjiao_xia {
  173. transform: rotate(180deg);
  174. }
  175. }
  176. }
  177. .select-mark-view {
  178. height: 100vh;
  179. height: 100%;
  180. position: fixed;
  181. width: 100%;
  182. background-color: rgba(0, 0, 0, 0.5);
  183. left: 0;
  184. top: 0px;
  185. z-index: 900;
  186. }
  187. & .select-fixed_bx {
  188. position: fixed;
  189. width: 100%;
  190. background-color: #FFFFFF;
  191. left: 0;
  192. z-index: 999;
  193. // box-shadow: 0 6px 10px #cccccc;
  194. padding:120px 30px 40px;
  195. border-radius: 0px 0px 20px 20px;
  196. transition: all 0.5s ease-in-out;
  197. // top: 100px;
  198. & .select-item-box {
  199. & .title {
  200. font-size: 24px;
  201. color: #333333;
  202. font-weight: 600;
  203. text-align: left;
  204. }
  205. & .item-child_box {
  206. // display: flex;
  207. padding: 20px 0 0;
  208. align-items: center;
  209. // flex-flow: wrap;
  210. // justify-content: space-between;
  211. & .admin-button-com {
  212. margin-bottom: 20px;
  213. padding: 18px 50px;
  214. margin-right: 20px;
  215. &.custom {
  216. width: 100%;
  217. }
  218. }
  219. }
  220. }
  221. }
  222. }
  223. </style>