<template>
  <div class="index-inner">
    <el-form
      ref="taskManageForm"
      :disabled="readDetaial"
      :model="form"
      :rules="rules"
      data-vv-scope="taskManageForm"
      label-width="110px"
      style="padding: 20px; width: 100%"
    >
      <el-collapse v-model="activeNames">
        <el-collapse-item name="1">
          <template slot="title">
            <span class="tip"></span>创建养护工单
          </template>
          <el-card>
            <el-row>
              <el-col :span="12">
                <el-form-item
                  label="工单号"
                  prop="workOrderInformation.jobNumber"
                >
                  <el-input
                    v-model="form.workOrderInformation.jobNumber"
                    disabled
                    placeholder="由后台生成"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="工单类型" prop="workOrderInformation.type">
                  <!-- <el-input v-model="form.type"></el-input> -->
                  <dict-select
                    v-model="form.workOrderInformation.type"
                    :disabled="disabledCreated"
                    :hasDefaultOption="true"
                    clearable
                    dictCode="yhgd-gdlx"
                    style="width: 100%"
                    @input="(val, obj) => handleDict(val, obj, 'yhgd-gdlx')"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item
                  label="路段"
                  prop="workOrderInformation.roadSegmentId"
                >
                  <!-- <el-input v-model="form.roadSegmentId"></el-input> -->
                  <!-- <router-info-selector
                    v-model="form.workOrderInformation.roadSegmentId"
                    :value="form.workOrderInformation.roadSegmentId"
                    @changed="changed"
                    @value="value"
                    :disabledCreated="disabledCreated"
                  /> -->
                  <sction-info-selector
                    v-model="form.workOrderInformation.roadSegmentName"
                    :disabledCreated="disabledCreated"
                    :value="form.workOrderInformation.roadSegmentName"
                    @changed="changed"
                    @value="value"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item
                  label="施工单位"
                  prop="workOrderInformation.companyName"
                >
                  <!-- <el-input v-model="form.responsiblePerson"></el-input> -->
                  <company-info-selector
                    v-model="form.workOrderInformation.companyName"
                    :disabledCreated="disabledCreated"
                    :valueName="form.companyIds"
                    @handleChanged="handleChanged"
                    @value="companyValue"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="位置" prop="workOrderInformation.position">
                  <el-input
                    v-model="form.workOrderInformation.position"
                    :disabled="disabledCreated"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item
                  label="合同"
                  prop="workOrderInformation.contractId"
                >
                  <!-- <el-input v-model="form.contractId"></el-input> -->
                  <el-select
                    v-model="form.workOrderInformation.contractId"
                    :disabled="disabledCreated"
                    placeholder="请选择合同"
                    style="width: 100%"
                    @change="contractChange"
                  >
                    <el-option
                      v-for="item in contractInfoList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item
                  label="类别"
                  prop="workOrderInformation.categoryId"
                >
                  <!-- <el-input v-model="form.categoryId"></el-input> -->
                  <el-select
                    v-model="form.workOrderInformation.categoryId"
                    :disabled="disabledCreated"
                    placeholder="请选择"
                    style="width: 100%"
                    @change="changesele"
                  >
                    <el-option
                      v-for="item in options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item
                  label="细目"
                  prop="workOrderInformation.detailsId"
                >
                  <!-- <el-input v-model="form.detailsId"></el-input> -->
                  <el-select
                    v-model="form.workOrderInformation.detailsId"
                    :disabled="disabledCreated"
                    placeholder="请选择"
                    style="width: 100%"
                  >
                    <el-option
                      v-for="item in cbkm"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item
                  label="要求修复时间"
                  prop="workOrderInformation.demandFinishTime"
                >
                  <!-- <el-input v-model="form.demandFinishTime"></el-input> -->
                  <el-date-picker
                    v-model="form.workOrderInformation.demandFinishTime"
                    :disabled="disabledCreated"
                    format="yyyy-MM-dd"
                    placeholder="选择日期"
                    style="width: 100%"
                    type="date"
                    value-format="yyyy-MM-dd"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="签发人" prop="workOrderInformation.issuer">
                  <el-input
                    v-model="form.workOrderInformation.issuer"
                    :disabled="disabledCreated"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item
                  label="签发日期"
                  prop="workOrderInformation.issueDate"
                >
                  <!-- <el-input v-model="form.issueDate"></el-input> -->
                  <el-date-picker
                    v-model="form.workOrderInformation.issueDate"
                    :disabled="disabledCreated"
                    format="yyyy-MM-dd"
                    placeholder="选择日期"
                    style="width: 100%"
                    type="date"
                    value-format="yyyy-MM-dd"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <!-- <el-col :span='12'>
                <el-form-item
                  label="方向"
                  prop="disease.direction"
                >
                  <dict-select
                    dictCode="fx"
                    :hasDefaultOption="true"
                    clearable
                    v-model="form.disease.direction"
                    style='width:100%'
                    @input='(val,obj)=>handleDict(val,obj,"fx")'
                    :disabled='disabledCreated'
                  />
                </el-form-item>
              </el-col> -->
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item
                  label="任务内容"
                  prop="workOrderInformation.taskContent"
                >
                  <el-input
                    v-model="form.workOrderInformation.taskContent"
                    :disabled="disabledCreated"
                    rows="3"
                    type="textarea"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col v-if="currentNode == 1" :span="24">
                <el-form-item
                  label="关联病害"
                  prop="workOrderInformation.description"
                >
                  <el-input
                    ref="diseaseName"
                    v-model="form.workOrderInformation.description"
                    :disabled="disabledCreated"
                    clearable
                    placeholder="选择关联病害"
                    @focus="handleFocusDisease"
                  >
                    <el-button
                      slot="append"
                      icon="el-icon-search"
                      type="primary"
                      @click="openDisease"
                    ></el-button>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
        </el-collapse-item>
        <el-collapse-item
          v-if="
            (currentNode == 2 ||
              currentNode == 3 ||
              currentNode == 4 ||
              currentNode == 5 ||
              currentNode == 6) &&
              isshow
          "
          name="2"
        >
          <template slot="title"><span class="tip"></span>关联病害</template>
          <el-card v-for="(item, index) in form.diseases" :key="index">
            <span class="number">{{ index + 1 }}</span>
            <el-row>
              <el-col :span="12">
                <el-form-item label="巡检类别">
                  <dict-select
                    v-model="item.type"
                    :hasDefaultOption="true"
                    dictCode="xjlb"
                    disabled
                    style="width: 100%"
                  />
                  <!-- <el-input
                    disabled
                    v-model="item.typeName"
                  ></el-input> -->
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="方向">
                  <dict-select
                    v-model="item.direction"
                    :hasDefaultOption="true"
                    clearable
                    dictCode="qlfx"
                    disabled
                    style="width: 100%"
                  />
                  <!-- <el-input
                    disabled
                    v-model="item.directionName"
                  ></el-input> -->
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="起点桩号">
                  <el-input v-model="item.startPeg" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="止点桩号">
                  <el-input v-model="item.endPeg" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="类别">
                  <el-select
                    v-model="item.categoryId"
                    disabled
                    placeholder="请选择"
                    style="width: 100%"
                    @change="val => changesele(val)"
                  >
                    <el-option
                      v-for="item in options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                  <!-- <el-input
                    disabled
                    v-model="item.subjectName"
                  ></el-input> -->
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="细目">
                  <el-select
                    v-model="item.detailsId"
                    disabled
                    placeholder="请选择"
                    style="width: 100%"
                    @change="val => dsubchange(val)"
                  >
                    <el-option
                      v-for="item in cbkm"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select>
                  <!-- <el-input
                    disabled
                    v-model="item.dsubjectName"
                  ></el-input> -->
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="病害部位">
                  <dict-select
                    v-model="item.positionName"
                    :hasDefaultOption="true"
                    clearable
                    dictCode="bhbw"
                    disabled
                    style="width: 100%"
                  />
                  <!-- <el-input
                    disabled
                    v-model="item.positionName"
                  ></el-input> -->
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="处理情况">
                  <el-input
                    v-model="item.handlingSituation"
                    disabled
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="病害描述">
                  <el-input v-model="item.description" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="病害 长(mm)">
                  <el-input v-model="item.paramLength" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="病害 宽(mm)">
                  <el-input v-model="item.paramWidth" disabled></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="病害 高(mm)">
                  <el-input v-model="item.paramHeight" disabled></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="病害照片列表">
                  <div
                    v-for="(itemImg, index) in item.accessories"
                    :key="index"
                    class="img-box"
                  >
                    <img :key="itemImg.id" :src="itemImg.url" />
                  </div>
                  <!-- <el-input
                    disabled
                    v-model="form.disease.diseasePicIds"
                  ></el-input> -->
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
        </el-collapse-item>

        <el-collapse-item
          v-if="
            currentNode == 3 ||
              currentNode == 4 ||
              currentNode == 5 ||
              currentNode == 6
          "
          name="3"
        >
          <template slot="title"><span class="tip"></span>施工填报</template>
          <el-card>
            <el-row>
              <el-col :span="12">
                <el-form-item
                  label="施工照片"
                  prop="workOrderInformation.constructionPicIds"
                >
                  <!-- <el-upload
                    :action="actionUrl"
                    list-type="picture-card"
                    :on-preview="handlePictureCardPreview"
                    :on-remove="handleRemove"
                  >
                    <i class="el-icon-plus"></i>
                  </el-upload>
                  <el-dialog :visible.sync="dialogVisible">
                    <img
                      width="100%"
                      :src="dialogImageUrl"
                      alt=""
                    >
                  </el-dialog> -->
                  <ImgPreviewUpload
                    v-if="dadToSon.sourceId && source"
                    ref="constructionPicIdsUrl"
                    :accept="`.jpg,.jpeg,.png,.JPG,.JPEG`"
                    :dadToSon="dadToSon"
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    :model="form.workOrderInformation.constructionPicIds"
                    @sonToDad="sonToDad"
                  >
                  </ImgPreviewUpload>
                  <!-- <file-upload
                    :dadToSon="dadToSon"
                    @sonToDad="sonToDad"
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    ref="constructionPicIdsUrl"
                    :model="form.workOrderInformation.constructionPicIds"
                    :accept="`.jpg,.jpeg,.png,.JPG,.JPEG`"
                    v-if="dadToSon.sourceId && source"
                  ></file-upload> -->
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item
                  label="起点桩号"
                  prop="workOrderInformation.constructionStartPegK"
                >
                  <el-input
                    v-model="form.workOrderInformation.constructionStartPegK"
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item
                  label="止点桩号"
                  prop="workOrderInformation.constructionEndPegK"
                >
                  <el-input
                    v-model="form.workOrderInformation.constructionEndPegK"
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <!-- <el-row>
              <el-col :span='12'>
                <el-form-item
                  label="现场负责人"
                  prop="name"
                >
                  <el-input v-model="form.name"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span='12'>
                <el-form-item
                  label="亮工时间"
                  prop="workOrderInformation.issueDate"
                >
                  <el-input v-model="form.name"></el-input>
                </el-form-item>
              </el-col>
            </el-row> -->
            <el-row>
              <el-col :span="24">
                <el-form-item
                  label="施工描述"
                  prop="workOrderInformation.constructionDesc"
                >
                  <el-input
                    v-model="form.workOrderInformation.constructionDesc"
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    rows="3"
                    type="textarea"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
        </el-collapse-item>
        <el-collapse-item
          v-if="
            currentNode == 3 ||
              currentNode == 4 ||
              currentNode == 5 ||
              currentNode == 6
          "
          name="4"
        >
          <template slot="title">
            <span class="tip"></span>关联信息、工程量清单
          </template>
          <el-card style="max-width: 100%; box-sizing: border-box">
            <el-button
              :disabled="currentNode == 4"
              icon="el-icon-plus"
              style="margin-bottom: 20px"
              type="primary"
              @click="addListItem"
            >
              添加
            </el-button>

            <el-table
              :data="tableData"
              border
              max-height="360"
              stripe
              style="max-width: 100%; min-width: 100%"
            >
              <el-table-column
                fixed="left"
                label="课目名称"
                min-width="130"
                prop="subjectName"
              >
                <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.subjectName"
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    readonly
                    suffix-icon="el-icon-search"
                    @focus="searchSubject(scope.$index)"
                  >
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column
                fixed="left"
                label="细课目名称"
                min-width="130"
                prop="fineSubjectName"
              >
                <template slot-scope="scope">
                  <el-input
                    v-model="scope.row.fineSubjectName"
                    disabled
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column label="单位" min-width="130" prop="spec">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.spec" disabled></el-input>
                </template>
              </el-table-column>
              <el-table-column label="单价(元)" min-width="130" prop="price">
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.price"
                    :controls="false"
                    :min="0"
                    :precision="2"
                    class="input-number"
                    disabled
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column label="数量" min-width="130" prop="amount">
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.amount"
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    :min="0"
                    class="input-number"
                    controls-position="right"
                    @change="val => changeAmount(val, scope.$index)"
                  >
                  </el-input-number>
                </template>
              </el-table-column>
              <el-table-column label="金额(元)" min-width="140" prop="money">
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.money"
                    :controls="false"
                    :min="0"
                    :precision="2"
                    class="input-number"
                    disabled
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                label="审核单价(元)"
                min-width="130"
                prop="auditPrice"
              >
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.auditPrice"
                    :controls="false"
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    :min="0"
                    :precision="2"
                    class="input-number"
                    @change="
                      val =>
                        changeColNum(
                          val,
                          scope.$index,
                          'auditPrice',
                          'auditAmount',
                          'auditMoney'
                        )
                    "
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                label="审核数量"
                min-width="130"
                prop="auditAmount"
              >
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.auditAmount"
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    :min="0"
                    class="input-number"
                    controls-position="right"
                    @change="
                      val =>
                        changeColNum(
                          val,
                          scope.$index,
                          'auditAmount',
                          'auditPrice',
                          'auditMoney'
                        )
                    "
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                label="审核金额(元)"
                min-width="140"
                prop="auditMoney"
              >
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.auditMoney"
                    :controls="false"
                    :min="0"
                    :precision="2"
                    class="input-number"
                    disabled
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                label="收方单价"
                min-width="130"
                prop="receiverPrice"
              >
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.receiverPrice"
                    :controls="false"
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    :min="0"
                    :precision="2"
                    class="input-number"
                    @change="
                      val =>
                        changeColNum(
                          val,
                          scope.$index,
                          'receiverPrice',
                          'receiverAmount',
                          'receiverMoney'
                        )
                    "
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                label="收方数量"
                min-width="130"
                prop="receiverAmount"
              >
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.receiverAmount"
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    :min="0"
                    class="input-number"
                    controls-position="right"
                    @change="
                      val =>
                        changeColNum(
                          val,
                          scope.$index,
                          'receiverAmount',
                          'receiverPrice',
                          'receiverMoney'
                        )
                    "
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                label="收方金额(元)"
                min-width="140"
                prop="receiverMoney"
              >
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.receiverMoney"
                    :controls="false"
                    :min="0"
                    :precision="2"
                    class="input-number"
                    disabled
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                align="center"
                fixed="right"
                label="操作"
                width="80"
              >
                <template slot-scope="scope">
                  <el-button
                    icon="el-icon-delete"
                    size="small"
                    type="danger"
                    @click="deleteListItem(scope.$index)"
                  />
                </template>
              </el-table-column>
            </el-table>
          </el-card>
        </el-collapse-item>
      </el-collapse>
    </el-form>
    <disease-dialog
      ref="disease"
      :single="true"
      @select="handleSelectDisease"
    ></disease-dialog>
    <selectContractDialog
      ref="selectContract"
      @change="getContractItem"
    ></selectContractDialog>
    <!-- <div class="el-dialog-footer">
      <span
        slot="footer"
        class="dialog-footer"
      >
        <el-button @click="handleCancel">取 消</el-button>
        <el-button
          type="primary"
          @click="dialogVisibleInfo = false"
        >导出</el-button>
      </span>
    </div> -->
  </div>
</template>

<script>
import {helper} from '../../../public/hotent.helper.js'
import req from '@/request.js'
import utils from '@/utils'
import basicData from '@/api/basicData.js'
import routerInfoSelector from '@/components/selector/routerInfoSelector.vue'
import DiseaseDialog from '@/components/dialog/DiseaseDialog.vue'
import selectContractDialog from '@/components/flowURLForm/selectContractDialog'
import sctionInfoSelector from '@/components/selector/sctionInfoSelector.vue'
import {mapState} from 'vuex'

const ImgPreviewUpload = () =>
  import('@/components/common/ImgPreviewUpload.vue')
export default {
  name: 'flowInfoDailog',
  components: {
    routerInfoSelector,
    DiseaseDialog,
    selectContractDialog,
    ImgPreviewUpload,
    sctionInfoSelector
  },
  data() {
    return {
      isSeconed: false, //判断是否调用两次saveData
      currentNode: 1,
      form: {
        //工单信息实体数据
        workOrderInformation: {
          type: 1, //工单类型 字典
          diseaseId: '', //病害描述
          roadSegmentId: '',
          typeValue: '派单项目',
          contractId: '', //1427556055054946304
          description: '',
          detailsId: ''
        },
        billOfQuantities: [],
        contract: {},
        defaultBpmCheckOpinion: {},
        disease: []
      },
      options: [],
      cbkm: [],
      activeNames: ['1', '2', '3', '4'],
      tableData: [],
      contractInfoList: [], //合同信息列表
      disabledCreated: false, //控制创建工单信息表单的选填
      dialogImageUrl: '',
      dialogVisible: false,
      isshow: false, //控制关联病害是否显示
      readDetaial: false,
      rules: {
        // contract: {
        //   contractNumber: {
        //     required: true,
        //     message: '请输入合同',
        //     trigger: 'blur',
        //   },
        // },
        // disease: {
        //   direction: {
        //     required: true,
        //     message: '请选择方向',
        //     trigger: 'blur'
        //   },
        //   startPeg: {
        //     required: true,
        //     message: '请输入起点桩号',
        //     trigger: 'blur'
        //   },
        //   endPeg: {
        //     required: true,
        //     message: '请输入止点桩号',
        //     trigger: 'blur'
        //   }
        // },
        workOrderInformation: {
          type: {
            required: true,
            message: '请输入工单类型',
            trigger: 'blur'
          },
          roadSegmentId: {
            required: true,
            message: '请选择路段名称',
            trigger: 'blur'
          },
          contractId: {
            required: true,
            message: '请选择合同',
            trigger: 'blur'
          },
          companyName: {
            required: true,
            message: '请选择施工单位',
            trigger: 'blur'
          },
          position: {
            required: true,
            message: '请输入位置',
            trigger: 'blur'
          },
          categoryId: {
            required: true,
            message: '请选择类别',
            trigger: 'blur'
          },
          detailsId: {
            required: true,
            message: '请输入细目',
            trigger: 'blur'
          },
          demandFinishTime: {
            required: true,
            message: '请输入要求修复时间',
            trigger: 'blur'
          },
          issuer: {
            required: true,
            message: '请输入签发人',
            trigger: 'blur'
          },
          issueDate: {
            required: true,
            message: '请输入签发日期',
            trigger: 'blur'
          },
          taskContent: {
            required: true,
            message: '请输入任务内容',
            trigger: 'blur'
          },
          // constructionPicIds: {
          //   required: true,
          //   message: '请上传照片',
          //   trigger: 'blur'
          // }
          description: {
            required: true,
            message: '请选择关联病害',
            trigger: 'blur'
          }
        }
      },
      dadToSon: {
        sourceId: ''
        // fileList: [

        // ],
      },
      source: false
    }
  },
  mounted() {
    this.currentNode = this.$route.query.node
    console.log(this.$route, '参数')
    if (this.$route.query.type) {
      this.readDetaial = true
    }
    // this.currentNode = 4
    console.log(this.currentNode, '节点')
    if (
      this.currentNode == 2 ||
      this.currentNode == 3 ||
      this.currentNode == 4 ||
      this.currentNode == 5 ||
      this.currentNode == 6
    ) {
      this.disabledCreated = true
    }
    const _this = this
    window.saveData = this.saveData
    this.id = utils.getUrlKey('id')
    let isEdit = utils.getUrlKey('isEdit')
    this.disabled = isEdit == 'r' ? true : false
    if (this.id) {
      req
        .get(window.context.yhxt + '/workOrderInformation/v1/getVo/' + this.id)
        .then(res => {
          console.log(res, '流程数据')
          if (res.data) {
            res.data.type ? (res.data.type = res.data.type + '') : null
            this.form = res.data
            let obj = {
              workOrderInformation: {},
              billOfQuantities: [],
              contract: {},
              defaultBpmCheckOpinion: {}
            }
            if (this.form.diseases) {
              this.isshow = true
              let str = ''
              this.form.diseases.forEach(item => {
                str += item.description + ';'
              })
              this.form.workOrderInformation.description = str
            }
            this.form = {...obj, ...this.form}
            this.tableData = this.form.billOfQuantities
            console.log(this.form, 'this.form')
            this.dadToSon.sourceId = this.form.workOrderInformation.id
            this.source = true
            this.dadToSon.fileList = this.form.accessories
            console.log(this.dadToSon.sourceId, 'this.dadToSon.sourceId')
          }
        })
    }
    let that = this
    window.addEventListener('message', function(e) {
      if (e.data.params) {
        console.log(e.data.params, 'message-relationData')
        that.form.workOrderInformation.description = e.data.params.description
        that.form.workOrderInformation.id = e.data.params.id
      }
    })
    Date.prototype.format = function(fmt) {
      var o = {
        'M+': this.getMonth() + 1, //月份
        'd+': this.getDate(), //日
        'h+': this.getHours(), //小时
        'm+': this.getMinutes(), //分
        's+': this.getSeconds(), //秒
        'q+': Math.floor((this.getMonth() + 3) / 3), //季度
        S: this.getMilliseconds() //毫秒
      }
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(
          RegExp.$1,
          (this.getFullYear() + '').substr(4 - RegExp.$1.length)
        )
      }
      for (var k in o) {
        if (new RegExp('(' + k + ')').test(fmt)) {
          fmt = fmt.replace(
            RegExp.$1,
            RegExp.$1.length == 1
              ? o[k]
              : ('00' + o[k]).substr(('' + o[k]).length)
          )
        }
      }
      return fmt
    }
    this.form.workOrderInformation.issueDate = new Date().format('yyyy-MM-dd')
    // 获取当前登录用户名
    let currentUser = JSON.parse(window.sessionStorage.getItem('currentUser'))
    this.form.workOrderInformation.issuer = currentUser.username
  },
  created() {
    this.getTypeOptions()
    this.getContractId()
  },
  computed: mapState({
    actionUrl: function() {
      //工程图纸中文件上传
      if (this.dialogImageUrl) {
        return window.context.portal + this.dialogImageUrl
      } else {
        return window.context.portal + '/bizAccessory/v1/minioDrawingUpload'
      }
    }
  }),
  methods: {
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePictureCardPreview(file) {
      console.log(file)
      this.dialogImageUrl = file.url
      this.dialogVisible = true
    },
    // imgUrl(url) {
    //   console.log(url)
    //   this.form.accessories = url
    // },
    sonToDad(data) {
      console.log(data)
      this.form.accessories = data
    },
    // 工程清单相关方法 start
    changeAmount(val, index) {
      let currentObj = this.tableData[index]
      currentObj.amount = val
      currentObj.money = currentObj.price * val
      currentObj.auditAmount = val
      currentObj.auditMoney = currentObj.price * val
      this.tableData.splice(index, 1, currentObj)
    },
    changeColNum(val, index, colums, otherCol, totalCol) {
      let currentObj = this.tableData[index]
      currentObj[colums] = val
      currentObj[totalCol] = currentObj[colums] * currentObj[otherCol]
      this.tableData.splice(index, 1, currentObj)
      console.log(this.tableData)
    },
    addListItem() {
      let length = this.tableData.length
      let workOrderInformationId =
        this.form.workOrderInformation && this.form.workOrderInformation.id
          ? this.form.workOrderInformation.id
          : ''
      let contractId =
        this.form.workOrderInformation &&
        this.form.workOrderInformation.contractId
          ? this.form.workOrderInformation.contractId
          : ''
      let newData = {
        // todo 回显时需加上工单id合同id，key
        key: length + 1,
        workOrderInformationId,
        contractId,
        subjectName: '',
        fineSubjectName: '',
        spec: '',
        price: 0,
        amount: 0,
        money: 0,
        auditPrice: 0,
        auditAmount: 0,
        auditMoney: 0,
        receiverPrice: 0,
        receiverAmount: 0,
        receiverMoney: 0
      }
      this.tableData.push(newData)
    },
    deleteListItem(index) {
      this.tableData.splice(index, 1)
    },
    searchSubject(index) {
      if (
        this.form.workOrderInformation &&
        this.form.workOrderInformation.contractId
      ) {
        this.$refs.selectContract.open(
          index,
          this.form.workOrderInformation.contractId
        )
      }
    },
    getContractItem(obj, index) {
      obj.key = index + 1
      obj.workOrderInformationId =
        this.form.workOrderInformation && this.form.workOrderInformation.id
          ? this.form.workOrderInformation.id
          : ''
      obj.auditPrice = obj.price
      this.tableData.splice(index, 1, obj)
    },
    // 工程清单相关方法 end
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url
      // this.dialogVisible = true
    },
    handleFocusDisease() {
      this.$refs.disease.open()
    },
    openDisease() {
      this.$refs.disease.open()
    },
    //选取病害回填数据
    handleSelectDisease(data) {
      console.log(data)
      if (data.id) {
        this.form.workOrderInformation.diseaseId += data.id + ';'
        this.form.workOrderInformation.description += data.description + ';'
        this.form.routeId = data.id
        this.form.createAccount = data.createAccount //创建人账号 运用于流程
        this.form.description = data.description //病号描述
        this.form.createTime = data.createTime //病害创建时间
        this.$refs.diseaseName.focus()
        this.$refs.diseaseName.blur()
      }
    },
    // //字典回调数据
    handleDict(val, obj, str) {
      if (str === 'yhgd-gdlx') {
        this.form.workOrderInformation.typeValue = obj.name
      } else if (str === 'fx') {
        this.form.disease.directionName = obj.name
      }
    },
    handleCancel() {
      this.$emit('handleCancel')
    },
    saveData() {
      const _this = this
      //验证表单是否填写完
      this.form.billOfQuantities = this.tableData
      console.log(this.form, 'ddddddddddddddddd')
      this.$refs.taskManageForm.validate(pass => {
        if (pass) {
          //请求保存提交
          console.log(this.form, 'this.form')
          this.$http
            .post('${yhxt}/workOrderInformation/v1/saveVo', this.form)
            .then(res => {
              console.log(res, 'resresree')
              if (res.data.state) {
                let params = {
                  type: 'saveData',
                  state: true,
                  businessKey: res.data.value.workOrderInformation.id,
                  sysCode: ''
                }
                params.vars = {}
                if (this.form.createAccount) {
                  params.vars.createAccount = this.form.createAccount
                }
                if (this.form.description) {
                  params.vars.description = this.form.description
                }
                if (this.form.createTime) {
                  params.vars.createTime = this.form.createTime
                }
                if (res.data.value.workOrderInformation.jobNumber) {
                  params.vars.jobNumber =
                    res.data.value.workOrderInformation.jobNumber
                }
                console.log(params.vars, '4444444444444444444444')
                hotent.sendMessage(params)
              }
            })
        }
      })
    },
    //路线信息赋值
    changed(obj) {
      // console.log(obj)
      this.form.workOrderInformation.roadSegmentName = obj.name
      this.form.workOrderInformation.roadSegmentId = obj.id
    },
    value(obj) {
      // console.log(obj)
      this.form.workOrderInformation.roadSegmentName = obj.name
      this.form.workOrderInformation.roadSegmentId = obj.id
    },
    //公司赋值
    handleChanged(obj) {
      // console.log(obj.valueInfo.join(','))
      this.form.workOrderInformation.companyIds = JSON.stringify(obj.valueInfo)
      this.form.workOrderInformation.companyName = obj.name
      this.form.workOrderInformation.companyId = obj.id
    },
    companyValue(obj) {
      // console.log(obj)
      this.form.workOrderInformation.companyName = obj.name
      this.form.workOrderInformation.companyId = obj.id
      this.form.workOrderInformation.companyIds = JSON.stringify(
        obj.id.split(' ')
      ) //必须是空格
    },
    changesele(value) {
      console.log(value)
      this.options.forEach(item => {
        if (value == item.value) {
          this.form.workOrderInformation.subjectName = item.label
          this.form.workOrderInformation.categoryId = item.value
        }
      })
      let arr = []
      basicData.getCostAccountManagement(value).then(res => {
        if (res.data.length > 0) {
          res.data.forEach(item => {
            if (item.pcode == value) {
              arr.push({
                label: item.subjectName,
                value: item.subjectCode
              })
            }
            this.cbkm = arr
            this.form.workOrderInformation.detailsId = arr[0].value
            this.form.workOrderInformation.dsubjectName = arr[0].label
          })
        }
      })
    },
    dsubchange(val) {
      console.log(val)
      this.cbkm.forEach(item => {
        if (item.value == val) {
          this.form.workOrderInformation.dsubjectName = item.label
          this.form.workOrderInformation.detailsId = item.value
        }
      })
      this.$forceUpdate()
    },
    //获取类型数据
    getTypeOptions() {
      if (this.options.length == 0) {
        let data = 'CBKM'
        basicData.getCostAccountManagement(data).then(res => {
          res.data.forEach(item => {
            this.options.push({
              label: item.subjectName,
              value: item.subjectCode
            })
          })
        })
      }
    },
    //获取合同信息
    getContractId() {
      basicData.getDailyMaintenanceontract().then(res => {
        this.contractInfoList = res.rows
        console.log(this.contractInfoList)
      })
    },
    //赋值合同名称
    contractChange(val) {
      console.log(val)
      // this.contractInfoList.forEach((item) => {
      //     this.form.workOrderInformation.contractId = item.id
      // })
    }
  }
}
</script>

<style lang="scss" scoped>
.index-inner {
  display: flex;
  justify-content: center;
  height: 100%;
  background-color: #103c5d;
  overflow-x: hidden;
}

.tip {
  display: inline-block;
  width: 6px;
  height: 16px;
  vertical-align: middle;
  margin-right: 6px;
  margin-top: 2px;
  background-color: #211bce;
}

.number {
  font-size: 14px;
  font-weight: bold;
  color: #409fff;
  margin-left: 20px;
}

::v-deep .el-collapse-item__header {
  // border: 0;
  border-bottom: 1px solid #eee;
  font-size: 16px;
}

::v-deep .el-collapse {
  border: 0;
  border-top: 1px solid #fff;
}

::v-deep .el-collapse-item__content {
  padding-top: 10px;
  padding-bottom: 0;
}

.el-dialog-footer {
  padding: 10px 20px 20px;
  text-align: right;
  box-sizing: border-box;
}

.img-box {
  width: 150px;
  height: 150px;
  border: 1px solid #eee;
  margin: 5px;
  display: inline-block;

  img {
    width: 100%;
    height: 100%;
    display: inline-block;
  }
}
</style>
