<template>
  <view class="list">
    <view class="grey-block"></view>
    <lb-picker ref="picker1"
      v-model="value"
      mode="selector"
      :list="list"
      @change="handleChange"
      @confirm="handleConfirm"
      @cancel="handleCancel">
      <!-- list-item为默认插槽 -->
      <view class="list-item">
        <text class="sub-title">该区域是默认插槽,点击即可弹出,无需调用open</text>
        <view class="item-content">
          <text class="item-title">绑定值:{{ value }}</text>
          <view class="item-value">
            <text class="item-label">{{ label }}</text>
            <text v-if="!label"
              class="item-placeholder">点我打开选择器</text>
          </view>
        </view>
      </view>
      <!-- 其他插槽 -->
      <view slot="cancel-text">插槽取消</view>
      <view slot="action-center">中间自定义</view>
      <view slot="confirm-text">插槽确定</view>
      <view slot="header-top">头部顶部自定义</view>
      <view slot="header-bottom">头部底部自定义</view>
      <view slot="picker-top">选择器顶部自定义</view>
      <view slot="picker-bottom">选择器底部自定义</view>
    </lb-picker>
    <view class="grey-block"></view>
    <text class="tips">自定义插槽元素样式交给开发者自由调整，插槽仅提供预留位置。</text>
    <view class="grey-block"></view>
  </view>
</template>

<script>
export default {
  data () {
    return {
      value: 2,
      label: '',
      list: []
    }
  },
  created () {
    let list = []
    for (let i = 1; i < 20; i++) {
      list.push({
        label: `选项${i}`,
        value: i
      })
    }
    this.list = list
  },
  onReady () {
    this.$nextTick(() => {
      // 此处可以调用getColumnsInfo方法获取默认值的选项信息
      const info = this.$refs.picker1.getColumnsInfo(this.value)
      console.log('根据value获取的信息：', info)
      this.label = info.item.label
    })
  },
  methods: {
    handleChange (e) {
      console.log('change::', e)
    },
    handleConfirm (e) {
      console.log('confirm::', e)
      if (e) {
        this.label = e.item.label
      }
    },
    handleCancel (e) {
      console.log('cancel::', e)
    }
  }
}
</script>

<style lang="scss" scoped>
@import "../../index/index.scss";
</style>
