<template>
  <div>
    <el-dialog  :close-on-click-modal="false"
      :title="!this.taskForm.taskId == '' ? $t('处理') : $t('详情')"

      :visible.sync="visible"
      :append-to-body="true">
      <el-form :model="taskForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="" label-width="80px">
        <el-form-item :label=" xpxp == 12 ? '预约续票' : '预约新票' ">
          <el-table :data="devList" :span-method="mergeMethod" border style="width: 100%;">
            <el-table-column label="作业单位" align="center" prop="workUnit"/>
            <el-table-column label="作业区域单元" align="center" prop="workArea"/>
            <el-table-column label="楼层位置" align="center" prop="floorLocation" :formatter="floorLocationFormat"/>
            <el-table-column label=" 作业日期" align="center" prop="workStartTime" width="100">
              <template slot-scope="scope">
                <span>{{ parseTime(scope.row.workStartTime, '{y}-{m}-{d}') }}</span>
              </template>
            </el-table-column>
            <el-table-column label="作业类型" align="center" prop="workType" :formatter="workTypeFormat"/>
            <el-table-column label="作业内容描述" align="center" prop="workDescription"/>
            <el-table-column label="作业人员数" align="center" prop="workPeopleNumber"/>
            <el-table-column label="预计作业时间" align="center" prop="estimateWorktime"/>
            <el-table-column label="联系人" align="center" prop="contact"/>
            <el-table-column label="联系方式" align="center" prop="phonenumber"/>
            <el-table-column label="状态" align="center" prop="status" width="100" :formatter="statusFormat"/>
            <el-table-column label="危害工作许可证号" align="center" prop="whgzxkzh"/>
            <el-table-column label="动火作业许可证号" align="center" prop="dhzyxkzh"/>
            <el-table-column label="火票级别" align="center" prop="hpjb" width="50" :formatter="hpjbFormat"/>
            <el-table-column label="限制空间许可证号" align="center" prop="xzkjxkzh"/>
            <el-table-column label="盲板作业许可证号" align="center" prop="mbzyxkzh"/>
            <el-table-column label="高处作业许可证号" align="center" prop="gczyxkzh"/>
            <el-table-column label="高处作业级别" align="center" prop="gczyjb" :formatter="gczyjbFormat"/>
            <el-table-column label="延期许可证号" align="center" prop="yqxkzh"/>
            <el-table-column label="票盒" align="center" prop="tag" width="60"/>
          </el-table>
        </el-form-item>
        <el-form-item :label="$t('申请时间')" prop="creattime">
          <el-input v-model="dataForm.creattime" disabled></el-input>
        </el-form-item>
      </el-form>
      <form ref="downloadForm" :action="downloadAction" target="FORMSUBMIT">
        <input name="approveId" v-model="dataForm.id" hidden/>
        <input name="processId" v-model="dataForm.processId" hidden/>
      </form>
      <span slot="footer" class="dialog-footer">
      <el-button v-if="this.taskForm.taskId == ''" @click="visible = false">{{ $t('message.return') }}</el-button>
      <el-button v-if="!this.taskForm.taskId == ''" type="primary"
                 @click="dataFormSubmit(1)" :disabled="submitDisabled">{{ $t('通过') }}</el-button>
      <el-button v-if="!this.taskForm.taskId == ''&&(this.isDevSup||this.isUserMag) && this.xpxp!= 12" type="success"
                 @click="updateDetail" :disabled="submitDisabled">{{ $t('修改') }}</el-button>
      <el-button v-if="!this.taskForm.taskId == ''" type="danger"
                 @click="dataFormSubmit(0)" :disabled="submitDisabled">{{ $t('作废') }}</el-button>
    </span>
      <div>
        <span>{{ $t('流转详情') }}</span>
        <el-table :data="historyList" border v-loading="historyLoading" style="width: 100%;">
          <el-table-column prop="taskName" header-align="center" align="center"
                           :label="$t('流程进度')"></el-table-column>
          <el-table-column prop="userName" header-align="center" align="center" :label="$t('姓名')"></el-table-column>
          <el-table-column prop="taskCreateTime" header-align="center" align="center"
                           :label="$t('开始时间')"></el-table-column>
          <el-table-column prop="taskEndTime" header-align="center" align="center"
                           :label="$t('结束时间')"></el-table-column>
          <el-table-column prop="comment" header-align="center" align="center"
                           :label="$t('审批意见')"></el-table-column>
        </el-table>
      </div>
      <record v-if="recordVisible" ref="recordDeal"></record>
    </el-dialog>
    <el-dialog  :close-on-click-modal="false" :title="title" :visible.sync="open" width="1200px" append-to-bod :before-close="detailCancel">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="承包商" prop="workUnit">
              <el-input v-model="form.workUnit" placeholder="请输入作业单位" :disabled="edit"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="作业区域" prop="workArea">
              <el-select v-model="form.workArea" placeholder="请选择作业区域" :disabled="isDevSup">
                <el-option
                  v-for="dict in workAreaOptions"
                  :key="dict.id"
                  :label="dict"
                  :value="dict"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="归属部门" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门"
                          :disabled="isDevSup"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
          </el-col>
          <el-col :span="12">
            <el-form-item label="楼层位置" prop="floorLocation">
              <el-select v-model="form.floorLocation" multiple placeholder="请选择楼层位置" :disabled="isDevSup">
                <el-option
                  v-for="dict in floorLocationOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="parseInt(dict.dictValue)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="作业时间" prop="workStartTime">
              <el-date-picker clearable size="small" style="width: 190px"
                              v-model="form.workStartTime"
                              type="date"
                              :disabled="isDevSup"
                              value-format="yyyy-MM-dd"
                              placeholder="选择作业时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <!--          <el-col :span="12">
                      <el-form-item label="作业结束" prop="workEndTime">
                        <el-date-picker clearable size="small" style="width: 190px"
                                        v-model="form.workEndTime"
                                        type="date"
                                        value-format="yyyy-MM-dd"
                                        placeholder="选择作业结束时间">
                        </el-date-picker>
                      </el-form-item>
                    </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="用户单位" prop="userUnit">
              <el-select v-model="form.userUnit" placeholder="请选择用户单位"
                         @change="checkCategoryPromotion(form.userUnit)" :disabled="isDevSup">
                <el-option
                  v-for="dict in userUnitOptions"
                  :key="dict.userUnit"
                  :label="dict.userUnit"
                  :value="dict.userUnit"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户主管" prop="userMg">
              <el-select v-model="form.userMg" placeholder="请先选择好用户单位" :disabled="isDevSup">
                <el-option
                  v-for="dict in userMgOptions"
                  :key="dict.userId"
                  :label="dict.nickName"
                  :value="dict.userId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-card v-for="(ruleForm, index) in ruleForm" :key="index" shadow="always">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
          <el-row>
            <el-col :span="18">
              <el-form-item label="作业内容描述" prop="workDescription">
                <el-input v-model="ruleForm.workDescription"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-button type="success" plain @click.prevent="addDomain(ruleForm)" style="float: right;">拷贝
              </el-button>
            </el-col>
            <el-col :span="3">
              <el-button type="info" plain @click.prevent="removeDomain(ruleForm)" style="float: right;">删除
              </el-button>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="6">
              <el-form-item label="作业类型" prop="workType">
                <el-select v-model="ruleForm.workType" placeholder="请选择作业类型" multiple clearable size="small">
                  <el-option
                    v-for="dict in workTypeOptions"
                    :key="dict.dictValue"
                    :label="dict.dictLabel"
                    :value="parseInt(dict.dictValue)"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="作业人数" prop="workPeopleNumber">
                <el-input-number v-model="ruleForm.workPeopleNumber" :min="1" :max="999" ></el-input-number>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="预计作业时间" prop="estimateWorktime">
                <el-input-number v-model="ruleForm.estimateWorktime" :min="1" :max="999" ></el-input-number>H
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-card>

      <el-button @click="resetForm1()">重置</el-button>
      <el-button @click="add">新增一条</el-button>
      <el-button @click="reduce" :disabled="flag">移除一条</el-button>

      <div slot="footer" class="dialog-footer">
        <el-button v-if="this.isUserMag" type="primary" @click="confirmDetail(1)" :disabled="save">保存并重新申请
        </el-button>
        <el-button v-else type="primary" @click="confirmDetail" :disabled="save">保存</el-button>
        <el-button @click="detailCancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getToken} from "@/utils/auth";
import {getHistorylist} from "@/api/ehs/approvedanger";
import record from "./spec-itemDetail";
import {getInvoice, listInvoice, handleApprove, addInvoice} from "@/api/invoice/invoice";
import Bookingworkticket from "@/views/invoice/bookingworkticket/index"
import log from "@/views/monitor/job/log";
import {getAllUserUnit, getUserByUnit} from "@/api/invoice/unit";
import {treeselect} from "@/api/system/dept";
import {
  getInfoById,
  updateBookingworkticket
} from "@/api/invoice/bookingworkticket";
import Treeselect from "@riophae/vue-treeselect";
import {selectDevice} from "@/api/invoice/device";

export default {
  name: "invoice-detail",
  components: {record, Bookingworkticket, Treeselect},
  data() {
    return {// 表单校验
      ruleForm: [{}],
      //禁用
      save: false,
      edit: true,
      flag: true,
      rules: {
        workArea: [
          {required: true, message: "作业区域不能为空", trigger: "blur"}
        ],
        floorLocation: [
          {required: true, message: "楼层位置不能为空", trigger: "blur"}
        ],
        workStartTime: [
          {required: true, message: "作业开始时间不能为空", trigger: "blur"}
        ],
        workEndTime: [
          {required: true, message: "作业结束时间不能为空", trigger: "blur"}
        ],
        userMg: [
          {required: true, message: "用户主管不能为空", trigger: "blur"}
        ],
        userUnit: [
          {required: true, message: "用户单位不能为空", trigger: "blur"}
        ],
        workType: [
          {required: true, message: "作业类型不能为空", trigger: "change"}
        ],
        workDescription: [
          {required: true, message: "作业内容不能为空", trigger: "change"}
        ],
        workPeopleNumber: [
          {required: true, message: "作业人数不能为空", trigger: "change"}
        ],
        estimateWorktime: [
          {required: true, message: "预计作业时间不能为空", trigger: "change"}
        ],
      },
      // 弹出层标题
      title: "",
      open: false,
      form: [],
      approveForm: {},
      isUserMag: false,
      isDevSup: false,
      xpxp: null,
      loading: true,
      bookingworkticketVisible: false,
      // 总条数
      total: 0,
      approvedangerList: [],
      // 状态字典
      statusOptions: [],
      // 作业单位字典
      workUnitOptions: [],
      // 作业区域字典
      workAreaOptions: [],
      // 单元号字典
      unitNumberOptions: [],
      // 楼层字典
      floorLocationOptions: [],
      // 用户单位字典
      userUnitOptions: [],
      // 用户主管字典
      userMgOptions: [],
      // 作业类型字典
      workTypeOptions: [],
      // 风险等级字典
      riskLevelOptions: [],
      // 监护人单位字典
      guardianUnitOptions: [],
      // 火票级别字典
      hpjbOptions: [],
      // 高处作业级别字典
      gczyjbOptions: [],
      recordVisible: false,
      // 遮罩层
      historyLoading: false,
      //显示详细列表
      IfDataIndex: false,
      //流转列表
      historyList: [],
      visible: false,
      devList: [],
      recordList: [],
      dataList: [],
      fileTips: '',
      showDelay: false,
      submitDisabled: false,
      dataListLoading: true,
      taskName: '',
      dataForm: {
        id: 0,
        userId: '',
        devId: '',
        devType: '',
        approveType: '',
        content: '',
        fileUrls: '',
        reUrls: '',
        status: '',
        creattime: '',
        plantCode: '',
        unit: '',
        devname: '',
        devno: '',
        files: [],
        delayDate: '',
        delayReason: '',
        delayMeasure: '',
        delayNotice: ''
      },
      taskForm: {
        comment: '',
        taskId: '',
        files: '',
        govDate: '',
        govFileList: []
      },
      // 查询参数
      queryParams: {
        processId: null,
      },
      doc: {
        file: "",
        // 是否显示弹出层（报告附件）
        open: false,
        // 弹出层标题（报告附件）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 报告附件上传位置编号
        ids: 0,
        // 设置上传的请求头部
        headers: {Authorization: "Bearer " + getToken()},
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/sems/specfile/uploadFile",
        commonfileList: null,
        pType: 'traning',
        pId: null
      },
      dataRule: {
        approveType: [
          {required: true, message: this.$t('approveType') + this.$t('notEmpty'), trigger: 'blur'}
        ],
        content: [
          {required: true, message: this.$t('content') + this.$t('notEmpty'), trigger: 'blur'}
        ]
      },
      downloadAction: process.env.VUE_APP_BASE_API + '/sems/approve/exportPDF',
      approveOption: [],
      belong: '',
      fileList: [],
      deptOptions: []
    };
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getTreeselect();
  },
  methods: {
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    //根据用户单位 查询对应选择的用户主管  根据用户单位 字段 查找对应的多个主管 返回 Sysuser的集合(id,name)
    checkCategoryPromotion(oneId) {

      getUserByUnit(oneId).then(response => {
        //     this.form.userMg=null;
        this.userMgOptions = response.data;
        //   let arr=  response.data.userIds.split(',');
      });
    },
    // 状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 火票级别字典翻译
    hpjbFormat(row, column) {
      return this.selectDictLabel(this.hpjbOptions, row.hpjb);
    },
    // 高处作业级别字典翻译
    gczyjbFormat(row, column) {
      return this.selectDictLabel(this.gczyjbOptions, row.gczyjb);
    },
    // 字典翻译
    workUnitFormat(row, column) {
      return this.selectDictLabel(this.workUnitOptions, row.workUnit);
    },
    // 字典翻译
    workAreaFormat(row, column) {
      return this.selectDictLabel(this.workAreaOptions, row.workArea);
    },
    // 字典翻译
    unitNumberFormat(row, column) {
      return this.selectDictLabel(this.unitNumberOptions, row.unitNumber);
    },
    // 字典翻译
    floorLocationFormat(row, column) {
      let floor = "";
      row.floorLocation.split(",").forEach(item => {
        floor += this.selectDictLabel(this.floorLocationOptions, item) + ","
      })
      return floor.substring(0, floor.length - 1);
    },
    // 字典翻译
    userMgFormat(row, column) {
      return this.selectDictLabel(this.userMgOptions, row.userMg);
    },
    // 字典翻译
    userUnitFormat(row, column) {
      return this.selectDictLabel(this.userUnitOptions, row.userUnit);
    },
    // 字典翻译
    workTypeFormat(row, column) {
      return this.selectDictLabels(this.workTypeOptions, row.workType);
    },
    // 字典翻译
    riskLevelFormat(row, column) {
      return this.selectDictLabel(this.riskLevelOptions, row.riskLevel);
    },
    // 字典翻译
    guardianUnitFormat(row, column) {
      return this.selectDictLabel(this.guardianUnitOptions, row.guardianUnit);
    },
    init(id, taskId, processId, taskName) {
      this.reset();
      this.fileList = [];
      this.getDicts("booking_work_status").then(response => {
        this.statusOptions = response.data;
      });
      this.getDeviceup();
      this.getDicts("book_unit_number").then(response => {
        this.unitNumberOptions = response.data;
      });
      this.getDicts("book_floor_location").then(response => {
        this.floorLocationOptions = response.data;
      });
      this.getDicts("book_user_mg").then(response => {
        this.userMgOptions = response.data;
      });
      this.getDicts("book_user_unit").then(response => {
        this.userUnitOptions = response.data;
      });
      // this.getDicts("book_user_unit").then(response => {
      //   this.userUnitOptions = response.data;
      // });
      getAllUserUnit({}).then(response => {
        this.userUnitOptions = response.data;
      });
      this.getDicts("book_work_type").then(response => {
        this.workTypeOptions = response.data;
      });
      this.getDicts("book_risk_level").then(response => {
        this.riskLevelOptions = response.data;
      });
      this.getDicts("book_guardian_unit").then(response => {
        this.guardianUnitOptions = response.data;
      });
      this.getDicts("HPJB").then(response => {
        this.hpjbOptions = response.data;
      });
      this.getDicts("GCZYJB").then(response => {
        this.gczyjbOptions = response.data;
      });
      this.dataForm.processId = processId
      this.taskName = taskName
      this.taskForm.taskId = taskId
      this.dataForm.id = id || 0
      this.visible = true
      this.queryParams.processId = processId;
      getHistorylist(this.queryParams).then(response => {
        this.historyList = response.rows;
        this.historyLoading = false
      });
      getInvoice(id).then(response => {
        this.taskForm.businessKey = response.data.id
        this.dataForm.userId = response.data.userId
        this.dataForm.devId = response.data.devId
        this.dataForm.devType = response.data.devType
        // this.dataForm.approveType = response.data.approveType
        this.dataForm.approveType = '维修'
        this.dataForm.content = response.data.content
        this.dataForm.fileUrls = response.data.fileUrls
        this.dataForm.reUrls = response.data.reUrls
        this.dataForm.status = response.data.status
        this.dataForm.creattime = response.data.creattime
        this.dataForm.plantCode = response.data.plantCode
        this.dataForm.unit = response.data.unit
        this.dataForm.devname = response.data.devname
        this.dataForm.devno = response.data.devno
        this.dataForm.files = response.data.files
        this.devList = response.data.devList
        this.isUserMag = this.devList[0].status == 0 ? true : false;
        this.isDevSup = this.devList[0].status == 2 ? true : false;
        this.xpxp = this.devList[0].xpxp
        this.dataForm.delayDate = response.data.delayDate
        this.dataForm.delayReason = response.data.delayReason
        this.dataForm.delayMeasure = response.data.delayMeasure
        this.dataForm.delayNotice = <response className="data delayNotice"></response>
      });

    },
    // 设备类型：字典翻译
    devTypeFormat(row, column) {
      // return this.selectDictLabel(this.devTypeOptions, row.devType);
    },
    // 审批类型字典翻译
    approveTypeFormat(row, column) {
      return this.selectDictLabel(this.approveTypeOptions, row.approveType);
    },

    // 取消按钮
    cancel() {
      this.visible = false;
      this.reset();
    },

    getDeviceup() {
      const queryForm = {
        pageNum: 1,
        pageSize: 20,
        devName: null,
        workArea: null,
        regionalHead: null,
        createrCode: null,
        createdate: null,
        updaterCode: null,
        updatedate: null,
        deptId: null,
        remarks: null
      };
      selectDevice(queryForm).then(response => {
        this.workAreaOptions = response.data
      });
    },

    detailCancel() {
      this.open = false;
      this.detailReset();
      this.$nextTick(() => {
        this.$refs.ruleForm[0].resetFields();
        if (this.$refs.ruleForm[1] != null) {
          this.$refs.ruleForm[1].resetFields();
        }
        if (this.$refs.ruleForm[2] != null) {
          this.$refs.ruleForm[2].resetFields();
        }
        if (this.$refs.ruleForm[3] != null) {
          this.$refs.ruleForm[3].resetFields();
        }
        if (this.$refs.ruleForm[4] != null) {
          this.$refs.ruleForm[4].resetFields();
        }
      })
    },
    // 表单重置
    reset() {
      this.historyList = [];
      this.devList = [];
      this.isUserMag = false;
      this.isDevSup = false;
      this.userUnitOptions = [];
    },
    detailReset() {
      this.form = {
        id: null,
        userId: null,
        devId: null,
        devType: null,
        approveType: null,
        content: null,
        fileUrls: null,
        reUrls: null,
        status: 0,
        creattime: null,
        enddate: null,
        processId: null,
        govDate: null,
        delayDate: null,
        delayReason: null,
        delayMeasure: null,
        delayNotice: null,
        apNo: null,
        checkDate: null,
        reportId: null,
        monthId: null,
        delFlag: null,
        deptId: null
      };
      this.resetForm("form");
    },

    /** 提交按钮 */
    // 表单提交
    dataFormSubmit(val) {
      this.submitDisabled = true
      this.dataForm.files = []
      if (this.taskForm.govFileList.length > 0) {
        for (let i = 0; i < this.taskForm.govFileList.length; i++) {
          let obj = {}
          obj.fileName = this.taskForm.govFileList[i].response.fileName
          obj.fileUrl = this.taskForm.govFileList[i].response.url
          this.dataForm.files.push(obj)
        }
      }
      this.taskForm.condition = val
      this.taskForm.govFiles = this.dataForm.files
      handleApprove(this.taskForm).then(response => {
        this.msgSuccess(this.$t('处理成功'));
        this.visible = false;
        this.submitDisabled = false
        this.$emit('refreshDataList')
      });
      this.$nextTick(function () {
        this.comment = ''
      })
    },
    recordHandle(devList, dataForm) {
      this.recordVisible = true
      this.$nextTick(() => {
        this.$refs.recordDeal.init(devList, dataForm);
      })
    },//合并单元格
    mergeMethod({row, column, rowIndex, columnIndex}) {
      if (columnIndex === 0) {
        const _row = this.setTable(this.devList).merge[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if (columnIndex === 1) {
        const _row = this.setTable(this.devList).merge[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if (columnIndex === 2) {
        const _row = this.setTable(this.devList).merge[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if (columnIndex === 3) {
        const _row = this.setTable(this.devList).merge[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if (columnIndex === 4) {
        const _row = this.setTable(this.devList).merge[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if (columnIndex === 10) {
        const _row = this.setTable(this.devList).merge[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if (columnIndex === 11) {
        const _row = this.setTable(this.devList).merge[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if (columnIndex === 12) {
        const _row = this.setTable(this.devList).merge[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }


    },
    //单元格整理
    setTable(tableData) {
      let spanArr = [],
        concat = 0;
      tableData.forEach((item, index) => {
        if (index === 0) {
          spanArr.push(1);
        } else {
          if (item.workUnit === tableData[index - 1].workUnit) {
            //第一列需合并相同内容的判断条件
            spanArr[concat] += 1;
            spanArr.push(0);
          } else {
            spanArr.push(1);
            concat = index;
          }
        }
      });
      return {
        merge: spanArr
      };
    },
    updateDetail() {
      this.save=false
      this.detailReset();
      const id = this.devList[0].bookingticketId
      getInfoById(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改预约作业票台账";
        this.ruleForm = response.data.tInvoiceWorkcontentList
        //  回显用户主管
        this.checkCategoryPromotion(this.form.userUnit);
        //  console.log(row.floorLocation)  将后台的字符串数组重新转换为el-select要的数组格式
        let arr = this.devList[0].floorLocation.split(",")
        let st = []
        // 将字符串数组的每一项转换成Number，生成一个新的数组
        for (var arrInt in arr) {
          st.push(parseInt(arr[arrInt]))
        }
        this.form.floorLocation = st
        for (let j = 0; j < this.ruleForm.length; j++) {
          let arr1 = this.ruleForm[j].workType.split(",")
          let st1 = []
          // 将字符串数组的每一项转换成Number，生成一个新的数组
          for (var arrInt in arr1) {
            st1.push(parseInt(arr1[arrInt]))
          }
          this.ruleForm[j].workType = st1
        }

        this.ruleForm.length = response.data.tInvoiceWorkcontentList.length
      });
    },
    //校验
    getFormPromise(formDone) {
      return new Promise(resolve => {
        formDone.validate(res => {
          resolve(res);
        });
      });
    },
    confirmDetail(val) {
      this.save = true
      let arr = []
      const basicForm = this.$refs.form;
      arr.push(basicForm)
      const genForm = this.$refs.ruleForm[0];
      arr.push(genForm)
      if (this.$refs.ruleForm[1] != null) {
        const genForm1 = this.$refs.ruleForm[1];
        arr.push(genForm1)
      }
      if (this.$refs.ruleForm[2] != null) {
        const genForm2 = this.$refs.ruleForm[2];
        arr.push(genForm2)
      }
      if (this.$refs.ruleForm[3] != null) {
        const genForm3 = this.$refs.ruleForm[3];
        arr.push(genForm3)
      }
      if (this.$refs.ruleForm[4] != null) {
        const genForm4 = this.$refs.ruleForm[4];
        arr.push(genForm4)
      }

      this.taskForm.condition = 2
      this.taskForm.govFiles = this.dataForm.files

      //多重校验
      Promise.all(arr.map(this.getFormPromise)).then(res => {
        const validateResult = res.every(item => !!item);
        if (validateResult) {
          if (this.form.id != null) {
            this.form.tInvoiceWorkcontentList = this.ruleForm
            this.form.floorLocation = this.form.floorLocation.join(',')
            for (let b = 0; b < this.ruleForm.length; b++) {
              this.ruleForm[b].workType = this.ruleForm[b].workType.join(',')
            }
            updateBookingworkticket(this.form).then(response => {
              this.approveForm.invoiceId = this.form.id
              var nowTime = this.getNowFormatDate()
              this.approveForm.userSupId = this.form.userMg
              if (val === 1) {
                handleApprove(this.taskForm).then(response => {
                  this.msgSuccess(this.$t('处理成功'));
                  addInvoice(this.approveForm).then(response => {
                    // this.msgSuccess(this.$t('预约成功'));
                    this.msgSuccess("已提交申请");

                    this.open = false;
                    this.visible = false;
                    this.$emit('refreshDataList')
                  })
                });
              } else {
                getInvoice(this.taskForm.businessKey).then(response => {
                  this.devList = response.data.devList;
                });
                this.open = false;
              }
              this.msgSuccess("修改成功");
            });
          }
        } else {
          this.msgError("表单校验未通过，每项申请内容都必填");
        }
      });

      this.$nextTick(function () {
        this.comment = ''
      })

    },
//拷贝
    addDomain(domain) {
      let arr = {}
      arr.workType = domain.workType;
      arr.workDescription = domain.workDescription;
      arr.riskLevel = domain.riskLevel;
      arr.workPeopleNumber = domain.workPeopleNumber;
      arr.estimateWorktime = domain.estimateWorktime;
      this.ruleForm.push(
        arr
      );
      this.flags()
    },
//删除自身
    removeDomain(item) {
      //如果子类大于1  可点击删除按钮
      if (this.ruleForm.length > 1) {
        var index = this.ruleForm.indexOf(item)
        if (index !== -1) {
          this.ruleForm.splice(index, 1)
        }
      }
      this.flags()
    },
// 表单添加一行
    add() {
      var arr = {}
      this.ruleForm.push(arr)
      this.flags()
    },
// 表单减少一行
    reduce() {

      this.ruleForm.length = this.ruleForm.length - 1
      this.flags()
    },
    // 重置方法
    resetForm1() {
      this.ruleForm = [{}]
    },
    //时间
    getNowFormatDate() {
      var date = new Date();
      var seperator1 = "-";
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var strDate = date.getDate();
      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      var currentdate = year + seperator1 + month + seperator1 + strDate;
      return currentdate;
    },
  }
}


</script>
