<template>
  <van-popup v-model="showPopup" position="bottom" round>
    <div class="modify-price-popup-con">
      <div class="header">
        <div class="title">修改价格</div>
        <m-icon
          class-name="close-icon"
          icon="icon-close"
          :size="16"
          @click="showPopup = false"
        />
      </div>
      <div class="content">
        <input type="number" v-model="price" placeholder="请输入新价格" />
      </div>
      <div class="bottom">
        <van-button type="primary" round block @click="handleConfirm">
          确 定
        </van-button>
      </div>
    </div>
  </van-popup>
</template>

<script>
export default {
  props: {
    value: {
      type: Boolean,
      default: false,
    },
  },
  watch: {
    value(val) {
      this.showPopup = val;
    },
    showPopup(val) {
      this.$emit("input", val);
      if (!val) {
        setTimeout(() => {
          this.price = "";
        }, 300);
      }
    },
  },
  data() {
    return {
      showPopup: false,
      price: "",
    };
  },
  methods: {
    handleConfirm() {
      this.$emit("confirm", this.price);
    },
  },
  mounted() {
    this.showPopup = this.value;
  },
};
</script>

<style lang="less">
.modify-price-popup-con {
  > .header {
    position: relative;
    margin-bottom: 10px;
    .title {
      text-align: center;
      font-size: 16px;
      font-weight: bold;
      padding: 15px 40px;
    }
    .close-icon {
      position: absolute;
      right: 15px;
      top: 50%;
      transform: translateY(-50%);
    }
  }
  > .content {
    height: 215px;
    padding: 0 18px;
    input {
      width: 100%;
      border-bottom: 1px solid #f1f1f1;
      font-size: 16px;
      padding: 8px 0;
      &::placeholder {
        color: #aeaeae;
      }
    }
  }
  > .bottom {
    padding: 10px 16px;
    button {
      height: 36px;
      font-size: 13px;
    }
  }
}
</style>