<template>
    <div>
        <!-- 批量签名 -->
        <el-dialog title="批量签名" width="65%" :visible="signatureVisable" @close="cancel"  center :distroy-on-close="true">
            <el-form ref="courtReviewform" :model="courtReviewform">
                <el-form-item
                    label="仲裁员："
                    prop="Arbitor"
                    :rules="[
                        {
                        required: true,
                        message: '仲裁员不能为空',
                        trigger: 'change',
                        },
                ]"
                >
                <el-select
                    placeholder="请选择仲裁员"
                     @change="changeArbitor"
                    v-model="courtReviewform.Arbitor"
                    clearable
                >
                    <el-option
                    v-for="item in atoDataList"
                    :key="item.value"
                    :label="item.nickName"
                    :value="item.phonenumber+item.userId"
                    ></el-option>
                </el-select>
                </el-form-item>
                </el-form>
            <el-table v-loading="loading" :data="dataList" style="width: 100%" @selection-change="handleSelectionChange">
                <el-table-column type="selection">
                </el-table-column>
                <el-table-column label="序号" type="index" align="center">
                    <template slot-scope="scope">
                        <span>{{
                            (queryParamsData.pageNum - 1) * queryParamsData.pageSize + scope.$index + 1
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="案件编号" prop="caseNum" align="center" width="150"  :show-overflow-tooltip="true" />
                <el-table-column label="申请人"  align="center" prop="applicantName" :show-overflow-tooltip="true" />
                <el-table-column label="案件标的" align="center" prop="caseSubjectAmount" />
                <el-table-column label="仲裁方式" align="center" prop="arbitratMethodName" :show-overflow-tooltip="true" />
                <!-- 仲裁员 -->
                <el-table-column label="仲裁员" align="center" prop="arbitratorName" />
                <!-- 开庭日期 -->
                <el-table-column label="开庭日期" align="center" prop="hearDate" :show-overflow-tooltip="true" />
                <el-table-column label="案件状态" align="center" prop="caseStatusName">
                    <template slot-scope="scope">
                        <el-tag type="success">
                            {{ scope.row.caseStatusName }}
                        </el-tag>
                    </template>
                </el-table-column>
            </el-table>
             <pagination  :total="total" :page.sync="queryParamsData.pageNum"
                :limit.sync="queryParamsData.pageSize"  @pagination="getBatchComfirmation(queryParamsData)"/>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancel"  class="endbutton"><span>取 消</span></el-button>
                <el-button 
                type="primary" 
                class="endbutton" 
                :disabled="dataList.length == 0 || batchData.length == 0" 
                @click="witnessing"><span>确认签名</span></el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import {selectBatchSignUrl,pageSignAdjudicate} from '@/api/caseAccess/caseEntry'
import { arbitrAtor} from "@/api/formationCourt/formationCourt";
export default {
    props:["signatureVisable"],
    data() {
        return {
             // 遮罩层
            loading: true,
            // 总条数
            total:0,
             // 查询参数
            queryParamsData: {
                caseStatus: 13,//待定
                pageNum: 1,
                pageSize: 10,
            },
            // 表格数据
            dataList: [],
            batchData: [],
            atoDataList:[],
            courtReviewform: {},
            Arbitor: "",
            paramsdata:{
                ids:[],
                psnAccount:""
            },
            
        }
    },
    watch: {
        signatureVisable(val) {
            if (val) {
                this.getBatchSignation(this.queryParamsData)
                this.getarbitrAtor()
            }
        }  
    },
    created(){
        this.getBatchSignation(this.queryParamsData)
        // this.getarbitrAtor()
    },
    methods:{
        // 列表查询
        getBatchSignation(val){
             this.loading = true;
            pageSignAdjudicate(val).then(res=>{
                this.dataList = res.rows
                this.total = res.total;
                 this.loading = false;
            })
        },
        // 选择勾选框
        handleSelectionChange(val){
             this.batchData = [];
            val.forEach(item => {
                this.batchData.push(item.signFlowId)
                this.paramsdata.ids = this.batchData
            })
        },
            // 获取仲裁员信息
    getarbitrAtor() {
    this.atoDataList =[]
      arbitrAtor({}).then((res) => {
        this.atoDataList = res.rows;
        // this.total = res.total; 
      });
    },
     changeArbitor(val) {
         this.paramsdata.psnAccount = val.slice(0,11)
   
    },
    // 确认签名
    witnessing(){
         this.$refs["courtReviewform"].validate((valid) => {
        if (valid) {
            console.log(this.paramsdata)
          selectBatchSignUrl(this.paramsdata).then((res) => { 
              this.$modal.msgSuccess("确认成功");
              this.cancel();
              this.getBatchSignation(this.queryParamsData)
              window.open(res.data.signUrl)
              
            //   this.$emit("getcaseApply", this.queryParams);
            })
            .catch((err) => {});
        }
      });
    },
     cancel() {
            this.$emit("signatureOperate");
        },       
    }
}
</script>