<template>
  <div>
    <div class="divborder newSearchDiv">
      <div class="filter">
        <label>{{ $t(1132) }}：</label>
        <Cascader
          :data="datalevel"
          :value="leveldata"
          trigger="click"
          change-on-select
          class="searchSelect"
          @on-change="changelevel"
        ></Cascader>
      </div>
      <div class="filter">
        <label>{{ $t(800191) }}：</label>
        <Select
          v-model="filterObj.typeMode"
          label-in-value
          clearable
          class="searchSelect"
        >
          <Option
            v-for="(value, key) in initPageData.defendTypeList"
            :value="key"
            :key="key"
            >{{ value }}</Option
          >
        </Select>
      </div>
      <div class="filter">
        <label>{{ $t(1115) }}：</label>
        <Select
          v-model="filterObj.valueType"
          label-in-value
          clearable
          class="searchSelect"
        >
          <Option
            v-for="(value, key) in initPageData.projectTypeList"
            :value="key"
            :key="key"
            >{{ value }}</Option
          >
        </Select>
      </div>
      <div class="filter">
        <label>{{ $t(950330) }}：</label>
        <Select
          v-if="filterObj.typeMode === '2' || filterObj.typeMode === '3'"
          v-model="filterObj.import"
          label-in-value
          clearable
          class="searchSelect"
        >
          <Option
            v-for="(item, key) in datalist2"
            :value="item.value"
            :key="key"
            >{{ item.name }}</Option
          >
        </Select>
        <Select
          v-else
          v-model="filterObj.import"
          label-in-value
          clearable
          class="searchSelect"
        >
          <Option
            v-for="(item, key) in datalist1"
            :value="item.value"
            :key="key"
            >{{ item.name }}</Option
          >
        </Select>
      </div>
      <div v-show="!morecondition">
        <div>
          <div class="filter">
            <label>{{ $t(1117) }}：</label>
            <Select
              v-model="filterObj.instructionCycle"
              label-in-value
              clearable
              class="searchSelect"
            >
              <Option
                v-for="(value, key) in initPageData.instructionCycleList"
                :value="key"
                :key="key"
                >{{ value }}</Option
              >
            </Select>
          </div>
          <div class="filter">
            <label>{{ $t(200154) }}：</label>
            <Select
              v-model="filterObj.dateRang"
              label-in-value
              clearable
              class="searchSelect"
            >
              <Option
                v-for="(value, key) in initPageData.dateRangList"
                :value="key"
                :key="key"
                >{{ value }}</Option
              >
            </Select>
          </div>
          <div class="filter">
            <label>{{ $t(100000) }}：</label>
            <Select
              v-model="filterObj.department"
              @on-change="changeDepartment($event, 'filter')"
              label-in-value
              clearable
              class="searchSelect"
            >
              <Option
                v-for="item in initPageData.departmentList"
                :value="item.id"
                :key="item.id"
                >{{ item.title }}</Option
              >
            </Select>
          </div>
          <div class="filter">
            <label>{{ $t(100046) }}：</label>
            <Select
              v-model="filterObj.user"
              label-in-value
              clearable
              class="searchSelect"
            >
              <Option
                v-for="item in initPageData.userList"
                :value="item.id"
                :key="item.id"
                >{{ item.name }}</Option
              >
            </Select>
          </div>
        </div>
        <div>
          <div class="filter">
            <label>{{ $t(200054) }}：</label>
            <Select
              v-model="filterObj.states"
              label-in-value
              clearable
              class="searchSelect"
            >
              <Option
                v-for="(item, key) in initPageData.statesList"
                :value="item.value"
                :key="key"
                >{{ item.name }}</Option
              >
            </Select>
          </div>
          <div class="filter">
            <label> <span v-text="$t('100040')">创建人</span>： </label>
            <Select
              v-model="filterObj.creator"
              filterable
              clearable
              remote
              :remote-method="initmidlist"
              class="searchSelect"
            >
              <Option
                v-for="item in midlist"
                :value="item.mid"
                :key="item.mid"
                >{{ item.name }}</Option
              >
            </Select>
          </div>
        </div>
      </div>
      <div class="searchBtn">
        <Button
          type="primary"
          class="twoWord"
          icon="ios-search"
          @click="search(1, pagesize)"
          >{{ $t("1001") }}</Button
        >
        <Button
          type="success"
          class="twoWord"
          icon="md-add-circle"
          @click="add()"
          >{{ $t("1002") }}</Button
        >
        <Button
          type="warning"
          class="twoWord"
          icon="ios-create-outline"
          @click="edit()"
          >{{ $t("1003") }}</Button
        >
        <Button
          type="error"
          class="twoWord intervalRight"
          icon="md-close-circle"
          @click="del()"
          >{{ $t("1004") }}</Button
        >
        <Button
          type="primary"
          class="fiveWord intervalRight"
          icon="ios-create-outline"
          @click="setExecutor()"
          >{{ $t("200206") }}</Button
        >
        <Button
          type="primary"
          class="fourWord"
          icon="md-download"
          @click="loadexcel()"
          >{{ $t("1005") }}</Button
        >
        <Upload
          style="display: inline-block"
          ref="upload"
          :action="action"
          name="excel-file"
          :headers="headers"
          :show-upload-list="false"
          :on-format-error="handleFormatError"
          :on-success="handleSuccess"
          :on-error="handleError"
          :format="['xlsx']"
        >
          <Button class="fourWord" icon="md-cloud-upload" type="primary">{{
            $t("upload-excel")
          }}</Button>
        </Upload>
        <Button
          type="primary"
          class="fourWord"
          icon="md-arrow-round-up"
          @click="toExcel()"
          >{{ $t("1007") }}</Button
        >
      </div>
      <MoreConbtn
        @getCon="morecondition = !morecondition"
        :morecondition="morecondition"
      ></MoreConbtn>
    </div>

    <div class="divborder newTableDiv">
      <Table
        class="tableClass"
        @on-selection-change="changeMultipleSelection"
        @on-current-change="handleRowChange"
        highlight-row
        :data="tableData1"
        :columns="tableColumns1"
      ></Table>
      <div class="pageDiv">
        <div class="pageDirection">
          <Page
            :total="total"
            :current="page"
            @on-change="changePage"
            show-elevator
            show-sizer
            show-total
            @on-page-size-change="handlePageSize"
            :page-size-opts="[10, 20, 30, 40, 100]"
          ></Page>
        </div>
      </div>
    </div>

    <!-- 添加模态框开始 -->
    <Modal class="newModalClass" v-model="addModal" :width="700">
      <p slot="header">
        <span>{{ $t("1002") }}</span>
      </p>
      <div class="modal_body defindlist">
        <div>
          <div>
            <Row>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("1025") }}：
                  </label>
                  <Cascader
                    class="searchInput"
                    :data="datalevel"
                    :value="add_leveldata"
                    trigger="click"
                    @on-change="handlelevelchange"
                  ></Cascader>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("960432") }}：
                  </label>
                  <Cascader
                    class="searchInput"
                    :data="datamachine"
                    :value="machinedata"
                    trigger="click"
                    change-on-select
                    @on-change="handlemachinechange"
                  ></Cascader>
                </div>
              </Col>
            </Row>

            <Row>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("800191") }}：
                  </label>
                  <Select
                    v-model="addObj.typemode"
                    :disabled="optType != 'add'"
                    label-in-value
                    class="searchSelect"
                    @on-change="changetypemode"
                  >
                    <Option
                      v-for="(value, key) in initPageData.defendTypeList"
                      :value="key"
                      :key="key"
                      >{{ value }}</Option
                    >
                  </Select>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("200058") }}：
                  </label>
                  <Input
                    class="searchInput"
                    type="text"
                    v-model="addObj.content"
                  />
                </div>
              </Col>
            </Row>

            <Row>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("1115") }}：
                  </label>
                  <Select
                    v-model="addObj.value_type"
                    label-in-value
                    class="searchSelect"
                  >
                    <Option
                      v-for="(value, key) in initPageData.projectTypeList"
                      :value="key"
                      :key="key"
                      >{{ value }}</Option
                    >
                  </Select>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("950330") }}：
                  </label>
                  <!-- <Select v-model="addObj.severity_level" label-in-value style="width:250px;display:block">
                                              <Option v-for="(value,key) in initPageData.levelList" :value="key" :key="key">{{value}}</Option>
                  </Select>-->
                  <Select
                    v-if="addObj.typemode === '2' || addObj.typemode === '3'"
                    v-model="addObj.severity_level"
                    label-in-value
                    clearable
                    class="searchSelect"
                  >
                    <Option
                      v-for="(item, key) in datalist2"
                      :value="item.value"
                      :key="key"
                      >{{ item.name }}</Option
                    >
                  </Select>
                  <Select
                    v-else
                    v-model="addObj.severity_level"
                    label-in-value
                    clearable
                    class="searchSelect"
                  >
                    <Option
                      v-for="(item, key) in datalist1"
                      :value="item.value"
                      :key="key"
                      >{{ item.name }}</Option
                    >
                  </Select>
                </div>
              </Col>
            </Row>

            <Row v-show="addObj.value_type === '2'">
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("200017") }}：
                  </label>
                  <Input
                    class="searchInput"
                    type="text"
                    v-model="addObj.unit"
                  />
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("200059") }}：
                  </label>
                  <InputNumber
                    v-model="addObj.up_limit"
                    :min="1"
                    class="searchInput"
                  ></InputNumber>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("200060") }}：
                  </label>
                  <InputNumber
                    v-model="addObj.lower_limit"
                    :min="1"
                    class="searchInput"
                  ></InputNumber>
                </div>
              </Col>
            </Row>

            <Row>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("200063") }}：
                  </label>
                  <InputNumber
                    v-model="addObj.standard_time"
                    :min="0"
                    class="searchInput"
                  ></InputNumber>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("1117") }}：
                  </label>
                  <Select
                    v-model="addObj.instruction_cycle"
                    :disabled="addObj.typemode === '3'"
                    label-in-value
                    clearable
                    class="searchSelect"
                  >
                    <Option
                      v-for="(value, key) in initPageData.instructionCycleList"
                      :value="key"
                      :key="key"
                      >{{ value }}</Option
                    >
                  </Select>
                </div>
              </Col>
            </Row>

            <Row>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("900745") }}：
                  </label>
                  <DatePicker
                    type="date"
                    v-model="addObj.first_instruction_time"
                    format="yyyy-MM-dd"
                    placement="top-start"
                    split-panels
                    class="searchInput"
                  ></DatePicker>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>{{ $t("200022") }}：</label>
                  <Select
                    v-model="addObj.failmode"
                    label-in-value
                    class="searchSelect"
                  >
                    <Option
                      v-for="item in initPageData.failmodeList"
                      :value="item.id"
                      :key="item.id"
                      >{{ item.faulttype }}</Option
                    >
                  </Select>
                </div>
              </Col>
            </Row>

            <Row>
              <Col span="12">
                <div class="filter" style="height: 100px !important">
                  <label style="vertical-align: top">
                    <i>*</i>
                    {{ $t("200002") }}：
                  </label>
                  <RadioGroup
                    v-model="addObj.datetype"
                    vertical
                    @on-change="radioChange()"
                  >
                    <Radio label="1" :disabled="addObj.typemode === '3'">
                      <span>{{ $t(200151) }}</span>
                    </Radio>
                    <Radio label="2" :disabled="addObj.typemode === '3'">
                      <span>{{ $t(200152) }}</span>
                    </Radio>
                    <Radio label="3" :disabled="addObj.typemode === '3'">
                      <span>{{ $t(200153) }}</span>
                    </Radio>
                  </RadioGroup>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <div
                    v-show="addObj.datetype === '2'"
                    style="margin-top: 35px"
                  >
                    <DatePicker
                      type="daterange"
                      v-model="addObj.datetime1"
                      format="yyyy-MM-dd"
                      placement="top-start"
                      split-panels
                      class="searchInput middleWidth"
                    ></DatePicker>
                  </div>
                  <div
                    v-show="addObj.datetype === '3'"
                    style="margin-top: 60px"
                  >
                    <inputNumber
                      v-model="addObj.count"
                      :min="1"
                      class="searchInput"
                      :disabled="addObj.typemode === '3'"
                    ></inputNumber>
                  </div>
                </div>
              </Col>
            </Row>
            <Row>
              <Col span="12">
                <div class="filter">
                  <label>{{ $t("950339") }}：</label>
                  <Input
                    class="searchInput"
                    type="text"
                    v-model="addObj.maintain_sparepart"
                  />
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>{{ $t("950337") }}：</label>
                  <Input
                    class="searchInput"
                    type="text"
                    v-model="addObj.maintain_tool"
                  />
                </div>
              </Col>
            </Row>
            <Row>
              <Col span="24">
                <div>
                  <label
                    style="width: 120px; text-align: right; margin-right: 5px"
                    >{{ $t("1030") }}：</label
                  >
                  <Input
                    style="display: inline-block; width: 444px"
                    type="textarea"
                    maxlength="120"
                    show-word-limit
                    :autosize="{ minRows: 4, maxRows: 4 }"
                    v-model="addObj.remark"
                  /></div
              ></Col>
            </Row>
            <Row>
              <Col span="24">
                <div class="filter">
                  <label
                    style="width: 300px !important; text-align: left !important"
                    >{{ $t("900803") }}：</label
                  >
                  <FileUpload
                    :uList="addObj.work"
                    :key="'work'"
                    @activeName="outFileUploadChild($event)"
                    v-model="addObj.work"
                  ></FileUpload>
                </div>
              </Col>
            </Row>
          </div>
        </div>
      </div>
      <div slot="footer">
        <Button
          type="text"
          size="large"
          @click="addModal = false"
          v-text="$t('1033')"
          >取消</Button
        >
        <Button type="primary" size="large" @click="adddata" v-text="$t('1011')"
          >确定</Button
        >
      </div>
    </Modal>
    <!-- 添加模态框结束 -->
    <!-- 修改模态框开始 -->
    <Modal class="newModalClass" v-model="editModal" :width="700">
      <p slot="header">
        <span>{{ $t("1003") }}</span>
      </p>
      <div class="modal_body defindlist">
        <div>
          <div>
            <Row>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("800191") }}：
                  </label>
                  <Select
                    v-model="editObj.typemode"
                    disabled
                    label-in-value
                    class="searchSelect"
                    @on-change="changetypemode"
                  >
                    <Option
                      v-for="(value, key) in initPageData.defendTypeList"
                      :value="key"
                      :key="key"
                      >{{ value }}</Option
                    >
                  </Select>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("200058") }}：
                  </label>
                  <Input
                    class="searchInput"
                    type="text"
                    v-model="editObj.content"
                  />
                </div>
              </Col>
            </Row>

            <Row>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("1115") }}：
                  </label>
                  <Select
                    v-model="editObj.value_type"
                    label-in-value
                    class="searchSelect"
                  >
                    <Option
                      v-for="(value, key) in initPageData.projectTypeList"
                      :value="key"
                      :key="key"
                      >{{ value }}</Option
                    >
                  </Select>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("950330") }}：
                  </label>
                  <Select
                    v-if="editObj.typemode === '2' || editObj.typemode === '3'"
                    v-model="editObj.severity_level"
                    label-in-value
                    clearable
                    class="searchSelect"
                  >
                    <Option
                      v-for="(item, key) in datalist2"
                      :value="item.value"
                      :key="key"
                      >{{ item.name }}</Option
                    >
                  </Select>
                  <Select
                    v-else
                    v-model="editObj.severity_level"
                    label-in-value
                    clearable
                    class="searchSelect"
                  >
                    <Option
                      v-for="(item, key) in datalist1"
                      :value="item.value"
                      :key="key"
                      >{{ item.name }}</Option
                    >
                  </Select>
                </div>
              </Col>
            </Row>

            <Row v-show="editObj.value_type === '2'">
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("200059") }}：
                  </label>
                  <InputNumber
                    v-model="editObj.up_limit"
                    :min="1"
                    class="searchInput"
                  ></InputNumber>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("200017") }}：
                  </label>
                  <Input
                    class="searchInput"
                    type="text"
                    v-model="editObj.unit"
                  />
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("200060") }}：
                  </label>
                  <InputNumber
                    v-model="editObj.lower_limit"
                    :min="1"
                    class="searchInput"
                  ></InputNumber>
                </div>
              </Col>
            </Row>

            <Row>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("200063") }}：
                  </label>
                  <InputNumber
                    v-model="editObj.standard_time"
                    :min="0"
                    class="searchInput"
                  ></InputNumber>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("1117") }}：
                  </label>
                  <Select
                    v-model="editObj.instruction_cycle"
                    :disabled="editObj.typemode === '3'"
                    label-in-value
                    clearable
                    class="searchSelect"
                  >
                    <Option
                      v-for="(value, key) in initPageData.instructionCycleList"
                      :value="key"
                      :key="key"
                      >{{ value }}</Option
                    >
                  </Select>
                </div>
              </Col>
            </Row>

            <Row>
              <Col span="12">
                <div class="filter">
                  <label>
                    <i>*</i>
                    {{ $t("900745") }}：
                  </label>
                  <DatePicker
                    type="date"
                    v-model="editObj.first_instruction_time"
                    format="yyyy-MM-dd"
                    placement="top-start"
                    split-panels
                    class="searchInput"
                  ></DatePicker>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>{{ $t("200022") }}：</label>
                  <Select
                    v-model="editObj.failmode"
                    label-in-value
                    class="searchSelect"
                  >
                    <Option
                      v-for="item in initPageData.failmodeList"
                      :value="item.id"
                      :key="item.id"
                      >{{ item.faulttype }}</Option
                    >
                  </Select>
                </div>
              </Col>
            </Row>

            <Row>
              <Col span="12">
                <div class="filter" style="height: 100px !important">
                  <label style="vertical-align: top">
                    <i>*</i>
                    {{ $t("200002") }}：
                  </label>
                  <RadioGroup
                    v-model="editObj.datetype"
                    vertical
                    @on-change="radioChange()"
                  >
                    <Radio label="1" :disabled="editObj.typemode === '3'">
                      <span>{{ $t(200151) }}</span>
                    </Radio>
                    <Radio label="2" :disabled="editObj.typemode === '3'">
                      <span>{{ $t(200152) }}</span>
                    </Radio>
                    <Radio label="3" :disabled="editObj.typemode === '3'">
                      <span>{{ $t(200153) }}</span>
                    </Radio>
                  </RadioGroup>
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <div
                    v-show="editObj.datetype === '2'"
                    style="margin-top: 35px"
                  >
                    <DatePicker
                      type="daterange"
                      v-model="editObj.datetime1"
                      format="yyyy-MM-dd"
                      placement="top-start"
                      split-panels
                      class="searchInput"
                    ></DatePicker>
                  </div>
                  <div
                    v-show="editObj.datetype === '3'"
                    style="margin-top: 60px"
                  >
                    <Input
                      v-model="editObj.count"
                      type="number"
                      :min="1"
                      :disabled="editObj.typemode === '3'"
                      class="searchInput"
                    />
                  </div>
                </div>
              </Col>
            </Row>

            <Row>
              <Col span="12">
                <div class="filter">
                  <label>{{ $t("950339") }}：</label>
                  <Input
                    class="searchInput"
                    type="text"
                    v-model="editObj.maintain_sparepart"
                  />
                </div>
              </Col>
              <Col span="12">
                <div class="filter">
                  <label>{{ $t("950337") }}：</label>
                  <Input
                    class="searchInput"
                    type="text"
                    v-model="editObj.maintain_tool"
                  />
                </div>
              </Col>
            </Row>
            <Row>
              <Col span="24">
                <div>
                  <label
                    style="width: 120px; text-align: right; margin-right: 5px"
                    >{{ $t("1030") }}：</label
                  >
                  <Input
                    style="display: inline-block; width: 444px"
                    type="textarea"
                    maxlength="120"
                    show-word-limit
                    :autosize="{ minRows: 4, maxRows: 4 }"
                    v-model="editObj.remark"
                  />
                </div>
              </Col>
            </Row>
            <Row>
              <Col span="24">
                <div class="filter">
                  <label
                    style="width: 300px !important; text-align: left !important"
                    >{{ $t("900803") }}：</label
                  >
                  <FileUpload
                    :uList="editObj.work"
                    :key="'work'"
                    @activeName="outFileUploadChild1($event)"
                    v-model="editObj.work"
                  ></FileUpload>
                </div>
              </Col>
            </Row>
          </div>
        </div>
      </div>
      <div slot="footer">
        <Button
          type="text"
          size="large"
          @click="editModal = false"
          v-text="$t('1033')"
          >取消</Button
        >
        <Button
          type="primary"
          size="large"
          @click="editdata"
          v-text="$t('1011')"
          >确定</Button
        >
      </div>
    </Modal>
    <!-- 添加模态框结束 -->

    <Modal v-model="modal1" :title="$t(900743)" @on-ok="ok">
      <img :src="workUrl" alt style="width: 100%" />
    </Modal>

    <Modal
      class="newModalClass"
      :title="$t(200206)"
      v-model="setExecutorModel"
      @on-ok="handlerSetExecutor('setExecutorObj')"
      :loading="loading"
      :width="400"
    >
      <div class="modal_body" style="height: 100px">
        <Form
          ref="setExecutorObj"
          :model="setExecutorObj"
          label-position="right"
          :label-width="80"
        >
          <FormItem :label="$t(200207)" class="ml10 clear">
            <Select
              v-model="setExecutorObj.department"
              :transfer="transferx"
              @on-change="changeDepartment($event, 'setExecutor')"
              label-in-value
              clearable
              class="searchSelect"
            >
              <Option
                v-for="item in initPageData.departmentList"
                :value="item.id"
                :key="item.id"
                >{{ item.title }}</Option
              >
            </Select>
          </FormItem>
          <FormItem :label="$t(200208)" class="ml10 clear">
            <Select
              v-model="setExecutorObj.users"
              :transfer="transferx"
              multiple
              class="searchSelect nowropStyle"
            >
              <Option
                v-for="item in setExecutorObj.userList"
                :value="item.id"
                :key="item.id"
                >{{ item.name }}</Option
              >
            </Select>
          </FormItem>
        </Form>
      </div>
    </Modal>

    <Modal
      :title="$t(200194)"
      v-model="changeExecutorModel"
      @on-ok="handlerChangeExecutor('changeExecutorObj')"
      :loading="loading"
      :styles="{ top: '40px', width: '600px' }"
    >
      <div
        class="modal_body"
        style="
          width: 100% !important;
          height: 380px !important;
          padding: 0 10px;
          overflow: hidden;
        "
      >
        <Form
          ref="changeExecutorObj"
          :model="changeExecutorObj"
          label-position="top"
        >
          <Row type="flex" justify="space-between" class="code-row-bg">
            <Col span="10" style="overflow-y: auto">
              <Table
                width="100%"
                @on-current-change="handleChangeExecutorRowChange"
                highlight-row
                :data="changeExecutorObj.planTimes"
                :columns="tableColumns2"
              ></Table>
            </Col>
            <Col span="14" class="pl20">
              <FormItem :label="$t(900745)" class="fl ml10 clear">
                <DatePicker
                  type="date"
                  v-model="changeExecutorObj.instruction_time"
                  format="yyyy-MM-dd"
                  placement="top-start"
                  split-panels
                  placeholder="Select date"
                  style="width: 120px"
                ></DatePicker>
              </FormItem>
              <FormItem :label="$t(200207)" class="fl ml10 clear">
                <Select
                  v-model="changeExecutorObj.department"
                  @on-change="changeDepartment($event, 'changeExecutor')"
                  label-in-value
                  clearable
                  style="width: 160px"
                >
                  <Option
                    v-for="item in initPageData.departmentList"
                    :value="item.id"
                    :key="item.id"
                    >{{ item.title }}</Option
                  >
                </Select>
              </FormItem>
              <FormItem :label="$t(200208)" class="fl ml10 clear">
                <Select v-model="changeExecutorObj.user" style="width: 200px">
                  <Option
                    v-for="item in changeExecutorObj.userList"
                    :value="item.id"
                    :key="item.id"
                    >{{ item.name }}</Option
                  >
                </Select>
              </FormItem>
            </Col>
          </Row>
        </Form>
      </div>
    </Modal>
  </div>
</template>

<script>
import axios from "@/libs/api.request";
import moment from "moment";
import FileUpload from "_c/file-upload/file-upload.vue";

export default {
  inject: ["reload"],
  name: "tpm-defend-list",
  components: {
    FileUpload,
  },
  data() {
    const validateTypeMode = (rule, value, callback) => {
      // 正整数
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(930117)));
      }
    };
    const validateValueType = (rule, value, callback) => {
      // 正整数
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(930118)));
      }
    };
    const validateSeverityLevel = (rule, value, callback) => {
      // 正整数
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(930119)));
      }
    };
    const validateUpLimit = (rule, value, callback) => {
      // 上限
      if (this.addObj.value_type === "2") {
        if (/^[1-9]\d*$/.test(value)) {
          if (value < this.addObj.lower_limit) {
            return callback(new Error(this.$t(920101)));
          }
          callback();
        } else {
          return callback(new Error(this.$t(930120)));
        }
      } else {
        callback();
      }
    };
    const validateLowerLimit = (rule, value, callback) => {
      // 下限
      if (this.addObj.value_type === "2") {
        if (/^[1-9]\d*$/.test(value)) {
          callback();
        } else {
          return callback(new Error(this.$t(930121)));
        }
      } else {
        callback();
      }
    };
    const validateUnit = (rule, value, callback) => {
      // 下限
      if (this.addObj.value_type === "2") {
        if (value != "") {
          callback();
        } else {
          return callback(new Error(this.$t(100106)));
        }
      } else {
        callback();
      }
    };
    const validateStandardTime = (rule, value, callback) => {
      // 正整数
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(930122)));
      }
    };
    const validateInstructionCycle = (rule, value, callback) => {
      // 正整数
      if (/^[1-9]\d*$/.test(value) || value === undefined) {
        callback();
      } else {
        return callback(new Error(this.$t(200156)));
      }
    };
    const validateDateType = (rule, value, callback) => {
      // 正整数
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(930123)));
      }
    };
    const validateFirstInstructionTime = (rule, value, callback) => {
      // 正整数
      if (value != "") {
        callback();
      } else {
        return callback(new Error(this.$t(930080)));
      }
    };

    return {
      action:
        this.axios.publicPath +
        "tpm/Upload/Submit?templateName=LevelPlanListSkf",
      transferx: true, // 优化下拉框
      leveldata: [], // 产线层级插件所需数据
      datalevel: [], // 产线层级选中数据
      levelid: 0, // 产线层级选中的section_id
      add_leveldata: [], // 添加产线层级value
      machinedata: [], // 设备层级value
      datamachine: [], // 设备层级
      add_machine: 0, // 添加模态框的设备层级id
      ids: [], // 选择数据的id集合
      add_value_type_cycle: false, // 执行周期
      morecondition: false,
      filterObj: {
        typeMode: 0,
        valueType: 0,
        import: 0,
        instructionCycle: 0,
        dateRang: 0,
        department: 0,
        user: 0,
        creator: 0,
      },
      midlist: [], // 创建人list
      initPageData: {
        departmentList: [],
        userList: [],
        defendTypeList: {
          1: "AM",
          2: "PM",
          3: "CMP",
        },
        projectTypeList: {
          1: this.$t(1118),
          2: this.$t(1119),
        },
        levelList: {
          1: this.$t(950331),
          2: this.$t(950332),
          3: this.$t(950333),
          4: this.$t(950334),
          5: this.$t(950335),
          6: this.$t(950336),
        },
        levelList2: {
          10: this.$t(930077),
          11: this.$t(800074),
          12: this.$t(930078),
          13: this.$t(930079),
        },
        instructionCycleList: {
          1: this.$t(1101),
          7: this.$t(1136),
          14: this.$t(1137),
          30: this.$t(1138),
          60: this.$t(1139),
          90: this.$t(1140),
          180: this.$t(1141),
          365: this.$t(1142),
        },
        dateRangList: {
          1: this.$t(200151),
          2: this.$t(200152),
          3: this.$t(200153),
        },
        failmodeList: {},
        statesList: [
          {
            value: 1,
            name: this.$t(960459),
          },
          {
            value: 2,
            name: this.$t(8000024),
          },
          {
            value: 3,
            name: this.$t(1134),
          },
        ],
      },
      treeContents: [],
      sectionname: "",
      map: {
        value: "machineid",
        label: "name",
        children: "children",
        expand: true,
        selected: false,
      },
      addModal: false, // 添加Modal的开关
      modal1: false,
      loading: true,
      modalTitle: "",
      optType: "add", // add,edit
      addObj: {
        id: 0,
        sectionId: 0, // 设备id 当选中产线时值为0
        planid: 0,
        typemode: 0, // 维护类型
        content: "", // 项目内容
        value_type: 0, // 项目类型
        severity_level: 0, // 项目分类
        unit: "", // 单位
        up_limit: 0, // 上限
        lower_limit: 0, // 下限
        failure_mode: "", // 对应失效模式
        standard_time: 0, // 计划用时
        instruction_cycle: 0, // 执行周期

        datetype: "1", // 执行类型
        datetime1: "", // 执行时间范围
        degree: 0, // 执行次数

        first_instruction_time: "", // 开始执行时间

        work: [], // 指导文件
        remark: "", // 备注
        maintain_tool: "", // 维护工具
        maintain_sparepart: "", // 维护备件
      },

      workUrl: "", // 指导文件预览
      selectedObj: {}, // 选中对象容器
      multipleSelectedObj: [],
      total: 0, // 刀位列表total
      page: 1, // 刀位列表当前页数
      pagesize: 10, // 刀位列表pagesize

      tableData1: [], // 刀位列表数据容器
      editModal: false, // 修改模态框
      editObj: {}, // 修改模态框
      tableColumns1: [
        {
          title: "全选",
          align: "center",
          width: 50,
          type: "selection",
        },
        {
          title: this.$t(1008),
          render: (h, params) => {
            return h("div", params.index + (this.page - 1) * this.pagesize + 1);
          },
          width: 60,
        },
        {
          title: this.$t(200003),
          key: "stas",
          width: 180,
        },
        {
          title: this.$t(800191),
          key: "mode",
          width: 90,
        },
        {
          title: this.$t(200058),
          key: "content",
          width: 250,
        },
        {
          title: this.$t(200054),
          key: "states",
          width: 120,
          render: (h, params) => {
            if (params.row.states === "已完成") {
              return h(
                "span",
                {
                  style: {
                    color: "#ddd",
                  },
                },
                params.row.states
              );
            } else {
              return h("span", {}, params.row.states);
            }
          },
        },
        {
          title: this.$t(800192) + "(min)",
          align: "center",
          key: "standard_time",
          width: 120,
        },
        {
          title: this.$t(950330),
          align: "center",
          key: "severity_level",
          width: 60,
        },
        {
          title: this.$t(100040),
          align: "center",
          key: "creator",
          width: 100,
        },
        {
          title: this.$t(1117),
          align: "center",
          key: "instruction_cycle1",
          width: 100,
        },
        {
          align: "center",
          title: this.$t(200053),
          key: "name",
          width: 100,
        },
        {
          title: this.$t(200064),
          align: "center",
          key: "first_instruction_time",
          width: 180,
        },
        {
          title: this.$t(1015),
          align: "center",
          children: [
            {
              title: this.$t(1118),
              width: 80,
              align: "center",
              key: "valuetype",
            },
            {
              title: this.$t(1119),
              align: "center",
              children: [
                {
                  title: this.$t(200017),
                  align: "center",
                  key: "unit",
                  width: 60,
                },
                {
                  title: this.$t(200059),
                  align: "center",
                  key: "up_limit",
                  width: 60,
                  render: (h, params) => {
                    if (params.row.valuetypenum == 1) {
                      this.up_limit = "";
                    }
                  },
                },
                {
                  title: this.$t(200060),
                  align: "center",
                  key: "lower_limit",
                  width: 60,
                  render: (h, params) => {
                    if (params.row.valuetypenum == 1) {
                      this.lower_limit = "";
                    }
                  },
                },
              ],
            },
          ],
        },
        {
          title: this.$t(200154),
          align: "center",
          key: "date_rang",
          width: 130,
        },
        {
          title: this.$t(900743),
          key: "work_instruction_name",
          align: "center",
          width: 130,
          render: (h, params) => {
            return h("div", [
              h(
                "span",
                {
                  on: {
                    click: () => {
                      this.modal1 = true;
                      this.workUrl = params.row.workUrl;
                    },
                  },
                },
                params.row.work_instruction_name
              ),
            ]);
          },
        },
        // {
        //   title: '对应失效模式',
        //   key: 'failure_mode',
        //   width: 100
        // },
        // {
        //   title: this.$t(1038),
        //   key: 'action',
        //   align: 'center',
        //   width: 80,
        //   render: (h, params) => {
        //     return h('div', [
        //       h('Button', {
        //         props: {
        //           type: 'primary',
        //           size: 'small'
        //         },
        //         style: {
        //           marginRight: '5px'
        //         // display: (params.row.station === "") ? "none" : "inline-block",
        //         },
        //         on: {
        //           click: (row) => {
        //             axios.request({
        //               url: '/tpm/Plan/GetPlanTime?planid=' + params.row.id,
        //               method: 'get'
        //             }).then(res => {
        //               if (res.data.data != undefined && res.data.data.length > 0) {
        //                 this.changeExecutorObj.planTimes = res.data.data
        //                 this.changeExecutorModel = true
        //               // 清空数据
        //               } else {
        //                 this.$Message.error('没有数据')
        //                 this.changeExecutorObj.planTimes = []
        //               // 清空数据
        //               }
        //             })
        //           }
        //         }
        //       }, '修改')

        //     ])
        //   }
        // }
      ],

      addModalRule:
        this.optType == "add"
          ? {
              add_leveldata: [
                {
                  validator: validate_add_leveldata,
                  required: true,
                  trigger: "blur",
                },
              ],
              add_machine: [
                {
                  validator: validate_add_machine,
                  required: true,
                  trigger: "blur",
                },
              ],
              typemode: [
                {
                  validator: validateTypeMode,
                  required: true,
                  trigger: "blur",
                },
              ],
              value_type: [
                {
                  validator: validateValueType,
                  required: true,
                  trigger: "blur",
                },
              ],
              severity_level: [
                {
                  validator: validateSeverityLevel,
                  required: true,
                  trigger: "blur",
                },
              ],
              unit: [
                {
                  validator: validateUnit,
                  required: true,
                  trigger: "blur",
                },
              ],
              up_limit: [
                {
                  validator: validateUpLimit,
                  required: true,
                  trigger: "blur",
                },
              ],
              lower_limit: [
                {
                  validator: validateLowerLimit,
                  required: true,
                  trigger: "blur",
                },
              ],
              standard_time: [
                {
                  validator: validateStandardTime,
                  required: true,
                  trigger: "blur",
                },
              ],
              instruction_cycle: [
                {
                  validator: validateInstructionCycle,
                  required: true,
                  trigger: "blur",
                },
              ],
              datetype: [
                {
                  validator: validateDateType,
                  required: true,
                  trigger: "blur",
                },
              ],
              content: [
                {
                  trigger: "blur",
                  required: true,
                  message: this.$t(90000038),
                },
              ],
              failure_mode: [
                {
                  trigger: "blur",
                  required: true,
                  message: this.$t(90000039),
                },
              ],
              first_instruction_time: [
                {
                  validator: validateFirstInstructionTime,
                  trigger: "blur",
                  required: true,
                },
              ],
              maintain_tool: [
                {
                  trigger: "blur",
                  required: true,
                  message: this.$t(90000040),
                },
              ],
              maintain_sparepart: [
                {
                  trigger: "blur",
                  required: true,
                  message: this.$t(90000041),
                },
              ],
            }
          : {
              typemode: [
                {
                  validator: validateTypeMode,
                  required: true,
                  trigger: "blur",
                },
              ],
              value_type: [
                {
                  validator: validateValueType,
                  required: true,
                  trigger: "blur",
                },
              ],
              severity_level: [
                {
                  validator: validateSeverityLevel,
                  required: true,
                  trigger: "blur",
                },
              ],
              unit: [
                {
                  validator: validateUnit,
                  required: true,
                  trigger: "blur",
                },
              ],
              up_limit: [
                {
                  validator: validateUpLimit,
                  required: true,
                  trigger: "blur",
                },
              ],
              lower_limit: [
                {
                  validator: validateLowerLimit,
                  required: true,
                  trigger: "blur",
                },
              ],
              standard_time: [
                {
                  validator: validateStandardTime,
                  required: true,
                  trigger: "blur",
                },
              ],
              instruction_cycle: [
                {
                  validator: validateInstructionCycle,
                  required: true,
                  trigger: "blur",
                },
              ],
              datetype: [
                {
                  validator: validateDateType,
                  required: true,
                  trigger: "blur",
                },
              ],
              content: [
                {
                  trigger: "blur",
                  required: true,
                  message: this.$t(90000038),
                },
              ],
              failure_mode: [
                {
                  trigger: "blur",
                  required: true,
                  message: this.$t(90000039),
                },
              ],
              first_instruction_time: [
                {
                  validator: validateFirstInstructionTime,
                  trigger: "blur",
                  required: true,
                },
              ],
              maintain_tool: [
                {
                  trigger: "blur",
                  required: true,
                  message: this.$t(90000040),
                },
              ],
              maintain_sparepart: [
                {
                  trigger: "blur",
                  required: true,
                  message: this.$t(90000041),
                },
              ],
            },

      setExecutorModel: false,
      setExecutorObj: {
        department: 0,
        userList: [],
        users: [],
      },
      changeExecutorModel: false,
      changeExecutorObj: {
        department: 0,
        userList: [],
        user: 0,
        planTimes: [],
        pTimeId: 0,
        planId: 0,
        instruction_time: "",
      },
      tableColumns2: [
        {
          title: this.$t("200053"),
          key: "name",
          width: 100,
        },
        {
          title: this.$t("200064"),
          key: "instruction_time_str",
        },
      ],
      datalist1: [
        {
          value: 1,
          name: this.$t(950331),
        },
        {
          value: 2,
          name: this.$t(950332),
        },
        {
          value: 3,
          name: this.$t(950333),
        },
        {
          value: 4,
          name: this.$t(950334),
        },
        {
          value: 5,
          name: this.$t(950335),
        },
        {
          value: 6,
          name: this.$t(950336),
        },
      ],
      datalist2: [
        {
          value: 10,
          name: this.$t(930077),
        },
        {
          value: 11,
          name: this.$t(800074),
        },
        {
          value: 12,
          name: this.$t(930078),
        },
        {
          value: 13,
          name: this.$t(930079),
        },
        {
          value: 14, // 不能乱改！！
          name: this.$t(930129),
        },
      ],
      headers: {
        token: localStorage.getItem("token"),
        timestamp: localStorage.getItem("timestamp"),
        nonce: localStorage.getItem("nonce"),
        sign: localStorage.getItem("sign"),
      },
    }; // end return data
  },

  created() {
    this.defaultPageData();
    this.search(1, 10); // 初始化列表
    this.initmidlist("");
    // this.initAddModal()
    // 格式化表格样式
    this.tableColumns1 = this.$time.initTableTitle(this.tableColumns1);
    this.tableColumns2 = this.$time.initTableTitle(this.tableColumns2);
  },

  methods: {
    radioChange() {
      console.log(this.addObj, this.editObj);
    },
    initmidlist(query) {
      var params = {
        name: query,
      };
      this.axios
        .request({
          // 初始化负责人
          url: "/config/projectuser/GetAllUserByCurrentProjectId",
          params,
          method: "get",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            if (res.data.data.length > 0) {
              this.midlist = res.data.data;
            }
          }
        });
    },
    adddata() {
      // 添加
      if (this.add_leveldata.length < 1) {
        this.$Message.error(this.$t(930116));
        return false;
      }
      if (this.machinedata.length < 1) {
        this.$Message.error(this.$t(600117));
        return false;
      }
      if (
        !this.addObj.typemode ||
        !this.addObj.content ||
        !this.addObj.value_type ||
        !this.addObj.severity_level ||
        !this.addObj.standard_time ||
        !this.addObj.instruction_cycle ||
        !this.addObj.first_instruction_time
      ) {
        this.$Message.error(this.$t(1063));
        return false;
      }
      if (this.addObj.value_type === "2") {
        if (
          !this.addObj.unit &&
          !this.addObj.up_limit &&
          !this.addObj.lower_limit
        ) {
          this.$Message.error(this.$t(1063));
          return false;
        }
      }
      if (this.addObj.datetype === "2") {
        if (this.addObj.datetime1 < 1) {
          this.$Message.error(this.$t(930115));
          return false;
        }
      }
      if (this.addObj.datetype === "3") {
        if (!this.addObj.count) {
          this.$Message.error(this.$t(200157));
          return false;
        }
      }
      this.addObj.machineid = this.machinedata[this.machinedata.length - 1];
      this.addObj.date_rang = this.addObj.datetype;
      this.addObj.first_instruction_time = moment(
        this.addObj.first_instruction_time
      ).format("YYYY-MM-DD");
      this.addObj.modeType = this.addObj.typemode;
      if (this.addObj.datetime1) {
        this.addObj.endtime = moment(this.addObj.datetime1[1]).format(
          "YYYY-MM-DD"
        );
        this.addObj.starttime = moment(this.addObj.datetime1[0]).format(
          "YYYY-MM-DD"
        );
      }
      if (this.addObj.work) {
        this.addObj.work_instruction_name =
          this.addObj.work.length > 0 ? this.addObj.work[0].name : "";
        this.addObj.work_instruction_url =
          this.addObj.work.length > 0 ? this.addObj.work[0].response.data : "";
      } else {
        this.addObj.work_instruction_name = "";
        this.addObj.work_instruction_url = "";
      }
      this.addObj.failure_mode = "";
      this.addObj.unit = this.addObj.unit ? this.addObj.unit : "";
      var data = this.addObj;
      if (!this.addObj.unit) {
        data.lower_limit = 0;
        data.up_limit = 0;
      } else {
        data.lower_limit = this.addObj.lower_limit;
        data.up_limit = this.addObj.up_limit;
      }
      this.axios
        .request({
          url: "/tpm/Plan/AddMachineIdPlan",
          data,
          method: "post",
        })
        .then((ret) => {
          if (ret.data.ret === 1) {
            this.$Message.success(this.$t(1055));
            this.addModal = false;
            this.reload();
          } else {
            this.$Message.error(this.$t(ret.data.msg));
            this.reload();
          }
        });
    },
    editdata() {
      if (
        !this.editObj.typemode ||
        !this.editObj.content ||
        !this.editObj.value_type ||
        !this.editObj.severity_level ||
        !this.editObj.standard_time ||
        !this.editObj.instruction_cycle ||
        !this.editObj.first_instruction_time
      ) {
        this.$Message.error(this.$t(1063));
        return false;
      }
      console.log(this.editObj.value_type);
      if (this.editObj.value_type === "2") {
        if (
          !this.editObj.unit &&
          !this.editObj.up_limit &&
          !this.editObj.lower_limit
        ) {
          this.$Message.error(this.$t(1063));
          return false;
        }
      }
      if (this.editObj.datetype === "2") {
        if (this.editObj.datetime1 < 1) {
          this.$Message.error(this.$t(930115));
          return false;
        }
      }
      if (this.editObj.datetype === "3") {
        if (!this.editObj.count) {
          this.$Message.error(this.$t(200157));
          return false;
        }
      }
      this.editObj.machineid = this.machinedata[this.machinedata.length - 1];
      this.editObj.date_rang = this.editObj.datetype;
      this.editObj.first_instruction_time = moment(
        this.editObj.first_instruction_time
      ).format("YYYY-MM-DD");
      this.editObj.modeType = this.editObj.typemode;
      if (typeof this.editObj.datetime1 === "string") {
        var arr = [
          this.editObj.datetime1.substr(0, 10),
          this.editObj.datetime1.substr(13),
        ];
        this.editObj.datetime1 = arr;
      }
      if (this.editObj.datetime1[0] !== "") {
        this.editObj.endtime = moment(this.editObj.datetime1[1]).format(
          "YYYY-MM-DD"
        );
        this.editObj.starttime = moment(this.editObj.datetime1[0]).format(
          "YYYY-MM-DD"
        );
      } else {
        this.editObj.endtime = "";
        this.editObj.starttime = "";
      }
      if (this.editObj.work) {
        this.editObj.work_instruction_name =
          this.editObj.work.length > 0 ? this.editObj.work[0].name : "";
        this.editObj.work_instruction_url =
          this.editObj.work.length > 0 ? this.editObj.work[0].url : "";
      } else {
        this.editObj.work_instruction_name = "";
        this.editObj.work_instruction_url = "";
      }
      this.editObj.itemid = this.editObj.id;
      this.editObj.planid = this.editObj.id;
      this.editObj.mode = this.editObj.failmode ? this.editObj.failmode : 0;
      // console.log(111)

      this.editObj.failure_mode = "";
      this.editObj.unit = this.editObj.unit ? this.editObj.unit : "";
      var data = this.$time.deepClone(this.$time.deepClone(this.editObj));
      if (!this.editObj.unit) {
        // console.log(43)
        data.lower_limit = 0;
        data.up_limit = 0;
      } else {
        data.lower_limit = this.editObj.lower_limit;
        data.up_limit = this.editObj.up_limit;
      }
      var base1 = [this.editObj];
      data.base = base1;
      this.axios
        .request({
          url: "/tpm/Plan/EditItem",
          data,
          method: "post",
        })
        .then((ret) => {
          if (ret.data.ret === 1) {
            this.$Message.success(this.$t(1060));
            this.editModal = false;
            this.search(this.page, this.pagesize);
          } else {
            this.$Message.error(this.$t("" + ret.data.msg));
          }
        });
    },
    defaultPageData() {
      this.initlevel(); // 初始化产线层级
      this.initDepartmentList();
      // this.inittree()
    },
    handlelevelchange(value) {
      // 添加框 生产线  变化函数
      this.add_leveldata = value;
      this.machinedata = [];
      this.initmachine();
    },
    initmachine() {
      // 根据生产线变化得到设备data
      var params = {
        section: this.add_leveldata[this.add_leveldata.length - 1],
      };
      axios
        .request({
          url: "/config/MachineAttribution/GetAttributionDataBySection",
          params,
          method: "get",
        })
        .then((ret) => {
          if (ret.data.ret === 1) {
            console.log(ret.data.data);
            const arr = [];
            this.datamachine = ret.data.data;
            if (ret.data.data.length > 0) {
              arr.push(ret.data.data[0].value);
              this.machinedata = arr;
            }
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    handlemachinechange(value, selectedData) {
      // 设备变化函数
      // this.tableData1 = []
      this.machinedata = value;
      this.add_machine = value[value.length - 1];
      // 加载失效模式
      this.inifailemode();
    },
    inifailemode() {
      var params = {
        machineid: this.add_machine,
      };
      axios
        .request({
          url: "/tpm/FaultType/GetFaultTypeListByMachineId",
          params,
          method: "get",
        })
        .then((ret) => {
          if (ret.data.ret === 1) {
            this.initPageData.failmodeList = ret.data.data;
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    typeModechange() {
      if (this.addObj.typemode == 3) {
        this.addObj.instruction_cycle = "90";
        this.add_value_type_cycle = true;
      } else {
        this.addObj.instruction_cycle = 0;
        this.add_value_type_cycle = false;
      }
    },
    initDepartmentList() {
      axios
        .request({
          url: "/config/ProjectSection/GetSections",
          method: "get",
        })
        .then((res) => {
          if (res.data.data != undefined && res.data.data.length > 0) {
            this.initPageData.departmentList = res.data.data;
          } else {
            this.initPageData.departmentList = [];
          }
        });
    },
    changeDepartment(item, opt) {
      if (item === undefined) {
        return false;
      }
      if (parseInt(item.value) > 0) {
        let params = {
          sectionid: item.value,
        };
        axios
          .request({
            url: "/config/ProjectUser/getUserListsBySectionId",
            params,
            method: "get",
          })
          .then((res) => {
            if (res.data.data != undefined && res.data.data.length > 0) {
              if (opt === "setExecutor") {
                this.setExecutorObj.userList = res.data.data;
              } else if (opt === "changeExecutor") {
                this.changeExecutorObj.userList = res.data.data;
              } else {
                this.initPageData.userList = res.data.data;
              }
            } else {
              if (opt === "setExecutor") {
                this.setExecutorObj.userList = [];
              } else if (opt === "changeExecutor") {
                this.changeExecutorObj.userList = [];
              } else {
                this.initPageData.userList = [];
              }
            }
            this.filterObj.user = 0;
            this.setExecutorObj.users = [];
            this.changeExecutorObj.user = 0;
          });
      }
    },
    changeMultipleSelection(val) {
      this.multipleSelectedObj = val;
      var arr = [];
      val.forEach((item) => {
        arr.push(item.id);
      });
      this.ids = arr;
    },
    initlevel() {
      // 初始化产线层级
      axios
        .request({
          url: "config/ProjectLevelSection/GetSectionTree",
          method: "get",
        })
        .then((res) => {
          const arr = [];
          if (res.data.data.length > 0) {
            this.datalevel = res.data.data;
            arr.push(res.data.data[0].value);
            this.leveldata = arr;
          }
        });
    },
    changelevel(data) {
      // 切换产线层级，触发事件
      // 请求数据
      this.levelid = data[data.length - 1];
    },
    changePage(value) {
      // 换页事件
      this.page = value;
      this.tableData1 = this.search(this.page, this.pagesize);
    },
    handleRowChange(currentRow, oldCurrentRow) {
      // 选中一条数据，触发事件
      this.selectedObj = currentRow;
      // console.log(this.selectedObj)
    },
    handlePageSize(value) {
      // 切换分页页数，触发事件
      this.pagesize = value;
      this.tableData1 = this.search(this.page, this.pagesize);
    },
    search(page, pagesize) {
      // 点击查询，触发事件
      var params = {
        value_type: this.filterObj.valueType,
        severity_level: this.filterObj.import,
        instruction_cycle: this.filterObj.instructionCycle,
        department: this.filterObj.department,
        person: this.filterObj.user,
        modeType: this.filterObj.typeMode,
        datetype: this.filterObj.dateRang,
        sectionid: this.levelid,
        page: page,
        pagesize: pagesize,
        state: this.filterObj.states ? this.filterObj.states : 0,
        creator: this.filterObj.creator,
      };
      axios
        .request({
          url: "/tpm/Plan/searchPlanTime",
          params,
          method: "get",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            this.total = res.data.total;
            this.mockTableData1(res.data.data);
            this.page = res.data.page;
          } else {
            this.$Message.error(this.$t(res.data.msg));
            this.tableData1 = [];
          }
        });
    },
    mockTableData1(tablelist) {
      // 转换数据，并赋值给列表数据容器tableData1
      let data = [];
      tablelist.forEach((item) => {
        if (item) {
          // console.log(item);
          data.push({
            id: item.id,
            mode: item.mode === 1 ? "AM" : item.mode === 2 ? "PM" : "CMP",
            planid: item.planid,
            content: item.content,
            stas: item.stas,
            valuetype: parseInt(item.value_type) === 1 ? "√" : "",
            valuetypenum: parseInt(item.value_type),
            unit: item.unit,
            up_limit: item.up_limit,
            lower_limit: item.lower_limit,
            severity_level:
              item.mode === 1
                ? this.initPageData.levelList[item.severity_level]
                : this.initPageData.levelList2[item.severity_level],
            work_instruction_name: item.work_instruction_name,
            failure_mode: item.failure_mode,

            standard_time: item.standard_time,
            date_rang:
              parseInt(item.date_rang) === 1
                ? this.$t("200151")
                : parseInt(item.date_rang) === 2
                ? item.date_rang_str + this.$t("200162")
                : this.$t("200162") + item.date_rang_str + this.$t("200163"),
            instruction_cycle1: this.initPageData.instructionCycleList[
              parseInt(item.instruction_cycle)
            ],
            remark: item.remark,
            name: item.name,
            first_instruction_time: item.first_instruction_time,
            workUrl: axios.publicPath + item.work_instruction_url,
            faulttype: item.faulttype,
            creator: item.creator,
            states:
              item.mode === 3
                ? item.state === 1
                  ? this.$t("500097")
                  : item.state === 2
                  ? this.$t("8000024")
                  : item.state === 3
                  ? this.$t("1134")
                  : item.state === 4
                  ? this.$t("8000025")
                  : ""
                : "待执行",
          });
        }
      });
      this.tableData1 = data;
      // console.log(this.tableData1);
    },
    //* *****************************************************************************************
    ok() {
      this.modal1 = false;
    },
    outFileUploadChild(files) {
      // 接受文件上传的数据
      this.addObj.work = files;
    },
    outFileUploadChild1(files) {
      // 接受文件上传的数据
      this.editObj.work = files;
    },
    initAddModal() {
      // this.addObj = {
      //   id: 0,
      //   sectionId: 0, // 设备id 当选中产线时值为0
      //   planid: 0,
      //   typemode: 0, // 维护类型
      //   content: '', // 项目内容
      //   value_type: 0, // 项目类型
      //   severity_level: 0, // 项目分类
      //   unit: '', // 单位
      //   up_limit: 0, // 上限
      //   lower_limit: 0, // 下限
      //   failure_mode: '', // 对应失效模式
      //   standard_time: 0, // 计划用时
      //   instruction_cycle: 0, // 执行周期
      //   datetype: 0, // 执行类型
      //   datetime1: '', // 执行时间范围
      //   degree: 0, // 执行次数
      //   first_instruction_time: '', // 开始执行时间
      //   work: [], // 指导文件
      //   remark: '', // 备注
      //   maintain_tool: '', // 维护工具
      //   maintain_sparepart: '' // 维护备件
      // }
      // this.$refs.addObj.resetFields()
    },
    add() {
      // 添加
      // this.addObj = {};
      this.addObj.standard_time = 1;
      this.addObj.datetype = "1";
      this.machinedata = [];
      this.add_leveldata = [];
      // this.$refs.addObj.resetFields()
      this.addModal = true;
      // this.modalTitle = '添加'
      // this.optType = 'add'
      // this.initAddModal() // 初始化
      // this.add_leveldata = [] // 添加时层级级联清空
      // this.machinedata = [] // 添加时设备级联清空
      // this.addObj.work = []
      // this.initPageData.failmodeList = []
    },
    edit() {
      if (this.selectedObj.id === "" || this.selectedObj.id === undefined) {
        this.$Message.error(this.$t("1043"));
        return false;
      }
      this.editModal = true;
      // this.modalTitle = '修改'
      // this.optType = 'edit'
      this.initEditModal();

      // this.$refs.addObj.resetFields()
    },
    initEditModal() {
      let params = {
        id: this.selectedObj.id,
      };
      axios
        .request({
          url: "/tpm/Plan/GetonePlan",
          params,
          method: "get",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            let item = res.data.data[0];
            console.log(item);
            let files =
              item.work_instruction_name != ""
                ? [
                    {
                      name: item.work_instruction_name,
                      url: this.axios.publicPath + item.work_instruction_url,
                      status: "finished",
                    },
                  ]
                : [];
            // this.$refs.tree.handleSelect(item.machineid)
            this.editObj = {
              id: item.id,
              sectionId: item.machineid, // 设备id 当选中产线时值为0
              typemode: item.mode.toString(), // 维护类型
              content: item.content, // 项目内容
              value_type: item.value_type.toString(), // 项目类型
              severity_level: item.severity_level, // 项目分类
              unit: item.unit, // 单位
              up_limit: item.up_limit ? parseInt(item.up_limit) : 0, // 上限
              lower_limit: item.lower_limit ? parseInt(item.lower_limit) : 0, // 下限
              failure_mode: item.failure_mode, // 对应失效模式
              standard_time: item.standard_time, // 计划用时
              instruction_cycle: item.instruction_cycle.toString(), // 执行周期
              datetype: item.date_rang.toString(), // 执行类型
              datetime1: item.date_rang_str, // 执行时间范围
              count: item.count, // 执行次数
              first_instruction_time: item.first_instruction_time_date, // 开始执行时间
              work: files, // 指导文件
              remark: item.remark, // 备注
              maintain_tool: item.maintain_tool, // 维护工具
              maintain_sparepart: item.maintain_sparepart, // 维护备件
              faulttype: item.faulttype,
            };
            // console.log(this.editObj);
            if (this.editObj.typemode === "3") {
              this.editObj.instruction_cycle = "90";
              this.add_value_type_cycle = true;
            }
            // this.changetypemode()

            // this.add_machine = this.addObj.sectionId
            // this.inifailemode()
            // this.addObj.failmode =this.addObj.faulttype
          }
        });
    },

    del() {
      // 删除
      if (this.ids.length < 1) {
        this.$Message.error(this.$t("1043"));
        return false;
      } else {
        var data = {
          ids: this.ids,
        };
        this.$Modal.confirm({
          title: this.$t("1018"),
          content: "",
          width: "290px",
          closable: true,
          okText: this.$t("1004"),
          onOk: () => {
            axios
              .request({
                url: "/tpm/Plan/DeletePlan",
                data,
                method: "post",
              })
              .then((res) => {
                if (res.data.ret === 1) {
                  this.$Message.success(this.$t("1058"));
                  this.search(1, this.pagesize);
                  this.ids = [];
                } else {
                  this.$Message.error(this.$t(res.data.msg));
                }
              });
          },
        });
      }
    },
    toExcel() {
      // 导出excel
      var params = {
        value_type: this.filterObj.valueType,
        severity_level: this.filterObj.import,
        instruction_cycle: this.filterObj.instructionCycle,
        department: this.filterObj.department,
        person: this.filterObj.user,
        modeType: this.filterObj.typeMode,
        datetype: this.filterObj.dateRang,
        sectionid: this.levelid,
        state: this.filterObj.states ? this.filterObj.states : 0,
        creator: this.filterObj.creator,
      };
      axios
        .request({
          url: "/tpm/Plan/exportAll",
          params,
          method: "get",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            window.location.href = axios.publicPath + "" + res.data.data;
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    loadexcel() {
      axios
        .request({
          url: "/tpm/Plan/GetTemplateSkf",
          method: "get",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            window.location.href = axios.publicPath + "" + res.data.data;
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    handleFormatError(file) {
      this.$Message.error(this.$t("950396") + file.name + this.$t("950397"));
    },
    handleSuccess(res, file) {
      if (res.ret == 1) {
        this.$Message.success(this.$t("950398"));
        this.search(this.page, this.pagesize);
      } else {
        if ((res.msg + "").indexOf(",") != -1) {
          this.page = 1;
          this.search(this.page, this.pagesize);
          inittip(res.msg);
        } else {
          this.$Message.error(this.$t(res.msg));
        }
      }
    },
    handleError() {
      this.$Message.error(this.$t("2010006") + "!");
    },
    handleSubmit(name) {
      // 添加
      this.$refs[name].validate((valid) => {
        if (valid) {
          // valid
          let data;
          if (this.optType === "add") {
            // 添加操作
            if (this.add_machine === 0) {
              this.$Message.error(this.$t(100150));
              this.clearLoading();
              return false;
            }
            if (
              this.addObj.datetype === "2" &&
              this.addObj.datetime1[0] === ""
            ) {
              this.$Message.error(this.$t(930114));
              this.clearLoading();
              return false;
            }
            if (
              this.addObj.datetype === "3" &&
              !/^[1-9]\d*$/.test(this.addObj.count)
            ) {
              this.$Message.error(this.$t(200157));
              this.clearLoading();
              return false;
            }
            data = {
              machineid: this.machinedata[this.machinedata.length - 1],
              content: this.addObj.content,
              count: this.addObj.count,
              date_rang: this.addObj.datetype,
              failure_mode: "",
              first_instruction_time:
                this.addObj.first_instruction_time != ""
                  ? this.changeDate(this.addObj.first_instruction_time)
                  : "",
              instruction_cycle: this.addObj.instruction_cycle,
              lower_limit: this.addObj.lower_limit.toString(),
              // machineid: this.addObj.sectionId,
              maintain_sparepart: this.addObj.maintain_sparepart,
              maintain_tool: this.addObj.maintain_tool,
              modeType: this.addObj.typemode,
              remark: this.addObj.remark,
              severity_level: this.addObj.severity_level,
              standard_time: this.addObj.standard_time,
              endtime:
                this.addObj.datetime1.length > 0 &&
                this.addObj.datetime1[1] != ""
                  ? this.changeDate(this.addObj.datetime1[1])
                  : "",
              starttime:
                this.addObj.datetime1.length > 0 &&
                this.addObj.datetime1[0] != ""
                  ? this.changeDate(this.addObj.datetime1[0])
                  : "",
              unit: this.addObj.unit,
              up_limit: this.addObj.up_limit.toString(),
              value_type: this.addObj.value_type,
              work_instruction_name:
                this.addObj.work.length > 0 ? this.addObj.work[0].name : "",
              work_instruction_url:
                this.addObj.work.length > 0
                  ? this.addObj.work[0].response.data
                  : "",
            };

            axios
              .request({
                url: "/tpm/Plan/AddMachineIdPlan",
                data,
                method: "post",
              })
              .then((res) => {
                if (res.data.ret === 1) {
                  // res.data.ret === 1
                  this.$Message.success(this.$t(1055));
                  this.addModal = false;
                  this.search(1, this.pagesize);
                } else {
                  this.$Message.error(this.$t(res.data.msg));
                  // 解决ok按钮loading的问题
                  this.clearLoading();
                }
              });
          } else {
            if (
              this.addObj.datetype === "2" &&
              this.addObj.datetime1[0] === ""
            ) {
              this.$Message.error(this.$t(930114));
              this.clearLoading();
              return false;
            }
            if (
              this.addObj.datetype === "3" &&
              !/^[1-9]\d*$/.test(this.addObj.count)
            ) {
              this.$Message.error(this.$t(200157));
              this.clearLoading();
              return false;
            }
            console.log(this.addObj.datetime1);
            data = {
              base: [
                {
                  content: this.addObj.content,
                  failure_mode: this.addObj.failure_mode,
                  instruction_cycle: this.addObj.instruction_cycle,
                  lower_limit: this.addObj.lower_limit,
                  maintain_sparepart: this.addObj.maintain_sparepart,
                  maintain_tool: this.addObj.maintain_tool,
                  remark: this.addObj.remark,
                  severity_level: this.addObj.severity_level,
                  standard_time: this.addObj.standard_time,
                  unit: this.addObj.unit,
                  up_limit: this.addObj.up_limit,
                  value_type: this.addObj.value_type,
                  work_instruction_name:
                    this.addObj.work.length > 0 ? this.addObj.work[0].name : "",
                  work_instruction_url:
                    this.addObj.work.length > 0
                      ? this.addObj.work[0].response.data
                      : "",
                },
              ],
              count: this.addObj.count === undefined ? 0 : this.addObj.count,
              date_rang: this.addObj.datetype,
              endtime:
                this.addObj.datetime1.length > 0 &&
                this.addObj.datetime1[1] != ""
                  ? this.addObj.datetime1[1].substr(13, 23)
                  : "",
              first_instruction_time: this.changeDate(
                this.addObj.first_instruction_time
              ),
              itemid: this.addObj.id,
              planid: this.selectedObj.planid,
              starttime:
                this.addObj.datetime1.length > 0 &&
                this.addObj.datetime1[0] != ""
                  ? this.addObj.datetime1[0].substr(0, 10)
                  : "",
              mode: this.addObj.failmode,
            };
            console.log(data);
            return false;
            // console.log(data)
            // this.clearLoading()
            // return false
            axios
              .request({
                url: "/tpm/Plan/EditItem",
                data,
                method: "post",
              })
              .then((res) => {
                if (res.data.ret === 1) {
                  // res.data.ret === 1
                  this.$Message.success(this.$t(1060));
                  this.addModal = false;
                  this.search(1, this.pagesize);
                } else {
                  this.$Message.error(this.$t(res.data.msg));
                  // this.$Message.error(this.$t(1061))
                  // 解决ok按钮loading的问题
                  this.clearLoading();
                }
              });
          }
        } else {
          // 解决ok按钮loading的问题
          this.clearLoading();
        }
      });
    },
    setExecutor() {
      var statex = false;
      if (this.multipleSelectedObj.length === 0) {
        this.$Message.error(this.$t("1043"));
        return false;
      }
      if (this.multipleSelectedObj.length == 1) {
        let params = {
          id: this.multipleSelectedObj[0].id,
        };
        axios
          .request({
            url: "/tpm/Plan/GetonePlanTimeUser",
            params,
            method: "get",
          })
          .then((res) => {
            if (res.data.ret === 1) {
              let item = res.data.data;
              this.setExecutorObj.userList = [];
              if (item.users.length > 0) {
                item.users.forEach((val) => {
                  this.setExecutorObj.userList.push({
                    id: val.id,
                    name: val.text,
                  });
                });
              }
              this.setExecutorObj.users = item.user.map((value) => {
                return parseInt(value);
              });
              this.setExecutorObj.department = parseInt(item.departid);
              // console.log(this.setExecutorObj)
            }
          });
      } else {
        this.multipleSelectedObj.forEach((item) => {
          if (item.states === "已完成") {
            statex = true;
          }
        });
        this.setExecutorObj.department = 0;
        this.setExecutorObj.users = [];
        this.setExecutorObj.userList = [];
      }
      if (statex) {
        this.$Message.error("选择的数据中存在已完成的状态，不能设置执行人");
        return false;
      }
      this.setExecutorModel = true;
    },
    handlerSetExecutor() {
      let data;
      if (this.setExecutorObj.department === 0) {
        this.$Message.error(this.$t(930016));
        this.clearLoading();
        return false;
      }
      if (this.setExecutorObj.users === []) {
        this.$Message.error(this.$t(500164));
        this.clearLoading();
        return false;
      }
      let planids = [];
      if (this.multipleSelectedObj.length > 0) {
        this.multipleSelectedObj.forEach((item) => {
          planids.push(item.id);
        });
      }
      data = {
        instruction_mid: this.setExecutorObj.users,
        plannid: planids,
      };
      // console.log(data)
      // return false
      axios
        .request({
          url: "/tpm/Plan/EditPlanTime",
          data,
          method: "post",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            // res.data.ret === 1
            this.$Message.success(this.$t(1060));
            this.setExecutorModel = false;
            this.search(1, this.pagesize);
          } else {
            this.$Message.error(this.$t(1061));
            // 解决ok按钮loading的问题
            this.clearLoading();
          }
        });
    },
    handleChangeExecutorRowChange(row) {
      this.changeExecutorObj.department = row.sectionid;
      this.changeExecutorObj.instruction_time = row.instruction_time_str;
      this.changeExecutorObj.pTimeId = row.id;
      this.changeExecutorObj.planId = row.planid;
      axios
        .request({
          url:
            "/config/ProjectUser/getUserListsBySectionId?sectionid=" +
            row.sectionid,
          method: "get",
        })
        .then((res) => {
          if (res.data.data != undefined && res.data.data.length > 0) {
            this.changeExecutorObj.userList = res.data.data;
            this.changeExecutorObj.user = row.mid;
          } else {
            this.changeExecutorObj.userList = [];
            this.changeExecutorObj.user = 0;
          }
        });
    },
    handlerChangeExecutor() {
      let data;
      if (this.changeExecutorObj.pTimeId === 0) {
        this.$Message.error(this.$t(9000396));
        this.clearLoading();
        return false;
      }
      if (
        this.changeExecutorObj.instruction_time === undefined ||
        this.changeExecutorObj.instruction_time === ""
      ) {
        this.$Message.error(this.$t(930080));
        this.clearLoading();
        return false;
      }

      if (this.changeExecutorObj.department === 0) {
        this.$Message.error(this.$t(930016));
        this.clearLoading();
        return false;
      }
      if (
        this.changeExecutorObj.user === 0 ||
        this.changeExecutorObj.user === undefined
      ) {
        this.$Message.error(this.$t(500164));
        this.clearLoading();
        return false;
      }

      data = {
        instruction_time: this.changeDate(
          this.changeExecutorObj.instruction_time
        ),
        instruction_mid: this.changeExecutorObj.user,
        ptimeid: [this.changeExecutorObj.pTimeId],
        planid: this.changeExecutorObj.planId,
      };
      // console.log(data)
      // return false
      axios
        .request({
          url: "/tpm/Plan/EditPlansTime",
          data,
          method: "post",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            // res.data.ret === 1
            this.$Message.success(this.$t(1060));
            this.changeExecutorModel = false;
          } else {
            this.$Message.error(this.$t(1061));
            // 解决ok按钮loading的问题
            this.clearLoading();
          }
        });
    },
    changeDate(dateA) {
      var dateee = new Date(dateA).toJSON();
      var date = new Date(+new Date(dateee) + 8 * 3600 * 1000)
        .toLocaleDateString()
        .replace(/T/g, " ")
        .replace(/\.[\d]{3}Z/, "")
        .replace(/\//g, "-");
      return date;
    },
    clearLoading() {
      this.loading = false;
      this.$nextTick(() => {
        this.loading = true;
      });
    },
    changecondition() {
      this.morecondition = !this.morecondition;
    },
    changetypemode() {
      if (this.addObj.typemode === "2" || this.addObj.typemode === "3") {
        if (this.addObj.typemode === "3") {
          this.addObj.datetype = "3";
          this.addObj.count = 1;
          this.addObj.instruction_cycle = "90";
          this.add_value_type_cycle = true;
        }
      } else {
        this.addObj.instruction_cycle = 0;
        this.add_value_type_cycle = false;
      }
      if (this.editObj.typemode === "2" || this.editObj.typemode === "3") {
        if (this.editObj.typemode === "3") {
          this.editObj.datetype = "3";
          this.editObj.count = 1;
          this.editObj.instruction_cycle = "90";
          this.edit_value_type_cycle = true;
        }
      } else {
        this.editObj.instruction_cycle = 0;
        this.edit_value_type_cycle = false;
      }
    },
  },
};
</script>
<style lang="less" scoped>
.treeSelect {
  span {
    background: #2d8cf1;
    color: #fff;
    margin: 0;
    padding: 0 4px;
    border-radius: 3px;
    cursor: pointer;
    vertical-align: top;
  }
}
.defindlist {
  .filter {
    label {
      width: 120px !important;
    }
  }
}
</style>
