<template>
  <div class="index-inner">
    <el-form
      style="padding: 20px; width: 100%"
      :model="form"
      label-width="110px"
      data-vv-scope="taskManageForm"
      ref="taskManageForm"
      :rules="rules"
      :disabled="readDetaial"
    >
      <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
                    dictCode="yhgd-gdlx"
                    :hasDefaultOption="true"
                    clearable
                    @input="(val, obj) => handleDict(val, obj, 'yhgd-gdlx')"
                    v-model="form.workOrderInformation.type"
                    style="width: 100%"
                    :disabled="disabledCreated"
                  />
                </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"
                    :value="form.workOrderInformation.roadSegmentName"
                    @changed="changed"
                    @value="value"
                    :disabledCreated="disabledCreated"
                  />
                </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"
                    :valueName="form.companyIds"
                    @handleChanged="handleChanged"
                    @value="companyValue"
                    :disabledCreated="disabledCreated"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="位置" prop="workOrderInformation.position">
                  <el-input
                    :disabled="disabledCreated"
                    v-model="form.workOrderInformation.position"
                  ></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"
                    placeholder="请选择合同"
                    style="width: 100%"
                    @change="contractChange"
                    :disabled="disabledCreated"
                  >
                    <el-option
                      v-for="item in contractInfoList"
                      :value="item.id"
                      :label="item.name"
                      :key="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"
                    placeholder="请选择"
                    @change="changesele"
                    style="width: 100%"
                    :disabled="disabledCreated"
                  >
                    <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"
                    placeholder="请选择"
                    style="width: 100%"
                    :disabled="disabledCreated"
                  >
                    <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"
                    type="date"
                    placeholder="选择日期"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    style="width: 100%"
                    :disabled="disabledCreated"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="签发人" prop="workOrderInformation.issuer">
                  <el-input
                    :disabled="disabledCreated"
                    v-model="form.workOrderInformation.issuer"
                  ></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"
                    type="date"
                    placeholder="选择日期"
                    format="yyyy-MM-dd"
                    value-format="yyyy-MM-dd"
                    style="width: 100%"
                    :disabled="disabledCreated"
                  >
                  </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"
                    type="textarea"
                    rows="3"
                    :disabled="disabledCreated"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24" v-if="currentNode == 1">
                <el-form-item
                  label="关联病害"
                  prop="workOrderInformation.description"
                >
                  <el-input
                    v-model="form.workOrderInformation.description"
                    placeholder="选择关联病害"
                    ref="diseaseName"
                    @focus="handleFocusDisease"
                    clearable
                    :disabled="disabledCreated"
                  >
                    <el-button
                      type="primary"
                      @click="openDisease"
                      slot="append"
                      icon="el-icon-search"
                    ></el-button>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
        </el-collapse-item>
        <el-collapse-item
          name="2"
          v-if="
            (currentNode == 2 ||
              currentNode == 3 ||
              currentNode == 4 ||
              currentNode == 5 ||
              currentNode == 6) &&
              isshow
          "
        >
          <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
                    dictCode="xjlb"
                    :hasDefaultOption="true"
                    v-model="item.type"
                    style="width: 100%"
                    disabled
                  />
                  <!-- <el-input
                    disabled
                    v-model="item.typeName"
                  ></el-input> -->
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="方向">
                  <dict-select
                    dictCode="qlfx"
                    :hasDefaultOption="true"
                    clearable
                    v-model="item.direction"
                    style="width: 100%"
                    disabled
                  />
                  <!-- <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 disabled v-model="item.startPeg"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="止点桩号">
                  <el-input disabled v-model="item.endPeg"></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"
                    placeholder="请选择"
                    @change="val => changesele(val)"
                    disabled
                    style="width: 100%"
                  >
                    <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"
                    placeholder="请选择"
                    disabled
                    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
                    dictCode="bhbw"
                    :hasDefaultOption="true"
                    clearable
                    v-model="item.positionName"
                    style="width: 100%"
                    disabled
                  />
                  <!-- <el-input
                    disabled
                    v-model="item.positionName"
                  ></el-input> -->
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="处理情况">
                  <el-input
                    disabled
                    v-model="item.handlingSituation"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="病害描述">
                  <el-input disabled v-model="item.description"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="病害 长(mm)">
                  <el-input disabled v-model="item.paramLength"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="病害 宽(mm)">
                  <el-input disabled v-model="item.paramWidth"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="病害 高(mm)">
                  <el-input disabled v-model="item.paramHeight"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label="病害照片列表">
                  <div
                    class="img-box"
                    v-for="(itemImg, index) in item.accessories"
                    :key="index"
                  >
                    <img :src="itemImg.url" :key="itemImg.id" />
                  </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
          name="3"
          v-if="
            currentNode == 3 ||
              currentNode == 4 ||
              currentNode == 5 ||
              currentNode == 6
          "
        >
          <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
                    :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"
                  >
                  </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
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    v-model="form.workOrderInformation.constructionStartPegK"
                  ></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item
                  label="止点桩号"
                  prop="workOrderInformation.constructionEndPegK"
                >
                  <el-input
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    v-model="form.workOrderInformation.constructionEndPegK"
                  ></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
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    v-model="form.workOrderInformation.constructionDesc"
                    type="textarea"
                    rows="3"
                  ></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-card>
        </el-collapse-item>
        <el-collapse-item
          name="4"
          v-if="
            currentNode == 3 ||
              currentNode == 4 ||
              currentNode == 5 ||
              currentNode == 6
          "
        >
          <template slot="title">
            <span class="tip"></span>关联信息、工程量清单
          </template>
          <el-card style="max-width: 100%; box-sizing: border-box">
            <el-button
              type="primary"
              @click="addListItem"
              style="margin-bottom: 20px"
              icon="el-icon-plus"
              :disabled="currentNode == 4"
            >
              添加</el-button
            >

            <el-table
              :data="tableData"
              border
              stripe
              style="max-width: 100%; min-width: 100%"
              max-height="360"
            >
              <el-table-column
                prop="subjectName"
                label="科目名称"
                min-width="130"
                fixed="left"
              >
                <template slot-scope="scope">
                  <el-input
                    readonly
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    v-model="scope.row.subjectName"
                    suffix-icon="el-icon-search"
                    @focus="searchSubject(scope.$index)"
                  >
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column
                prop="fineSubjectName"
                label="细科目名称"
                min-width="130"
                fixed="left"
                ><template slot-scope="scope">
                  <el-input
                    disabled
                    v-model="scope.row.fineSubjectName"
                  ></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="spec" label="单位" min-width="130">
                <template slot-scope="scope">
                  <el-input disabled v-model="scope.row.spec"></el-input>
                </template>
              </el-table-column>
              <el-table-column prop="price" label="单价(元)" min-width="130">
                <template slot-scope="scope">
                  <el-input-number
                    disabled
                    :min="0"
                    :precision="2"
                    class="input-number"
                    :controls="false"
                    v-model="scope.row.price"
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column prop="amount" label="数量" min-width="130">
                <template slot-scope="scope">
                  <el-input-number
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    :min="0"
                    class="input-number"
                    controls-position="right"
                    v-model="scope.row.amount"
                    @change="val => changeAmount(val, scope.$index)"
                  >
                  </el-input-number>
                </template>
              </el-table-column>
              <el-table-column prop="money" label="金额(元)" min-width="140">
                <template slot-scope="scope">
                  <el-input-number
                    disabled
                    :min="0"
                    :precision="2"
                    class="input-number"
                    :controls="false"
                    v-model="scope.row.money"
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                prop="auditPrice"
                label="审核单价(元)"
                min-width="130"
              >
                <template slot-scope="scope">
                  <el-input-number
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    :min="0"
                    :precision="2"
                    class="input-number"
                    :controls="false"
                    v-model="scope.row.auditPrice"
                    @change="
                      val =>
                        changeColNum(
                          val,
                          scope.$index,
                          'auditPrice',
                          'auditAmount',
                          'auditMoney'
                        )
                    "
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                prop="auditAmount"
                label="审核数量"
                min-width="130"
              >
                <template slot-scope="scope">
                  <el-input-number
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    :min="0"
                    class="input-number"
                    controls-position="right"
                    v-model="scope.row.auditAmount"
                    @change="
                      val =>
                        changeColNum(
                          val,
                          scope.$index,
                          'auditAmount',
                          'auditPrice',
                          'auditMoney'
                        )
                    "
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                prop="auditMoney"
                label="审核金额(元)"
                min-width="140"
              >
                <template slot-scope="scope">
                  <el-input-number
                    disabled
                    :min="0"
                    :precision="2"
                    class="input-number"
                    :controls="false"
                    v-model="scope.row.auditMoney"
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                prop="receiverPrice"
                label="收方单价"
                min-width="130"
              >
                <template slot-scope="scope">
                  <el-input-number
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    :min="0"
                    :precision="2"
                    class="input-number"
                    :controls="false"
                    v-model="scope.row.receiverPrice"
                    @change="
                      val =>
                        changeColNum(
                          val,
                          scope.$index,
                          'receiverPrice',
                          'receiverAmount',
                          'receiverMoney'
                        )
                    "
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                prop="receiverAmount"
                label="收方数量"
                min-width="130"
              >
                <template slot-scope="scope">
                  <el-input-number
                    :disabled="
                      currentNode == 4 || currentNode == 5 || currentNode == 6
                    "
                    :min="0"
                    class="input-number"
                    controls-position="right"
                    v-model="scope.row.receiverAmount"
                    @change="
                      val =>
                        changeColNum(
                          val,
                          scope.$index,
                          'receiverAmount',
                          'receiverPrice',
                          'receiverMoney'
                        )
                    "
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                prop="receiverMoney"
                label="收方金额(元)"
                min-width="140"
              >
                <template slot-scope="scope">
                  <el-input-number
                    disabled
                    :min="0"
                    :precision="2"
                    class="input-number"
                    :controls="false"
                    v-model="scope.row.receiverMoney"
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column
                label="操作"
                fixed="right"
                width="80"
                align="center"
              >
                <template slot-scope="scope">
                  <el-button
                    type="danger"
                    size="small"
                    icon="el-icon-delete"
                    @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;
}
/deep/ .el-collapse-item__header {
  // border: 0;
  border-bottom: 1px solid #eee;
  font-size: 16px;
}
/deep/ .el-collapse {
  border: 0;
  border-top: 1px solid #fff;
}
/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>
