<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(100074) }}：</label>
        <Cascader
          :data="datamt"
          :value="mtdata"
          trigger="click"
          @on-change="machineTypeChange"
          class="searchSelect"
        ></Cascader>
      </div>
      <div class="filter">
        <label>{{ $t(200002) }}：</label>
        <Select
          v-model="filterObj.status"
          label-in-value
          clearable
          class="searchSelect"
        >
          <Option :value="1" :key="1">{{ $t(200032) }}</Option>
          <Option :value="2" :key="2">{{ $t(200033) }}</Option>
          <Option :value="3" :key="3">{{ $t(200034) }}</Option>
          <Option :value="4" :key="4">{{ $t(200035) }}</Option>
          <Option :value="5" :key="5">{{ $t(900704) }}</Option>
          <Option :value="6" :key="6">{{ $t(960459) }}</Option>
        </Select>
      </div>
      <div class="filter">
        <label>{{ $t("900572") }}：</label>
        <Select
          v-model="Trouble_code1"
          label-in-value
          :disabled="mtdata.length > 1 ? false : true"
          class="searchSelect"
          @on-change="Trouble_change"
          style="margin-right: 10px"
        >
          <Option :value="1" v-text="$t('200022')">失效模式</Option>
          <Option :value="2" v-text="$t('1590018')">失效原因</Option>
          <Option :value="3" v-text="$t('1950472')">修复行动</Option>
        </Select>
        <Select
          v-model="Trouble_code2"
          label-in-value
          :disabled="mtdata.length > 1 && Trouble_code1 > 0 ? false : true"
          class="searchSelect"
        >
          <Option
            v-for="(item, key) in Trouble_codelist"
            :value="item.id"
            :key="key"
            >{{ item.faulttype }}</Option
          >
        </Select>
      </div>
      <!-- 次级搜索条件--隐藏 -->
      <div v-show="!morecondition">
        <div>
          <div class="filter">
            <label>{{ $t(200001) }}：</label>
            <Input
              type="text"
              class="searchInput"
              v-model="filterObj.repairid"
              :placeholder="$t('1034')"
            />
          </div>
          <div class="filter">
            <label>{{ $t(1590006) }}：</label>
            <Select
              class="searchSelect"
              v-model="filterObj.repairname"
              filterable
              clearable
            >
              <Option
                v-for="(option, index) in options1"
                :value="option.id"
                :key="index"
                >{{ option.name }}</Option
              >
            </Select>
          </div>
          <div class="filter">
            <label>{{ $t("8000046") }}：</label>
            <Select
              v-model="filterObj.andonType"
              label-in-value
              clearable
              class="searchSelect"
            >
              <Option
                v-for="(item, key) in andonList"
                :value="item.id"
                :key="key"
                >{{ item.name }}</Option
              >
            </Select>
          </div>
          <div class="filter">
            <label>{{ $t(1590009) }}：</label>
            <Select
              v-model="filterObj.compare"
              label-in-value
              clearable
              class="searchSelect"
              style="margin-right: 10px"
            >
              <Option value="2" :key="2">{{ $t(200026) }}</Option>
              <Option value="1" :key="1">{{ $t(200027) }}</Option>
            </Select>
            <Input
              type="text"
              class="searchInput"
              v-model="filterObj.compare_time"
              :placeholder="$t(200028)"
            />
          </div>
        </div>
        <div>
          <div class="filter">
            <label>{{ this.$t("1590028") }}：</label>
            <Select
              v-model="filterObj.cost"
              label-in-value
              clearable
              class="searchSelect"
            >
              <Option
                v-for="(value, key) in feedbackobj.costlist"
                :value="key"
                :key="key"
                >{{ value }}</Option
              >
            </Select>
          </div>
          <div class="filter">
            <label>{{ $t(900934) }}：</label>
            <Select
              v-model="filterObj.workordertype"
              label-in-value
              clearable
              class="searchSelect"
            >
              <Option :value="1" :key="1">{{ $t(930004) }}</Option>
              <Option :value="2" :key="2">{{ $t(930005) }}</Option>
            </Select>
          </div>
          <div class="filter">
            <label>{{ $t(1590010) }}：</label>
            <DatePicker
              type="datetimerange"
              @on-change="timechange"
              :value="filterObj.startTime"
              placement="bottom-end"
              split-panels
              placeholder=""
              class="searchInput MaxWidth"
            ></DatePicker>
          </div>
        </div>
      </div>
      <div class="searchBtn">
        <Button
          type="primary"
          class="twoWord"
          icon="ios-search"
          @click="search(1, pagesize)"
          >{{ $t("1001") }}</Button
        >
        <Button
          type="error"
          class="twoWord intervalRight"
          icon="md-close-circle"
          @click="del()"
          >{{ $t(1004) }}</Button
        >
        <Button
          type="primary"
          class="fourWord"
          icon="md-download"
          @click="toExcel()"
          >{{ $t(1007) }}</Button
        >
        <Button
          type="warning"
          class="fourWord"
          icon="md-download"
          @click="feedback()"
          >{{ $t(901104) }}</Button
        >
        <Button
          type="primary"
          class="fourWord"
          icon="md-download"
          @click="editFeedback()"
          >{{ $t("90000031") }}</Button
        >
        <Button
          type="primary"
          class="fourWord"
          icon="md-download"
          @click="editNote()"
          >{{ $t("90000032") }}</Button
        >
      </div>
      <!-- 更多条件 按钮 -->
      <MoreConbtn
        @getCon="morecondition = !morecondition"
        :morecondition="morecondition"
      ></MoreConbtn>
    </div>
    <div class="divborder newTableDiv">
      <Table
        class="tableClass"
        width="100%"
        :loading="tableloading"
        @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
      :title="modalTitle"
      v-model="addModal"
      @on-ok="handleSubmit('addObj')"
      :loading="loading"
      :styles="{ top: '40px', width: '900px' }"
    >
      <div class="modal_body" style="width: 100% !important; padding: 0 20px">
        <Form
          ref="addObj"
          :model="addObj"
          label-position="left"
          :label-width="80"
          :rules="addModalRule"
        >
          <Row type="flex" justify="space-between" class="code-row-bg">
            <Col span="14">
              <Row type="flex" justify="space-between" class="code-row-bg">
                <Col span="12">
                  <FormItem
                    :label="$t(200012)"
                    v-show="optType === 'add'"
                    prop="createtime"
                  >
                    <DatePicker
                      type="datetime"
                      v-model="addObj.createtime"
                      @on-change="addObj.createtime = $event"
                      format="yyyy-MM-dd hh:mm:ss"
                      placement="bottom-end"
                      placeholder="Select date"
                      style="width: 160px"
                    ></DatePicker>
                  </FormItem>
                </Col>
                <Col span="12">
                  <FormItem
                    :label="$t(1041)"
                    v-show="optType === 'add'"
                    prop="machineid"
                  >
                    <Select
                      v-model="addObj.machineid"
                      label-in-value
                      clearable
                      style="width: 160px"
                    >
                      <Option
                        v-for="(item, key) in initPageData.machineList"
                        :tag="item.typeid"
                        :value="item.id"
                        :key="key"
                        >{{ item.machinename }}</Option
                      >
                    </Select>
                  </FormItem>
                </Col>
              </Row>
              <Row type="flex" justify="space-between" class="code-row-bg">
                <Col span="12">
                  <FormItem :label="$t(901108)" prop="taketime">
                    <InputNumber
                      v-model="addObj.taketime"
                      :disabled="optType === 'edit'"
                      :placeholder="$t(200028)"
                    ></InputNumber>
                    <!-- :max="10" :min="1" -->
                  </FormItem>
                </Col>
                <Col span="12">
                  <FormItem :label="$t(200013)" prop="bxr">
                    <Select
                      v-model="addObj.bxr"
                      label-in-value
                      clearable
                      style="width: 160px"
                    >
                      <Option
                        v-for="(item, key) in initPageData.bxrList"
                        :value="item.value"
                        :key="key"
                        >{{ item.label }}</Option
                      >
                    </Select>
                  </FormItem>
                </Col>
              </Row>
              <Row type="flex" justify="space-between" class="code-row-bg">
                <Col span="12">
                  <FormItem :label="$t(200041)" prop="repairtime">
                    <InputNumber
                      v-model="addObj.repairtime"
                      :placeholder="$t(200028)"
                      :disabled="optType === 'edit'"
                    ></InputNumber>
                    <!-- :max="10" :min="1" -->
                  </FormItem>
                </Col>
                <Col span="12">
                  <FormItem :label="$t(200049)" prop="qdr">
                    <Select
                      v-model="addObj.qdr"
                      label-in-value
                      clearable
                      style="width: 160px"
                    >
                      <Option
                        v-for="(item, key) in initPageData.qdrList"
                        :value="item.value"
                        :key="key"
                        >{{ item.label }}</Option
                      >
                    </Select>
                  </FormItem>
                </Col>
              </Row>
              <Row type="flex" justify="space-between" class="code-row-bg">
                <Col span="12">
                  <FormItem :label="$t(200023)" prop="wxr">
                    <Select v-model="addObj.wxr" multiple style="width: 158px">
                      <Option
                        v-for="(item, key) in initPageData.wxrList"
                        :value="item.value"
                        :key="key"
                        >{{ item.label }}</Option
                      >
                    </Select>
                  </FormItem>
                </Col>
                <Col span="12">
                  <FormItem :label="$t(200050)" prop="fxr">
                    <Select
                      v-model="addObj.fxr"
                      label-in-value
                      clearable
                      style="width: 160px"
                    >
                      <Option
                        v-for="(item, key) in initPageData.fxrList"
                        :value="item.value"
                        :key="key"
                        >{{ item.label }}</Option
                      >
                    </Select>
                  </FormItem>
                </Col>
              </Row>
              <Row type="flex" justify="space-between" class="code-row-bg">
                <Col span="12">
                  <FormItem :label="$t(200005)" prop="faultType">
                    <Select
                      v-model="addObj.faultType"
                      @on-change="faultTypeChangeAdd"
                      label-in-value
                      clearable
                      style="width: 160px"
                    >
                      <Option
                        v-for="(value, key) in initPageData.faultTypeList"
                        :value="key"
                        :key="key"
                        >{{ value }}</Option
                      >
                    </Select>
                  </FormItem>
                </Col>
                <Col span="12">
                  <FormItem :label="$t(900572)" prop="ssType">
                    <Select
                      v-model="addObj.ssType"
                      label-in-value
                      clearable
                      style="width: 160px"
                    >
                      <Option
                        v-for="(item, key) in initPageData.ssTypeList"
                        :value="item.value"
                        :key="key"
                        >{{ item.label }}</Option
                      >
                    </Select>
                  </FormItem>
                </Col>
              </Row>
              <Row type="flex" justify="space-between" class="code-row-bg">
                <Col span="12">
                  <FormItem :label="$t(200173)" prop="offlinestatus">
                    <Select
                      v-model="addObj.offlinestatus"
                      label-in-value
                      clearable
                      style="width: 160px"
                    >
                      <Option :value="0" :key="0">{{ $t(1000021) }}</Option>
                      <Option :value="1" :key="1">{{ $t(1000020) }}</Option>
                    </Select>
                  </FormItem>
                </Col>
                <Col span="12">
                  <FormItem :label="$t(800041)">
                    <input
                      class="publicinput"
                      type="text"
                      v-model="addObj.remark"
                    />
                  </FormItem>
                </Col>
              </Row>
              <Row type="flex" justify="space-between" class="code-row-bg">
                <Col span="24">
                  <FormItem :label="$t(200048)">
                    <ImgsUpload
                      :uList="addObj.bxImgList"
                      :key="'bxImgs'"
                      @activeName="outImgsUploadChild($event, 'bx')"
                      v-model="addObj.bxImgList"
                    ></ImgsUpload>
                  </FormItem>
                </Col>
              </Row>
              <Row type="flex" justify="space-between" class="code-row-bg">
                <Col span="24">
                  <FormItem :label="$t(200008)" prop="fault_description">
                    <input
                      class="publicinput"
                      style="width: 96%"
                      type="text"
                      v-model="addObj.fault_description"
                    />
                  </FormItem>
                </Col>
              </Row>
              <Row type="flex" justify="space-between" class="code-row-bg">
                <Col span="24">
                  <FormItem :label="$t(1590011)">
                    <ImgsUpload
                      :uList="addObj.gzImgList"
                      :key="'gzImgs'"
                      @activeName="outImgsUploadChild($event, 'gz')"
                      v-model="addObj.gzImgList"
                    ></ImgsUpload>
                  </FormItem>
                </Col>
              </Row>
              <Row type="flex" justify="space-between" class="code-row-bg">
                <Col span="24">
                  <FormItem :label="$t(200009)" prop="repair_process">
                    <input
                      class="publicinput"
                      style="width: 96%"
                      type="text"
                      v-model="addObj.repair_process"
                    />
                  </FormItem>
                </Col>
              </Row>
              <Row type="flex" justify="space-between" class="code-row-bg">
                <Col span="24">
                  <FormItem :label="$t(200010)" prop="real_faultid_desc">
                    <input
                      class="publicinput"
                      style="width: 96%"
                      type="text"
                      v-model="addObj.real_faultid_desc"
                    />
                  </FormItem>
                </Col>
              </Row>
            </Col>
            <Col span="2"></Col>
            <Col span="8">
              <SparePart
                :inputSpareParts="addObj.items"
                @activeName="outSparePartChild($event)"
              ></SparePart>
            </Col>
          </Row>
        </Form>
      </div>
    </Modal>

    <Modal
      :title="$t(1590012)"
      v-model="carousel"
      :loading="loading"
      :styles="{ top: '40px', width: '900px', height: '400px' }"
    >
      <div
        class="modal_body"
        style="
          width: 100% !important;
          height: 400px !important;
          padding: 0 10px;
          overflow: hidden;
        "
      >
        <Carousel v-if="carousel" v-model="carouselValue">
          <CarouselItem v-for="(item, index) in carouselData" :key="index">
            <span
              style="
                font-size: 0;
                width: 848px;
                height: 400px;
                display: table-cell;
                text-align: center;
                vertical-align: middle;
              "
            >
              <img alt :src="item" style="max-width: 100%; max-height: 100%" />
            </span>
            <span v-show="false">{{ index }}</span>
          </CarouselItem>
        </Carousel>
      </div>
    </Modal>
    <Modal
      class="newModalClass"
      :title="$t(901104)"
      v-model="feedbackmodel"
      :loading="loading"
      :styles="{ width: '500px', height: '340px' }"
    >
      <div class="modal_body">
        <div class="filter">
          <label>{{ this.$t("200013") }}：</label>
          <Input v-model="selectedObj.creator" disabled class="searchInput" />
        </div>
        <div class="filter">
          <label><i>*</i>{{ this.$t("200022") }}：</label>
          <Select
            v-model="feedbackobj.mode"
            label-in-value
            clearable
            class="searchSelect"
          >
            <Option
              v-for="(item, key) in feedbackobj.modelist"
              :value="item.id"
              :key="key"
              >{{ item.name }}</Option
            >
          </Select>
        </div>
        <div class="filter">
          <label><i>*</i>{{ this.$t("1590018") }}：</label>
          <Select
            v-model="feedbackobj.reason"
            label-in-value
            clearable
            class="searchSelect"
            filterable
            filter-by-label
          >
            <Option
              v-for="(item, key) in feedbackobj.reasonlist"
              :value="item.id"
              :key="key"
              :label="item.name"
              >{{ item.name }}</Option
            >
          </Select>
        </div>
        <div class="filter">
          <label>{{ this.$t("1950472") }}：</label>
          <Select
            v-model="feedbackobj.action"
            label-in-value
            clearable
            class="searchSelect"
          >
            <Option
              v-for="(item, key) in feedbackobj.actionlist"
              :value="item.id"
              :key="key"
              >{{ item.name }}</Option
            >
          </Select>
        </div>
        <div class="filter">
          <label><i>*</i>{{ this.$t("1590028") }}：</label>
          <Select
            v-model="feedbackobj.cost"
            label-in-value
            clearable
            class="searchSelect"
          >
            <Option
              v-for="(value, key) in feedbackobj.costlist"
              :value="key"
              :key="key"
              >{{ value }}</Option
            >
          </Select>
        </div>
        <div class="filter">
          <label>{{ this.$t("90000033") }}：</label>
          <Select
            v-model="feedbackobj.department"
            @on-change="changeDepartment($event, 'filter')"
            label-in-value
            clearable
            class="searchSelect"
          >
            <Option
              v-for="(item, key) in feedbackobj.departmentList"
              :value="item.id"
              :key="key"
              >{{ item.title }}</Option
            >
          </Select>

          <Select
            v-model="feedbackobj.user"
            :max-tag-count="2"
            clearable
            multiple
            class="searchSelect nowropStyle"
            style="margin-left: 10px"
          >
            <Option
              v-for="(item, key) in feedbackobj.userList"
              :value="item.id"
              :key="item.id"
              >{{ item.name }}</Option
            >
          </Select>
        </div>
        <div class="filter" style="display: flex; margin-bottom: 45px">
          <label>{{ $t("1030") }}：</label>
          <Input
            type="textarea"
            v-model="feedbackobj.remark"
            maxlength="300"
            show-word-limit
            class="searchInput MaxWidth"
            :autosize="{ minRows: 2, maxRows: 2 }"
          />
        </div>

        <div class="filter" style="display: flex; margin-bottom: 30px">
          <label>{{ $t("200011") }}：</label>
          <Input
            type="textarea"
            v-model="str_sparepart"
            maxlength="300"
            disabled
            class="searchInput MaxWidth"
            :autosize="{ minRows: 2, maxRows: 2 }"
          />
        </div>
      </div>
      <div slot="footer">
        <Button type="text" size="large" @click="closefeedback()">{{
          $t("1033")
        }}</Button>
        <Button type="primary" size="large" @click="addfeedback()">{{
          $t("1027")
        }}</Button>
      </div>
    </Modal>
    <Modal
      class="newModalClass"
      v-model="noteModal"
      :title="$t('90000032')"
      :styles="{ width: '840px' }"
    >
      <div class="modal_body newTableDiv" style="padding-right: 40px">
        <Table
          @on-selection-change="changeMultipleSelection"
          highlight-row
          :data="tableData2"
          :columns="tableColumns2"
          class="tableClass"
        ></Table>
        <div class="pageDiv">
          <div class="pageDirection">
            <Page
              :total="noteTotal"
              :current="notePage"
              @on-change="changePage2"
              show-elevator
              show-sizer
              show-total
              @on-page-size-change="handlePageSize2"
              :page-size-opts="[10, 20, 30, 40, 100]"
            ></Page>
          </div>
        </div>
      </div>
    </Modal>

    <!-- 详情模态框开始 -->
    <Modal
      class="newModalClass"
      :title="$t('950253')"
      v-model="detail_Model"
      :styles="{ width: '820px' }"
    >
      <div class="modal_body" style="width: 740px !important">
        <div style="margin-bottom: 10px">
          <div>
            <label>{{ $t("200013") }}：</label>
            <input
              type="text"
              v-model="detail_obj.creator"
              disabled
              class="publicinput ivu-input"
              style="
                width: 600px;
                background-color: rgb(235, 235, 228);
                color: black;
              "
            />
          </div>
        </div>
        <div style="margin-bottom: 10px">
          <div>
            <label>{{ $t("900810") }}：</label>
            <textarea
              name
              id
              v-model="detail_obj.remark"
              cols="97"
              disabled
              rows="3"
              style="resize: none; border-radius: 5px; vertical-align: middle"
            ></textarea>
          </div>
        </div>
        <div style="margin-bottom: 10px">
          <div>
            <label>{{ $t("900701") }}：</label>
            <textarea
              name
              id
              v-model="detail_obj.repair_remark"
              disabled
              cols="97"
              rows="3"
              style="resize: none; border-radius: 5px; vertical-align: middle"
            ></textarea>
          </div>
        </div>
        <div style="margin-bottom: 10px">
          <div>
            <label>{{ $t("200011") }}：</label>
            <textarea
              name
              id
              v-model="detail_obj.sparepart"
              cols="97"
              disabled
              rows="3"
              style="resize: none; border-radius: 5px; vertical-align: middle"
            ></textarea>
          </div>
        </div>
        <div style="margin-bottom: 10px">
          <div>
            <Row
              type="flex"
              justify="center"
              style="text-align: center; font-size: 16px"
            >
              <Col span="2">
                <div class="detail_border">{{ $t("1590001") }}</div>
              </Col>
              <Col span="2">
                <Icon type="md-arrow-forward" />
              </Col>
              <Col span="2">
                <div class="detail_border">{{ $t("1590002") }}</div>
              </Col>
              <Col span="2">
                <Icon type="md-arrow-forward" />
              </Col>
              <Col span="2">
                <div class="detail_border">{{ $t("1590003") }}</div>
              </Col>
              <Col span="2">
                <Icon type="md-arrow-forward" />
              </Col>
              <Col span="2">
                <div class="detail_border">{{ $t("1590004") }}</div>
              </Col>
              <Col span="2">=</Col>
              <Col span="2">
                <div class="detail_border">{{ $t("90000034") }}</div>
              </Col>
              <Col span="2"></Col>
            </Row>
            <br />
          </div>
          <div>
            <Row
              type="flex"
              justify="center"
              style="text-align: center; font-size: 16px"
            >
              <Col span="2">
                <div class="detail_border">{{ detail_obj.time1 }}</div>
              </Col>
              <Col span="2">(分钟)</Col>
              <Col span="2">
                <div class="detail_border">{{ detail_obj.time2 }}</div>
              </Col>
              <Col span="2">(分钟)</Col>
              <Col span="2">
                <div class="detail_border">{{ detail_obj.time3 }}</div>
              </Col>
              <Col span="2">(分钟)</Col>
              <Col span="2">
                <div class="detail_border">{{ detail_obj.time4 }}</div>
              </Col>
              <Col span="2">(分钟)</Col>
              <Col span="2">
                <div class="detail_border">{{ detail_obj.time6 }}</div>
              </Col>
              <Col span="2">(分钟)</Col>
            </Row>
          </div>
          <br />
          <div>
            <Row
              type="flex"
              justify="center"
              style="text-align: center; font-size: 16px"
            >
              <Col span="2">
                <div class="detail_border">&nbsp;{{ detail_obj.user1 }}</div>
              </Col>
              <Col span="2"></Col>
              <Col span="2">
                <div class="detail_border">&nbsp;{{ detail_obj.user2 }}</div>
              </Col>
              <Col span="2"></Col>
              <Col span="2">
                <div class="detail_border">&nbsp;{{ detail_obj.user3 }}</div>
              </Col>
              <Col span="2"></Col>
              <Col span="2">
                <div class="detail_border">&nbsp;{{ detail_obj.user4 }}</div>
              </Col>
              <Col span="2"></Col>
              <Col span="2">
                <div class="detail_border">&nbsp;{{ detail_obj.user6 }}</div>
              </Col>
              <Col span="2"></Col>
            </Row>
          </div>
          <br />
          <div v-if="piclist.length > 0" style="width: 670px; height: 300px">
            <Carousel :height="300" style="width: 670px" loop>
              <CarouselItem v-for="(item, key) in piclist" :key="key">
                <div style="width: 670px; height: 300px">
                  <img :src="item" style="width: 670px; height: 300px" alt />
                </div>
              </CarouselItem>
            </Carousel>
          </div>
        </div>
      </div>
      <div slot="footer">
        <Button
          type="primary"
          size="large"
          @click="detail_Model = false"
          v-text="$t('1011')"
          >确定</Button
        >
      </div>
    </Modal>
  </div>
</template>
<script>
import axios from "@/libs/api.request";
import ImgsUpload from "_c/image-upload/imgs-upload.vue";
import SparePart from "_c/spare-part/spare-part.vue";
import moment from "moment";
export default {
  name: "tpm-list",
  components: {
    ImgsUpload,
    SparePart,
  },
  data() {
    const validateCreateTime = (rule, value, callback) => {
      // 正整数
      if (value != "") {
        callback();
      } else {
        return callback(new Error(this.$t(200102)));
      }
    };
    const validatePositiveInteger = (rule, value, callback) => {
      // 正整数
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(1590017)));
      }
    };
    const validateMachine = (rule, value, callback) => {
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(9000416)));
      }
    };
    const validateBxr = (rule, value, callback) => {
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(1590016)));
      }
    };
    const validateQdr = (rule, value, callback) => {
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(1590015)));
      }
    };
    const validateWxr = (rule, value, callback) => {
      if (value.length > 0) {
        callback();
      } else {
        return callback(new Error(this.$t(1590014)));
      }
    };
    const validateFxr = (rule, value, callback) => {
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(1590013)));
      }
    };
    const validateFaultType = (rule, value, callback) => {
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(500215)));
      }
    };
    const validateSSType = (rule, value, callback) => {
      if (/^[1-9]\d*$/.test(value)) {
        callback();
      } else {
        return callback(new Error(this.$t(100296)));
      }
    };
    return {
      datalevel: [], // 产线层级插件所需数据
      leveldata: [], // 产线层级选中数据
      levelid: 0, // 产线层级选中的section_id

      datamt: [], // 插件所需数据
      mtdata: [], // 选中数据
      mtid: 0, //
      Trouble_code1: "", // 故障代码第一个下拉框
      Trouble_code2: "", // 故障代码第二个下拉框
      Trouble_codelist: [], // 故障代码第二个下拉框列表
      ids: [], // 选取多啊行数据时，id的集合
      morecondition: false,
      feedbackmodel: false,
      filterObj: {
        machineType: "", /// config/MachineType/GetEditDcategory
        machineTypeMixed: "",
        faultType: 0,
        faultContent: "",
        repairname: "",
        repairid: "",
        compare: 2,
        compare_time: "",
        status: "",
        startTime: [], // '2020-01-01', '2020-01-31'
        morecondition: false, // 隐藏条件
        andonType: 0, // 安灯分类
        workordertype: 0,
      },

      initPageData: {
        machineTypeList: [], // filter设备类型  下拉菜单
        machineTypeMixedList: [], // filter子设备类型 下拉菜单
        faultTypeList: {
          1: this.$t(200022),
          2: this.$t(1590018),
          3: this.$t(1590019),
        }, // filter故障类型  下拉菜单
        faultContentList: [], // filter失效模式 下拉菜单
        statusEnum: {
          // filter工单状态
          1: this.$t(200032),
          2: this.$t(200033),
          3: this.$t(200034),
          4: this.$t(200035),
          5: this.$t(900704),
          6: this.$t(960459),
        },
        allUser: [],
        machineList: [], // addModal 设备名称 下拉菜单
        bxrList: [], // addModal报修人下拉菜单
        wxrList: [], // addModal维修人下拉菜单
        fxrList: [],
        ssTypeList: [], // addModal失效模式 下拉菜单
      },
      str_sparepart: "",
      addModal: false, // 添加Modal的开关
      loading: true,
      modalTitle: "",
      optType: "add", // add,edit
      tableloading: false,
      addObj: {
        id: 0,
        machineid: "", // 【设备id】!!!
        machineTypeId: 0, // 设备类型id
        createtime: "", // 报修时间
        bxr: "", // 报修人
        taketime: 0, // 响应用时
        repairtime: 0, // 维修用时
        qdr: 0, // 签到人
        wxr: [], // 维修人
        fxr: "", // 复线人
        faultType: "", // 故障类型，根据设备变动
        ssType: 0, // 失效模式，根据故障类型变动
        offlinestatus: 0, // 停机是，否
        remark: "", // 备注
        bxImgList: [], // 报修时上传照片
        images: "",
        fault_description: "", // 故障描述
        gzImgList: [], // 故障相关图片
        fault_desc_img: "",
        repair_process: "", // 维修排查过程
        real_faultid_desc: "", // 故障原因
        items: [],
        SparepartOut: "",
      },
      feedbackobj: {
        mode: "",
        modelist: [],
        reason: "",
        reasonlist: [],
        action: "",
        actionlist: [],
        costlist: {
          1: this.$t(930101),
          2: this.$t(930102),
          3: this.$t(930103),
          4: this.$t(930104),
          5: this.$t(930105),
          6: this.$t(930106),
          7: this.$t(930107),
          8: this.$t(930108),
          9: this.$t(930109),
          10: this.$t(930110),
          11: this.$t(930111),
          12: this.$t(600233),
        },
        department: "", // 部门
        departmentList: [], // 部门列表
        user: [], // 合作人
        userList: [], // 合作维修人
        remark: "",
      },
      selectedObj: {}, // 选中对象容器

      total: 0, // 刀位列表total
      page: 1, // 刀位列表当前页数
      pagesize: 10, // 刀位列表pagesize
      detail_Model: false, // 详情模态框
      piclist: [],
      detail_obj: {}, // 详情对象
      carouselValue: 0, // 预览图片
      carousel: false,
      carouselData: [],
      options1: [], // 人员list
      tableData1: [], // 刀位列表数据容器
      tableColumns1: [
        {
          title: "全选",
          width: 60,
          type: "selection",
        },
        // {
        //   // 列表字段属性集合
        //   type: "index2",
        //   title: this.$t(1008),
        //   key: "xuhao",
        //   render: (h, params) => {
        //     return h(
        //       "span",
        //       params.index + (this.page - 1) * this.pagesize + 1
        //     );
        //   },
        //   width: 80,
        // },
        {
          title: this.$t(200001),
          key: "work_order",
          width: 120,
        },
        {
          title: this.$t(1041),
          key: "station",
          width: 150,
        },
        {
          title: this.$t(100069),
          key: "location",
          width: 200,
        },
        {
          title: this.$t(200173),
          key: "offlinestatus", // 1,0
          width: 80,
        },
        {
          title: this.$t(8000046),
          key: "andontypename",
          width: 140,
        },
        {
          title: this.$t(1590028),
          key: "costname",
          width: 120,
        },

        {
          title: this.$t(200002),
          key: "repairstatus", // status:1,2,3,4,5,6
          width: 100,
        },
        {
          title: this.$t(200008),
          key: "fault_description",
          width: 140,
        },
        {
          title: this.$t(900746),
          width: 100,
          align: "center",
          render: (h, params) => {
            let images = params.row.imagesStr;
            let num;
            if (images) {
              let imagesArr = images.split(",");
              num = imagesArr.length;
            } else {
              num = 0;
            }
            return h("div", {
              domProps: {
                innerHTML: num,
              },
            });
          },
        },

        {
          title: this.$t(200012),
          key: "createtimeformat",
          width: 140,
          align: "center",
        },

        {
          title: this.$t(200023),
          key: "add_repairmid_name", // ele.totaltime+分钟
          width: 100,
        },
        {
          title: this.$t(200022),
          key: "faultcontent",
          width: 120,
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          render: (h, params) => {
            return h("span", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small",
                  },
                  style: {
                    marginRight: "5px",
                  },
                  on: {
                    click: (row) => {
                      this.detail_obj = params.row;
                      this.piclist = params.row.fault_desc_imgurls;
                      this.watch_detail();
                    },
                  },
                },
                "详情"
              ),
            ]);
          }, // end render
        },
      ],
      addModalRule: {
        createtime: [
          {
            required: true,
            validator: validateCreateTime,
            trigger: "blur",
          },
        ],
        machineid: [
          {
            required: true,
            validator: validateMachine,
            trigger: "blur",
          },
        ],
        taketime: [
          {
            required: true,
            validator: validatePositiveInteger,
            trigger: "blur",
          },
        ],
        bxr: [
          {
            required: true,
            validator: validateBxr,
            trigger: "blur",
          },
        ],
        repairtime: [
          {
            required: true,
            validator: validatePositiveInteger,
            trigger: "blur",
          },
        ],
        qdr: [
          {
            required: true,
            validator: validateQdr,
            trigger: "blur",
          },
        ],
        wxr: [
          {
            required: true,
            validator: validateWxr,
            trigger: "blur",
          },
        ],
        fxr: [
          {
            required: true,
            validator: validateFxr,
            trigger: "blur",
          },
        ],
        faultType: [
          {
            required: true,
            validator: validateFaultType,
            trigger: "blur",
          },
        ],
        ssType: [
          {
            required: true,
            validator: validateSSType,
            trigger: "blur",
          },
        ],
        fault_description: [
          {
            required: true,
            message: this.$t(950324),
            trigger: "blur",
          },
        ],
        repair_process: [
          {
            required: true,
            message: this.$t(1590020),
            trigger: "blur",
          },
        ],
        real_faultid_desc: [
          {
            required: true,
            message: this.$t(950325),
            trigger: "blur",
          },
        ],
      },
      noteModal: false, // 编辑记录弹框
      // notePerson: "", //编辑人
      // noteTime: "", //编辑时间
      // noteDetail: "", //编辑信息，
      andonList: [], // 安灯列表,
      tableData2: [],
      tableColumns2: [
        {
          // 列表字段属性集合
          type: "index2",
          title: this.$t(1008),
          key: "xuhao",
          render: (h, params) => {
            return h(
              "span",
              params.index + (this.notePage - 1) * this.notePagesize + 1
            );
          },
          width: 80,
        },
        {
          title: this.$t(200001),
          key: "work_order",
          width: 100,
        },
        {
          title: this.$t(700138),
          key: "create_time_str",
          width: 150,
        },
        {
          title: this.$t(100016),
          key: "user_name",
          width: 100,
        },
        {
          title: this.$t(800041),
          key: "content",
        },
      ],
      noteTotal: 0,
      notePage: 1,
      notePagesize: 10,
    };
  },
  created() {
    this.search(1, 10); // 初始化列表
    this.initlevel(); // 初始化产线层级
    this.initMT(); // 初始化设备类型下拉菜单
    this.initAddModal();
    this.iniandonlist();
    this.remoteMethod1("");
    // 格式化表格样式
    this.tableColumns1 = this.$time.initTableTitle(this.tableColumns1);
    this.tableColumns2 = this.$time.initTableTitle(this.tableColumns2);
  },
  // methods ************************************************************************************
  methods: {
    remoteMethod1(query) {
      // console.log(query);
      // if (query !== '') {
      // this.loading1 = true;
      // this.loading1 = false;
      var params = {
        name: query,
      };
      this.axios
        .request({
          url: "/config/projectuser/GetAllUserByCurrentProjectId",
          params,
          method: "get",
        })
        .then((res) => {
          if (res.data.ret === 1 && res.data.data.length > 0) {
            var arr = [];
            res.data.data.forEach((item) => {
              arr.push({
                id: item.mid,
                name: item.name,
              });
            });
            this.options1 = arr;
          } else {
            this.options1 = [];
          }
        });
      const list = this.options1.map((item) => {
        return {
          value: item,
          label: item,
        };
      });
      // this.options1 = list.filter(item => item.label.toLowerCase().indexOf(query.toLowerCase()) > -1);
      // } else {
      //     this.options1 = [];
      // }
    },
    watch_detail() {
      this.detail_Model = true;
    },
    changelevel(data) {
      // 切换产线层级，触发事件
      // 请求数据
      this.levelid = data[data.length - 1];
    },
    initMT() {
      axios
        .request({
          url: "/config/MachineType/GetMachineTypeTree",
          method: "get",
        })
        .then((res) => {
          this.datamt = res.data.data;
          this.mtdata = [];
        });
    },
    changeMultipleSelection(val) {
      var arr = [];
      val.forEach((item) => {
        arr.push(item.id);
      });
      this.ids = arr;
    },
    Trouble_change() {
      // 故障代码变化
      var params = {
        type: this.Trouble_code1,
      };
      this.axios
        .request({
          url: "/tpm/FaultType/GetFaultTypeListByType",
          params,
          method: "get",
        })
        .then((res) => {
          if (res.data.ret == 1) {
            this.Trouble_codelist = res.data.data;
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    initMachineType() {
      // 初始化产线层级
      axios
        .request({
          url: "/config/MachineType/GetEditDcategory",
          method: "get",
        })
        .then((res) => {
          if (res.data.data != undefined && res.data.data.length > 0) {
            this.initPageData.machineTypeList = res.data.data;
          } else {
            this.initPageData.machineTypeList = [];
          }
        });
    },
    faultTypeChange(data) {},

    faultTypeChangeAdd(row) {
      // obj=>{label:'',value:''}
      let params = {
        type: row === undefined ? 1 : row.value,
      };
      let temp = [];
      axios
        .request({
          url: "/tpm/FaultType/GetFaultTypeListByType",
          params,
          method: "get",
        })
        .then((res) => {
          if (res.data.ret === 1 && res.data.data != undefined) {
            res.data.data.forEach((item) => {
              temp.push({
                label: item.faulttype,
                value: item.id,
                tag: item.description,
              });
            });
          }
        });
      this.initPageData.ssTypeList = temp;
    },
    showImages(index, imageurls) {
      this.carouselData = imageurls;
      this.carousel = true;
    },
    timechange(value) {
      this.filterObj.startTime = value;
    },
    changeDate(dateA) {
      var dateee = new Date(dateA).toJSON();
      var date = new Date(+new Date(dateee) + 8 * 3600 * 1000)
        .toISOString()
        .replace(/T/g, " ")
        .replace(/\.[\d]{3}Z/, "");
      return date;
    },

    initlevel() {
      // 初始化产线层级
      axios
        .request({
          url: "config/ProjectLevelSection/GetSectionTree",
          method: "get",
        })
        .then((res) => {
          const arr = [];
          this.datalevel = res.data.data;
          arr.push(res.data.data[0].value);
          this.leveldata = arr;
        });
    },
    changePage(value) {
      // 换页事件
      this.page = value;
      this.search(this.page, this.pagesize);
    },
    handleRowChange(currentRow, oldCurrentRow) {
      // 选中一条数据，触发事件
      this.selectedObj = currentRow;
    },
    handlePageSize(value) {
      // 切换分页页数，触发事件
      this.pagesize = value;
      this.search(this.page, this.pagesize);
    },
    machineTypeChange(data) {
      this.filterObj.machinetype1 = data.length > 0 ? data[0] : 0;
      this.filterObj.machinetype2 = data.length > 1 ? data[1] : 0;
      this.mtdata = data;
    },
    search(page, pagesize) {
      this.tableloading = true;
      // 点击查询，触发事件
      var data = {
        compare:
          this.filterObj.compare === undefined ? "" : this.filterObj.compare,
        compare_time: this.filterObj.compare_time,
        endtime: this.filterObj.startTime[1],
        fault_id: this.Trouble_code1, // this.filterObj.faultContent,
        faulttype_id: this.Trouble_code2, // parseInt(this.filterObj.faultType),
        page: page,
        pagesize: pagesize,
        repairid: this.filterObj.repairid,
        repairname: "",
        repairmid: this.filterObj.repairname ? this.filterObj.repairname : 0,
        section_id: this.levelid,
        startTime: this.filterObj.startTime[0],
        status: this.filterObj.status,
        type_id: this.filterObj.machinetype1,
        concrete_id: this.filterObj.machinetype2,
        cost: this.filterObj.cost,
        andonType: this.filterObj.andonType,
        workordertype: this.filterObj.workordertype,
      };
      axios
        .request({
          url: "/tpm/Repair/GetRepairListNew",
          data,
          method: "post",
        })
        .then((res) => {
          this.tableloading = false;
          if (res.data.ret === 1) {
            this.total = res.data.total;
            this.mockTableData1(res.data.data);
            this.page = res.data.page;
          } else {
            this.tableData1 = [];
          }
        })
        .catch(function (error) {
          this.tableloading = false;
          // console.log(error);
        });
    },
    mockTableData1(tablelist) {
      // 转换数据，并赋值给列表数据容器tableData1
      let data = [];
      tablelist.forEach((item) => {
        if (item) {
          let imagesurls = item.images != "" ? item.images.split(",") : [];
          let imagesurl = imagesurls.length + "个";
          let fault_desc_imgurls =
            item.fault_desc_img != "" ? item.fault_desc_img.split(",") : [];
          let fault_desc_imgurl = fault_desc_imgurls.length + "个";
          data.push({
            id: item.id,
            station: item.station,
            location: item.location,
            offlinestatus:
              item.offlinestatus == 1 ? this.$t(300030) : this.$t(300031), // 1，0
            faulttype: item.faulttype,
            faultcontent: item.faultcontent,
            imagesurl: imagesurl, // item.images.split(",")
            imagesurls: imagesurls,
            remark: item.remark,
            repairstatus: this.initPageData.statusEnum[item.status], // 1，2，3，4，5，6
            status: item.status,
            fault_description: item.fault_description,
            fault_desc_imgurl: fault_desc_imgurl, /// /item.fault_desc_img.split(",")
            fault_desc_imgurls: fault_desc_imgurls, /// /item.fault_desc_img.split(",")
            repair_process: item.repair_process,
            real_faultid_desc: item.real_faultid_desc,
            sparepart: item.sparepart,
            repair_remark: item.repair_remark,
            createtimeformat: item.createtimeformat,
            repairtime: item.repairtime + this.$t(200028),
            totaltime: item.totaltime + this.$t(200028),
            add_repairmid_name: item.add_repairmid_name,
            cost: item.cost,
            costname: this.feedbackobj.costlist[item.cost],
            machineId: item.machineId,
            fault_id: item.fault_id,
            fault_description_id: item.fault_description_id,
            add_repairmid: item.add_repairmid,
            add_repairmid_sectionid: item.add_repairmid_sectionid,
            andontypename: item.andontypename,
            time1: item.time1,
            time2: item.time2,
            time3: item.time3,
            time4: item.time4,
            time5: item.time5,
            time6: item.time6,
            work_order: item.work_order,
            creator: item.creator,
            user1: item.user1,
            user2: item.user2,
            user3: item.user3,
            user4: item.user4,
            user5: item.user5,
            user6: item.user6,
            imagesStr: item.images,
          });
        }
      });
      this.tableData1 = data;
    },

    initAddModal() {
      this.initAllMachines(); // 初始化添加维修记录弹层中的全部设备下拉菜单
      this.initbxrList(); // 初始化  报修人下拉列表
      this.initqdrList(2); // 初始化 type=2签到人，维修人下拉列表
      this.initqdrList(1); // 初始化 type=1复线人下拉列表
      this.initPageData.ssTypeList = []; // 初始化故障代码 下拉列表
      this.addObj = {
        id: 0,
        machineid: "", // 【设备id】!!!
        machineTypeId: 0, // 设备类型id
        createtime: "", // 报修时间
        bxr: "", // 报修人
        taketime: 0, // 响应用时
        repairtime: 0, // 维修用时
        qdr: 0, // 签到人
        wxr: [], // 维修人
        fxr: "", // 复线人
        faultType: "", // 故障类型，根据设备变动
        ssType: 0, // 失效模式，根据故障类型变动
        offlinestatus: 0, // 停机是，否
        remark: "", // 备注
        bxImgList: [], // 报修时上传照片
        images: "",
        fault_description: "", // 故障描述
        gzImgList: [], // 故障相关图片
        fault_desc_img: "",
        repair_process: "", // 维修排查过程
        real_faultid_desc: "", // 故障原因
        items: [],
        SparepartOut: "",
      };
    },
    initAllMachines() {
      var data = {
        sectionId: 0,
      };
      axios
        .request({
          url: "/config/Machine/GetAllMachines",
          data,
          method: "get",
        })
        .then((res) => {
          let temp = [];
          if (
            res.data.ret === 1 &&
            res.data.data != undefined &&
            res.data.data.length > 0
          ) {
            res.data.data.forEach((item) => {
              temp.push({
                machinename: item.title, // 设备名称
                typeid: item.typeid, // 设备类型id
                id: item.id, // 设备id
              });
            });
          }
          this.initPageData.machineList = temp;
        });
    },
    initbxrList() {
      axios
        .request({
          url: "/config/ProjectUser/GetAllUserByCurrentProjectId",
          method: "get",
        })
        .then((res) => {
          let temp = [];
          if (
            res.data.ret === 1 &&
            res.data.data != undefined &&
            res.data.data.length > 0
          ) {
            res.data.data.forEach((item) => {
              temp.push({
                label: item.name,
                value: item.mid,
                id: item.id,
              });
            });
          }
          this.initPageData.bxrList = temp;
        });
    },
    initqdrList(type) {
      axios
        .request({
          url: "/config/ProjectUser/GetProductionUsers?typeId=" + type,
          method: "get",
        })
        .then((res) => {
          let temp = [];
          if (
            res.data.ret === 1 &&
            res.data.data != undefined &&
            res.data.data.length > 0
          ) {
            res.data.data.forEach((item) => {
              temp.push({
                label: item.name,
                value: item.mid,
              });
            });
          }
          if (type === 2) {
            // 维修人，签到人列表
            this.initPageData.qdrList = temp;
            this.initPageData.wxrList = temp;
          } else {
            this.initPageData.fxrList = temp;
          }
        });
    },

    add() {
      // 添加
      this.addModal = true;
      this.modalTitle = this.$t(1002);
      this.optType = "add";
      this.initAddModal(); // 初始化
      this.$refs.addObj.resetFields();
    },
    edit() {
      if (this.selectedObj.id === "" || this.selectedObj.id === undefined) {
        this.$Message.error(this.$t("1043"));
        return false;
      }
      this.addModal = true;
      this.modalTitle = this.$t(1003);
      this.optType = "edit";
      this.initEditModal();
      this.$refs.addObj.resetFields();
    },
    initEditModal() {
      let params = {
        id: this.selectedObj.id,
      };
      axios
        .request({
          url: "/tpm/Repair/getRepairInfoDetail",
          params,
          method: "get",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            this.addObj.bxImgList = [];
            let item = res.data.data;
            this.addObj.id = item.id;
            // 根据machinetype_id找到machineid,因为接口给的machineId=0!!!
            if (this.initPageData.machineList.length > 0) {
              this.initPageData.machineList.forEach((dropdown_item) => {
                if (dropdown_item.typeid === item.machinetype_id) {
                  this.addObj.machineid = dropdown_item.id;
                }
              });
            }
            this.addObj.machineTypeId = item.machinetype_id;
            this.addObj.createtime = moment(item.createtime * 1000).format(
              "YYYY-MM-DD HH:mm:ss"
            );
            this.addObj.bxr = item.mid;
            this.addObj.taketime = item.taketime;
            this.addObj.repairtime = item.repairtime;
            this.addObj.qdr = item.signmid;
            this.addObj.wxr = item.add_repairmid.split(",").map((value) => {
              return parseInt(value);
            });
            this.addObj.fxr = item.checkmid;
            this.addObj.faultType = item.faultlist_id.toString();
            this.addObj.ssType = item.faultcontent_id;
            this.addObj.offlinestatus = item.offlinestatus;
            this.addObj.remark = item.remark;
            let tempBximgs = item.images.split(",");
            let bximgs = [];
            if (tempBximgs.length > 0) {
              tempBximgs.forEach((item) => {
                if (item != "") {
                  bximgs.push({
                    name: "abc.png",
                    url: item,
                    status: "finished",
                  });
                }
              });
            }
            this.addObj.bxImgList = bximgs;

            this.addObj.images = item.images;
            this.addObj.fault_description = item.fault_description;
            let tempGzimgs = item.fault_desc_img.split(",");
            let gzimgs = [];
            if (tempGzimgs.length > 0) {
              tempGzimgs.forEach((item) => {
                if (item != "") {
                  gzimgs.push({
                    name: "abc.png",
                    url: item,
                    status: "finished",
                  });
                }
              });
            }
            this.addObj.gzImgList = gzimgs;

            this.addObj.repair_process = item.repair_process;
            this.addObj.real_faultid_desc = item.real_faultid_desc;
            this.addObj.items = [];
            let spareList = item.sparepartid.split(",");
            let tempSpareList = [];
            if (spareList.length > 0) {
              let spareIndex = 1;
              spareList.forEach(function (spareid_num, index) {
                let tempArr = spareid_num.split("*");
                if (spareid_num.length > 0) {
                  tempSpareList.push({
                    spareid: tempArr[0],
                    spare: "spare name",
                    num: parseInt(tempArr[1]),
                    index: spareIndex,
                  });
                  spareIndex++;
                }
              });
              this.addObj.items = tempSpareList;
            }
            this.addObj.SparepartOut = item.sparepartid;
            this.faultTypeChangeAdd();
          }
        });
    },

    del() {
      if (this.ids.length < 1) {
        this.$Message.error(this.$t("1017"));
        return false;
      }
      this.confirm();
    },
    confirm() {
      // 确认删除
      this.$Modal.confirm({
        title: this.$t("1018"),
        content: "",
        width: "290px",
        closable: true,
        okText: this.$t("1004"),
        onOk: () => {
          var data = {
            ids: this.ids,
          };
          this.axios
            .request({
              url: "/tpm/Repair/DeleteRepairOne",
              data,
              method: "post",
            })
            .then((res) => {
              if (res.data.ret === 1) {
                this.search(1, this.pagesize);
                this.$Message.success(this.$t("1"));
                this.ids = [];
              } else {
                this.$Message.error(this.$t(res.data.msg));
                // alert(123)
                // this.$Message.error(this.$t())
                return false;
              }
            });
        },
        onCancel: () => {
          return false;
        },
      });
    },

    toExcel() {
      // 导出excel
      var data = {
        compare:
          this.filterObj.compare === undefined ? "" : this.filterObj.compare,
        compare_time: this.filterObj.compare_time,
        endtime: this.filterObj.startTime[1],
        fault_id: this.Trouble_code1, // this.filterObj.faultContent,
        faulttype_id: this.Trouble_code2, // parseInt(this.filterObj.faultType),
        page: 1,
        pagesize: 99999,
        repairid: this.filterObj.repairid,
        repairname: "",
        repairmid: this.filterObj.repairname ? this.filterObj.repairname : 0,
        section_id: this.levelid,
        startTime: this.filterObj.startTime[0],
        status: this.filterObj.status,
        type_id: this.filterObj.machinetype1,
        concrete_id: this.filterObj.machinetype2,
        cost: this.filterObj.cost,
        andonType: this.filterObj.andonType,
      };
      axios
        .request({
          url: "/tpm/Repair/GetRepairListExcel",
          data,
          method: "post",
        })
        .then((res) => {
          if (res.data.ret === 1) {
            window.location.href = axios.publicPath + "" + res.data.data;
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    handleSubmit(name) {
      // 添加
      this.$refs[name].validate((valid) => {
        if (valid) {
          // valid
          let tempBxList = [];
          this.addObj.bxImgList.forEach((item) => {
            // 报修相关
            tempBxList.push(item.url);
          });
          this.addObj.images = tempBxList.join(",");
          let tempGzList = [];
          this.addObj.gzImgList.forEach((item) => {
            // 故障相关
            tempGzList.push(item.url);
          });
          this.addObj.fault_desc_img = tempGzList.join(",");
          let data = {};
          if (this.optType === "add") {
            // 添加操作
            data = {
              SparepartOut: this.addObj.SparepartOut,
              checkmid: this.addObj.fxr,
              createtime: this.changeDate(this.addObj.createtime), // "2020-01-11 00:00:00"
              fault_desc_img: this.addObj.fault_desc_img,
              fault_description: this.addObj.fault_description,
              faultcontent_id: this.addObj.ssType,
              faultid: parseInt(this.addObj.faultType),
              images: this.addObj.images,
              machineid: this.addObj.machineid,
              mid: this.addObj.bxr,
              offlinestatus: this.addObj.offlinestatus,
              real_faultid_desc: this.addObj.real_faultid_desc,
              remark: this.addObj.remark,
              repair_process: this.addObj.repair_process,
              repairmid: this.addObj.wxr.join(","),
              repairtime: this.addObj.repairtime,
              signmid: this.addObj.qdr,
              taketime: this.addObj.taketime,
            };
            axios
              .request({
                url: "/tpm/Repair/AddRepairRecord",
                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.loading = false;
                  this.$nextTick(() => {
                    this.loading = true;
                  });
                }
              });
          } else {
            data = {
              SparepartOut: this.addObj.SparepartOut,
              checkmid: this.addObj.fxr,
              fault_desc_img: this.addObj.fault_desc_img,
              fault_description: this.addObj.fault_description,
              faultcontent_id: this.addObj.ssType,
              faultid: parseInt(this.addObj.faultType),
              id: this.addObj.id,
              images: this.addObj.images,
              machineid: this.addObj.machineid,
              mid: this.addObj.bxr,
              offlinestatus: this.addObj.offlinestatus,
              real_faultid_desc: this.addObj.real_faultid_desc,
              remark: this.addObj.remark,
              repair_process: this.addObj.repair_process,
              repairmid: this.addObj.wxr.join(","),
              repairtime: this.addObj.repairtime,
              signmid: this.addObj.qdr,
              taketime: this.addObj.taketime,
            };
            axios
              .request({
                url: "/tpm/Repair/EditRepairInfo",
                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(1000028));
                  // 解决ok按钮loading的问题
                  this.loading = false;
                  this.$nextTick(() => {
                    this.loading = true;
                  });
                }
              });
          }
        } else {
          // 解决ok按钮loading的问题
          this.loading = false;
          this.$nextTick(() => {
            this.loading = true;
          });
        }
      });
    },
    outImgsUploadChild(uploadList, type) {
      // type: gz=>故障 bx=>报修
      if (type === "gz") {
        this.addObj.gzImgList = uploadList;
      } else {
        this.addObj.bxImgList = uploadList;
      }
    },
    outSparePartChild(items) {
      this.addObj.items = items;
    },
    changecondition() {
      this.morecondition = !this.morecondition;
    },
    feedback() {
      if (this.selectedObj.id === "" || this.selectedObj.id === undefined) {
        this.$Message.error(this.$t("1043"));
        return false;
      }
      if (this.selectedObj.status !== 5) {
        this.$Message.error(this.$t("901099"));
        return false;
      }
      this.str_sparepart = "";
      this.feedbackmodel = true;
      this.feedbackobj.modelist = this.iniselect(1);
      this.feedbackobj.reasonlist = this.iniselect(2);
      this.feedbackobj.actionlist = this.iniselect(3);
      this.getDepartlist(0); // 获取部门
      this.getSpareparts(this.selectedObj.id); // 获取备件
    },
    // 获取部门
    getDepartlist(type) {
      axios
        .request({
          url: "/config/ProjectSection/GetSections",
          method: "get",
        })
        .then((res) => {
          if (res.data.data != undefined && res.data.data.length > 0) {
            this.feedbackobj.departmentList = res.data.data;
            // if (type === 1) {
              // this.feedbackobj.department = this.selectedObj.add_repairmid_sectionid;
              let params = {
                sectionid: 0,//this.feedbackobj.department
                page:1,
                pagesize:100000000
              };
              axios
                .request({
                  url: "/config/user/GetUsers",///config/ProjectUser/getUserListsBySectionId
                  params,
                  method: "get",
                })
                .then((res) => {
                  if (res.data.data != undefined && res.data.data.length > 0) {
                    this.feedbackobj.userList = res.data.data;
                    if (
                      this.selectedObj.add_repairmid != undefined &&
                      this.selectedObj.add_repairmid != ""
                    ) {
                      var arr = this.selectedObj.add_repairmid.split(",");
                      var arr1 = [];
                      arr.forEach((ele) => {
                        arr1.push(parseInt(ele));
                      });
                      this.feedbackobj.user = arr1;
                    }
                  } else {
                    this.feedbackobj.userList = [];
                  }
                });
            // }
          } else {
            this.feedbackobj.departmentList = [];
          }
        });
    },
    // 合作维修人
    changeDepartment(item, opt) {
      if (item === undefined) {
        return false;
      }
      if (parseInt(item.value) > 0) {
        let params = {
          sectionid: item.value,
          page:1,
          pagesize:100000000
        };
        axios
          .request({
            url: "/config/user/GetUsers",///config/ProjectUser/getUserListsBySectionId
            params,
            method: "get",
          })
          .then((res) => {
            if (res.data.data != undefined && res.data.data.length > 0) {
              this.feedbackobj.userList = res.data.data;
              // this.feedbackobj.user = [];
            } else {
              this.feedbackobj.userList = [];
            }
          });
      }
    },
    closefeedback() {
      this.feedbackmodel = false;
      this.feedbackobj = {};
    },
    // 编辑反馈
    editFeedback() {
      if (this.selectedObj.id === "" || this.selectedObj.id === undefined) {
        this.$Message.error(this.$t("1043"));
        return false;
      }
      if (this.selectedObj.status !== 6) {
        this.$Message.error(this.$t("901099"));
        return false;
      }
      this.str_sparepart = "";
      this.feedbackmodel = true;
      this.feedbackobj.modelist = this.iniselect(1);
      this.feedbackobj.reasonlist = this.iniselect(2);
      this.feedbackobj.actionlist = this.iniselect(3);
      this.getDepartlist(1); // 获取部门
      this.feedbackobj.cost = "" + this.selectedObj.cost; // 字符串型
      this.feedbackobj.remark = this.selectedObj.repair_remark;
      this.getSpareparts(this.selectedObj.id); // 获取备件
    },
    addfeedback() {
      if (this.feedbackobj.mode === undefined || this.feedbackobj.mode === "") {
        this.$Message.error(this.$t("100296"));
        return false;
      }
      if (
        this.feedbackobj.reason === undefined ||
        this.feedbackobj.reason === ""
      ) {
        this.$Message.error(this.$t("901098"));
        return false;
      }
      if (this.feedbackobj.cost === undefined || this.feedbackobj.cost === "") {
        this.$Message.error(this.$t("901097"));
        return false;
      }
      var data = {
        repairid: this.selectedObj.id,
        mode: this.feedbackobj.mode,
        reason: this.feedbackobj.reason,
        action: this.feedbackobj.action,
        remark: this.feedbackobj.remark,
        cost: this.feedbackobj.cost,
        midarr:
          this.feedbackobj.user.length > 0
            ? this.feedbackobj.user.join(",")
            : "",
      };
      var url = "";
      if (this.selectedObj.status === 5) {
        url = "/tpm/apprepair/AddFeedBack";
      } else {
        url = "/tpm/apprepair/EditFeedBack";
      }

      this.axios
        .request({
          url: url,
          data,
          method: "post",
        })
        .then((res) => {
          if (res.data.ret == 1) {
            this.$Message.success(this.$t(1055));
            this.feedbackmodel = false;
            this.page = 1;
            this.search(this.page, this.pagesize);
          } else {
            this.$Message.error(this.$t(res.data.msg));
          }
        });
    },
    iniselect(type) {
      let temp = [];
      var params = {
        machineid: this.selectedObj.machineId,
        faulttype: type,
      };
      this.axios
        .request({
          url: "/tpm/FaultType/GetFaultTypeListByMachineId",
          params,
          method: "get",
        })
        .then((res) => {
          if (res.data.ret == 1) {
            res.data.data.forEach((item) => {
              temp.push({
                id: item.id,
                name: item.faulttype,
              });
            });
          }
        });
      if (type === 1) {
        this.feedbackobj.mode = this.selectedObj.fault_id;
      } else if (type === 2) {
        this.feedbackobj.reason = this.selectedObj.fault_description_id;
      } else {
        this.feedbackobj.action = parseInt(this.selectedObj.repair_process);
      }

      return temp;
    },
    iniandonlist() {
      var params = {
        level: 2,
      };
      this.axios
        .request({
          url: "/tpm/andon/GetErrorsByLevel",
          params,
          method: "get",
        })
        .then((res) => {
          if (res.data.ret == 1) {
            this.andonList = res.data.data;
          }
        });
    },
    // 编辑记录
    editNote() {
      this.noteModal = true;
      this.getNotes(this.notePage, this.notePagesize);
    },
    // 获取记录
    getNotes(page, pagesize) {
      this.axios
        .request({
          url:
            "/tpm/apprepair/GetEditRecord?page=" +
            page +
            "&pagesize=" +
            pagesize,
          method: "get",
        })
        .then((res) => {
          let temp = [];
          if (res.data.ret == 1) {
            res.data.data.forEach((item) => {
              temp.push({
                repair_id: item.repair_id,
                create_time_str: item.create_time_str,
                user_name: item.user_name,
                content: item.content,
                work_order: item.work_order,
              });
            });
            this.tableData2 = temp;
            this.noteTotal = res.data.total;
          }
        });
    },
    getSpareparts(id) {
      var params = { repair_id: id };
      this.axios
        .request({
          url: "/tpm/AppSparepart/GetPrepareSpareparts",
          methods: "get",
          params,
        })
        .then((res) => {
          if (res.data.ret == 1) {
            var data = res.data.data;
            var str = "";
            if (data.length > 0) {
              data.forEach((item) => (str += item.name + ","));
            }
            this.str_sparepart = str.substring(0, str.length - 1);
          }
        });
    },
    changePage2(value) {
      // 换页事件
      this.notePage = value;
      this.getNotes(this.notePage, this.notePagesize);
    },
    handlePageSize2(value) {
      // 切换分页页数，触发事件
      this.notePagesize = value;
      this.getNotes(this.notePage, this.notePagesize);
    },
  },
  watch: {
    "addObj.items"(val) {
      let temp = [];
      val.forEach((item) => {
        // 备件相关
        temp.push(item.spareid + "*" + item.num);
      });
      this.addObj.SparepartOut = temp.join(",");
    },
  },
};
</script>
<style lang="less" scoped>
.detail_border {
  border: 0.5px solid blue;
}
</style>
