<template>
  <div class="rise">
    <div class="rise-title">{{ typeTitle }}</div>
    <div class="rise-info">
      <cr-swipe-cell v-for="(item, index) in list" :ref="`swipe_${index}`" :key="index">
        <div class="rise-info__cell">
          <dl class="rise-info__cell__msg">
            <dt>{{ item.invoiceTitle }}</dt>
            <dd v-if="item.invoiceTitleType === 2">{{ item.taxNumber }}</dd>
          </dl>
          <div class="rise-info__cell__edit" @click.stop="onUpdate(item)">编辑</div>
        </div>
        <template #right>
          <cr-button
            class="rise-info__delete"
            square
            type="danger"
            text="删除"
            @click="onDelete(item)"
          />
        </template>
      </cr-swipe-cell>
    </div>
  </div>
</template>

<script>
const DELETE_TITLE = 'on-delete';
const UPDATE_TITLE = 'on-update';
export default {
  props: {
    list: {
      type: Array,
      default: () => []
    },
    typeTitle: {
      type: String,
      default: ''
    }
  },
  data() {
    return {};
  },
  methods: {
    onUpdate(item) {
      this.$emit(UPDATE_TITLE, item);
    },
    onDelete(item) {
      this.$dialog({
        customClass: 'cr-dialog-invoice',
        closeOnClickOverlay: true,
        message: '确认删除抬头?',
        onConfirm: () => {
          this.$emit(DELETE_TITLE, item);
        }
      });
    }
  }
};
</script>
<style lang="less" scoped>
@import './common.less';
.rise {
  background-color: @white;
  border-radius: 10px;
  border: 1px solid @white;
  width: 352px;
  margin: 0 auto;
  margin-bottom: 12px;

  &-title {
    .text-size(12);
    color: @gray-4;
    height: 46px;
    line-height: 46px;
    padding-left: 12px;
    .border-bottom();
  }
  &-info {
    padding-bottom: 8px;
    overflow: hidden;
    @{deep} .cr-button--normal {
      width: 46px;
      padding: 0;
      margin-left: 1px;
    }
    &__cell {
      padding: 10px 12px;
      display: flex;
      // justify-content: space-between;
      &__msg {
        flex: 1;
        padding: 2px 0;
        dt {
          .text-size(14);
          color: @black;
          max-width: 280px;
          white-space: nowrap;
          text-overflow: ellipsis;
          overflow: hidden;
        }
        dd {
          .text-size(12);
          color: @gray-4;
          margin-top: 2px;
        }
      }

      &__edit {
        line-height: 100%;
        font-size: 14px;
        padding-left: 10px;
        position: relative;
        display: flex;
        align-items: center;
        &::before {
          content: '';
          width: 1px;
          height: 100%;
          background-color: @gray-7;
          position: absolute;
          left: 0;
          top: 0;
          transform: scaleX(0.5);
        }
      }
    }
  }
}
</style>
