<template>
  <view class="app-content">
    <templete v-if="!$util.isEmpty(userInfo)">
      <view class="app-round_bg"></view>
      <view class="module-com user-info">
        <view class="user-info_top">
            <view class="user-info_lf">
                <AppAvatarModule class="avatar" :src="userInfo.avatar" :width="100"></AppAvatarModule>
                <view class="dec-bx">
                  <view>
                      {{userInfo.name}}
                  </view>
                  <view>
                      No.{{userInfo.sn}}
                  </view>
                </view>
            </view>
        </view>
        <view class="user-info_data order-wrap">
            <view class="total-blo">
              <view
                class="total-list"
                v-for="(item, index) in orderData"
                :key="index"
                @click="pageTo(item)"
              >
                <view class="app-color-3">{{ item.name }}</view>
                <view class="list-num">{{ item.value }}</view>
              </view>
          </view>
        </view>
      </view>
      <view class="module-com user-address_bx">
          <view class="address-tit">
            门店地址
          </view>
          <view class="address-des_bx">
            <view>
                <view>
                  {{userInfo.name}} {{userInfo.mobile}}
                </view>
                <view>
                  {{userInfo.address}}
                </view>
            </view>
            <view>
              <i @click="callUp" class="iconfont icondianhua1"></i>
            </view>
          </view>
      </view>
      <view class="module-com user-open_bx">
        <view class="input-line-wrap">
            <tui-list-cell class="line-cell" :hover="false">
              <div class="tui-title">允许欠款</div>
              <div class="switch_bx">
                <text></text>
                <switch :checked="form.debt == 0 ? false : true" @change="remindChangeFn" />
              </div>
            </tui-list-cell>
            <!-- <tui-list-cell class="line-cell" :hover="false" :arrow="true">
              <div class="tui-title">消费记录</div>
              <input v-model="form.name" placeholder-class="phcolor" class="tui-input" name="name" placeholder="请输入" maxlength="50" type="text" />
            </tui-list-cell> -->
        </view>
      </view>
    </templete>
    <kd-entrance></kd-entrance>
  </view>
</template>

<script>
import { mapGetters } from "vuex";
import AppAvatarModule from "@/components/module/app-avatar";
import TuiListCell from '@/components/plugin/list-cell'
import { share } from "@/mixins";
import {
  getUserDet,
  debt
} from "@/api/member";
export default {
  name: "member-detail",
  components: {
    AppAvatarModule,
    TuiListCell
  },
  mixins: [share],
  props: {},
  data() {
    return {
      userInfo: {},
      form:{
        name:'',
        debt: 0
      },
      // 订单总览
      orderData: [
        {
          name: "欠款金额",
          value: '0.00',
          url: "",
          type: 4,
          query: {}
        },
        {
          name: "消费次数",
          value: '0',
          url: "",
          type: 4,
          query: {}
        },
        {
          name: "消费金额",
          url: "/admin/home/order",
          type: 4,
          query: {},
          value: '0.00'
        }
      ],
    };
  },
  computed: {},
  onLoad() {},
  methods: {
    async remindChangeFn(e){
      this.form.debt = e.detail.value ? 1 : 0;
      try {
          let res = await  debt({
            debt: this.form.debt,
            customId: this.userInfo.id
          })
          let msg = e.detail.value?'已开启':'已禁止'
          this.$msg(msg);
        } catch (err) {
          console.log(err)
          // 错误捕获
        }
   
    },
    callUp() {
      uni.makePhoneCall({
        phoneNumber: this.userInfo.mobile
      });
    },
    init() {
      this._getUserDet();
    },
    _getUserDet() {
      getUserDet({ id: this.option.id }).then(res => {
        this.userInfo = res.data;
        this.form.debt = this.userInfo.debt
        this.orderData[0].value = this.userInfo.debtAmount
        this.orderData[1].value = this.userInfo.buyNum
        this.orderData[2].value = this.userInfo.buyAmount
      });
    },
    orderMoreFn() {
      this.orderMoreStatus = false;
    },
    modalCancel() {
    }
  }
};
</script>

<style lang='scss' scoped>
// 公共
.module-com {
  margin: 0 30px 20px;
  padding: 20px;
  background-color: #fff;
  // box-shadow: 0px 6px 16px #ddd;
  border-radius: 10px;
  position: relative;
  z-index: 10;
}
// 用户信息
.user-info {
  padding: 60px 20px 60px;
  position: relative;
  top: 51px;
  & .user-info_top {
    position: relative;
    display: flex;
    align-items: center;
    height: 100px;
    & .user-info_lf {
      position: relative;
      padding-left: 10px;
      flex: 1;
       & .avatar {
         position: absolute;
         left: 10px;
         top: 50%;
         transform: translate(0,-50%);
       }
       & .dec-bx {
         padding-left: 130px;
         & > view:nth-child(1) {
           color: #333333;
           font-size: 36px;
           margin-bottom: 3px;
         }
         & > view:nth-child(2) {
           color: #666666;
           font-size: 30px;
         }
       }
    }
    & .already-shop {
      color: #09BB07;
      font-size: 30px;
      font-weight: 400;
      & > .iconfont {
        padding-right: 8px;
        font-size: 32px;
      }
    }
  }
}
.invite-bt {
    color: #FFFFFF;
    font-size: 26px;
    font-weight: 400;
    width: 140px;
    height: 50px;
    line-height: 50px;
    background-color: #3385FF;
    text-align: center;
    border-radius: 25px;
    border: 1px solid #DDDDDD;
    padding: 0;
    user-select: none;
    outline: none;
    &.white{
     background-color: #FFFFFF;
     color: #666666;
    }
  }
// 总览
.total-wrap,
.order-wrap {
  .total-tit {
    padding: 18px 0 18px 20px;
    border-bottom: 1px solid $borderColor;
    font-weight: 600;
    font-size: 24px;
    color:#333333;
  }
  .total-blo {
    @include disFlex(center, space-between);
    flex-wrap: wrap;
    padding: 30px 0 0px;
    .total-list {
      width: 33%;
      text-align: center;
      margin:20px 0px;
      border-right: 1px solid $borderColor;
      .app-color-3 {
        font-size: 24upx;
      }
      .list-num {
        margin-top: 8px;
        margin-bottom: 8px;
        font-size: 36px;
        font-weight: bold;
        &.color-blue {
          color: #3385FF;
        }
      }
    }
    .total-list:nth-child(3n) {
      border-right: none;
    }
    .total-list:nth-child(n + 4) {
      padding-bottom: 0;
    }
  }
}
.user-address_bx {
  margin-top: 70px;
  padding:20px 0;
  & .address-tit {
    color: #999999;
    font-size: 24px;
    font-weight: 600;
    padding:10px 0 20px 20px;
    border-bottom: 1px solid #EEEEEE;
  }
  & .address-des_bx {
    display: flex;
    padding: 20px 10px 30px 20px;
    & > view:nth-child(1) {
      flex: 1;
      margin-top: 10px;

      & > view:nth-child(1) {
        color: #333333;
        font-size: 28px;
        font-weight: bold;
        display: flex;
        align-items: center;
        & .admin-button-com {
          margin-left: 10upx;
          border-radius: 25upx;
        }
      }
      & > view:nth-child(2) {
          color: #666666;
          font-size: 28px;
          font-weight: 400;
          margin-top: 20px; 
      }
    }
    & > view:nth-child(2) {
      display: flex;
      & .icondianhua1 {
          font-size: 44px;
          color: #3385FF;
          margin-left: 10px;
        }
    }
  }
}
.user-open_bx {
  margin-top: 20px;
  padding: 0;
  & .switch_bx {
    flex: 1;
    text-align:right;
    & > text {
      color: #999999;
      font-size: 28px;
      display: inline-block;
      margin-right: 22px;
    }
  }

}
</style>
