<template>
  <div class="user-detail">

    <el-row :gutter="20" style="margin-bottom: 20px;">
      <el-col :span="12">
        <el-card class="user-card">
          <div class="card-content">
            <div class="text item">
              <a :href="detail.avatar" target="_blank">
                <img :src="detail.avatar"/>
              </a>
            </div>
            <div class="text item">
              <div>
                <label>用户：</label>{{detail.nickname}} (ID: {{id}})
              </div>
              <div>
                <label>tel：</label>{{detail.mobile}}
              </div>
              <div>
                <label>生日：</label>{{detail.birthday}}
              </div>
              <div>
                <label>注册时间：</label>{{detail.created_at}}
              </div>
              <div>
                <label>最后登录：</label>{{detail.last_login_at}}
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card class="user-card">
          <div style="min-height: 150px">
            <div class="card-content" v-if="subDetail.nickname">
              <div class="text item">
                <a :href="subDetail.avatar" target="_blank">
                  <img :src="subDetail.avatar"/>
                </a>
              </div>
              <div class="text item">
                <div>
                  <label>用户：</label>{{subDetail.nickname}} (ID: {{subDetail.user_id}})
                </div>
                <div>
                  <label>tel：</label>{{subDetail.mobile}}
                </div>
              </div>
            </div>
            <p class="fl" v-if="!subDetail.nickname" style="clear:both;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;（暂无子账户）</p>
            <p class="fl" v-if="subDetail.nickname" style="clear:both;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;（子账户）</p>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!--<el-tabs type="border-card" v-model="tabs">-->
    <el-tabs type="border-card" v-model="tabs">
      <el-tab-pane label="回访信息" name="callback">
        <call-back :hasUserInfo="true" :callbackObj="callbackObj" @updateUser="getDetail"></call-back>
      </el-tab-pane>
      <el-tab-pane label="期数列表" name="periods">
        <el-table @expand-change="changeRow" :data="periodList">
          <el-table-column type="expand">
            <template slot-scope="scope">
              <el-table :data="list">
                <el-table-column
                  label="到课率">
                  <template slot-scope="scope2">
                    <span>{{ scope2.row.arrive_course_rate  | percent}}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="看课率">
                  <template slot-scope="scope2">
                    <span>{{ scope2.row.watch_course_rate  | percent}}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="完课率">
                  <template slot-scope="scope2">
                    <span>{{ scope2.row.over_course_rate  | percent}}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="打卡率">
                  <template slot-scope="scope2">
                    <span>{{ scope2.row.clock_rate  | percent}}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="全勤打卡率">
                  <template slot-scope="scope2">
                    <span>{{ scope2.row.over_clock_rate  | percent}}</span>
                  </template>
                </el-table-column>
                <el-table-column
                  label="转化率">
                  <template slot-scope="scope2">
                    <span>{{ scope2.row.transform_rate  | percent}}</span>
                  </template>
                </el-table-column>
              </el-table>
            </template>
          </el-table-column>
          <el-table-column prop="periods_title" label="期数名称" width="170px">
            <template slot-scope="scope">
              <router-link :to="{name:'class', query: { goods_id: scope.row.goods_id, periods_id: scope.row.periods_id}}">
                <div v-html="periodName(scope.row)"></div>
                <!--{{periodName(scope.row)}}-->
              </router-link>
            </template>
          </el-table-column>
          <el-table-column label="看课权限">
            <template slot-scope="scope">
              {{scope.row.is_view_course === 1 ? '是' : '否'}}
            </template>
          </el-table-column>
          <el-table-column className="f-c" label="老师">
            <template slot-scope="scope">
              <router-link :to="`/teacher/${scope.row.teacher_id}`">
                <div class="f-c">
                  <div>
                    <img class="avatar" :src="scope.row.teacher_qr"> {{scope.row.teacher_name}}
                  </div>
                </div>
              </router-link>
            </template>
          </el-table-column>
          <el-table-column prop="join_num" label="加入人数"></el-table-column>
          <el-table-column prop="max_join_num" label="最大加入人数"></el-table-column>
          <el-table-column prop="start_at" label="开课时间"></el-table-column>
          <el-table-column prop="created_at" label="创建时间"></el-table-column>
          <el-table-column label="操作" width="340px">
            <template slot-scope="scope">
              <el-button @click="showUser(scope.row)" size="mini" type="primary"> 班级成员</el-button>
              <el-button size="mini" type="warning" v-if="!$store.state.readonly" @click="editPrivilege(scope.row)">编辑</el-button>
              <el-button size="mini" type="primary" @click="onGetUserDescList(scope.row)">备注</el-button>
              <el-button size="mini" type="primary" @click="showSourceByDate(scope.row)">看课情况</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="系统订单列表" name="order">
        <el-table :data="userList">
          <el-table-column prop="out_trade_no" label="订单号"></el-table-column>
          <el-table-column label="购买人" className="f-c" width="150">
            <template slot-scope="scope">
              <img class="avatar" :src="scope.row.user_avatar"/> {{scope.row.user_nickname}}<br>(ID:{{scope.row.user_id}})
            </template>
          </el-table-column>
          <el-table-column prop="periods_title" label="期数名称" width="170px">
            <template slot-scope="scope">
              <div v-html="periodName(scope.row)"></div>
              <!--{{periodName(scope.row)}}-->
            </template>
          </el-table-column>
          <el-table-column prop="goods_name" label="商品名称"></el-table-column>
          <el-table-column width="250" prop="invite_id" className="f-c" label="推广人属性">
            <template slot-scope="scope">
              <div @click="showSource(scope.row)" v-if="scope.row.invite_earnings > 0 && scope.row.invite_id !== 0" style="display: flex;color: #409eff;cursor: pointer">
                <img :src="scope.row.invite_avatar" class="avatar"/>
                类型：{{scope.row.invite_type}}
                <br>
                收益：{{scope.row.invite_earnings / 100}}
                <br>
                用户ID:{{scope.row.invite_id}}
                <br>
                昵称：{{scope.row.invite_nickname}}
                <br>
                手机：{{scope.row.invite_mobile}}
              </div>
              <div v-if="scope.row.invite_earnings === 0 && scope.row.invite_id !== 0" style="display: flex;">
                <img :src="scope.row.invite_avatar" class="avatar"/>
                类型：{{scope.row.invite_type}}
                <br>
                收益：{{scope.row.invite_earnings / 100}}
                <br>
                用户ID:{{scope.row.invite_id}}
                <br>
                昵称：{{scope.row.invite_nickname}}
                <br>
                手机：{{scope.row.invite_mobile}}
              </div>
              <div v-if="scope.row.invite_id === 0">
                无
              </div>
            </template>
          </el-table-column>
          <el-table-column
            label="优惠活动">
            <template slot-scope="scope">
          <span v-if="scope.row.order_coupon_id === 0">
            无
          </span>
              <el-button type="text" v-if="scope.row.order_coupon_id !== 0" @click="showCoupon(scope.row)">
                优惠券
              </el-button>
            </template>
          </el-table-column>
          <el-table-column
            label="付款状态"
            width="80">
            <template slot-scope="scope">
              <el-button type="text" v-if="scope.row.status === 5 || scope.row.status === 3" @click="showRef(scope.row)">{{scope.row.status|status}}</el-button>
              <div v-if="scope.row.status !== 5 && scope.row.status !== 3">{{scope.row.status|status}}</div>
            </template>
          </el-table-column>
          <el-table-column
            label="实付金额"
            width="80">
            <template slot-scope="scope">
              {{scope.row.money|moneytFilter}}
            </template>
          </el-table-column>
          <el-table-column
            label="收货地址">
            <template slot-scope="scope">
              <div v-if="scope.row.user_address_id && scope.row.address_info">
                {{scope.row.address_info.receive_name}}<br>
                {{scope.row.address_info.receive_mobile}}<br>
                {{scope.row.address_info.province_name}}{{scope.row.address_info.city}}{{scope.row.address_info.area}}{{scope.row.address_info.address}}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="pay_at"
            label="购买时间">
          </el-table-column>
          <el-table-column
            prop="created_at"
            label="下单时间">
          </el-table-column>
        </el-table>
        <page :total="total" :limit="limit" @pageChange="onPageChange" @sizeChange="onSizeChange"/>
      </el-tab-pane>
      <el-tab-pane label="外部订单列表" name="yunji">
        <el-table :data="yunjiList">
          <el-table-column prop="order_id" width="80" label="订单号">
          </el-table-column>
          <el-table-column prop="nickname" label="购买人">
            <template slot-scope="scope">
              <div v-if='scope.row.user_id !== 0'>
                <img class="avatar" :src="scope.row.avatar"/>
                <div>{{scope.row.nickname}}<br>(ID:{{scope.row.user_id}})</div>
              </div>
              <div v-if='scope.row.user_id === 0'>暂未绑定用户</div>
            </template>
          </el-table-column>
          <el-table-column prop="periods_title" label="期数名称" width="170px">
            <template slot-scope="scope">
              <div v-html="periodName(scope.row)"></div>
              <!--{{periodName(scope.row)}}-->
            </template>
          </el-table-column>
          <el-table-column prop="goods_name" label="商品名称"></el-table-column>
          <el-table-column prop="invite_type" label="来源">
            <template slot-scope="scope">
              {{scope.row.invite_type}}（{{scope.row.invite_name}}）
            </template>
          </el-table-column>
          <el-table-column prop="teacher_name" label="班级老师"></el-table-column>
          <el-table-column label="付款状态" width="80">
            <template slot-scope="scope">
              <el-button type="text" v-if="scope.row.status === 5 || scope.row.status === 3" @click="showRef(scope.row)">{{scope.row.status|status}}</el-button>
              <div v-if="scope.row.status !== 5 && scope.row.status !== 3">{{scope.row.status|status}}</div>
            </template>
          </el-table-column>
          <el-table-column prop="money" label="实付金额" width="70">
            <template slot-scope="scope">
              {{scope.row.money/100}}元
            </template>
          </el-table-column>
          <el-table-column label="收货地址" width="150px">
            <template slot-scope="scope">
              姓名：{{scope.row.receiver_name}}
              <br>
              tel：{{scope.row.receiver_phone}}
              <br>
              {{scope.row.receiver_province}} {{scope.row.receiver_city}} {{scope.row.receiver_area}} {{scope.row.receiver_address}}
            </template>
          </el-table-column>
          <el-table-column prop="active_at" label="激活时间" width="90">
            <template slot-scope="scope">
              {{scope.row.active_at === '0000-00-00 00:00:00'?'未激活':scope.row.active_at}}
            </template>
          </el-table-column>
          <el-table-column prop="create_time" label="下单时间" width="90"></el-table-column>
          <el-table-column prop="pay_time" label="付款时间" width="90"></el-table-column>
          <el-table-column prop="user_status" :formatter="userStatusFormatter" label="沟通状态" width="90"></el-table-column>
          <el-table-column prop="desc" label="备注"></el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="地址列表" name="address">
        <el-button size="mini" type="" v-if="!addressList.length" @click="addAddress()">新增</el-button>
        <el-table :data="addressList">
          <el-table-column prop="receive_name" label="收件人名称"></el-table-column>
          <el-table-column prop="receive_mobile" label="收件人手机号"></el-table-column>
          <el-table-column prop="province_name" label="省"></el-table-column>
          <el-table-column prop="city" label="市"></el-table-column>
          <el-table-column prop="area" label="地区名称"></el-table-column>
          <el-table-column prop="address" label="详细地址"></el-table-column>
          <!-- <el-table-column
            prop="is_del"
            label="是否删除">
            <template slot-scope="scope">
              {{scope.row.is_del == 0?'否':'是'}}
            </template>
          </el-table-column> -->
          <el-table-column prop="created_at" label="创建时间"></el-table-column>
          <el-table-column prop="updated_at" label="更新时间"></el-table-column>
          <el-table-column label="操作" width="100px">
            <template slot-scope="scope">
              <el-button size="mini" type="warning" v-if="!$store.state.readonly&&scope.row.is_del == 0" @click="editAddress(scope.row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="绑定记录" name="subList">
        <el-table :data="subListData">
          <el-table-column prop="cur_date" label="绑定时间"></el-table-column>
          <el-table-column prop="unbind_at" label="解绑时间"></el-table-column>
          <el-table-column prop="user_nickname" label="主账号"></el-table-column>
          <el-table-column prop="sub_user_nickname" label="子账号"></el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="发货记录" name="deliverRecord">
        <el-table :data="deliverRecordList">
          <el-table-column width="220" className="f-c" label="用户">
            <template slot-scope="scope">
              <img class="avatar" :src="scope.row.user_avatar"/> {{scope.row.user_nickname}}<br>(ID:{{scope.row.user_id}})<br>手机：{{scope.row.user_mobile}}
            </template>
          </el-table-column>
          <el-table-column prop="address" label="收货地址">
            <template slot-scope="scope">
              {{scope.row.receive_name}}<br>
              {{scope.row.receive_mobile}}<br>
              {{scope.row.province_name}}{{scope.row.city_name}}{{scope.row.area_name}}{{scope.row.address}}
            </template>
          </el-table-column>
          <el-table-column prop="periods_title" label="期数名称"></el-table-column>
          <el-table-column prop="theme_name" label="主题"></el-table-column>
          <el-table-column prop="deliver_start_at" label="预计发货开始时间"></el-table-column>
          <el-table-column prop="deliver_end_at" label="预计发货结束时间"></el-table-column>
          <el-table-column prop="deliver_at" label="发货时间"></el-table-column>
          <el-table-column prop="status" label="物流状态">
            <template slot-scope="scope">
              <!-- {{scope.row.status|LogisticsStatusFil}}<br> -->
              <span>名称:{{scope.row.express_name}}<br>单号:{{scope.row.express_no}}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column width="150" label="操作" v-if="!$store.state.readonly" fixed="right">
            <template slot-scope="scope">
              <el-button  @click="editAddress(scope.row)"  plain type="info" size="mini">
                    编辑收货地址
                  </el-button>
            </template>
          </el-table-column> -->
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="成长记录" name="growthRecord">
        <el-table :data="growthRecordList">
          <el-table-column
            prop="element_title"
            width="200"
            label="歌曲名">
          </el-table-column>
          <el-table-column
            prop="category_name"
            width="200"
            label="课程">
          </el-table-column>
          <el-table-column
            prop="interest"
            width="100"
            label="兴趣度">
          </el-table-column>
          <el-table-column
            prop="concent"
            width="100"
            label="专注度">
          </el-table-column>
          <el-table-column
            prop="parent_child"
            width="100"
            label="亲子互动">
          </el-table-column>
          <el-table-column
            prop="growth_record"
            label="成长记录">
            <template slot-scope="scope">
              <el-popover
                placement="top-start"
                width="200"
                trigger="hover"
                :content="scope.row.growth_record">
                <el-button slot="reference">{{scope.row.growth_record}}</el-button>
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column
            prop="created_at"
            width="200"
            label="提交时间">
          </el-table-column>
        </el-table>
        <page :total="total" :limit="limit" @pageChange="onRecordPageChange" @sizeChange="onRecordSizeChange"/>
      </el-tab-pane>
    </el-tabs>
    <teacher-dialog :dialogObj="dialogObj" @reflash="getDetail"></teacher-dialog>
    <user-list :userObj="userObj"/>
    <source-dialog :dialogObj="sourceDialog"/>
    <refund-detail :dialogObj="refundDetail"/>
    <coupon-dialog :dialogObj="couponDetail"/>
    <el-dialog :modal="false" :visible.sync="privilegeDialog.show" title="编辑权限">
      <el-form label-width="120px">
        <el-form-item label="是否添加老师">
          <el-select v-model="privilegeDialog.is_add_teacher" placeholder="请选择">
            <el-option
              v-for="(data,index) in isAddTeacherList"
              :key="index"
              :label="data.label"
              :value="data.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="看课权限">
          <el-switch
            v-model="privilegeDialog.isAllowView"
            active-color="#13ce66"
            inactive-color="#ff4949">
          </el-switch>
        </el-form-item>
        <el-form-item label="意向等级">
          <el-input-number v-model="privilegeDialog.weight" :min="0" :step="1"></el-input-number>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="privilegeDialog.show = false">取 消</el-button>
        <el-button type="primary" @click="changePrivilegeSub()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 地址编辑 -->
    <address-dialogC :dialogObj="addressDialog" @reflash="onUpdateAddress"></address-dialogC>
    <!-- 备注 -->
    <el-dialog :modal="false" :visible.sync="descDialog.show" title="备注列表" width="60%">
      <el-form label-width="90px">
        <el-form-item>
          <el-button style="float: right" type="primary" plain @click="editComment(descDialog.id)">添加备注</el-button>
        </el-form-item>
      </el-form>
      <el-table
        :data="descDialog.descList"
        style="width: 100%">
        <el-table-column
          label="用户" className="f-c" min-width="150">
          <template slot-scope="scope" v-if="descDialog.userInfo">
            <img :src="descDialog.userInfo.avatar" style="width: 40px;height: 40px;border-radius: 50px"> {{descDialog.userInfo.nickname}}(ID:{{descDialog.userInfo.user_id}})
          </template>
        </el-table-column>
        <el-table-column
          prop="desc"
          label="备注">
        </el-table-column>
        <el-table-column
          prop="operator"
          label="备注人">
        </el-table-column>
        <el-table-column
          prop="created_at"
          label="创建时间">
        </el-table-column>
        <el-table-column
          prop="updated_at"
          label="更新时间">
        </el-table-column>
      </el-table>
      <page :nowPage="descDialog.nowPage" :total="descDialog.total" :limit="descDialog.limit" @pageChange="onDescDialogPageChange" @sizeChange="onDescDialogSizeChange"/>
    </el-dialog>
    <!-- 看课情况 -->
    <el-dialog :modal="false" :visible.sync="lookDetail.show">
      <el-table
        v-loading="lookDetail.loading"
        :data="lookDetail.list"
        style="width: 100%">
        <el-table-column
          prop="start_at"
          label="日期">
        </el-table-column>
        <el-table-column
          label="爸妈看一看">
          <template slot-scope="scope">
            <span v-if="scope.row.watch_list && scope.row.watch_list.length > 0 && scope.row.watch_list.find(i=>{return i.page_id === 1})">
              {{scope.row.watch_list.find(i=>{return i.page_id === 1}).stay_time}}
            </span>
            <span v-if="!scope.row.watch_list.find(i=>{return i.page_id === 1})">
              暂未上课
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="宝贝玩一玩">
          <template slot-scope="scope">
            <span v-if="scope.row.watch_list && scope.row.watch_list.length > 0 && scope.row.watch_list.find(i=>{return i.page_id === 2})">
              {{scope.row.watch_list.find(i=>{return i.page_id === 2}).stay_time}}
            </span>
            <span v-if="!scope.row.watch_list.find(i=>{return i.page_id === 2})">
              暂未上课
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="爸妈秀宝贝">
          <template slot-scope="scope">
            <span v-if="scope.row.watch_list && scope.row.watch_list.length > 0 && scope.row.watch_list.find(i=>{return i.page_id === 3})">
              <div v-html="scope.row.watch_list.find(i=>{return i.page_id === 3}).learn_report"></div>
            </span>
            <span v-if="!scope.row.watch_list.find(i=>{return i.page_id === 3})">
              暂未秀宝贝
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="多元趣味课">
          <template slot-scope="scope">
            <span v-if="scope.row.watch_list && scope.row.watch_list.length > 0 && scope.row.watch_list.find(i=>{return i.page_id === 5})">
              {{scope.row.watch_list.find(i=>{return i.page_id === 5}).stay_time}}
            </span>
            <span v-if="!scope.row.watch_list.find(i=>{return i.page_id === 5})">
              暂未上课
            </span>
          </template>
        </el-table-column>
        <el-table-column
          label="分享">
          <template slot-scope="scope">
            <span v-if="scope.row.watch_list && scope.row.watch_list.length > 0 && scope.row.watch_list.find(i=>{return i.page_id === 4})">
              已分享
            </span>
            <span v-if="!scope.row.watch_list.find(i=>{return i.page_id === 4})">
              暂未分享
            </span>
          </template>
        </el-table-column>
      </el-table>
      <page :nowPage="lookDetail.nowPage" :total="lookDetail.total" :limit="lookDetail.limit" @pageChange="onLookDetailPageChange" @sizeChange="onLookDetailSizeChange"/>
    </el-dialog>
    <sourceByDateDialog :dialogObj=sourceByDateDialogJson ref="sourceByDateDialogDom"></sourceByDateDialog>
  </div>
</template>

<script>
  import {
    getOrderListApi,
    getUserDetailApi,
    getPeriodsStatisticsApi,
    userLookApi,
    getUserDescListApi,
    addPeriodsClassUserDescApi,
    getDeliverRecordApi,
    updateUserPrivilegeApi,
    getyunjiApi,
    fetchAddressListApi,
    getSubAccountInfoApi,
    getUserSubAccountListApi,
    getGrowthRecordApi
  } from "../../service/api";
  import page from '../framework/page'
  import sourceDialog from '../order/sourceDialog'
  import refundDetail from '../order/refundDetail'
  import couponDialog from '../order/couponDialog'
  import addressDialogC from "./addressdialog";
  import {INVITETYPE, ORDERSTATUS, BUYTYPE, USERSTATUSFORMATER} from "../../util/wordbook";
  import teacherDialog from './dialog'
  import UserList from '../class/userList'
  import CallBack from '@/components/userDetail/callBack';
  import sourceByDateDialog from '../teacherDetail/sourceByDateDialog'
  import AddressArray from "../framework/address-picker/addr";

  export default {
    name: "index",
    components: {
      page,
      teacherDialog,
      UserList,
      refundDetail,
      sourceDialog,
      couponDialog,
      sourceByDateDialog,
      addressDialogC,
      CallBack
    },
    props: [
      'parentDetail'
    ],
    data() {
      return {
        callbackObj: {
          user_id: '',
          teacher_id: '',
          timestamp: '',
          info: {}
        },
        userList: [],
        yunjiList: [],
        addressList: [],
        total: 0,
        addressDialog: {
          show: false
        },
        addressParams: {},
        sourceDialog: {
          show: false,
          out_trade_no: ''
        },
        //tabs: 'periods',
        tabs: 'callback',
        couponDetail: {
          show: false,
          order_coupon_id: ''
        },
        refundDetail: {
          show: false,
          out_trade_no: ''
        },
        nowPage: 1,
        limit: 5,
        id: '',
        detail: {},
        subDetail: {},
        subListData: [],
        periodList: [],
        dialogObj: {
          show: false,
          title: '绑定老师',
          id: 0,
          teacher_id: 0
        },
        list: [],
        userObj: {
          classId: '',
          title: '',
          show: false,
        },
        privilegeDialog: {
          show: false,
          isAllowView: false,
          is_add_teacher: 0,
          weight: 0,
          id: ''
        },
        descDialog: {
          show: false,
          descList: [],
          nowPage: 1,
          limit: 10,
          total: 0,
          userInfo: null
        },
        lookDetail: {
          show: false,
          loading: false,
          list: [],
          nowPage: 1,
          limit: 10,
          total: 0
        },
        isAddTeacherList: [
          {
            label: '暂未处理',
            value: 0
          },
          {
            label: '老师主动添加用户',
            value: 1
          },
          {
            label: '用户主动添加老师',
            value: 2
          },
          {
            label: '待通过',
            value: 3
          },
          {
            label: '手机号不是微信号',
            value: 4
          },
          {
            label: '用户已拒绝',
            value: 5
          }
        ],
        sourceByDateDialogJson: {},
        deliverRecordList: [],
        growthRecordList:[]
      }
    },
    created() {
      // this.id = this.parentDetail ? this.parentDetail.id : this.$route.params.id;
      this.id = this.parentDetail ? this.parentDetail.id : (this.$route.query.userid ? this.$route.query.userid : '');
      this.callbackObj.user_id = this.id;
      // this.callbackObj.teacher_id = this.parentDetail.teacher_id ? this.parentDetail.teacher_id : '';
      this.callbackObj.teacher_id = this.parentDetail && this.parentDetail.teacher_id ? this.parentDetail.teacher_id : (this.$route.query.teacherid ? this.$route.query.teacherid : '');
      this.callbackObj.timestamp = (new Date()).getTime();
    },
    mounted() {
      this.getDetail();
    },
    watch: {
      'tabs'(value) {
        if (value === 'order') {
          this.getUser()
        }
        if (value === 'yunji') {
          this.getyunjiOrder()
        }
        if (value === 'address') {
          this.getAddressList()
        }
        if (value === 'subList') {
          this.getUserSubAccountList()
        }
        if (value === 'deliverRecord') {
          this.getDeliverRecordList()
        }
        if (value === 'growthRecord') {
          this.getGrowthRecordList()
        }


      }
    },
    methods: {
      // editAddress(row){
      //   this.addressParams = row
      //   this.addressParams.show=true
      //   console.log(row)
      // },
      periodName(val) {
        let str = '';
        if (!val.periods_title) {
          str = '-'
        } else {
          if (val.goods_id) {
            str += `【${val.goods_id}】`
          }
          if (val.periods_title) {
            str += `${val.periods_title}<br>`
          }
          if (val.watch_num) {
            str += `${val.watch_num}课时`
          }
          if (val.start_at) {
            str += `（${val.start_at.slice(5).replace('-', '')}）`
          }
          if (val.has_watch_num || val.has_watch_num == 0) {
            str += `-d${val.has_watch_num}`
          }
        }
        return str
      },
      getDeliverRecordList() {
        getDeliverRecordApi({user_id: this.id, page: 1, limit: 20}).then(res => {
          this.deliverRecordList = res.list
          console.log(this.deliverRecordList)
        })
      },
      getGrowthRecordList() {
        getGrowthRecordApi({user_id: this.id, page: this.recordPage, limit: this.limit}).then(res => {
          this.growthRecordList = res.list
          this.total = res.total
          console.log(this.growthRecordList)
        })
      },
      onUpdateAddress() {
        this.dialogObj.show = false;
        this.getAddressList();
      },
      addAddress(row) {
        this.addressDialog.userid = this.id;
        this.addressDialog.show = true;
      },
      editAddress(row) {
        if (!row || !row.province_name) {
          this.addressDialog.province = "";
          this.addressDialog.city = "";
          this.addressDialog.district = "";
        } else {
          let provinceObj = AddressArray.filter(item => {
            return item.label === row.province_name;
          });
          if (provinceObj && provinceObj.length > 0) {
            this.addressDialog.province = row.province_id ? row.province_id : provinceObj[0].value;
            if (!row.city) {
              this.addressDialog.city = "";
            } else {
              let cityObj = provinceObj[0].children.filter(city => {
                return city.label === row.city;
              });
              this.addressDialog.city = row.city_id ? row.city_id : cityObj[0].value;
              if (!row.area) {
                this.addressDialog.district = "";
              } else {
                let districtObj = cityObj[0].children.filter(district => {
                  return district.label === row.area;
                });
                this.addressDialog.district = row.area_id ? row.area_id : districtObj[0].value;
              }
            }
          } else {
            this.addressDialog.province = "";
            this.addressDialog.district = "";
            this.addressDialog.city = "";
          }
        }
        this.addressDialog.detail = row ? row.address : "";
        this.addressDialog.receive_mobile = row ? row.receive_mobile : "";
        this.addressDialog.receive_name = row ? row.receive_name : "";
        this.addressDialog.province_name = row ? row.province_name : "";
        this.addressDialog.city_name = row ? row.city : "";
        this.addressDialog.district_name = row ? row.area : "";

        this.addressDialog.is_del = row.is_del;
        this.addressDialog.id = row.id;
        this.addressDialog.show = true;
        console.log(this.addressDialog)
        // debugger
      },
      getAddressList() {
        fetchAddressListApi(this.id).then(res => {
          this.addressList = res
          // console.log(this.addressList)
        })
      },
      userStatusFormatter(val) {
        return (USERSTATUSFORMATER[val.user_status])
      },
      showSourceByDate(row) {
        this.sourceByDateDialogJson = {
          "periods_id": row.periods_id,
          "user_id": row.user_id,
          json: {
            limit: 10,
            page: 0
          }
        }
        this.$refs.sourceByDateDialogDom.dialogShow = true
      },
      getUserLook() {
        if (!this.lookDetail.data) return;
        this.lookDetail.show = true;
        this.lookDetail.loading = true;
        let json = {
          limit: this.lookDetail.limit,
          page: this.lookDetail.nowPage
        }
        let data = this.lookDetail.data;
        userLookApi(data.periods_id, data.user_id, json).then(res => {
          this.lookDetail.list = res.list;
          this.lookDetail.loading = false;
          this.lookDetail.total = res.total;
        })
      },
      onLookDetailPageChange(val) {
        this.lookDetail.nowPage = val
        this.getUserLook();
      },
      onLookDetailSizeChange(val) {
        this.lookDetail.limit = val
        this.lookDetail.nowPage = 1;
        this.getUserLook();
      },
      onDescDialogPageChange(val) {
        this.descDialog.nowPage = val
        this.getUserDescList()
      },
      onDescDialogSizeChange(val) {
        this.descDialog.limit = val
        this.descDialog.nowPage = 1;
        this.getUserDescList()
      },
      showRef(data) {
        this.refundDetail.show = true;
        this.refundDetail.out_trade_no = data.out_trade_no;
      },
      showCoupon(data) {
        this.couponDetail.show = true;
        this.couponDetail.order_coupon_id = data.order_coupon_id;
      },
      showSource(data) {
        this.sourceDialog.show = true;
        this.sourceDialog.out_trade_no = data.out_trade_no;
      },
      changeRow(data, b) {
        this.list = [];
        if (b.indexOf(data) > -1) {
          getPeriodsStatisticsApi(data.periods_id).then(res => {
            data.arrive_course_rate = res.arrive_course_rate;
            data.watch_course_rate = res.watch_course_rate;
            data.over_course_rate = res.over_course_rate;
            data.work_rate = res.work_rate;
            data.over_work_rate = res.over_work_rate;
            data.clock_rate = res.clock_rate;
            data.over_clock_rate = res.over_clock_rate;
            data.transform_rate = res.transform_rate;
            this.list = [data];
          })
        }
      },
      onPageChange(val) {
        this.nowPage = val;
        this.getUser();
      },
      onSizeChange(val) {
        this.nowPage = 1;
        this.limit = val;
        this.getUser();
      },
      onRecordPageChange(val) {
        this.recordPage = val;
        this.getGrowthRecordList();
      },
      onRecordSizeChange(val) {
        this.recordPage = 1;
        this.limit = val;
        this.getGrowthRecordList();
      },
      getUser() {
        let json = {
          user_id: this.id,
          limit: this.limit,
          page: this.nowPage,
          status: '1,3,4,5'
        };
        getOrderListApi(json).then(res => {
          res.list.forEach(i => {
            i.refundList = []
          });
          this.userList = res.list;
          this.total = res.total
        })
      },
      getDetail() {
        if (!this.id) return;
        getUserDetailApi(this.id).then(res => {
          this.detail = res;
          if (res.periods_list) {
            this.periodList = res.periods_list
          }
          this.callbackObj.info = res; // 用户的所有数据
        })
        getSubAccountInfoApi(this.id).then(res => {
          if (res.family_user == 1) {
            this.subDetail = res.sub_user_info
          }
        })
      },
      getUserSubAccountList() {
        getUserSubAccountListApi(this.id).then(res => {
          this.subListData = res
        })
      },
      bindTeacher() {
        let data = this.detail
        this.dialogObj = {
          show: true,
          title: '绑定老师',
          id: data.user_id,
          teacher_id: data.teacher_id
        }
      },
      showUser(data) {
        let classType = data.type == 1 ? '(带班班级)' : '(观摩班级)'
        console.log(data)
        this.userObj = {
          classId: data.class_id,
          show: true,
          title: `${data.teacher_name}班级用户列表${classType}`,
          teacherId: data.teacher_id,
          periods_id: data.periods_id,
          goods_id: data.goods_id,
          classPage: true,
          type: data.type
        }
      },
      //编辑备注 看课情况
      editPrivilege(val) {
        this.privilegeDialog = {
          id: val.id,
          isAllowView: val.is_view_course === 1,
          is_add_teacher: val.is_add_teacher ? val.is_add_teacher : 0,
          weight: val.weight ? val.weight : 0,
          show: true
        }
      },
      onGetUserDescList(val) {
        this.descDialog.show = true;
        this.descDialog.userInfo = {
          user_id: val.user_id,
          avatar: this.detail.avatar,
          nickname: this.detail.nickname
        };
        this.descDialog.id = val.id;
        this.getUserDescList();
      },
      getUserDescList() {
        let json = {
          page: this.descDialog.nowPage,
          limit: this.descDialog.limit
        };
        getUserDescListApi(this.descDialog.id, json).then(res => {
          this.descDialog.descList = res.list;
          this.descDialog.total = res.total;
        })
      },
      userLook(data) {
        this.lookDetail.show = true;
        this.lookDetail.loading = true;
        let json = {
          limit: this.lookDetail.limit,
          page: this.lookDetail.nowPage
        }
        this.lookDetail.data = {
          periods_id: data.periods_id,
          user_id: data.user_id
        }
        userLookApi(data.periods_id, data.user_id, json).then(res => {
          this.lookDetail.list = res.list;
          this.lookDetail.loading = false;
          this.lookDetail.total = res.total;
        })
      },
      editComment(id) {
        this.$prompt('', '添加备注', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputValue: ''
        }).then(({value}) => {
          addPeriodsClassUserDescApi(id, {desc: value}).then(res => {
            this.$message({
              type: 'success',
              message: '编辑备注成功'
            })
            this.getUserDescList();
          });
        })
      },
      changePrivilegeSub() {
        this.$confirm('此操作将修改用户权限?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let _json = {
            is_view_course: this.privilegeDialog.isAllowView ? 1 : 0,
            is_add_teacher: this.privilegeDialog.is_add_teacher,
            weight: this.privilegeDialog.weight
          }
          updateUserPrivilegeApi(this.privilegeDialog.id, _json).then(res => {
            this.$message({
              type: 'success',
              message: '修改成功!'
            });
            this.privilegeDialog.show = false;
            // this.getUser()
            this.getDetail()
          });
        });
      },
      getyunjiOrder() {
        let json = {
          limit: this.limit,
          page: this.nowPage
        };
        json.user_id = this.id
        getyunjiApi(json).then(res => {
          this.total = res.total;
          this.yunjiList = res.list ? res.list : [];
        });
      }
    },
    filters: {
      payMentFilter(val) {
        return val == '1' ? '已付款' : '未付款'
      },
      courseTypeFilter(val) {
        return val.type == '1' ? `正式课(${val.duration}个月)` : `试听课(${val.duration}天)`
      },
      inviteType(value) {
        return INVITETYPE[value]
      },
      status(value) {
        return ORDERSTATUS[value]
      },
      buyType(value) {
        return BUYTYPE[value]
      },
      moneytFilter(val) {
        return val = val / 100 + '元'
      },
      percent(val) {
        return (val * 100).toFixed(2) + '%'
      },
      isdel(val) {
        return val == 0 ? '未删除' : '已删除'
      }
    }
  }
</script>

<style scoped lang="less">
  @import "../../util/public";

  .box {
    display: flex;
  }

  .user-card {
    /*margin: 10px;*/
    /*width: 600px;*/
    /*padding: 20px;*/
    // display: flex;
    .text.item {
      line-height: 30px;
    }

    .card-content {
      img {
        float: left;
      }
    }

    label {
      color: #5982e6;
      width: 100px;
      display: inline-block;
      text-align: right;
    }

    .el-col {
      height: 30px;
      line-height: 30px;
    }

    .title {
      height: 50px;
      line-height: 60px;
      margin-bottom: 20px;

      a {
        display: block;

        img {
          width: 80px;
          border-radius: 100px;
        }
      }
    }
  }

  .width400 {
    width: 400px;
  }

  .avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
  }

  .user {
    height: 100%;
    overflow: auto;
    /*padding: 20px 0;*/

    .btn-content {
      text-align: center;
    }
  }

  .header {
    padding: 0 20px;
    margin-bottom: 20px;
  }

  .header {
    .el-row {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      color: #666;
      font-size: 16px;
      margin: 25px 0;

      label {
        margin-right: 10px;
      }
    }

    .avatar {
      margin-right: 10px;
    }
  }

  .b-title {
    padding: 20px;
    color: #666;
  }
</style>

<style>
  .user-detail {
    padding: 20px;
  }
</style>

