<template>
  <zj-tab-page ref="tabPage" :defaultActives="[{ key: 'list', label: $route.meta.title + '-列表', essential: true }]">
    <template slot-scope="{ activeKey, data }">
      <div
        :style="{
          width: '100%',
          height: activeKey == 'list' ? '100%' : '0px',
          overflow: 'hidden'
        }"
      >
        <template-page
          ref="pageRef"
          :get-list="getList"
          :table-attributes="tableAttributes"
          :table-events="tableEvents"
          :operationColumnWidth="260"
          :options-evens-group="optionsEvensGroup"
          :moreParameters="moreParameters"
          :column-parsing="columnParsing"
          :operation="operation()"
          :exportList="exportList"
        >
          <div slot="moreSearch">
            <el-radio-group v-model="examineStatus" size="mini" @change="changeType">
              <el-radio-button label="">全部</el-radio-button>
              <el-radio-button label="WAIT">入住申请待审核</el-radio-button>
              <el-radio-button label="WAIT_WORKER">待师傅购买</el-radio-button>
              <el-radio-button label="POLICY_WAIT">保险待审核</el-radio-button>
              <el-radio-button label="OK">状态正常</el-radio-button>
              <el-radio-button label="FAIL">已驳回</el-radio-button>
              <el-radio-button label="EXPIRED">证件快过期</el-radio-button>
              <el-radio-button label="OVERDUE">证件已过期</el-radio-button>
              <el-radio-button label="STOP">已暂停</el-radio-button>
              <el-radio-button label="QUIT">已经离职</el-radio-button>
            </el-radio-group>
            <br /><br />
          </div>
        </template-page>
      </div>
      <div
        v-if="~['detail', 'edit', 'entryAudit', 'insuranceAudit'].indexOf(activeKey)"
        style="box-sizing: border-box; padding: 16px"
      >
        <zj-form-container ref="formRef" :form-data="formData" :styleSwitch="false">
          <zj-form-module
            title="详情"
            label-width="100px"
            :showPackUp="false"
            :form-data="formData.user"
            :form-items="formItems"
          >
          </zj-form-module>
          <zj-form-module
            title="证件信息"
            label-width="100px"
            :showPackUp="false"
            :form-data="formData"
            :form-items="formItems2"
          >
          </zj-form-module>
          <zj-form-module
            title="保险信息"
            label-width="100px"
            :showPackUp="false"
            :form-data="formData"
            :form-items="formItems3"
          >
          </zj-form-module>
        </zj-form-container>
        <div slot="footer" class="dialog-footer">
          <el-button
            v-if="[2, 3].includes(openType)"
            size="mini"
            type="primary"
            @click="
              () => {
                if ([2].includes(openType)) {
                  formData.examineStatus = 'OK'
                } else if ([3].includes(openType)) {
                  formData.policyExamineStatus = 'OK'
                }
                shenheBool = true
              }
            "
            >审核通过</el-button
          >
          <el-button
            v-if="[2, 3].includes(openType)"
            size="mini"
            type="danger"
            @click="
              () => {
                if ([2].includes(openType)) {
                  formData.examineStatus = 'FAIL'
                } else if ([3].includes(openType)) {
                  formData.policyExamineStatus = 'FAIL'
                }
                shenheBool = true
              }
            "
            >审核驳回</el-button
          >
          <el-button v-if="activeKey == 'edit'" size="mini" type="primary" @click="submit">保存</el-button>
          <el-button size="mini" @click="data.removeTab()">取 消</el-button>
        </div>
      </div>
    </template>
    <el-dialog title="审核" width="700px" :modal="false" :visible.sync="shenheBool" :before-close="shenheClose">
      <el-form ref="form" :model="formData" label-width="120px" size="mini">
        <el-form-item label="入驻网点">
          <span>{{ `(${formData.websitId})${formData.websitName}` }}</span>
        </el-form-item>
        <el-form-item label="师傅名称">
          <span>{{ formData.user && formData.user.nickName }}</span>
        </el-form-item>
        <el-form-item label="联系电话">
          <span>{{ formData.user && formData.user.mobile }}</span>
        </el-form-item>
        <el-form-item label="师傅编号">
          <span>{{ formData.user && formData.user.workerNumber }}</span>
        </el-form-item>
        <el-form-item label="审核备注" v-if="[2].includes(openType)">
          <el-input type="textarea" v-model="formData.examineRemark"></el-input>
        </el-form-item>
        <el-form-item label="审核备注" v-if="[3].includes(openType)">
          <el-input type="textarea" v-model="formData.policyExamineRemark"></el-input>
        </el-form-item>
        <el-form-item>
          <div style="text-align: right">
            <el-button @click="shenheClose">取消</el-button>
            <el-button type="primary" v-if="[2].includes(openType)" @click="examineWait">确定</el-button>
            <el-button type="primary" v-if="[3].includes(openType)" @click="workerManagerExamine">确定</el-button>
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>
  </zj-tab-page>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import import_mixin from '@/components/template/import_mixin.js'
import { required, mobileRequired, mobile } from '@/components/template/rules_verify.js'
import {
  memberListPageV2,
  memberPageExport,
  workerManagerDetail,
  workerManagerActivation,
  workerManagerAgainQuit,
  workerManagerQuit,
  workerManagerStop,
  workerManagerUpdate,
  workerManagerExamineWait,
  workerManagerExamine
} from '@/api/masterManagement'
import operation_mixin from '@/components/template/operation_mixin.js'
import ImageUpload from '@/components/file-upload'
import editTable from '@/components/template/editTable.js'
export default {
  components: { TemplatePage, ImageUpload },
  mixins: [import_mixin, operation_mixin, editTable],
  data() {
    return {
      // 事件组合
      optionsEvensGroup: [],
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: false,
        'row-class-name': this.tableRowClassName
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange
      },
      // 勾选选中行
      recordSelected: [],
      /** 表单变量 */
      formData: {
        bankAccount: '',
        companyWechatId: '',
        companyWechatName: '',
        createTime: '',
        examineBy: '',
        examineRemark: '',
        examineStatus: '',
        examineTime: '',
        slaveWorkerId: '',
        userId: '',
        websitId: '',
        websitName: '',
        policyExamineRemark: '',
        workerNumber: '',
        workerImgs: [],
        user: {},
        workerImgsCp: [{ type: '', number: '', startTime: '', endTime: '', reexamineTime: '', filesList: [] }],
        workerPolicies: []
      },
      examineStatus: '',
      openType: 0,
      shenheBool: false
    }
  },
  computed: {
    // 更多参数
    moreParameters() {
      return []
    },
    formItems() {
      return [
        {
          md: 6,
          isShow: true,
          name: 'el-select',
          options: [
            { label: '入住申请待审核', value: 'WAIT' },
            { label: '待师傅购买', value: 'WAIT_WORKER' },
            { label: '保险待审核', value: 'POLICY_WAIT' },
            { label: '状态正常', value: 'OK' },
            { label: '已驳回', value: 'FAIL' },
            { label: '证件快过期', value: 'EXPIRED' },
            { label: '证件已过期', value: 'OVERDUE' },
            { label: '已暂停', value: 'STOP' },
            { label: '已经离职', value: 'QUIT' }
          ],
          attributes: { placeholder: '请输入', disabled: true },
          formItemAttributes: {
            label: '状态',
            prop: 'examineStatus_t',
            rules: []
          }
        },
        {
          md: 6,
          isShow: true,
          name: 'el-select',
          options: [
            { label: '普通用户', value: 'GENERAL' },
            { label: '分销员', value: 'SERVICE' },
            { label: '师傅', value: 'WORKER' }
          ],
          attributes: { placeholder: '请输入', disabled: true },
          formItemAttributes: {
            label: '用户类型',
            prop: 'type',
            rules: []
          }
        },
        {
          md: 6,
          isShow: true,
          name: 'el-input',
          attributes: { placeholder: '请输入' },
          formItemAttributes: {
            label: '师傅名称',
            prop: 'nickName',
            rules: []
          }
        },
        {
          md: 6,
          isShow: true,
          name: 'el-input',
          attributes: { placeholder: '请输入' },
          formItemAttributes: {
            label: '联系电话',
            prop: 'mobile',
            rules: []
          }
        },
        {
          md: 12,
          isShow: true,
          name: 'el-input',
          attributes: { placeholder: '请输入', disabled: true },
          formItemAttributes: {
            label: '入驻网点',
            prop: 'websitName',
            rules: []
          }
        },
        {
          md: 6,
          isShow: true,
          name: 'el-input',
          attributes: { placeholder: '请输入', disabled: true },
          formItemAttributes: {
            label: '师傅编号',
            prop: 'workerNumber',
            rules: []
          }
        },
        {
          md: 6,
          isShow: true,
          name: 'el-input',
          attributes: { placeholder: '请输入' },
          formItemAttributes: {
            label: '银行卡',
            prop: 'bankAccount',
            rules: []
          }
        },
        {
          md: 24,
          isShow: true,
          name: 'el-input',
          attributes: {
            placeholder: '请输入',
            type: 'textarea'
          },
          formItemAttributes: {
            label: '备注',
            prop: 'examineRemark',
            rules: []
          }
        }
      ]
    },
    formItems2() {
      return [
        {
          name: 'slot-component',
          md: 24,
          formItemAttributes: {
            'label-width': '0px',
            label: '',
            prop: 'items',
            rules: []
          },
          render: (h, { props }) => {
            return (
              <zj-table
                columns={[
                  {
                    columnAttributes: {
                      label: '证件名称',
                      prop: 'type'
                    },
                    render: (h, { row, column, index }) => {
                      return (
                        <div class="redbordererr">
                          <el-form-item
                            label=""
                            label-width="0px"
                            prop={`workerImgsCp.${index}.${column.columnAttributes.prop}`}
                          >
                            <el-select
                              value={row[column.columnAttributes.prop]}
                              onInput={val => {
                                row[column.columnAttributes.prop] = val
                              }}
                              placeholder="请选择"
                              disabled={true}
                            >
                              {[
                                { value: 'HIGHT', label: '高空证' },
                                { value: 'ID', label: '身份证' }
                              ].map((item, index_) => (
                                <el-option key={index_} label={item.label} value={item.value}></el-option>
                              ))}
                            </el-select>
                          </el-form-item>
                        </div>
                      )
                    }
                  },
                  {
                    columnAttributes: {
                      label: '证件号码',
                      prop: 'number'
                    },
                    render: (h, { row, column, index }) => {
                      return (
                        <div class="redbordererr">
                          <el-input
                            value={row[column.columnAttributes.prop]}
                            onInput={val => {
                              row[column.columnAttributes.prop] = val
                            }}
                            placeholder="请输入内容"
                          ></el-input>
                        </div>
                      )
                    }
                  },
                  {
                    columnAttributes: {
                      label: '有效期开始日期',
                      prop: 'startTime'
                    },
                    render: (h, { row, column, index }) => {
                      return (
                        <div class="redbordererr">
                          <el-form-item
                            label=""
                            label-width="0px"
                            prop={`workerImgsCp.${index}.${column.columnAttributes.prop}`}
                          >
                            <el-date-picker
                              value={row[column.columnAttributes.prop]}
                              onInput={val => {
                                row[column.columnAttributes.prop] = val
                              }}
                              type="date"
                              placeholder="选择日期"
                            ></el-date-picker>
                          </el-form-item>
                        </div>
                      )
                    }
                  },
                  {
                    columnAttributes: {
                      label: '有效期结束日期',
                      prop: 'endTime'
                    },
                    render: (h, { row, column, index }) => {
                      return (
                        <div class="redbordererr">
                          <el-form-item
                            label=""
                            label-width="0px"
                            prop={`workerImgsCp.${index}.${column.columnAttributes.prop}`}
                          >
                            <el-date-picker
                              value={row[column.columnAttributes.prop]}
                              onInput={val => {
                                row[column.columnAttributes.prop] = val
                              }}
                              type="date"
                              placeholder="选择日期"
                            ></el-date-picker>
                          </el-form-item>
                        </div>
                      )
                    }
                  },
                  {
                    columnAttributes: {
                      label: '复审日期',
                      prop: 'reexamineTime'
                    },
                    render: (h, { row, column, index }) => {
                      if (index) {
                        return (
                          <div class="redbordererr">
                            <el-form-item
                              label=""
                              label-width="0px"
                              prop={`workerImgsCp.${index}.${column.columnAttributes.prop}`}
                            >
                              <el-date-picker
                                value={row[column.columnAttributes.prop]}
                                onInput={val => {
                                  row[column.columnAttributes.prop] = val
                                }}
                                type="date"
                                placeholder="选择日期"
                              ></el-date-picker>
                            </el-form-item>
                          </div>
                        )
                      } else {
                        return null
                      }
                    }
                  },
                  {
                    columnAttributes: {
                      label: '正面',
                      prop: 'positive',
                      width: 130
                    },
                    render: (h, { row, column, index }) => {
                      return (
                        <div class="redbordererr">
                          <ImageUpload fileList={row[column.columnAttributes.prop]} limit={1} isEdit={true} />
                        </div>
                      )
                    }
                  },
                  {
                    columnAttributes: {
                      label: '反面',
                      prop: 'negative',
                      width: 130
                    },
                    render: (h, { row, column, index }) => {
                      return (
                        <div class="redbordererr">
                          <ImageUpload fileList={row[column.columnAttributes.prop]} limit={1} isEdit={true} />
                        </div>
                      )
                    }
                  }
                ]}
                table-data={this.formData.workerImgsCp || []}
              />
            )
          }
        }
      ]
    },
    formItems3() {
      return [
        {
          name: 'slot-component',
          md: 24,
          formItemAttributes: {
            label: '',
            'label-width': '0px',
            prop: 'workerPolicies',
            rules: []
          },
          render: (h, { props, onInput }) => {
            var { value } = props
            return this.convertTableJson(
              value,
              [
                {
                  columnAttributes: {
                    label: '保险公司名字',
                    prop: 'company',
                    'min-width': '200px'
                  },
                  render: (h, { row, column, index }) => {
                    return (
                      <div class="redbordererr">
                        <el-form-item
                          label=""
                          label-width="0px"
                          prop={`workerPolicies.${index}.${column.columnAttributes.prop}`}
                          rules={[{ required: true, message: '请填写', trigger: 'blur' }]}
                        >
                          <el-input
                            value={row[column.columnAttributes.prop]}
                            onInput={val => {
                              row[column.columnAttributes.prop] = val
                            }}
                            placeholder="请输入内容"
                            disabled={row.type == 'IN'}
                          ></el-input>
                        </el-form-item>
                      </div>
                    )
                  }
                },
                {
                  columnAttributes: {
                    label: '购买类型',
                    prop: 'type',
                    'min-width': '200px'
                  },
                  render: (h, { row, column, index }) => {
                    return (
                      <div class="redbordererr">
                        <el-form-item
                          label=""
                          label-width="0px"
                          prop={`workerPolicies.${index}.${column.columnAttributes.prop}`}
                          rules={[{ required: true, message: '请填写', trigger: 'blur' }]}
                        >
                          <el-select
                            value={row[column.columnAttributes.prop]}
                            onInput={val => {
                              row[column.columnAttributes.prop] = val
                            }}
                            placeholder="请输入内容"
                            disabled={true}
                          >
                            {[
                              { label: '线下购买', value: 'LINE' },
                              { label: '在线购买', value: 'IN' }
                            ].map((item, index_) => (
                              <el-option key={index_} label={item.label} value={item.value}></el-option>
                            ))}
                          </el-select>
                        </el-form-item>
                      </div>
                    )
                  }
                },
                {
                  columnAttributes: {
                    label: '保险单名称',
                    prop: 'policyName',
                    'min-width': '200px'
                  },
                  render: (h, { row, column, index }) => {
                    return (
                      <div class="redbordererr">
                        <el-form-item
                          label=""
                          label-width="0px"
                          prop={`workerPolicies.${index}.${column.columnAttributes.prop}`}
                          rules={[{ required: true, message: '请填写', trigger: 'blur' }]}
                        >
                          <el-input
                            value={row[column.columnAttributes.prop]}
                            onInput={val => {
                              row[column.columnAttributes.prop] = val
                            }}
                            placeholder="请输入内容"
                            disabled={row.type == 'IN'}
                          ></el-input>
                        </el-form-item>
                      </div>
                    )
                  }
                },
                {
                  columnAttributes: {
                    label: '保单类型',
                    prop: 'policyType',
                    'min-width': '200px'
                  },
                  render: (h, { row, column, index }) => {
                    return (
                      <div class="redbordererr">
                        <el-form-item
                          label=""
                          label-width="0px"
                          prop={`workerPolicies.${index}.${column.columnAttributes.prop}`}
                          rules={[{ required: true, message: '请填写', trigger: 'blur' }]}
                        >
                          <el-select
                            disabled={row.type == 'IN'}
                            value={row[column.columnAttributes.prop]}
                            onInput={val => {
                              row[column.columnAttributes.prop] = val
                            }}
                            placeholder="请输入内容"
                          >
                            {[
                              { label: '意外险', value: 'AC' },
                              { label: '雇主险', value: 'EM' },
                              { label: '工伤险', value: 'IN' }
                            ].map((item, index_) => (
                              <el-option key={index_} label={item.label} value={item.value}></el-option>
                            ))}
                          </el-select>
                        </el-form-item>
                      </div>
                    )
                  }
                },
                {
                  columnAttributes: {
                    label: '保单状态',
                    prop: 'status',
                    'min-width': '200px'
                  },
                  render: (h, { row, column, index }) => {
                    return (
                      <div class="redbordererr">
                        <el-form-item
                          label=""
                          label-width="0px"
                          prop={`workerPolicies.${index}.${column.columnAttributes.prop}`}
                          rules={[{ required: true, message: '请填写', trigger: 'blur' }]}
                        >
                          <el-select
                            disabled={true}
                            value={row[column.columnAttributes.prop]}
                            onInput={val => {
                              row[column.columnAttributes.prop] = val
                            }}
                            placeholder="请输入内容"
                          >
                            {[
                              { label: '保障中', value: 'ON' },
                              { label: '失效', value: 'OFF' },
                              { label: '待生效', value: 'WAIT_ON' }
                            ].map((item, index_) => (
                              <el-option key={index_} label={item.label} value={item.value}></el-option>
                            ))}
                          </el-select>
                        </el-form-item>
                      </div>
                    )
                  }
                },
                {
                  columnAttributes: {
                    label: '保险单号',
                    prop: 'policyOrder',
                    'min-width': '200px'
                  },
                  render: (h, { row, column, index }) => {
                    return (
                      <div class="redbordererr">
                        <el-form-item
                          label=""
                          label-width="0px"
                          prop={`workerPolicies.${index}.${column.columnAttributes.prop}`}
                          rules={[{ required: true, message: '请填写', trigger: 'blur' }]}
                        >
                          <el-input
                            disabled={row.type == 'IN'}
                            value={row[column.columnAttributes.prop]}
                            onInput={val => {
                              row[column.columnAttributes.prop] = val
                            }}
                            placeholder="请输入内容"
                          ></el-input>
                        </el-form-item>
                      </div>
                    )
                  }
                },
                {
                  columnAttributes: {
                    label: '有效期开始日期',
                    prop: 'startTime',
                    'min-width': '200px'
                  },
                  render: (h, { row, column, index }) => {
                    return (
                      <div class="redbordererr">
                        <el-form-item
                          label=""
                          label-width="0px"
                          prop={`workerPolicies.${index}.${column.columnAttributes.prop}`}
                          rules={[{ required: true, message: '请填写', trigger: 'blur' }]}
                        >
                          <el-date-picker
                            value={row[column.columnAttributes.prop]}
                            onInput={val => {
                              row[column.columnAttributes.prop] = val
                            }}
                            type="date"
                            placeholder="选择日期"
                          ></el-date-picker>
                        </el-form-item>
                      </div>
                    )
                  }
                },
                {
                  columnAttributes: {
                    label: '有效期结束日期',
                    prop: 'endTime',
                    'min-width': '200px'
                  },
                  render: (h, { row, column, index }) => {
                    return (
                      <div class="redbordererr">
                        <el-form-item
                          label=""
                          label-width="0px"
                          prop={`workerPolicies.${index}.${column.columnAttributes.prop}`}
                          rules={[{ required: true, message: '请填写', trigger: 'blur' }]}
                        >
                          <el-date-picker
                            value={row[column.columnAttributes.prop]}
                            onInput={val => {
                              row[column.columnAttributes.prop] = val
                            }}
                            type="date"
                            placeholder="选择日期"
                          ></el-date-picker>
                        </el-form-item>
                      </div>
                    )
                  }
                },
                {
                  columnAttributes: {
                    label: '附件',
                    prop: 'policyUrls',
                    'min-width': '440px'
                  },
                  render: (h, { row, column, index }) => {
                    return (
                      <div class="redbordererr">
                        <ImageUpload fileList={row[column.columnAttributes.prop]} limit={100} isEdit={true} />
                      </div>
                    )
                  }
                }
              ],
              {
                isEdit: true,
                isAdd: this.openType !== 0,
                isDel: true,
                isUpdate: false,
                isConfirm: false
              },
              {
                add: () => {
                  this.formData.workerPolicies.push({
                    company: '',
                    endTime: '',
                    exTime: '',
                    policyId: '',
                    policyName: '',
                    policyOrder: '',
                    policyPrice: '',
                    policyType: '',
                    startTime: '',
                    status: '',
                    type: 'LINE',
                    websitId: '',
                    websitName: '',
                    websitUserId: '',
                    workerId: '',
                    workerName: ''
                  })
                  this.isEditTableIndex = this.formData.workerPolicies.length - 1
                },
                delete: ({ row, column, index }, cb) => {
                  if (this.isEditTableIndex == index) {
                    this.isEditTableIndex = -1
                  } else if (this.isEditTableIndex > index) {
                    this.isEditTableIndex--
                  }
                  cb && cb()
                }
              }
            )
          }
        }
      ]
    }
  },
  methods: {
    // 切换状态
    changeType(val) {
      this.$refs.pageRef.refreshList()
    },
    exportList: memberPageExport,
    // 列表请求函数
    getList(p) {
      try {
        var pam = JSON.parse(JSON.stringify(p))
        if (this.examineStatus) {
          pam.params.push({ param: 'b.examine_status', compare: '=', value: this.examineStatus })
        }
        return memberListPageV2(pam)
      } catch (error) {
        console.log(error)
      }
    },
    // 列表导出函数
    exportList: memberPageExport,
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      if (item.jname === 'idCardImg') {
        defaultData.render = (h, { row, index, column }) => {
          return (
            <div style="padding:0 6px;cursor: pointer;">
              {row.idCardImg
                ? row.idCardImg
                    .split(',')
                    .map(url => (
                      <el-image
                        src={this.$showImgUrl(url)}
                        preview-src-list={[this.$showImgUrl(url)]}
                        fit="fit"
                        style="width:80px;height:80px;"
                      />
                    ))
                : null}
            </div>
          )
        }
      }
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    // 表格操作列
    operation() {
      return this.operationBtn({
        // 详情
        detail: {
          btnType: 'text',
          click: ({ row, index, column }) => {
            this.$refs.tabPage.addTab({
              activeKey: 'detail',
              key: 'detail',
              label: '详情',
              triggerEvent: () => {
                this.guanbi()
                this.openType = 0
                this.$nextTick(() => {
                  this.openWindows(row)
                })
              },
              closeEvent: () => {}
            })
          }
        },
        // 编辑
        edit: {
          btnType: 'text',
          conditions: ({ row, index, column }) => {
            return ['OK', 'FAIL', 'STOP', 'QUIT'].includes(row.examineStatus)
          },
          click: ({ row, index, column }) => {
            this.$refs.tabPage.addTab({
              activeKey: 'edit',
              key: 'edit',
              label: '编辑',
              triggerEvent: () => {
                this.guanbi()
                this.openType = 1
                this.$nextTick(() => {
                  this.openWindows(row)
                })
              },
              closeEvent: () => {}
            })
          }
        },
        // 入驻申请审核
        entryAudit: {
          btnType: 'text',
          conditions: ({ row, index, column }) => {
            return ['WAIT'].includes(row.examineStatus)
          },
          click: ({ row, index, column }) => {
            this.$refs.tabPage.addTab({
              activeKey: 'entryAudit',
              key: 'entryAudit',
              label: '入驻申请审核',
              triggerEvent: () => {
                this.guanbi()
                this.openType = 2
                this.$nextTick(() => {
                  this.openWindows(row)
                })
              },
              closeEvent: () => {}
            })
          }
        },
        // 保险审核
        insuranceAudit: {
          btnType: 'text',
          conditions: ({ row, index, column }) => {
            return ['POLICY_WAIT'].includes(row.examineStatus)
          },
          click: ({ row, index, column }) => {
            this.$refs.tabPage.addTab({
              activeKey: 'insuranceAudit',
              key: 'insuranceAudit',
              label: '保险审核',
              triggerEvent: () => {
                this.guanbi()
                this.openType = 3
                this.$nextTick(() => {
                  this.openWindows(row)
                })
              },
              closeEvent: () => {}
            })
          }
        },
        // 激活
        activate: {
          btnType: 'text',
          conditions: ({ row, index, column }) => {
            return ['STOP'].includes(row.examineStatus)
          },
          click: ({ row, index, column }) => {
            workerManagerActivation({ id: row.id }).then(res => {
              this.$message({ type: 'success', message: '激活成功!' })
              this.$refs.pageRef.refreshList()
            })
          }
        },
        // 重新入职
        reEntry: {
          btnType: 'text',
          conditions: ({ row, index, column }) => {
            return ['QUIT'].includes(row.examineStatus)
          },
          click: ({ row, index, column }) => {
            workerManagerAgainQuit({ id: row.id }).then(res => {
              this.$message({ type: 'success', message: '入职成功!' })
              this.$refs.pageRef.refreshList()
            })
          }
        },
        // 暂停
        pause: {
          btnType: 'text',
          conditions: ({ row, index, column }) => {
            return ['OK'].includes(row.examineStatus)
          },
          click: ({ row, index, column }) => {
            workerManagerStop({ id: row.id }).then(res => {
              this.$message({ type: 'success', message: '暂停成功!' })
              this.$refs.pageRef.refreshList()
            })
          }
        },
        // 离职
        dimission: {
          btnType: 'text',
          conditions: ({ row, index, column }) => {
            return ['OK'].includes(row.examineStatus)
          },
          click: ({ row, index, column }) => {
            workerManagerQuit({ id: row.id }).then(res => {
              this.$message({ type: 'success', message: '离职成功!' })
              this.$refs.pageRef.refreshList()
            })
          }
        },
        // 师傅组别
        masterGroup: {
          btnType: 'text',
          conditions: ({ row, index, column }) => {
            return true
          },
          click: ({ row, index, column }) => {}
        }
      })
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.examineStatus === '待审核') {
        return 'redbackground'
      } else {
        return ''
      }
    },
    guanbi() {
      this.$refs?.formRef?.$refs?.inlineForm?.clearValidate()
      this.$data.formData = this.$options.data().formData
    },
    openWindows(row, cb) {
      workerManagerDetail({ id: row.id }).then(res => {
        this.formData = {
          ...res.data,
          user: {
            ...res.data.user,
            examineStatus_t: res.data.examineStatus
          },
          workerImgsCp: [
            {
              type: 'ID',
              number: res.data?.user?.idCard || '',
              startTime: res.data?.user?.idCardStartTime || '',
              endTime: res.data?.user?.idCardEndTime || '',
              reexamineTime: '',
              positive:
                (res.data?.workerImgs || [])
                  .filter(item => item.type == 'ID')
                  .map(item => ({
                    name: item.imgName,
                    url: item.imgUrl
                  }))?.[0] || [],
              negative:
                (res.data?.workerImgs || [])
                  .filter(item => item.type == 'ID')
                  .map(item => ({
                    name: item.imgName,
                    url: item.imgUrl
                  }))?.[1] || []
            },
            {
              type: 'HIGHT',
              number: res.data?.user?.number || '',
              startTime: res.data?.user?.startTime || '',
              endTime: res.data?.user?.endTime || '',
              reexamineTime: res.data?.user?.hightExamineTime || '',
              positive:
                (res.data?.workerImgs || [])
                  .filter(item => item.type == 'HIGHT')
                  .map(item => ({
                    name: item.imgName,
                    url: item.imgUrl
                  }))?.[0] || [],
              negative:
                (res.data?.workerImgs || [])
                  .filter(item => item.type == 'HIGHT')
                  .map(item => ({
                    name: item.imgName,
                    url: item.imgUrl
                  }))?.[1] || []
            }
          ],
          workerPolicies: res.data?.workerPolicies?.map(item => {
            return {
              ...item,
              policyUrls: item.policyUrl.split(',').map(url => ({ url }))
            }
          })
        }
        cb?.()
      })
    },
    getPam() {
      return {
        ...this.formData,
        user: {
          ...this.formData.user,
          idCard: this.formData?.workerImgsCp?.find(item => item.type == 'ID')?.number,
          idCardStartTime: this.formData?.workerImgsCp?.find(item => item.type == 'ID')?.startTime,
          idCardEndTime: this.formData?.workerImgsCp?.find(item => item.type == 'ID')?.endTime,
          number: this.formData?.workerImgsCp?.find(item => item.type == 'HIGHT')?.number,
          startTime: this.formData?.workerImgsCp?.find(item => item.type == 'HIGHT')?.startTime,
          endTime: this.formData?.workerImgsCp?.find(item => item.type == 'HIGHT')?.endTime,
          hightExamineTime: this.formData?.workerImgsCp?.find(item => item.type == 'HIGHT')?.reexamineTime
        },
        workerImgs: [
          {
            type: 'ID',
            imgName: '身份证正面',
            imgUrl: this.formData?.workerImgsCp?.find(item => item.type == 'ID')?.positive?.[0]?.url || ''
          },
          {
            type: 'ID',
            imgName: '身份证反面',
            imgUrl: this.formData?.workerImgsCp?.find(item => item.type == 'ID')?.negative?.[0]?.url || ''
          },
          {
            type: 'HIGHT',
            imgName: '高空证正面',
            imgUrl: this.formData?.workerImgsCp?.find(item => item.type == 'HIGHT')?.positive?.[0]?.url || ''
          },
          {
            type: 'HIGHT',
            imgName: '高空证反面',
            imgUrl: this.formData?.workerImgsCp?.find(item => item.type == 'HIGHT')?.negative?.[0]?.url || ''
          }
        ],
        workerPolicies: this.formData?.workerPolicies?.map(item => {
          return {
            ...item,
            policyUrl: item.policyUrls?.map(v => v.url)?.join(',')
          }
        })
      }
    },
    submit() {
      this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
        if (valid) {
          workerManagerUpdate(this.getPam()).then(res => {
            this.$message({ type: 'success', message: `保存成功!` })
            this.guanbi()
            this.$refs.pageRef.refreshList()
          })
        }
      })
    },
    examineWait() {
      this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
        if (valid) {
          workerManagerExamineWait(this.getPam()).then(res => {
            this.$message({ type: 'success', message: `保存成功!` })
            this.shenheClose()
            this.$refs.pageRef.refreshList()
          })
        }
      })
    },
    workerManagerExamine() {
      this.$refs.formRef.validate((valid, invalidFields, errLabels) => {
        if (valid) {
          workerManagerExamine(this.getPam()).then(res => {
            this.$message({ type: 'success', message: `保存成功!` })
            this.shenheClose()
            this.$refs.pageRef.refreshList()
          })
        }
      })
    },
    shenheClose() {
      this.shenheBool = false
    }
  }
}
</script>

<style lang="scss" scoped>
.tab {
  padding: 20px 20px 0 20px;
}
</style>
<style lang="scss">
.redbackground {
  background: rgb(248, 185, 185) !important;
}
.lcsebackground {
  background: rgb(212, 245, 212) !important;
}
.dialog-footer {
  text-align: right !important;
}
</style>
