 <template>
  <ai-list v-loading="isLoading" class="detail">
    <template slot="title">
      <ai-title title="会话存档详情" isShowBack isShowBottomBorder @onBackClick="cancel(false)"></ai-title>
    </template>
    <template #left>
      <div class="addressBook-left">
        <div class="addressBook-left__title">
          <h2 :class="[tabIndex === 0 ? 'tab-active' : '']">群聊会话</h2>
          <h2 :class="[tabIndex === 1 ? 'tab-active' : '']">私聊会话</h2>
        </div>
        <div class="addressBook-left__list--title">
          <el-input
              size="mini"
              placeholder="请输入联系人姓名"
              v-model="searchName"
              clearable
              suffix-icon="iconfont iconSearch">
          </el-input>
        </div>
        <div class="addressBook-left__list--wrapper">
          <div class="addressBook-left__list--item active">
            <img src="https://img1.baidu.com/it/u=413643897,2296924942&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500" alt=""> 张三
          </div>
          <div class="addressBook-left__list--item">
            <img src="https://img1.baidu.com/it/u=413643897,2296924942&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500" alt=""> 张三
          </div>
          <div class="addressBook-left__list--item">
            <img src="https://img1.baidu.com/it/u=413643897,2296924942&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500" alt=""> 张三
          </div>
        </div>
      </div>
    </template>
    <template slot="content">
      <div class="content-right-title">
        <div class="tab-content">
          <h2 class="tab-active">全部</h2>
          <h2>图片/视频</h2>
          <h2>文件</h2>
        </div>
        <div class="search-content">
          <el-date-picker v-model="time" size="small" type="daterange" value-format="yyyy-MM-dd"
            range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" @change="onChange">
          </el-date-picker>
          <el-input size="small" placeholder="输入搜索内容" v-model="search.name" clearable
              @clear="current = 1, search.name = '', getTableData()" suffix-icon="iconfont iconSearch"
              v-throttle="() => {(current = 1), getTableData();}"/>
              <ai-download :instance="instance" url="/app/appconvenientaddressbook/export" :params="search" fileName="会话存档"
                       :disabled="tableData.length == 0">
            <el-button icon="iconfont iconExported" :disabled="tableData.length == 0">导出</el-button>
          </ai-download>
        </div>
      </div>
      <div class="content-right-info">
        <div v-for="(item, index) in list" :key="index">
          <div class="item item-left" v-if="item.type">
            <p class="time">2023-04-26 16:11:43</p>
            <div class="item-content-flex">
              <img src="https://img1.baidu.com/it/u=413643897,2296924942&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500" alt="" class="user-img">
              <div class="content">
                <span></span>
                <p>{{item.content}}</p>
              </div>
              <i class="el-icon-warning"></i>
            </div>
          </div>
          <div class="item item-right" v-else>
            <p class="time">2023-04-26 16:11:43</p>
            <div class="item-content-flex">
              <img src="https://img1.baidu.com/it/u=413643897,2296924942&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=500" alt="" class="user-img">
              <div class="content">
                <span></span>
                <p>{{item.content}}</p>
              </div>
              <i class="el-icon-warning"></i>
            </div>
          </div>
        </div>
      </div>
    </template>
  </ai-list>
</template>

<script>
  export default {
    name: 'Detail',

    props: {
      instance: Function,
      dict: Object,
      params: Object
    },

    data () {
      return {
        info: {},
        isShow: false,
        currIndex: 0,
        isLoading: false,
        tableData: [],
        form: {
          code: ''
        },
        colConfigs: [
          { slot: 'goods', label: '商品' },
          { prop: 'merchandiseIntegral', align: 'center', label: '单价' },
          { prop: 'merchandiseNumber', align: 'center', label: '数量' },
          { prop: 'merchandiseIntegral', align: 'center', label: '小计' }
        ],



        tabIndex: 0,
        searchName: '',
        time: [],
        search: {
          name: ''
        },
        current: 1,
        list: [
          {type: 0, content: '123全部全部全部全部全部全部全部全部全部全部全部全部'},
          {type: 1, content: '123'},
          {type: 0, content: '456'},
          {type: 0, content: '123'},
          {type: 1, content: '123'},
        ]
      }
    },

    created () {
      // this.isLoading = true
      if (this.params && this.params.id) {
        this.id = this.params.id
        this.dict.load(['merchandiseOrderStatus']).then(() => {
          // this.getInfo(this.params.id)
        })
      }
    },

    methods: {
      getInfo (id) {
        this.instance.post(`/app/appintegralmerchandiseorder/queryDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = res.data
            this.tableData = [this.info]
          }

          this.isLoading = false
        }).catch(() => {
          this.isLoading = false
        })
      },

      onConfirm() {
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.instance.post(`/app/appintegralmerchandiseorder/writeOffOrder`, null, {
              params: {
                code: this.form.code,
                id: this.params.id
              }
            }).then(res => {
              if (res.code == 0) {
                this.isShow = false
                this.getInfo(this.params.id)
                this.$message.success('核销成功')
              }
            })
          }
        })
      },

      cancel () {
        this.$emit('change', {
          type: 'List',
          isRefresh: true
        })
      }
    }
  }
</script>

<style scoped lang="scss">
  .detail {
    .addressBook-left {
      width: 100%;
      height: auto;
      background: #FAFAFB;

      .addressBook-left__title {
        display: flex;
        align-items: center;
        width: 100%;
        height: 40px;
        background: #ffffff;

        h2 {
          flex: 1;
          height: 100%;
          line-height: 40px;
          color: #222;
          font-size: 14px;
          text-align: center;
          cursor: pointer;
          border-bottom: 2px solid transparent;

          &.tab-active {
            color: #2266FF;
            border-bottom: 2px solid #2266FF;
          }
        }
      }

      .addressBook-left__list--wrapper {
        height: calc(100% - 68px);
        padding: 8px;
        .addressBook-left__list--item {
          line-height: 44px;
          font-size: 16px;
          color: #333;
          margin-bottom: 8px;
          padding: 8px;
          cursor: pointer;
          img {
            width: 44px;
            height: 44px;
            border-radius: 50%;
            margin-right: 8px;
            vertical-align: middle;
          }
        }
        .addressBook-left__list--item:hover {
          background-color: #E8EFFF;
        }
        .active {
          background-color: #E8EFFF;
          color: #26f;
        }
      }
      .addressBook-left__list--title {
        display: flex;
        align-items: center;
        margin: 8px 8px 0;

        .addressBook-left__list--search {
          flex: 1;

          :deep( input ){
            width: 100%;
          }
        }

        .el-button {
          width: 84px;
          flex-shrink: 1;
          margin-right: 8px;
        }
      }
    }

    :deep( .ai-list__content--right ){
      flex: 1;
      min-width: 0;
      margin-left: 1px;
      box-shadow: none;

      .ai-list__content--right-wrapper {
        width: 100%;
      }
    }

    :deep .ai-list__content--right-wrapper {
      padding: 0!important;
    }

    .content-right-title {
      height: 40px;
      border-bottom: 1px solid #ddd;
      display: flex;
      justify-content: space-between;
      box-sizing: content-box;
      .tab-content {
        display: flex;
        align-items: center;
        width: 300px;
        height: 40px;
        background: #ffffff;

        h2 {
          flex: 1;
          height: 100%;
          line-height: 40px;
          color: #222;
          font-size: 14px;
          text-align: center;
          cursor: pointer;
          border-bottom: 2px solid transparent;

          &.tab-active {
            color: #2266FF;
            border-bottom: 2px solid #2266FF;
          }
        }
      }
      .search-content {
        display: flex;
        padding: 4px 8px 4px 0;
        .ai-download,
        .el-input {
          margin-left: 8px;
        }
        .el-input {
          width: 240px;
        }
        .el-date-editor--daterange {
          width: 240px;
        }
        :deep .el-date-editor .el-range-separator {
          width: 30px;
        }
      }
    }
    .content-right-info {
      padding: 24px 16px;
      .item {
        margin-bottom: 48px;
        .time {
          color: #999;
          font-size: 14px;
          line-height: 44px;
        }
        .item-content-flex {
          display: flex;
          .user-img {
            width: 44px;
            height: 44px;
            margin-right: 8px;
          }
          .content {
            max-width: calc(100% - 144px);
            position: relative;
            span {
              width: 0px;
              height: 0px;
              border: 10px solid transparent;
              position: absolute;
              top: 20px;
            }
            p {
              display: inline-block;
              padding: 14px 54px 14px 32px;
              background-color: #fff;
              font-family: PingFangSC-Regular;
              font-size: 32px;
              color: #333;
              word-break: break-all;
            }
          }
          .fail-icon {
            width: 32px;
            height: 32px;
            margin: auto 0 auto 24px;
          }
        }
      }
      .item-left {
        .content {
          span {
            left: -18px;
            border-right-color: #fff;
          }
        }
      }
      .item-right {
        width: 100%;
        justify-content: right;
        .user-img {
          margin: 0 0 0 20px;
        }
        .content {
          span {
            border-left-color: #C7E7FE;
            right: -18px;
          }
          p {
            background-color: #C7E7FE;
            padding: 14px 32px 14px 54px;
          }
        }
      }
    }
  }

</style>
