<template>
  <div class="app-main app-content">
    <view class="input-wrap_box">
      <view>
        <AppSearchModule placeholder="输入字母搜索，如花朵朵搜索hdd" @input="searchFn"/>
      </view>
    </view>
    <block v-if="!$util.isEmpty(list.data)">
      <block v-for="(item, index) in list.data" :key="index">
        <tui-list-cell :arrow="true" @click="selectCurrent(item)">
          <div class="tui-msg-box">
            <img :src="item.avatar" class="tui-msg-pic" mode="widthFix" />
            <div class="tui-msg-item">
              <div class="tui-msg-name">
                <div class="tui-user-name">{{ item.name }}</div>
              </div>
              <div class="tui-msg-content">
                <span>{{ item.visitTime.substr(5,11) }}</span>
                <span style="margin-left:50rpx;width:70rpx;color:red;font-weight:500">
                  <text v-if="item.level == 1"></text>
                  <text v-else-if="item.level == 0" style="color:#999;">{{ item.levelName }}</text>
                  <text v-else>{{ item.levelName }}</text>
                </span>
                <span v-if="item.debtAmount > 0" class="debt-amount">欠款：<span class="amount_num">{{item.debtAmount}}</span></span>
              </div>
            </div>
          </div>
          <div class="tui-msg-right">
            <badge-module
              type="danger"
              :dot="item.level == 3 ? true : false"
              v-if="item.messageNum > 0"
              >{{ item.messageNum }}</badge-module
            >
          </div>
        </tui-list-cell>
      </block>
    </block>
    <block v-else>
      <app-wrapper-empty :is-empty="$util.isEmpty(list.data)" />
    </block>
  </div>
</template>

<script>
import TuiListCell from "@/components/plugin/list-cell";
import BadgeModule from "@/components/plugin/badge";
import AppWrapperEmpty from "@/components/app-wrapper-empty";
import appVipModule from "@/components/module/app-vip";
import AppTag from "@/components/module/app-tag.vue";
import AppSearchModule from "@/components/module/app-search";
import { list } from "@/mixins";
import { getList } from "@/api/member";
export default {
  name: "selectCustom",
  components: {
    TuiListCell,
    BadgeModule,
    AppWrapperEmpty,
    appVipModule,
    AppTag,
    AppSearchModule
  },
  mixins: [list],
  data() {
    return {
      tabIndex: 0
    };
  },
  onPullDownRefresh() {
    this.resetList();
    this._list().then((res) => {
      uni.stopPullDownRefresh();
    });
  },
  onReachBottom() {
    if (!this.list.finished) {
      this._list().then((res) => {
        uni.stopPullDownRefresh();
      });
    } else {
      uni.stopPullDownRefresh();
    }
  },
  onLoad(option) {},
	onShow(){
		uni.removeStorageSync('newClient');
	},
  methods: {
    selectCurrent(item){
       
      let style = this.option.style ? this.option.style : 1
      if(style == 1){
        //点开单选客户后再选花材
        this.$util.pageTo({url: '/admin/billing/index',type:2,query: {customId: item.id,customName:item.name}})
      }else if(style == 2){
        //已经选完花材后重选客户
        let pages = getCurrentPages();
        let prevPage = pages[ pages.length - 2 ];
        prevPage.$vm.form.customId = item.id;
        prevPage.$vm.form.customName = item.name;
        uni.navigateBack({})
      }
    },
    init() {
      if(!this.AUTHORITY_SHOW) {
        this._list();
      }
    },
    searchFn(e) {
        this.resetList();
        this.seekVal = e;
        this._list();
    },
    _list() {
      return getList({
          search: "",
          type:this.tabIndex,
          page: this.list.page,
          name: this.seekVal,
        }).then((res) => {
          this.completes(res);
          if (this.$util.isEmpty(res.data)){
            return false;
          }
        });
    },
    change(e) {
      if (this.tabIndex == e.index) {
        return false;
      }
      this.tabIndex = e.index;
      this.resetList();
      this._list();
    },
  },
};
</script>

<style lang="scss" scoped>
.app-content {
  padding-top: 100px;
  padding-bottom: 20px;
}
.tabs-wrap {
  position: fixed;
  .tabs-left {
    width: 80%;
  }
  .tabs-right {
    width: 19%;
    border-left: $borderColor;
    @include disFlex(center, center);
  }
}
  .input-wrap_box {
    background-color: #fff;
    position: fixed;
    top: 0;
    z-index: 10;
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    padding: 0 30px;
    & > view:nth-child(1) {
      flex: 1;
    }
  }
.tui-msg-box {
  display: flex;
  align-items: center;

  .tui-msg-pic {
    width: 80upx;
    height: 80upx;
    border-radius: 50%;
    margin-right: 20upx;
  }

  .tui-msg-item {
    max-width: 500upx;
    min-height: 80upx;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    & > div {
      @include disFlex(center, flex-start);
      & > div:first-child {
        margin-right: 8px;
      }
    }
    .level-img {
      /deep/.vip-text {
        left: 70px;
        top: 8px;
      }
    }
    .normal-img {
      width: 70px;
      padding: 2px 6px;
      color: #999;
      background-color: #f0f2f6;
      border-radius: 20px;
      .vip-text {
        font-size: 24px;
        transform: scale(0.6);
        position: relative;
        top: -2px;
        left: -8px;
      }
    }
    .member-img {
      width: 70px;
      padding: 2px 6px;
      color: green;
      background-color: #f0f2f6;
      border-radius: 20px;
      .vip-text {
        font-size: 24px;
        transform: scale(0.6);
        position: relative;
        top: -2px;
        left: -8px;
      }
    }
    .iconfont {
      color: #00aaed;
    }
  }

  .tui-msg-name {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 30upx;
    line-height: 1;
    color: #262b3a;
    .tui-user-name {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      width: 290rpx;
    }
  }

  .tui-msg-content {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 24upx;
    line-height: 1;
    color: #9397a4;
    .debt-amount{
      margin-left:40rpx;
      .amount_num{
        color:red;
      }
    }
  }
}
.tui-msg-right {
  max-width: 120upx;
  height: 80upx;
  margin-left: auto;
  margin-right: 24px;
  text-align: right;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.user_tag {
  border: 1px solid #cccccc;
  padding: 5px 12px 5px 12px;
  border-radius: 25px;
  color: #bbbbbb;
  margin-right: 10px;
  margin-bottom: 12px;
  display: inline-block;
  font-size: 30rpx;
}
</style>