index.vue 7.66 KB
<template>
  <view class="order-popup">
    <popup
      :position="position"
      :animation="animation"
      ref="popup"
      @onConfirm="confirm"
      @onCancel="cancel"
    >
      <view class="popup-title flex">
        {{title}}
        <view
          class="popup-close flex"
          @click="close"
        >
          <uni-icons
            type="closeempty"
            size="16"
          ></uni-icons>
        </view>
      </view>
      <template v-if="!componentObject.hideSearch">
        <view class="popup-search">
          <input
            class="input"
            type="text"
            :placeholder="componentObject.placeholder || '请输入'"
            placeholder-class="placeholder"
            v-model="componentObject.searchValue"
            confirm-type="search"
            @confirm="handleSearch"
          >
          <view
            class="clear flex"
            @click="clear"
          >
            <uni-icons
              type="closeempty"
              size="16"
              v-if="componentObject.searchValue"
            ></uni-icons>
          </view>
        </view>
      </template>
      <view :class="['popup-body',{ 'hide-search' :componentObject.hideSearch}]">
        <scroll-view
          scroll-y
          :class="['popup-scroll-view',{show:loadComplete}]"
        >
          <component
            :is="componentObject.name"
            :params.sync="componentObject"
            :data="data"
            :dataKey="dataKey"
            ref="componentRef"
            @choose="chooseContent = $event"
            @openSkuPopup="openSkuPopup"
            @onComplete="loadComplete = true"
          ></component>
        </scroll-view>
        <image
          v-if="!loadComplete"
          class="loading"
          src="../../assets/images/common/loadding.gif"
        />
      </view>
    </popup>
    <sku-popup
      ref="skuPopupRef"
      @onConfirm="skuConfirm"
    ></sku-popup>
  </view>
</template>

<script type='text/ecmascript-6'>
import Popup from './components/Popup.vue'
import config from './config'
import EmployeeList from './components/EmployeeList.vue'
import DiversionMerchant from './components/DiversionMerchant.vue'
import CarModelList from './components/CarModelList.vue'
import CouponList from './components/CouponList.vue'
import GoodsList from './components/GoodsList.vue'
import PackageList from './components/PackageList.vue'
import SkuGoodsList from './components/SkuGoodsList.vue'
import SkuPopup from './components/SkuPopup.vue'
import DateTime from './components/DateTime.vue'
export default {
  components: {
    Popup,
    EmployeeList,
    DiversionMerchant,
    CarModelList,
    CouponList,
    GoodsList,
    PackageList,
    SkuGoodsList,
    SkuPopup,
    DateTime
  },
  name: '',
  props: {
    animation: {
      type: Boolean,
      default: true
    },

    maskClick: {
      type: Boolean,
      default: false
    },
    popupType: {
      type: [Number, String],
      default: 0
    },
    data: [Object, Array],
    externalData: null,
    dataKey: String
  },

  provide () {
    return {
      userInfo: this.userInfo,
      baseConfigData: this.baseConfigData
    }
  },
  data () {
    return {
      position: 'bottom',
      chooseContent: null,
      componentObject: null,
      loadComplete: false
    }
  },
  watch: {
    popupType: {
      handler (val) {
        this.componentObject = config.componentConfig[this.popupType]
        if (val == 11 || val == 12) this.position = 'right'
      },
      deep: true,
      immediate: true
    },
    externalData: {
      handler (val) {
        if (val && this.componentObject) this.componentObject.cacheData = val
      },
      deep: true,
    }
  },
  computed: {
    title () {
      return config.componentConfig[this.popupType].title
    },
    userInfo () {
      return uni.$storage.get("userInfo")
    },
    baseConfigData () {
      return this.$store.state.boutique.baseConfigData
    }
  },
  mounted () {
  },
  methods: {
    componentRef () {
      return this.$refs.componentRef
    },
    open () {
      this.$refs.popup.open()
      this.initPopupData()
    },
    cancel () {
      this.$refs.popup.close()
      this.$emit('cancel')
    },
    close () {
      this.$refs.popup.close()
      this.$emit('close')
    },
    initPopupData () {
      let componentRef = this.componentRef()
      if (!componentRef) setTimeout(this.initPopupData, .1e3)
      else componentRef.getList && componentRef.getList(this.componentObject.searchValue)
    },
    handleSearch () {
      let componentRef = this.componentRef()
      if (!componentRef) uni.showToast({
        title: '请稍后再试',
        icon: 'none'
      })
      else componentRef.handleSearch(this.componentObject.searchValue)
    },
    confirm () {
      let { chooseContent, popupType, componentObject } = this
      if (popupType === 13) {
        chooseContent = this.componentRef().getResult()
      }
      if (chooseContent) {
        this.$emit('onConfirm', {
          chooseContent,
          popupType
        })
        this.$refs.popup.close()
      } else {
        if (componentObject.nullTips) uni.showToast({
          title: componentObject.nullTips,
          icon: 'none'
        })
      }
    },
    openSkuPopup (data) {
      this.confirm()
      this.$refs.skuPopupRef.open(data)
    },
    skuConfirm (e) {
      this.$emit('onConfirm', {
        chooseContent: [e],
        popupType: 12
      })
    },
    clear () {
      this.componentObject.searchValue = ''
      this.handleSearch()
    }
  }
}
</script>

<style scoped lang='scss'>
.popup-box {
  border-radius: 32rpx 32rpx 0 0;
  background: #ffffff;
  height: 70vh;
  .popup-title {
    height: 104rpx;
    justify-content: center;
    position: relative;
    color: #333333;
    font-size: 36rpx;
    font-weight: 500;
    .popup-close {
      position: absolute;
      height: 100%;
      top: 0;
      right: 0;
      padding: 0 48rpx;
      font-weight: 400;
      color: #1a1a1a;
    }
  }
  .popup-search {
    height: 80rpx;
    border-radius: 40rpx;
    background: #f5f7fa;
    margin: 0 48rpx;
    position: relative;
    .input {
      height: 100%;
      width: 100%;
      text-align: center;
      color: #333;
      font-size: 32rpx;
    }
    .placeholder {
      height: 100%;
      color: #999ea8;
      font-family: uniicons;
      display: flex;
      align-items: center;
      justify-content: center;
      &::after {
        display: block;
        content: '\e654';
        margin-left: 8rpx;
        height: 100%;
        display: flex;
        align-items: center;
        font-size: 36rpx;
      }
    }
    .clear {
      position: absolute;
      right: 0;
      top: 0;
      height: 100%;
      padding: 0 48rpx;
    }
  }
  .popup-body {
    height: calc(100% - 392rpx);
    position: relative;
    .popup-scroll-view {
      height: 100%;
      padding-top: 32rpx;
      opacity: 0;

    }
    .loading {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: toRpx(64);
      height: toRpx(64);
    }
    .show{
      opacity: 1;
    }
  }
  .hide-search {
    height: calc(100% - 280rpx);
  }
  .popup-footer {
    padding: 64rpx 0;
    justify-content: center;
    gap: 0 32rpx;
    .popup-btn {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 720rpx;
      height: 80rpx;
      border-radius: 64rpx;
      background: #f0f1f5;
      color: #333333;
      font-size: 32rpx;
      font-weight: 500;
    }
    .popup-confirm {
      color: #fff;
      background: linear-gradient(0deg, #2c66f7 0%, #48a6ff 100%);
    }
  }
}
.right-box {
  width: 46vw;
  height: 100vh;
  border-radius: 32rpx 0 0 32rpx;
  .popup-footer {
    margin: 0 48rpx;
  }
}
</style>