<template>
  <div class="teacher">
    <div class="header">
      <el-card style="width: 450px;display: inline-block;margin-right: 10px">
        <div slot="header">
          <span><label>{{detail.type | teacherType}}：</label> {{detail.name}}（T{{detail.squad}}）</span>
          <el-button style="float: right;margin-top: -6px;" size="small" type="success" v-if="!$store.state.readonly" plain @click="onAddUser(true)">老师绑定用户</el-button>
        </div>
        <div class="card-content">
          <div class="text item">
            <a :href="detail.qr" target="_blank">
              <img :src="detail.qr"/>
            </a>
          </div>
          <div class="text item style-fix">
            <span>
              <label>微信号：</label> {{detail.alias}}
            </span>
            <span>
              <label>带班总人数：</label>{{detail.total_join_num}}
            </span>
            <span>
              <label>老师状态：</label>{{detail.status === 0 ? '正常' : '禁用'}}
            </span>
            <span>
              <label>顾问：</label>{{detail.adviser}}
            </span>
            <span>
              <label>开始时间：</label>{{detail.teacher_start}}
            </span>
          </div>
        </div>
      </el-card>
      <el-card style="width: 450px;display: inline-block;margin-right: 10px" v-if="detail.user_info">
        <div slot="header">
          <span>绑定用户</span>
          <el-button @click="createInviteLink(detail.user_info)" style="float: right;" size="mini" plain type="primary">复制专属链接</el-button>
        </div>
        <div class="card-content">
          <div class="text item">
            <a :href="detail.user_info.avatar" target="_blank">
              <img class="avatar" :src="detail.user_info.avatar"/>
            </a>
          </div>
          <div class="text item">
            <label>微信号：</label> {{detail.user_info.nickname}}
          </div>
          <div class="text item">
            <label>用户ID：</label> {{detail.user_info.user_id}}
          </div>
        </div>
      </el-card>
      <el-card style="width: 320px;display: inline-block" v-if="task4Data">
        <div slot="header">
          <span>当月销售转化率【{{nowDate}}】</span>
        </div>
        <div class="text item">
          <el-progress type="circle" style="float: left;margin-right: 10px" :percentage="Number(task4Data.trans_rate.split('%')[0])"></el-progress>
        </div>
        <div class="card-content">
          <div class="text item">
            <label>当月带班人数：</label> {{task4Data.total_user_num}}
          </div>
          <div class="text item">
            <label>当月购课人数：</label> {{task4Data.total_sale_num}}
          </div>
          <div class="text item">
            <label>当月累计业绩：</label> {{task4Data.total_money}}
          </div>
        </div>
      </el-card>
    </div>
    <el-tabs type="border-card" v-model="tabs">
      <!--<el-tab-pane label="客户管理" name="customer">
        <customerDetail :customerObj="customerObj"></customerDetail>
      </el-tab-pane>-->
      <el-tab-pane label="今日任务" name="task">
        <task :parentDetail="parentDetail" :detail="detail"></task>
      </el-tab-pane>
      <el-tab-pane label="期数列表" name="periods">
        <el-table @expand-change="changeRow" :data="list">
          <el-table-column type="expand">
            <template slot-scope="scope">
              <el-table :data="[scope.row]">
                <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.work_rate  | percent}}</span>
                  </template>
                </el-table-column>
                <el-table-column label="全勤作业率">
                  <template slot-scope="scope2">
                    <span>{{ scope2.row.over_work_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="期数名称"></el-table-column>-->
          <el-table-column prop="periods_title" label="期数名称">
            <template slot-scope="scope">
              <div v-html="periodName(scope.row)"></div>
              <!--{{periodName(scope.row)}}-->
            </template>
          </el-table-column>
          <el-table-column prop="class_name" label="班级名称"></el-table-column>
          <el-table-column prop="join_num" label="已进班人数" width="90px"></el-table-column>
          <el-table-column prop="need_add_teacher_num" label="需加好友数" width="90px"></el-table-column>
          <el-table-column prop="max_join_num" label="最大班级人数" width="105px"></el-table-column>
          <el-table-column prop="start_at" label="开课时间" width="110px"></el-table-column>
          <el-table-column prop="source" label="活动方案">
            <template slot-scope="scope">
              {{scope.row.source | classSource}}
            </template>
          </el-table-column>
          <el-table-column label="操作" width="100">
            <template slot-scope="scope">
              <el-button @click="showUser(scope.row)" size="mini" plain type="primary">班级成员</el-button>
            </template>
          </el-table-column>
        </el-table>
        <page :total="total" :limit="limit" @pageChange="onPageChange" @sizeChange="onSizeChange"/>
      </el-tab-pane>
      <el-tab-pane label="系统订单列表" name="order">
        <el-form ref="form" :model="form" label-width="100px" inline>
          <el-form-item label="用户ID">
            <el-input v-model="form.user_id"></el-input>
          </el-form-item>
          <el-form-item label="用户昵称">
            <el-input v-model="form.nickname"></el-input>
          </el-form-item>
          <el-form-item label="用户手机号">
            <el-input v-model="form.mobile"></el-input>
          </el-form-item>
          <el-form-item label="收件人手机号">
            <el-input v-model="form.receive_mobile"></el-input>
          </el-form-item>
          <el-form-item label="商品名称">
            <el-select v-model="form.goods_id" filterable placeholder="请选择" @change="getOrderList" clearable>
              <el-option
                v-for="(data,index) in goodList"
                :key="index"
                :label="data | filterGoods"
                :value="data.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="订单状态">
            <el-select multiple v-model="form.status" placeholder="请选择" @change="getOrderList" clearable>
              <el-option
                v-for="item in orderStatusOption"
                :key="item.id"
                :label="item.value"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="交易订单号">
            <el-input v-model="form.out_trade_no"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" plain @click="getOrderList">搜索</el-button>
          </el-form-item>
        </el-form>
        <el-table :data="tableData" class="order_list" fixed>
          <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}})<br>手机：{{scope.row.user_mobile}}
            </template>
          </el-table-column>
          <!--<el-table-column prop="periods_title" label="期数名称"></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="width:100%;display: flex;color: #409eff;cursor: pointer">
                <img :src="scope.row.invite_avatar" class="avatar"/>
                类型：{{scope.row.invite_type}} ({{scope.row.invite_name}})
                <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}} ({{scope.row.invite_name}})
                <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="购买时间" sortable></el-table-column>
          <el-table-column prop="created_at" label="下单时间" sortable></el-table-column>
          <el-table-column prop="desc" label="备注"></el-table-column>
          <el-table-column width="50" label="操作" v-if="!$store.state.readonly" fixed="right">
            <template slot-scope="scope">
              <el-popover placement="top" width="200">
                <div style="text-align: center">
                  <el-button @click="editComment(scope.row.id, scope.row.desc)" type="info" plain size="mini">编辑备注</el-button>
                </div>
                <el-button slot="reference" size="mini" type="text">操作</el-button>
              </el-popover>
            </template>
          </el-table-column>
        </el-table>
        <page :total="orderListObj.total" :limit="orderListObj.limit" @pageChange="onPageChange2" @sizeChange="onSizeChange2"/>
      </el-tab-pane>
      <el-tab-pane label="外部订单列表" name="yunji">
        <el-form ref="form" :model="form" label-width="100px" inline>
          <el-form-item label="用户ID">
            <el-input v-model="form.user_id"></el-input>
          </el-form-item>
          <el-form-item label="用户昵称">
            <el-input v-model="form.nickname"></el-input>
          </el-form-item>
          <el-form-item label="用户手机号">
            <el-input v-model="form.mobile"></el-input>
          </el-form-item>
          <el-form-item label="收件人手机号">
            <el-input v-model="form.receive_mobile"></el-input>
          </el-form-item>
          <el-form-item label="商品名称">
            <el-select v-model="form.goods_id" filterable placeholder="请选择" @change="getyunjiList" clearable>
              <el-option
                v-for="(data,index) in goodList"
                :key="index"
                :label="data | filterGoods"
                :value="data.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="订单状态">
            <el-select multiple v-model="form.status" placeholder="请选择" @change="getyunjiList" clearable>
              <el-option
                v-for="item in orderStatusOption"
                :key="item.id"
                :label="item.value"
                :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="交易订单号">
            <el-input v-model="form.out_trade_no"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" plain @click="getyunjiList">搜索</el-button>
          </el-form-item>
        </el-form>
        <el-table :data="yunjiList" class="order_list" fixed>
          <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="期数名称"></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 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>
        <page :total="yunjiListObj.total" :limit="yunjiListObj.limit" @pageChange="onPageChange3" @sizeChange="onSizeChange3"/>
      </el-tab-pane>
      <el-tab-pane label="话术列表" name="huashu">
        <div class="cssbox">
          <el-tabs v-model="questionListParams.type" type="card" @tab-click="handleClick">
            <el-tab-pane label="话术" name="1"></el-tab-pane>
            <el-tab-pane label="流程" name="2"></el-tab-pane>
          </el-tabs>
          <!-- </el-col> -->
          <el-collapse v-model="modularId" @change="handleChange" accordion>
            <el-collapse-item v-for="(item,index) in modularList" :name="item.id" :key="index">
              <template slot="title">
                {{item.title}}
              </template>
              <div class="search">
                <el-input placeholder="请输入关键字" v-model="questionListParams.keywords"></el-input>
                <el-button type="primary" plain @click="handleChange">搜索</el-button>
              </div>
              <el-table :data="modularContent" style="width: 100%">
                <el-table-column prop="title" label="标题"></el-table-column>
                <el-table-column prop="keywords" label="关键字"></el-table-column>
                <el-table-column label="创建时间" prop="created_at"></el-table-column>
                <el-table-column width="250" v-if="!$store.state.readonly" label="操作">
                  <template slot-scope="scope">
                    <el-button size="mini" plain type="warning" @click="showContent(scope.row)">查看内容</el-button>
                  </template>
                </el-table-column>
              </el-table>
              <page :total="contentTotal" :limit="contentLimit" @pageChange="onPageChangeC" @sizeChange="onSizeChangeC"/>
            </el-collapse-item>
          </el-collapse>
          <page :total="modularTotal" :limit="modularLimit" @pageChange="onPageChangeModular" @sizeChange="onSizeChangeModular"/>
          <!-- 查看内容 -->
          <el-dialog
            title=""
            center
            append-to-body
            ref="ruleForm"
            :visible.sync="postModularContentDialog"
            width="800px">
            <div class="quesion">
              <p style="font-weight:bold">标题:&nbsp;</p><span>{{postModularParams.title}}</span>
            </div>
            <div class="quesion">
              <p style="font-weight:bold">关键字:&nbsp;&nbsp;&nbsp;</p><span>{{postModularParams.keywords}}</span>
            </div>
            <div class="ans">
              <p style="font-weight:bold">内容:</p>
              <div v-html="postModularParams.content"></div>
            </div>
            <!-- <el-form ref="form" :model="postModularParams">
              <el-row>
                <el-col :span="24">
                  <el-form-item label="商品详情" label-width="80px" required>
                    <editor-detail :lookData="postModularParams"/>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form> -->
          </el-dialog>
        </div>
      </el-tab-pane>
    </el-tabs>
    <source-dialog :dialogObj="sourceDialog"/>
    <refund-detail :dialogObj="refundDetail"/>
    <coupon-dialog :dialogObj="couponDetail"/>

    <user-list :userObj="userObj" @reflash="getTeacherDetail"/>
    <choose-good-dialog :dialogObj="chooseGoodDialogObj" @changeShow="changeShow"/>

    <el-dialog append-to-body :visible.sync="addShow" top="5vh">
      <el-form label-width="90px" inline>
        <!--<el-form-item label="用户id">-->
        <!--<el-input v-model="addId"></el-input>-->
        <!--</el-form-item>-->
        <el-form-item>
          <el-input style="width: 160px;" placeholder="ID" @change="getUser" v-model="searchFrom.userId"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input style="width: 160px;" placeholder="昵称" @change="getUser" v-model="searchFrom.nickName"></el-input>
        </el-form-item>
        <el-form-item>
          <el-input style="width: 160px;" placeholder="电话" @change="getUser" v-model="searchFrom.mobile"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" plain @click="getUser">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-table border size="small" :data="userList" ref="multipleTable" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column className="f-c" label="用户">
          <template slot-scope="scope">
            <img style="margin-right:8px;width: 50px;height: 50px;border-radius: 50px" :src="scope.row.avatar">{{scope.row.nickname}}(ID:{{scope.row.user_id}})
          </template>
        </el-table-column>
        <el-table-column prop="mobile" label="手机号"></el-table-column>
      </el-table>
      <page :total="userObj.total" :limit="userObj.limit" :small="true" @pageChange="onPageChange3" @sizeChange="onSizeChange3"/>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addShow = false">取 消</el-button>
        <el-button type="primary" @click="onAdd">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
  import {
    getTeacherDetailApi,
    getClassStatisticsApi,
    task4Api,
    getUserListApi,
    getQuestionModularListApi,
    getQuestionModularDetailApi,
    teacherBindUserApi,
    getOrderListApi,
    getGoodsListApi,
    editOrderDescApi,
    updateOrderTeacherApi,
    getyunjiApi,
    getClassListApi,
    getSourceStudentApi
  } from "../../service/api";
  import {
    TEACHERTYPE,
    ORDERSTATUSOPTION,
    GOODSTYPE,
    ORDERSTATUS,
    CLASSSOURCE,
    USERSTATUSFORMATER
  } from "../../util/wordbook";
  import AddressArray from '../framework/address-picker/addr'
  import task from './task'
  import page from '../framework/page'
//  import customerDetail from './customer'
  import sourceDialog from './sourceDialog'
  import couponDialog from './couponDialog'
  import refundDetail from './refundDetail'
  import UserList from '../class/userList'
  import chooseGoodDialog from './chooseGoodDialog'

  let studentSource = {}
  export default {
    name: "index",
    props: [
      'parentDetail'
    ],
    components: {
      page,
      task,
      UserList,
      chooseGoodDialog,
      couponDialog,
      refundDetail,
      sourceDialog,
//      customerDetail
    },
    data() {
      let nowDate = new Date();
      let month = (nowDate.getMonth() + 1);
      if (month < 10) month = '0' + month.toString();
      nowDate = nowDate.getFullYear() + '-' + month;
      return {
        modularContentTitle: "",
        modularTotal: 0,
        modularNowPage: 1,
        modularLimit: 10,
        contentTotal: 0,
        contentNowPage: 1,
        contentLimit: 10,
        postModularContentDialog: false,
        modularId: "",
        questionListParams: {
          type: "1",
          pid: "",
          keywords: ''
        },
        postModularParams: {},
        modularList: [],
        modularContent: [],
        tabs: 'task',
        nowDate: nowDate,
        yunjiList: [],
        searchFrom: {
          user_id: '',
          is_add_teacher: '',
          is_view_course: '',
          start_at: '',
          end_at: ''
        },
        form: {
          nickname: '',
          user_id: '',
          status: [1, 3, 4, 5],
          goods_id: '',
          out_trade_no: '',
          receive_mobile: "",
          mobile: "",
        },
        task4Data: null,
        goodList: [],
        orderStatusOption: ORDERSTATUSOPTION,
        tableData: [],
        userList: [],
        list: [],
        id: this.parentDetail ? this.parentDetail.id : this.$route.params.id,
        isBindUser: true,
        addShow: false,
        detail: {},
        total: 0,
        limit: 10,
        nowPage: 1,
        customerObj: {
          alias: '',
          name: '',
          adviser: ''
        },
        userObj: {
          classId: '',
          title: '',
          show: false,
          total: 0,
          limit: 10,
          nowPage: 1,
        },
        addId: '',
        multipleSelection: [],
        chooseGoodDialogObj: {
          show: false,
          code: ''
        },
        orderListObj: {
          total: 0,
          limit: 10,
          nowPage: 1,
        },
        yunjiListObj: {
          total: 0,
          limit: 10,
          nowPage: 1,
        },
        sourceDialog: {
          show: false,
          out_trade_no: ''
        },
        couponDetail: {
          show: false,
          order_coupon_id: ''
        },
        refundDetail: {
          show: false,
          out_trade_no: ''
        },
      }
    },
    methods: {
      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
      },
      onPageChangeModular(val) {
        this.modularNowPage = val;
        this.getList();
      },
      onSizeChangeModular(val) {
        this.modularNowPage = 1;
        this.modularLimit = val;
        this.getList();
      },
      onPageChangeC(val) {
        this.contentNowPage = val;
        this.handleChange();
      },
      onSizeChangeC(val) {
        this.contentNowPage = 1;
        this.contentLimit = val;
        this.handleChange();
      },
      showContent(data) {
        this.modularContentTitle = data.title
        getQuestionModularDetailApi(data.id).then(res => {
          this.postModularParams = Object.assign({}, res);
          // console.log(this.postModularParams);
          this.postModularContentDialog = true;
        });
      },
      handleChange() {
        this.modularContent = [];
        // console.log(val);
        let json = {
          type: this.questionListParams.type,
          page: this.contentNowPage,
          limit: this.contentLimit
        };
        if (this.modularId) {
          json.pid = this.modularId;
        }
        if (this.questionListParams.keywords) {
          json.keywords = this.questionListParams.keywords;
        }
        // this.postModularParams.pid = this.modularId;
        getQuestionModularListApi(json.type, json).then(res => {
          this.modularContent = res.list;
          console.log(res);
          // debugger
          this.contentTotal = res.total;
        });
      },
      handleClick(tab) {
        // console.log(tab.name,413)
        this.questionListParams.type = tab.name;
        // this.postModularParams.type = tab.name;
        this.getList();
      },
      getList() {
        let json = {
          type: this.questionListParams.type,
          modularPage: this.modularNowPage,
          modularLimit: this.modularLimit
        };
        if (this.questionListParams.pid) {
          json.pid = this.questionListParams.pid;
        }
        getQuestionModularListApi(json.type, json).then(res => {
          this.modularList = res.list;
          console.log(this.modularList);
          // debugger
          this.modularTotal = res.total;
        });
      },
      userStatusFormatter(val) {
        return (USERSTATUSFORMATER[val.user_status])
      },
      getTask4() {
        task4Api(this.id).then(res => {
          this.task4Data = res
        })
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
      onAdd() {
        let json = {
          is_buy: 0
        }
        if (this.multipleSelection.length === 0) {
          this.$message({
            type: 'error',
            message: '请选择用户!'
          });
          return
        } else if (this.multipleSelection.length !== 1) {
          this.$message({
            type: 'error',
            message: '只能选择一个用户!'
          });
          return
        }
        this.addId = this.multipleSelection[0].user_id;
        if (!this.addId) {
          return
        }
        if (!this.isBindUser) {

        } else {
          teacherBindUserApi(this.id, {user_id: this.addId}).then(res => {
            this.$message({
              type: 'success',
              message: '绑定成功!'
            });
            this.id = this.parentDetail ? this.parentDetail.id : this.$route.params.id;
            this.getTeacherDetail();
            this.getGoodsOption();
            this.addShow = false;
          })
        }
      },
      onAddUser(flag) {
        this.isBindUser = flag;
        this.addShow = true;
        this.getUser();
      },
      getUser() {
        let json = {
          page: this.userObj.nowPage,
          limit: this.userObj.limit,
        };
        if (this.searchFrom.userId) {
          json.user_id = this.searchFrom.userId
        }
        if (this.searchFrom.nickName) {
          json.nickname = this.searchFrom.nickName
        }
        if (this.searchFrom.mobile) {
          json.mobile = this.searchFrom.mobile
        }
        getUserListApi(json).then(res => {
          this.userList = res.list;
          this.userObj.total = res.total;
        })
      },
      changeRow(data, b) {
        if (b.indexOf(data) > -1) {
          getClassStatisticsApi(data.periods_id, data.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;
          })
        }
      },
      showUser(data) {
        console.log(data)
        let classType = data.type == 1 ? '(带班班级)' : '(观摩班级)'
        this.userObj = {
          classId: data.id,
          show: true,
          title: `${this.detail.name}班级用户列表${classType}`,
          teacherId: data.teacher_id,
          periods_id: data.periods_id,
          goods_id: data.goods_id,
          type: data.type
        }
      },
      /*onPageChange3(val) {
        this.userObj.nowPage = val;
        this.getUser()
      },*/
      /*onSizeChange3(val) {
        this.userObj.limit = val;
        this.userObj.nowPage = 1;
        this.getUser();
      },*/
      onPageChange(val) {
        this.nowPage = val;
        this.getTeacherDetail();

      },
      onSizeChange(val) {
        this.limit = val;
        this.nowPage = 1;
        this.getTeacherDetail();
      },
      onPageChange2(val) {
        this.orderListObj.nowPage = val;
        this.getOrderList()
      },
      onSizeChange2(val) {
        this.orderListObj.limit = val;
        this.orderListObj.nowPage = 1;
        this.getOrderList()
      },
      onPageChange3(val) {
        this.yunjiListObj.nowPage = val;
        this.getyunjiList()
      },
      onSizeChange3(val) {
        this.yunjiListObj.limit = val;
        this.yunjiListObj.nowPage = 1;
        this.getyunjiList()
      },
      getTeacherDetail() {
        this.searchFrom = {
          user_id: '',
          is_add_teacher: '',
          is_view_course: '',
          start_at: '',
          end_at: ''
        };
        let id = this.id;
        let json = {
          limit: this.limit,
          page: this.nowPage
        }
        // getClassListApi(this.id,json).then(res =>{
        //   console.log(res)
        //   debugger
        // })
        console.log(9999999)
        console.log(this.id)
        // debugger
        getTeacherDetailApi(id, json).then((res) => {
          console.log(res)
          this.detail = res;
          if (this.detail.class_list) {
            this.detail.class_list.list.forEach(data => {
              data.arrive_course_rate = 0;
              data.watch_course_rate = 0;
              data.over_course_rate = 0;
              data.work_rate = 0;
              data.over_work_rate = 0;
              data.clock_rate = 0;
              data.over_clock_rate = 0;
              data.transform_rate = 0;
            });

            this.list = this.detail.class_list.list || [];
            this.total = this.detail.class_list.total;
          }
          // this.getOrderList();
        })
      },
      createInviteLink(val) {
        this.chooseGoodDialogObj.show = true;
        //类型选择项
        if (this.detail.type == 0) {
          this.chooseGoodDialogObj.code = `CC-TEACHER-${val.user_id}`;

        } else if (this.detail.type == 1) {
          this.chooseGoodDialogObj.code = `CC-XXMM-${val.user_id}`;
        } else {
          this.chooseGoodDialogObj.code = `CC-TEACHER-${val.user_id}`;
        }

      },
      changeShow() {
        this.chooseGoodDialogObj.show = false;
        this.chooseGoodDialogObj.code = '';
      },
      getOrderList() {
        let json = {
          limit: this.orderListObj.limit,
          page: this.orderListObj.nowPage
        };
        if (this.form.nickname) {
          json.nickname = this.form.nickname
        }
        if (this.form.user_id) {
          json.user_id = this.form.user_id
        }
        if (this.form.status) {
          json.status = this.form.status.toString()
        }
        if (this.form.goods_id) {
          json.goods_id = this.form.goods_id
        }
        if (this.form.receive_mobile) {
          json.receive_mobile = this.form.receive_mobile
        }
        if (this.form.out_trade_no) {
          json.out_trade_no = this.form.out_trade_no
        }
        if (this.form.mobile) {
          json.mobile = this.form.mobile
        }
        // if(this.id){
        //   json.invite_id=this.id;
        //   debugger
        // }
        // json.teacher_id=this.id;
        //  json.invite_id=this.id;
        if (this.detail.user_id !== 0) {
          json.invite_id = this.detail.user_id;
          getOrderListApi(json).then((res) => {
            res.list.forEach(i => {
              i.refundList = []
            });
            this.tableData = res.list;
            this.orderListObj.total = res.total
          })
        }

      },
      getGoodsOption() {
        let json = {
          page: 1,
          limit: 100,
          course_type: 0,
        };
        getGoodsListApi(json).then(res => {
          this.goodList = res.list;
        })
      },
      editComment(id, desc) {
        this.$prompt('', '编辑备注', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          inputType: 'textarea',
          inputValue: desc || ''
        }).then(({value}) => {
          this.$confirm('确定保存?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            editOrderDescApi(id, 'order', {desc: value}).then(res => {
              this.$message({
                type: 'success',
                message: '编辑备注成功'
              });
              this.getOrderList();
            });
          });
        })
      },
      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;
      },
      getyunjiList() {
        let json = {
          limit: this.yunjiListObj.limit,
          page: this.yunjiListObj.nowPage
        };
        if (this.form.nickname) {
          json.nickname = this.form.nickname
        }
        if (this.form.user_id) {
          json.user_id = this.form.user_id
        }
        if (this.form.status) {
          json.status = this.form.status.toString()
        }
        if (this.form.goods_id) {
          json.goods_id = this.form.goods_id
        }
        if (this.form.receive_mobile) {
          json.receive_mobile = this.form.receive_mobile
        }
        if (this.form.out_trade_no) {
          json.out_trade_no = this.form.out_trade_no
        }
        if (this.form.mobile) {
          json.mobile = this.form.mobile
        }
        if (this.id) {
          json.teacher_id = this.id;
        }
        getyunjiApi(json).then(res => {
          this.yunjiListObj.total = res.total;
          this.yunjiList = res.list ? res.list : [];
        });
      }
    },
    filters: {
      teacherType(value) {
        return TEACHERTYPE[value]
      },
      percent(val) {
        return (val * 100).toFixed(2) + '%'
      },
      status(value) {
        return ORDERSTATUS[value]
      },
      moneytFilter(val) {
        return val = val / 100 + '元'
      },
      filterGoods(val) {
        return '[' + val.id + ']' + '[' + GOODSTYPE[val.goods_type] + ']' + '[' + val.current_price / 100 + '元]' + val.name
      },
      classSource(val) {
        // return CLASSSOURCE[val]
        return studentSource[val]
      }
    },
    created() {
      this.customerObj.alias = this.parentDetail ? this.parentDetail.alias : this.$route.params.alias;
      this.customerObj.name = this.parentDetail ? this.parentDetail.name : this.$route.params.name;
      this.customerObj.adviser = this.parentDetail ? this.parentDetail.adviser : this.$route.params.adviser;
    },
    mounted() {
      this.getTeacherDetail();
      console.log(this.parentDetail)
//      this.id = this.parentDetail ? this.parentDetail.id : this.$route.params.id;
      this.getTask4();
      getSourceStudentApi().then(res => {
        let obj = {}
        res.forEach((item, index) => {
          obj[item.type] = item.name
        })
        studentSource = obj
        // console.log(obj)
      });
      this.getGoodsOption();
    },
    watch: {
      'tabs'(value) {
        if (value === 'order') {
          this.getOrderList();
        }
        if (value === 'yunji') {
          this.getyunjiList();
        }
        if (value === 'huashu') {
          this.getList();
        }
      }
    }
  }
</script>

<style scoped lang="less">
  .b-title {
    padding: 20px;
    color: #666;
  }

  .teacher {
    padding: 20px 0;
  }

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

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

  .text.item {
    line-height: 40px;

    label {
      width: 120px;
    }

    &.style-fix {
      /*display: flex;
      flex-direction: column;
      justify-content: space-between;*/
      line-height: 25px;

      span {
        display: block;
      }
    }
  }

  .el-card {
    /*height: 50px;*/
    display: flex;
    justify-content: flex-start;
    align-items: center;

    .avatar {
      width: 120px;
      margin-right: 10px;
      height: 120px;
      border-radius: 1000px;
    }

    img {
      width: 120px;
      float: left;
      margin-right: 10px;
    }

    label {
      color: #5982e6;
      width: 120px;
    }
  }

  .card-content:after {
    content: '';
    display: block;
    clear: both;
  }

  .order_list {
    .avatar {
      width: 50px;
      min-width: 50px;
      height: 50px;
      margin-right: 5px;
      border-radius: 50%;
    }
  }

  .search {
    padding: 10px 30px;

    .el-input {
      display: inline-block;
      width: 300px;
    }
  }
</style>
<style>
  .demo-table-expand {
    font-size: 0;
  }

  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }

  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }

  .f-c > .cell {
    display: flex !important;
    flex-flow: row;
    justify-content: flex-start;
    align-items: center;
  }
</style>


