<style lang="scss">
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>
<template>
  <section class="content">
    <h4>短信记录列表</h4>
    
    <el-divider></el-divider>
    <el-form :inline="true">
      <el-form-item label="手机号" >
          <el-input v-model="queryParams.phone" placeholder="请输入手机号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getData" type="primary">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="list"
      style="width: 100%; margin-top: 10px"
      height="50vh"
    >
      <el-table-column align="center" prop="phone" label="手机号" />
      <el-table-column align="center" prop="code" label="验证码" />
      <el-table-column align="center" prop="result" label="发送状态">
          <template slot-scope="scope">
            <div>
                <span style="color:green;" v-if="scope.row.result && scope.row.result.indexOf('success') >-1">成功</span>
                <span v-else="失败">失败:{{scope.row.result}}</span>
             </div>
          </template>
      </el-table-column>
      <el-table-column align="center" prop="ctime" label="创建时间" />
      <el-table-column align="center" prop="date" label="操作" width="320">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row)" size="mini" type="warning"
            >重新发送</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <Page
      ref="pageButton"
      :current="form.page"
      :page_size="form.page_size"
      :total="total"
      @pageChange="gopage"
    />
    <!-- 新增医生 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="手机号" prop="name">
          <el-input
            clearable
            v-model="form.phone"
            placeholder="请输入手机号"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">取 消</el-button>
        <el-button type="primary" @click="submitForm">发 送</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import Page from "../../components/Page";
import fuEditor from "@/components/fuEditor/index.vue";
export default {
  components: {
    Page,
    fuEditor
  },
  data() {
    return {
      loading: false,
      queryParams: {
        page: 1,
      },
      form: {},
      form1: {},
      form2: {},
      list: [{}, {}],
      total: 0,
      title: "新增用户",
      open: false,
      doctorList: [],
      rules: {},
      myConfig: {
	      // 编辑器自动被内容撑高
	      autoHeightEnabled: true,
	      // 初始容器高度
	      initialFrameHeight: 500,
	      // 初始容器宽度
	      initialFrameWidth: '100%',
	      // 上传文件接口，实现上传图片功能必须的配置，这个地址会在后端配置的时候产生，此处先放上结果
	      serverUrl: '/api/admin/ueditor/upload',
	    },
    };
  },
  methods: {
    del(id) {
      this.$confirm("确认删除?", "提示", {
        type: "warning",
      }).then(() => {
        this.$api
          .delDoctorInfo({
            id: id,
          })
          .then((res) => {
            if (!res.data.code) {
              this.$msgSuccess("删除成功");
              this.getData();
            } else {
              this.$msgError(res.data.message);
            }
          });
      });
    },
    gopage(size) {
      if (size) {
        this.queryParams.page_size = size;
      }
      this.queryParams.page = this.$refs.pageButton.page;
      this.getData();
    },
    getData() {
      this.loading = true;
      this.$api.getPhoneRecordList(this.queryParams).then((res) => {
        this.list = res.data.data.list;
        this.total = res.data.data.total;
        this.loading = false;
      });
    },
    handleAdd() {
      this.open = true;
      this.title = "新增医生";
      this.form = {};
    },
    edit(row) {
      this.title = "重新发送";
      this.open = true;
      this.form = row;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
          this.$api.sendPhoneCode(this.form).then(res=>{
            if(res.data.data.indexOf("success")>-1){
              this.$message.success("成功")
              this.open = false
              this.getData()
            }
          })
      });
    },
    remoteMethod(query) {
      if (query !== "") {
        // this.loading = true;
        this.$api
          .getDoctorsSearchList({
            name: query,
          })
          .then((res) => {
            this.doctorList = res.data.data;
            this.$set(this.doctorList, res.data.data);
            // this.loading = false;
          });
      } else {
        this.doctorList = [];
      }
    },
  },
  created() {
    this.getData();
  },
};
</script>