shopSelect.vue 7.0 KB

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