<template>
  <div class="table">
    <el-table
      v-loading="loading"
      class="search-table"
      :data="tData"
      :height="tableHeight"
      style="width: 100%"
      border
      @sort-change="sortfunc"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        fixed
        type="selection"
        width="55"
      />
      <el-table-column
        v-for="item in tableColumn"
        :key="item.prop"
        :prop="item.prop"
        :label="item.label"
        :sortable="item.prop=='appointBeginTime'||item.prop=='assistantBeginTime'?'custom':false"
        :show-overflow-tooltip="item.showtooltip"
        min-width="170"
        align="center"
      >
        <template slot-scope="scope">
          <div v-if="scope.column.property == 'appointBeginTime'">
            <p>{{ scope.row.appointBeginTime }}</p>
            <p>{{ scope.row.appointEndTime }}</p>
          </div>
          <div v-else-if="scope.column.property == 'assistantBeginTime'">
            <p>{{ scope.row.assistantBeginTime }}</p>
            <p>{{ scope.row.assistantEndTime }}</p>
          </div>
          <div v-else-if="scope.column.property == 'receptionBeginTime'">
            <p>{{ scope.row.receptionBeginTime }}</p>
            <p>{{ scope.row.receptionEndTime }}</p>
          </div>
          <div v-else>
            <p>{{ scope.row[scope.column.property] }}</p>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        fixed="right"
        align="center"
        min-width="400"
      >
        <template slot-scope="scope">
          <el-button
            v-if="showBtn(scope.row, 25)"
            type="primary"
            size="small"
            class="btn"
            @click="witeDiagnose(scope.row)"
          >
            设为待问诊
          </el-button>
          <el-button
            v-if="
              showBtn(scope.row, 21, 22, 23, 24, 25, 26, 3, 2) && menuType == 1
            "
            type="primary"
            size="small"
            class="btn"
            @click="changeRun(scope.row)"
          >
            更换运营
          </el-button>
          <el-button
            type="primary"
            size="small"
            class="btn"
            @click="goDetail(scope.row, false)"
          >
            查看详情
          </el-button>
          <el-button
            v-if="
              showBtn(scope.row, 2, 21, 22, 23, 24, 25, 26, 3) && menuType == 1
            "
            type="primary"
            size="small"
            class="btn"
            @click="cancelRefund(scope.row)"
          >
            取消/退款
          </el-button>
          <el-button
            v-if="showBtn(scope.row, 21)"
            type="primary"
            size="small"
            class="btn"
            @click="witeGo(scope.row)"
          >
            设为稍后跟进
          </el-button>
          <el-button
            v-if="showBtn(scope.row, 22, 21)"
            type="primary"
            size="small"
            class="btn"
            @click="waitMatchDot(scope.row)"
          >
            设为待匹配医生
          </el-button>
          <el-button
            v-if="showBtn(scope.row, 3, 4, 5, 6, 21, 22, 23, 24, 25, 26)"
            type="primary"
            size="small"
            class="btn"
            @click="sendMessage(scope.row)"
          >
            发送消息
          </el-button>
          <el-button
            v-if="showBtn(scope.row, 3, 26)"
            type="primary"
            size="small"
            class="btn"
            @click="joinDiagnose(scope.row)"
          >
            加入问诊
          </el-button>
          <!--          <el-button type="primary" size="small" class="btn" v-if="showBtn(scope.row,2)" @click="matchRun(scope.row)">匹配运营</el-button>-->
          <el-button
            v-if="showBtn(scope.row, 2, 3, 4, 6, 21, 22, 23, 24, 25, 26, 5, 6)"
            type="primary"
            size="small"
            class="btn"
            @click="goDetail(scope.row, true)"
          >
            编辑
          </el-button>
          <!--          <el-button type="primary" size="small" class="btn" v-if="showBtn(scope.row,21)" @click="waitDiagnose(scope.row)">设为待分诊</el-button>-->
          <el-button
            v-if="showBtn(scope.row, 23)"
            type="primary"
            size="small"
            class="btn"
            @click="waitHzeDot(scope.row)"
          >
            设为待协调医生
          </el-button>
          <el-button
            v-if="showBtn(scope.row, 23, 24)"
            type="primary"
            size="small"
            class="btn"
            @click="waitMatchTime(scope.row)"
          >
            设为待确认时间
          </el-button>
          <el-button
            v-if="showBtn(scope.row, 3, 25, 26)"
            type="primary"
            size="small"
            class="btn"
            @click="reMatchDot(scope.row,10)"
          >
            重新匹配医生
          </el-button>
          <el-button
            v-if="showBtn(scope.row, 3, 25, 26)"
            type="primary"
            size="small"
            class="btn"
            @click="reMatchDot(scope.row,16)"
          >
            重新联系助诊医生
          </el-button>
          <el-button
            v-if="showBtn(scope.row, 3, 26)"
            type="primary"
            size="small"
            class="btn"
            @click="changeTime(scope.row)"
          >
            修改时间
          </el-button>
          <!--          <el-button type="primary" size="small" class="btn" v-if="showBtn(scope.row,26)" @click="call(scope.row)">发起问诊</el-button>-->
          <el-button
            v-if="showBtn(scope.row, 3)"
            :type="scope.row.completed?'danger':'primary'"
            size="small"
            class="btn"
            @click="doneHandle(scope.row)"
          >
            设为已完成
          </el-button>
          <el-button
            v-if="showBtn(scope.row, 2)"
            type="primary"
            size="small"
            class="btn"
            @click="setOffice(scope.row)"
          >
            设置科室
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <div class="pagination">
      <el-pagination
        background
        :current-page="pageNo"
        :page-sizes="[15, 30, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalRows"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
  import { TABLE_COLUMN } from '@/utils/constants';
  // 0 只填写了患者信息（急速问诊才会有的状态），1 初始状态（未支付），2待问诊（待匹配运营）（支付成功待完善）3 问诊中（已完善），4、已问诊  5、取消，  6 已结算
  // 21 已匹配， 22 待分诊， 23 待匹配接诊医生， 24 待协调医生  25 待设置问诊时间， 26 待问诊
  export default {
    props: {
      menuType: {
        type: Number,
        default: 1,
      },
      tData: {
        type: Array,
        default: [],
      },
      pageNo: {
        type: Number,
        default: 1,
      },
      pageSize: {
        type: Number,
        default: 20,
      },
      totalRows: {
        type: Number,
        default: 0,
      },
      loading: {
        type: Boolean,
        default: false,
      },
      tableHeight: {
        type: Number,
        default: 500,
      },
      multipleSelection: {
        type: Array,
        default: [],
      },
    },

    data() {
      return {
        tableColumn: TABLE_COLUMN,
      };
    },
    mounted() {},
    methods: {

      sortfunc(data) {
        this.$emit('sortfunc', data);
      },
      showBtn(row, ...arr) {
        return arr.includes(row.status);
      // return true;
      },
      // 选择
      handleSelectionChange(val) {
        this.multipleSelection = val;
        this.$emit('update:multipleSelection', this.multipleSelection);
      },
      // 设为待问诊
      witeDiagnose(row) {
        this.$emit('witeDiagnose', row);
      },
      // 更换运营
      changeRun(row) {
        this.$emit('changeRun', row);
      },
      // 查看详情 \编辑
      goDetail(row, flag) {
        this.$emit('goDetail', row, flag);
      },
      // 取消/退款
      cancelRefund(row) {
        this.$emit('cancelRefund', row);
      },
      // 设为稍后跟进
      witeGo(row) {
        this.$emit('witeGo', row);
      },
      // 设为待匹配医生
      waitMatchDot(row) {
        this.$emit('waitMatchDot', row);
      },
      // 发送消息
      sendMessage(row) {
        this.$emit('sendMessage', row);
      },
      // 加入问诊
      joinDiagnose(row) {
        this.$emit('joinDiagnose', row);
      },
      // 匹配运营
      // matchRun(row) {
      //   this.$emit("matchRun", row);
      // },
      // 设为待分诊
      // waitDiagnose(row) {
      //   this.$emit("waitDiagnose", row);
      // },
      // 设为待协调医生
      waitHzeDot(row) {
        this.$emit('waitHzeDot', row);
      },
      // 设为待确认时间
      waitMatchTime(row) {
        this.$emit('waitMatchTime', row);
      },
      // 重新匹配医生
      reMatchDot(row, type) {

        this.$emit('reMatchDot', row, type);
      },
      // 修改时间
      changeTime(row) {
        this.$emit('changeTime', row);
      },
      // 发起问诊
      // call(row) {
      //   this.$emit("call", row);
      // },
      // 设为已完成
      doneHandle(row) {
        this.$emit('doneHandle', row);
      },
      goEdite(row) {
        this.$emit('goEdite', row);
      },
      handleSizeChange(value) {
        this.$emit('handleSizeChange', value);
      },
      handleCurrentChange(value) {
        this.$emit('handleCurrentChange', value);
      },
      setOffice(value) {
        this.$emit('setOffice', value);
      },
    },
  };
</script>

<style scoped>
.btn {
  margin-top: 5px;
}
</style>
