<template>
<!-- 批量用印 -->
    <div>
        <el-dialog title="批量用印" width="60%" :visible="printingVisable" @close="cancel" center :distroy-on-close="true">
            <!-- 查询机构信息 -->
            <el-form ref="courtReviewform" :model="courtReviewform">
                <el-form-item
                    label="查询机构:"
                    prop="Arbitor"
                    :rules="[
                        {
                        required: true,
                        message: '查询机构不能为空',
                        trigger: 'blur',
                        },
                ]"
                >
                <el-select
                    placeholder="请选择查询机构"
                    @change="changeArbitor"
                    v-model="courtReviewform.Arbitor"
                    clearable
                >
                    <el-option
                     v-for="item in atoDataList"
                    :key="item.id"
                    :label="item.identifyName"
                    :value="item.operPhone"
                    ></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"  :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"  />
            <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="confirmSeals" :loading="loadingSubmit"><span>确认用印</span></el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import {selectBatchSealUrl,pageSignAdjudicate} from '@/api/caseAccess/caseEntry'
import {deptIdentifyList} from '@/api/officialSeal/officialSeal'
export default {
    props:["printingVisable"],
    data() {
        return {
             // 遮罩层
            loading: true,
            loadingSubmit: false,
            // 总条数
            total:0,
             // 查询参数
            queryParamsData: {
                caseStatus: 14, 
                pageNum: 1,
                pageSize: 10,
            },
           // 表格数据
            dataList: [],
            batchData: [],
            atoDataList:[],
            courtReviewform: {},
            Arbitor: "",
            paramsdata:{
                ids:[],
                psnAccount:""
            },
        }
    },
    watch: {
        printingVisable(val) {
            if (val) {
                this.getBatchPrinting(this.queryParamsData)
                this.getarbitrAtor()
            }
        }  
    },
    created(){
        this.getBatchPrinting(this.queryParamsData)
        // this.getarbitrAtor()
    },
    methods:{
        // 列表查询
         getBatchPrinting(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 =[]
                deptIdentifyList({}).then((res) => {
                    console.log(res)
                    this.atoDataList = res.rows;
                    // this.total = res.total; 
                });
        },
        // 下拉获取电话号码
        changeArbitor(val){
            this.paramsdata.psnAccount = val
        },
        // 确认用印
        confirmSeals(){
         this.$refs["courtReviewform"].validate((valid) => {
            if (valid) {
                this.loadingSubmit = true;
          selectBatchSealUrl(this.paramsdata).then((res) => { 
              this.$modal.msgSuccess("确认成功");
              this.cancel();
              this.getBatchPrinting(this.queryParamsData)
              window.open(res.data.signUrl)
              this.loadingSubmit = false;
              
            //   this.$emit("getcaseApply", this.queryParams);
            })
            .catch((err) => {
                this.loadingSubmit = false;
            });
        }
      });
    },
        cancel() {
         this.$emit("printingOperate");
        },
    }
}
</script>