<template>
    <basic-container>
        <avue-crud 
        :data="data" 
        :option="option" 
        @on-load="onLoad" 
        :before-open="beforeOpen"
        :page.sync="page"
        @current-change="currentChange"
        @size-change="sizeChange"
        @refresh-change="refreshChange"
        >
            <template slot="menu" slot-scope="{ row }">
                <el-button
                @click="checkClick(row)"
                type="text"
                size="small"
                >查看</el-button>
            </template>
        </avue-crud>
        <!-- 暂不处理弹窗 -->
        <el-dialog
          title="暂不处理"
          :visible.sync="refuseDialogVisible"
          width="30%"
          :modal=false
          class="refuseDialog"
          @close = "resetForm('causeForm')"
          >
          <!-- <p class="refuseDialogTitle">原因：</p> -->
          <div>
            <el-form :model="causeForm" :rules="rules" ref="causeForm">
              <el-form-item label="原因：" prop="cause">
                <el-input
                  type="textarea"
                  placeholder="请输入原因"
                  v-model="causeForm.cause">
                </el-input>
              </el-form-item>
            </el-form>
          </div>
          <span slot="footer" class="dialog-footer">
            <el-button @click="resetForm('causeForm')" size="small">取 消</el-button>
            <el-button type="primary" @click="noProcessingBtn('causeForm')" size="small">暂不处理</el-button>
          </span>
        </el-dialog>
        <!--查看保单详情dialog-->
        <check-dialog ref="check" v-show="false" @refresh = "refreshChange"></check-dialog>
    </basic-container>
</template>
<script>
import checkDialog from "../examineDialog/ExamineDialogSus";
import {getListNew,getNoProcessing} from "@/api/manage/company";
import { getStationDic , getStation } from "@/api/manage/station";
export default {
    data() {
      return {
        //status:3,//认证状态 0：审核通过；1：审核不通过； 2：已驳回 3:待完善；4.待审核；5，暂不处理；9：终止合作
        query: {
          status:9
        },
        rowData:{},
        causeForm:{},
        rules: {
          cause: [
            {required: true, message: '请输入原因', trigger: 'blur'},
          ]
        },
        noProcessingStatus:5,//	5:暂不处理;9:终止合作
        loading: true,
        page: {
          pageSize: 10,
          currentPage: 1,
          total: 0,
        },
        refuseDialogVisible: false,
        data: [],
        option:{
          title:'表格的标题',
          titleSize:'h3',
          titleStyle:{
            color:'red'
          },
          border: true,
          addBtn: false,
          editBtn:false,
          index: true,
          indexLabel: "序号",
          menuWidth:90,
          delBtn:false,
          page:false,
          align:'center',
          menuAlign:'center',
          
          column:[
             {
              label:'用工单位',
              prop:'companyName'
            },
            {
              label:'所属市场',
              prop:'stationId',
              dicUrl: getStationDic(),
              props: {
                label: "stationName",
                value: "stationId",
              },
            },
            {
              label:'保证金',
              prop:'trialOn',
              dicData:[
              {
                label:'已缴',
                value:0
              },
              {
                label:'未缴',
                value:1
              },
              {
                label:'免缴',
                value:2
              },
              {
                label: " ",
                value: -1,
              },
              ]
            },
            {
              label:'商保状态',
              prop:'insuranceOn',
              dicData:[
              {
                label:'停用',
                value:0
              },
              {
                label:'启用',
                value:1
              },
              {
                label: " ",
                value: -1,
              },
              ]
            },
            {
              label:'合同',
              prop:'isSign',
              dicData:[
              {
                label:'未签',
                value:0
              },
              {
                label:'已签',
                value:1
              }
              ]
            },
            {
              label:'电子合同',
              prop:'contractOn',
              dicData:[
              {
                label:'关闭',
                value:0
              },
              {
                label:'开启',
                value:1
              }
            ],
            },
            {
              label: "注册时间",
              prop: "createTime",
              type: "date",
              format: "yyyy-MM-dd HH:mm:ss",
              valueFormat: "yyyy-MM-dd HH:mm:ss",
              width:150
            },
            {
              label: "提交审核时间",
              prop: "createTime",
              type: "date",
              format: "yyyy-MM-dd HH:mm:ss",
              valueFormat: "yyyy-MM-dd HH:mm:ss",
              width:150
            },
            {
              label: "审核通过时间",
              prop: "reviewTime",
              type: "date",
              format: "yyyy-MM-dd HH:mm:ss",
              valueFormat: "yyyy-MM-dd HH:mm:ss",
              width:150
            },
          ]
        }
      }
    },
    components: {
      checkDialog
    },
    methods:{
        currentChange(currentPage) {
          this.page.currentPage = currentPage;
        },
        sizeChange(pageSize) {
          this.page.pageSize = pageSize;
        },
        //查看
        checkClick(row){
            this.$refs.check.openDialog(row,'stop');
        },
        /*刷新本页 带搜索参数*/
        refreshChange() {
          this.onLoad(this.page, this.query);
        },
        //暂不处理
        refuseClick(row){
            this.rowData = row
            this.refuseDialogVisible = true;
        },
        //暂不处理按钮
        noProcessingBtn(formName){
           this.$refs[formName].validate((valid) => {
             if (valid) {
                this.refuseDialogVisible = false;
                this.loading = true;
                getNoProcessing(this.rowData.id,this.causeForm.cause,this.noProcessingStatus).then((res)=>{
                  if (res.data.code==200) {
                    this.$message.success(res.data.msg);
                    this.loading=false;
                    this.onLoad(this.page, this.query);
                  }else{
                    this.$message.error(res.data.msg)
                    this.loading=false;
                  }   
                })
             }
           })  
          
        },
        //更新form表单
        resetForm(formName){
          this.$refs[formName].resetFields();
          this.refuseDialogVisible = false;
        },
        // beforeOpen(){
        //   this.onLoad(this.page, this.query);
        // },
        onLoad(page, params = {}) {
        this.loading = true;
        getListNew(
          page.currentPage,
          page.pageSize,
          Object.assign(this.query, params)
        ).then((res) => {
          const data = res.data.data;
          //console.log(getStationDic());
          getStation().then((res)=>{
            console.log(res);
          })
          this.page.total = data.total;
          this.data = data.records;
          this.loading = false;

        });
      },
    },
}
</script>
<style>
  .refuseDialog .el-dialog__body{
    padding: 0 20px;
  }
</style>