<template>
  <div class="main-contain">
    <div class="position">
      <bread-crumb :crumbs="crumbs"></bread-crumb>

       <div>

        <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toGet">CA企业认证</el-button> -->

        <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="openForm(0)">新增</el-button>
        <el-button
        type="primary"
        size="small"
        @click="BatchDelete"
        >医药师登记</el-button>


       <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toJiaBan">加班</el-button> -->


          <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toJiaoYou">加油</el-button>
       

         <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTest">短信</el-button> -->

        <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestOne">创建个人用户实名</el-button>

          <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestFive">创建企业用户并实名</el-button>




          <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestFour">添加企业成员</el-button>

          <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestTwo">创建个人印章</el-button>

           <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestThree">创建合同</el-button>  -->

         <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestSeven">添加合同签署人</el-button> -->

        <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestTen"
          >
           短信验证码
          </el-button>  -->


         <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestNight">后台签署</el-button>
           -->

          <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestElement">创建企业用章</el-button> -->


          <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestThrityMent">生成PDF</el-button>  -->


        <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestTwo">创建个人印章</el-button> -->


          <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestThree">创建合同</el-button>


          <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestSeven">添加合同签署人</el-button>


          <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestTen"
          >
           获取短信验证码
          </el-button>

          <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestNight">后台签署</el-button>

          <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toTestThrity">合同详情查询</el-button>


         <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toWatch">合同在线预览</el-button>

          <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toEnd">结束签署</el-button> -->



         <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toSendInformaton">发送短信验证码</el-button>  -->


          <!--<el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toSavePDFInformation">生成PDF</el-button>-->


        <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toCheckPDFInformation">PDF验证</el-button> -->


          <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toAutoDrug">自动生成</el-button> -->


          <!-- <el-button
          type="primary"
          size="small"
          icon="el-icon-circle-plus-outline"
          style="float:left"
          @click="toAutoDiagnose">自动脚本</el-button> -->
     </div>


    </div>
    <div class="app-container">
      <el-table
        :row-style="{ color: '#303133' }"
        :header-cell-style="{
          backgroundColor: 'rgb(245, 247, 250)',
          color: '#606266'
        }"
        style="width:100%;"
        ref="table"
        border
        :data="admins"
        v-loading="is_loading_admins"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
              align="center"
              type="selection"
              width="55">
        </el-table-column>
        <el-table-column
          label="用户名"
          prop="user_name"
          min-width="160"
          align="center"
        ></el-table-column>
        <el-table-column v-if="this.$store.getters.xt_user.org_id != 10206" label="医保医师编码" prop="doctor_number" min-width="160" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.doctor_number== 0"></span>
            <span v-if="scope.row.doctor_number!= 0">{{scope.row.doctor_number}}</span>
          </template>
        </el-table-column>

        <el-table-column  v-if="this.$store.getters.xt_user.org_id == 10206" label="员工ID" prop="doctor_number" min-width="160" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.doctor_number== 0"></span>
            <span v-if="scope.row.doctor_number!= 0">{{scope.row.doctor_number}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="最后登录IP"
          prop="ip"
          min-width="150"
          align="center"
        ></el-table-column>
        <el-table-column
          label="最后登录时间"
          prop="last_login_time"
          min-width="170"
          align="center"
        >
          <template slot-scope="scope">
            <span>{{
              scope.row.last_login_time == 0
                ? ""
                : _parseTime(scope.row.last_login_time, "{y}-{m}-{d} {h}:{i}")
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="角色"
          prop="role_name"
          min-width="160"
          align="center"
        ></el-table-column>
        <el-table-column label="状态" min-width="100" align="center">
          <template slot-scope="scope">
            <div
              v-if="scope.row.status == 1"
              style="color: #67C23A; font-size:20px;"
            >
              <li class="el-icon-success"></li>
            </div>
            <div v-else style="color: #F56C6C; font-size:20px;">
              <li class="el-icon-error"></li>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="240" align="center">
          <template slot-scope="scope">


           <!-- <span>
              <el-button type="primary" size="small" @click="toRenZhen(scope.row.user_id,scope.row.user_name)">
                    <span>CA个人认证</span>
              </el-button>
            </span> -->

           <!-- <span>
              <el-button type="primary" size="small" @click="toQianShu(scope.row.user_id,scope.row.user_name)">
                    <span>创建签署人用户</span>
              </el-button>
            </span>

            <span>
              <el-button type="primary" size="small" @click="toYinZhang(scope.row.user_id,scope.row.user_name)">
                    <span>创建个人印章</span>
              </el-button>
            </span>  -->
<!--
            <span>
              <el-button type="primary" size="small" @click="toShouQuan(scope.row.user_id,scope.row.user_name)">
                    <span>创建企业印章</span>
              </el-button>
            </span>  -->
            <el-tooltip
              class="item"
              effect="dark"
              content="编辑"
              placement="top"
            >
              <el-button
                type="primary"
                icon="el-icon-edit-outline"
                size="small"
                @click="openForm(scope.row.user_id)"
              ></el-button>
            </el-tooltip>
            <!-- </router-link> -->
            <el-tooltip
              class="item"
              effect="dark"
              content="移除"
              placement="top"
            >
              <el-button
                type="danger"
                size="small"
                icon="el-icon-delete"
                v-if="
                  scope.row.status == 1 &&
                    org.creator != scope.row.user_id &&
                    scope.row.user_id != local_user_id
                "
                @click="disableAdminAction(scope.row)"
              ></el-button>
            </el-tooltip>
            <el-tooltip
              class="item"
              effect="dark"
              content="恢复"
              placement="top"
            >
              <el-button
                size="small"
                type="info"
                icon="el-icon-refresh"
                v-if="
                  scope.row.status == 0 &&
                    org.creator != scope.row.user_id &&
                    scope.row.user_id != local_user_id
                "
                @click="recoverAdminAction(scope.row)"
              ></el-button>
            </el-tooltip>
            <span v-if="scope.row.user_type == 2">
              <el-button type="primary" size="small" icon="el-icon-refresh-left" @click="toReturn(scope.row.user_id,scope.row.is_mark)">
                    <span v-if="scope.row.is_mark ==0">登记</span>
                    <span v-if="scope.row.is_mark ==1">撤销</span>
              </el-button>
            </span>
          </template>
        </el-table-column>
      </el-table>

      <el-row style="margin-top: 15px;" v-if="admin_total_count > 10">
        <el-col :span="24">
          <el-pagination
            :total="admin_total_count"
            :current-page.sync="current_page"
            @current-change="pageChange"
            :page-size="10"
            layout="total, prev, pager, next, jumper"
          ></el-pagination>
        </el-col>
      </el-row>
      <admin-info-form ref="admininfoform"></admin-info-form>
    </div>

    <el-dialog
      title="CA企业认证"
      :visible.sync="dialogVisible"
      width="50%">
      <span>

        <el-form>
          <el-row>
            <el-col>
               <el-form-item label="企业类型:">
                <el-select
                  v-model="form.org_type"
                  filterable
                  clearable
                  allow-create
                  placeholder="选择"
                >
                  <el-option
                    v-for="item in businessList"
                    :key="item.id"
                    :label="item.name "
                    :value="item.id"
                  ></el-option>
                </el-select>
               </el-form-item>
            </el-col>

            <el-col>
               <el-form-item label="企业名称:">
                 <el-input style="width:200px" v-model="form.enterprise_name" placeholder="请按营业执照上面的公司填写名称"></el-input>
               </el-form-item>
            </el-col>

            <el-col>
               <el-form-item label="统一社会信用代码:">
                 <el-input style="width:200px" v-model="form.code" placeholder="请输入统一社会信息代码"></el-input>
               </el-form-item>
            </el-col>

            <el-col>
               <el-form-item label="组织机构代码:">
                 <el-input style="width:200px" v-model="form.org_code" placeholder="请输入统一社会信息代码"></el-input>
               </el-form-item>
            </el-col>


            <el-col>
               <el-form-item label="法定代表人:">
                 <el-input style="width:200px" v-model="form.legal_person_name" placeholder="请输入统一社会信息代码"></el-input>
               </el-form-item>
            </el-col>

            <el-col>
               <el-form-item label="法定代表人身份证:">
                 <el-input style="width:200px" v-model="form.legal_id_card_num" placeholder="请输入统一社会信息代码"></el-input>
               </el-form-item>
            </el-col>

            <el-col>
               <el-form-item label="法人手机号码:">
                 <el-input style="width:200px" v-model="form.legal_phone" placeholder="请输入法人手机号码"></el-input>
               </el-form-item>
            </el-col>
          </el-row>
        </el-form>

      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveEnterprise">立即认证</el-button>
      </span>
    </el-dialog>


    <el-dialog
      title="CA个人认证"
      :visible.sync="persionDialogVisible"
      width="50%">
      <span>

        <el-form>
          <el-row>

            <el-col>
               <el-form-item label="姓名:">
                 <el-input style="width:200px" v-model="personForm.display_name" placeholder="请输入姓名"></el-input>
               </el-form-item>
            </el-col>

            <el-col>
               <el-form-item label="身份证号:">
                 <el-input style="width:200px" v-model="personForm.id_card_num" placeholder="请输入身份证号"></el-input>
               </el-form-item>
            </el-col>

            <el-col>
               <el-form-item label="手机号:">
                 <el-input style="width:200px" v-model="personForm.phone" placeholder="请输入手机号"></el-input>
               </el-form-item>
            </el-col>


            <el-col>
               <el-form-item label="验证码:">
                 <el-input style="width:100px" v-model="form.code" placeholder="请输入验证码"></el-input>
                 <el-button type="primary" size="small" @click="getCode">获取验证码</el-button>
               </el-form-item>
            </el-col>

          </el-row>
        </el-form>

      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="persionDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="savePersonEnterprise">立即认证</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { adminMainView, getAdmins, setAdminStatus,toSign,toTestOne,toTestTwo,toTestThree,toTestFour,toTestFive,toTestSeven,toTestEight,toTestNight,toTestTen,toTestElement,toTestThrityMent,saveEnterprise,getEnterPriseById,getMobileCode,savePersionEnterPrise,getPerseEnterPriseById,CreatePersionSeal,CreateNewEnterPrise,toTestThrity,toEndEnterPrise,getEnterPriseDetail
  ,CreateQianshuUserName,CreateSKDSendInformation,toSavePDFInformation,toCheckPDFInformation,getdruginfoInformation,toAutoDrug,toAutoDiagnose,toAutoJiaYou} from "@/api/role/admin";
import { getRoles } from "@/api/role/role";
import { UploadPrintOrder } from "@/api/role/admin"
import { parseTime } from "@/utils";
import BreadCrumb from "@/xt_pages/components/bread-crumb";
import AdminInfoForm from "./components/AdminInfoForm";
import axios from 'axios'
export default {
  name: "adminManage",
  data() {
    return {
      crumbs: [
        { path: false, name: "管理中心" },
        { path: false, name: "员工管理" }
      ],
      is_loading_admins: true,
      admins: [], // [{user_id, user_name, role_name, title_name, ip, last_login_time, status}]
      admin_total_count: 0,
      current_page: 1,
      roles: [],
      is_exist_role: false,
      org: null,
      isSubSuperAdmin: false,
      local_user_id: 0,
      selectDrug:[],
      dialogVisible:false,
      persionDialogVisible:false,
      businessList:[
        {id:1,name:"企业"},
        {id:2,name:"个体工商户"},
        {id:3,name:"政府机构"}
      ],
      form:{
        id:0,
        org_type:"",
        enterprise_name:"",
        code:"",
        org_code:"",
        legal_person_name:"",
        legal_id_card_num:"",
        legal_phone:"",
      },
      personForm:{
        id:0,
        display_name:"",
        phone:"",
        id_card_num:"",
        admin_user_id:"",
        code:"",
      }
    };
  },
  components: {
    BreadCrumb,
    AdminInfoForm
  },
  created: function() {

    this.local_user_id = this.$store.getters.xt_user.user.id;
    let page = 1;
    this.getRoles(page);
    adminMainView()
      .then(rs => {
        this.is_loading_admins = false;
        var resp = rs.data;
        if (resp.state === 1) {
           var adminData = resp.data.admins
           console.log("数据",adminData)
          this.admins.push(...adminData);
          this.admin_total_count = resp.data.total_count;
          this.is_exist_role = resp.data.is_exist_role;
          this.current_page = 1;
          this.org = resp.data.org;
          this.isSubSuperAdmin = resp.data.isSubSuperAdmin;

          //能进入当前页面的角色只有超级管理员和子管理员，如果当前角色是子管理员，需要把超级管理员和其他子管理员的信息去除，子管理员不能编辑超级管理员和其他子管理员信息，
          if (this.isSubSuperAdmin) {
            //去除管理员信息
            for (let i = 0; i < this.admins.length; i++) {
              if (this.admins[i].user_id == this.org.creator) {
                this.admins.splice(i, 1);
                i--;
              }
            }

            //去除其他子管理员信息
            for (let i = 0; i < this.admins.length; i++) {
              if (
                this.admins[i].user_id != this.local_user_id &&
                this.admins[i].is_sub_super_admin
              ) {
                //将自己排除在外
                console.log(this.admins[i]);

                this.admins.splice(i, 1);
                i--;
              }
            }
          }
        } else {
          this.$message.error(resp.msg);
        }
      })
      .catch(err => {
        this.is_loading_admins = false;
        this.$message.error(err);
      });
  },
  computed: {
    should_update_admins() {
      return this.$store.getters.xt_role_temps.did_admins_changed;
    }
  },
  methods: {
    getRoles(page) {
      getRoles(page)
        .then(rs => {
          this.loading_roles = false;
          const resp = rs.data;
          if (resp.state === 1) {
            this.roles.push(...resp.data.roles);
          } else {
            this.$message.error(resp.msg);
          }
        })
        .catch(err => {
          this.loading_roles = false;
          this.$message.error(err);
        });
    },
    openForm(adminId) {
      this.$refs["admininfoform"].open(adminId, this.roles);
    },
    _parseTime(time, format) {
      return parseTime(time, format);
    },
    requestAdminsWithPage: function(page) {
      this.admins.splice(0, this.admins.length);
      this.is_loading_admins = true;
      getAdmins(page)
        .then(rs => {
          this.is_loading_admins = false;
          const resp = rs.data;
          console.log(resp);
          if (resp.state === 1) {
             var admindata = resp.data.admins

            this.admins.push(...admindata);
            this.admin_total_count = resp.data.total_count;
          } else {
            this.$message.error(resp.msg);
          }
        })
        .catch(err => {
          this.is_loading_admins = false;
          this.$message.error(err);
        });
    },
    addAdminAction: function() {
      this.$router.push({ path: "/role/admin/create" });
    },
    disableAdminAction: function(row) {
      this.$msgbox({
        title: "提示",
        message: "是否确定要移除该用户",
        showCancelButton: true,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        beforeClose: (action, instance, done) => {
          if (action === "confirm") {
            instance.confirmButtonLoading = true;
            instance.confirmButtonText = "删除中...";

            setAdminStatus(row.user_id, false)
              .then(rs => {
                done();
                instance.confirmButtonLoading = false;

                const resp = rs.data;
                if (resp.state === 1) {
                  row.status = 0;
                } else {
                  this.$message.error(resp.msg);
                }
              })
              .catch(err => {
                done();
                instance.confirmButtonLoading = false;
                this.$message.error(err);
              });
          } else {
            done();
          }
        }
      });
    },
    recoverAdminAction: function(row) {
      const loading = this.$loading({
        lock: true,
        text: "正在恢复管理员...",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });

      setAdminStatus(row.user_id, true)
        .then(rs => {
          loading.close();

          const resp = rs.data;
          if (resp.state === 1) {
            row.status = 1;
          } else {
            this.$message.error(resp.msg);
          }
        })
        .catch(err => {
          loading.close();
          this.$message.error(err);
        });
    },
    pageChange: function(nextPage) {
      this.requestAdminsWithPage(nextPage);
    },
  //  toLogin(){
  //     var that = this
  //     axios.get('http://127.0.0.1:9532/sz/api/doctor/get').then(function(response) {
  //     if (response.data.state == 0) {
  //         that.$message.error(response.data.msg)
  //         return false
  //       } else {
  //         that.$message({ message: '登记成功', type: 'success' })
  //         }
  //        }).catch(function(error) {
  //     })
  //   },

   BatchDelete() {
      if (this.selectDrug.length == 0) {
        this.$message.error("请选择要登记的信息");
        return false;
      }
      this.$confirm(
        "确认要登记所选记录吗? <br>",
        "备案提示",
        {
          dangerouslyUseHTMLString: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        var ids = [];
        var idMap = {};
        console.log("3333333",this.selectDrug)
        for (const index in this.selectDrug) {
          ids.push(this.selectDrug[index].user_id);
          idMap[this.selectDrug[index].user_id] = this.selectDrug[index].user_id;
        }

        var idss = ids.join(',')
        let params = {
          ids:idss,
          admin_user_id:this.$store.getters.xt_user.user.id
        }
        console.log("prams222",params)
        var that = this
        axios.get('http://127.0.0.1:9532/sz/api/doctor/get',{ params: params }).then(function(response) {
         if (response.data.state == 0) {
               that.$message.error(response.data.data.msg)
               return false
            } else {
              that.$message.error(response.data.data.msg)
              if(response.data.data.msg == ""){
                  that.$message.success("登记成功!")
                  that.adminMainView()
               }
               if(response.data.data.msg!=""){
                  that.$message.error(response.data.data.msg)
                  that.adminMainView()
               }
             }
           }).catch(function(error) {
        })
       });
     },
     toReturn(id,is_mark){
       var that = this
         let params = {
           'id':id,
           "is_mark":is_mark,
           "admin_user_id":this.$store.getters.xt_user.user.id
        }

         axios.get('http://127.0.0.1:9532/sz/api/medical/get',{params:params}).then(function(response) {
          if (response.data.state == 0) {
               that.$message.error(response.data.data.msg)
               return false
            } else {

              if(response.data.data.msg == ""){
                  that.$message.success("登记成功!")
                  that.adminMainView()
               }
               if(response.data.data.msg!=""){
                  that.$message.error(response.data.data.msg)
                  that.adminMainView()
               }
             }
           }).catch(function(error) {
        })
     },

   handleSelectionChange(val) {
      this.selectDrug = val;
    },
    toTest(){
      toSign().then(response=>{
        if(response.data.state ==1){
          var sign = response.data.data.sign
          console.log("sign",sign)
        }
      })
    },
    toTestOne(){
      toTestOne().then(response=>{
        if(response.data.state==1){
          var sign = response.data.data.sign
          console.log("sign",sign)
        }
      })
    },
    toTestTwo(){
      toTestTwo().then(response=>{
        if(response.data.state ==1){
          var sign = response.data.data.sign
          console.log("sign",sign)
        }
      })
    },
    toTestThree(){
      toTestThree().then(response=>{
        if(response.data.state ==1){
          var sign = response.data.data.sign
          console.log("sign",sign)
        }
      })
    },
    toTestFour(){
      toTestFour().then(response=>{
        if(response.data.state==1){
          var sign =  response.data.data.sign
          console.log("sign",sign)
        }
      })
    },
    toTestFive(){
      toTestFive().then(response=>{
        if(response.data.state==1){
          var sign =  response.data.data.sign
          console.log("sign",sign)
        }
      })
    },
    toTestSeven(){
      toTestSeven().then(response=>{
        if(response.data.state ==1){
          var sign =  response.data.data.sign
          console.log("sign",sign)
        }
      })
    },
    toTestEight(){
      toTestEight().then(response=>{
        if(response.data.state== 1){
          var sign =  response.data.data.sign
          console.log("sign",sign)
           this.$message.success("保存")
        }
      })
    },
    toTestNight(){
      toTestNight().then(response=>{
        if(response.data.state == 1){
          var sign =  response.data.data.sign
          console.log("sign",sign)
          this.$message.success("保存")
          var maprequest = response.data.data.maprequest
          console.log("maprequest",maprequest)
        }
      })
    },
    toTestTen(){
      toTestTen().then(response=>{
        if(response.data.state == 1){
          var sign =  response.data.data.sign
          console.log("sign",sign)
          this.$message.success("保存")
        }
      })
    },
    toTestElement(){
      toTestElement().then(response=>{
         if(response.data.state == 1){
          var sign =  response.data.data.sign
          console.log("sign",sign)
          this.$message.success("保存")
         }
      })
    },
    toTestThrityMent(){
      toTestThrityMent().then(response=>{
        var sign =  response.data.data.sign
        console.log("sign",sign)
        this.$message.success("保存")
      })
    },

    saveEnterprise(){

        var params = {
          id:this.form.id,
          org_type:parseInt(this.form.org_type),
          enterprise_name:this.form.enterprise_name,
          code:this.form.code,
          org_code:this.form.org_code,
          legal_person_name:this.form.legal_person_name,
          legal_id_card_num:this.form.legal_id_card_num,
          legal_phone:this.form.legal_phone,
        }
       console.log("paramswowo",params)
      saveEnterprise(params).then(response=>{
        if(response.data.state==1){
          var enterPrise =  response.data.data.enterPrise
          this.dialogVisible = false
          this.$message.success("保存成功!")
        }
      })
    },
    toGet(){
      getEnterPriseById().then(response=>{
        if(response.data.state == 1){
          this.dialogVisible = true
          var enterPrise =  response.data.data.enterPrise
          this.form.id = enterPrise.id
          this.form.org_type = enterPrise.org_type?enterPrise.org_type:""
          this.form.enterprise_name = enterPrise.enterprise_name
          this.form.code = enterPrise.code
          this.form.org_code = enterPrise.org_code
          this.form.legal_person_name = enterPrise.legal_person_name
          this.form.legal_id_card_num  = enterPrise.legal_id_card_num
          this.form.legal_phone = enterPrise.legal_phone
        }
      })
    },
    toRenZhen(admin_user_id,user_name){

      getPerseEnterPriseById(admin_user_id).then(response=>{
        if(response.data.state== 1){
          var lastPerson =  response.data.data.lastPerson
          this.personForm.id = lastPerson.id
          this.personForm.display_name = user_name
          this.personForm.phone = lastPerson.phone
          this.personForm.id_card_num = lastPerson.id_card_num
          this.personForm.admin_user_id =lastPerson.admin_user_id
          this.persionDialogVisible = true
        }
      })


    },
    getCode(){
        var params = {
          phone:this.personForm.phone,
        }
       console.log("paramsowowo",params)
      getMobileCode(params).then(response=>{
        if(response.data.state == 1){
          var sign = response.data.data.sign
          console.log("sign",sign)
          this.$message.success("发送成功!")
        }
      })
    },
    savePersonEnterprise(){
        var params = {
          id:this.personForm.id,
          display_name:this.personForm.display_name,
          phone:this.personForm.phone,
          id_card_num:this.personForm.id_card_num,
          admin_user_id:this.personForm.admin_user_id,
          code:this.personForm.code,
        }
       console.log("param2o2o2o2",params)
      savePersionEnterPrise(params).then(response=>{
        if(response.data.state == 1){
          var personEnterPrse = response.data.data.personEnterPrse
          this.$message.success("认证成功")
          this.persionDialogVisible = false
        }
      })
    },
    toYinZhang(admin_user_id){
      CreatePersionSeal(admin_user_id).then(response=>{
        if(response.data.state == 1){
          var personSeal =  response.data.data.personSeal
          this.$message.success("创建成功")
        }
      })
    },
    toShouQuan(admin_user_id){
      CreateNewEnterPrise(admin_user_id).then(response=>{
         if(response.data.state == 1){
           var newEnterPrise =  response.data.data.newEnterPrise
           this.$message.success("保存成功!")
         }
      })
    },
    toTestThrity(){
      toTestThrity().then(response=>{
         if(response.data.state == 1){
            var sign =  response.data.data.sign
            console.log("signwoowow",sign)
         }
      })
    },
    toEnd(){
      toEndEnterPrise().then(response=>{
        if(response.data.state == 1){
          var sign = response.data.data.sign

          this.$message.success("保存成功")
        }
      })
    },
    toWatch(){
      getEnterPriseDetail().then(response=>{
        if(response.data.state == 1){
          var sign = response.data.data.sign

          this.$message.success("保存成功")
        }
      })
    },

    toQianShu(admin_user_id){

      CreateQianshuUserName(admin_user_id).then(response=>{
         if(response.data.state==1){
          var sign =  response.data.data.sign
          var userId =  response.data.data.userId
          this.$message.success("签署成功!")
         }
      })
    },

    toSendInformaton(){
      CreateSKDSendInformation().then(response=>{
        if(response.data.state==1){
          var information =  response.data.data.information

          var orderId = response.data.data.orderId
        }
      })
    },
    toSavePDFInformation(){
      toSavePDFInformation().then(response=>{
         if(response.data.state == 1){
          var information =  response.data.data.information

           var orderId = response.data.data.orderId

          //  var base64Img = 'data:image/png;base64'+","+orderId
          //  console.log("base64Img",base64Img)
          //  var imgFile = this.base64ImgtoFile(base64Img)
          //  this.downloadBlob(imgFile, 'test.png')
          //  console.log("imgFilewoowow",imgFile)

           const blob = this.base64ToBlob(orderId, 'application/pdf');
           this.openPdf(blob);

         }
      })
    },
    openPdf(blob) {
      const objectUrl = URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = objectUrl;
      a.target = '_blank';
      a.click();
      URL.revokeObjectURL(objectUrl);
    },
     base64ToBlob(base64Data, contentType) {
      contentType = contentType || '';
      const sliceSize = 1024;
      const byteCharacters = window.atob(base64Data);
      const bytesLength = byteCharacters.length;
      const slicesCount = Math.ceil(bytesLength / sliceSize);
      const byteArrays = new Array(slicesCount);

      for (let sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
        const begin = sliceIndex * sliceSize;
        const end = Math.min(begin + sliceSize, bytesLength);

        const bytes = new Array(end - begin);
        for (let offset = begin, i = 0; offset < end; ++i, ++offset) {
          bytes[i] = byteCharacters[offset].charCodeAt(0);
        }
        byteArrays[sliceIndex] = new Uint8Array(bytes);
      }

      return new Blob(byteArrays, {
        type: contentType
      });
    },
    downloadBlob(blob, filename) {
      const url = URL.createObjectURL(blob);
      const a = document.createElement('a');
      a.href = url;
      a.download = filename;
      a.click();
      URL.revokeObjectURL(url);
    },
    toCheckPDFInformation(){
      toCheckPDFInformation().then(response=>{
        if(response.data.data == 1){
          var information =  response.data.data.information
        }
      })
    },

    base64ImgtoFile(dataurl, filename = 'file') {
      let arr = dataurl.split(',')
      let mime = arr[0].match(/:(.*?);/)[1]
      let suffix = mime.split('/')[1]
      let bstr = atob(arr[1])
      let n = bstr.length
      let u8arr = new Uint8Array(n)
      while (n--) {
        u8arr[n] = bstr.charCodeAt(n)
      }
      return new File([u8arr], `${filename}.${suffix}`, {
        type: mime
      })
    },
    // toDrugInfo(){
    //   getdruginfoInformation().then(response=>{
    //      if(response.data.state==1){

    //      }
    //   })
    // }
    toJiaBan(){
      UploadPrintOrder().then(response=>{
        if(response.data.state ==1){

        }
      })
    },
    toAutoDrug(){
      toAutoDrug().then(Response=>{

      })
    },
    toAutoDiagnose(){
      toAutoDiagnose().then(response=>{
        
      })
    },
    toJiaoYou(){
      toAutoJiaYou().then(response=>{

      })
    }

  },
  watch: {
    should_update_admins(should_change) {
      if (should_change) {
        this.requestAdminsWithPage(this.current_page);
      }
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.el-button + .el-button {
  margin-left: 0 !important;
}
</style>
<style>
.el-table td,
.el-table th.is-leaf,
.el-table--border,
.el-table--group {
  border-color: #d0d3da;
}
.el-table--border::after,
.el-table--group::after,
.el-table::before {
  background-color: #d0d3da;
}
</style>
