<template>
  <div class="mod-config">

 <!--    <div>-->
<!--        <span @click="favoriteFunction()">-->
<!--         <icon-svg :name="favorite?'xiangqufill':'xiangqu'" class="sl-svg"></icon-svg>-->
<!--        </span>-->
<!--    </div>-->

    <el-form :inline="true" label-position="top" :model="searchData" @keyup.enter.native="getDataList()">
      <el-form-item :label="'BU'">
        <el-select v-model="searchData.buDesc" placeholder="请选择" clearable style="width: 100px">
          <el-option
            v-for = "i in userBuList"
            :key = "i.buNo"
            :label = "i.buDesc"
            :value = "i.buDesc">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'紧急程度'">
        <el-select v-model="searchData.urgency" placeholder="请选择" clearable style="width: 100px">
          <el-option label="特急" value="特急"></el-option>
          <el-option label="紧急" value="紧急"></el-option>
          <el-option label="一般" value="一般"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'反馈单号'">
        <el-input v-model="searchData.feedBackID" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'设备编码'">
        <el-input v-model="searchData.objectID" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'故障原因'">
        <el-input v-model="searchData.defectDesc" clearable style="width: 120px"></el-input>
      </el-form-item>
      <el-form-item :label="'状态'">
        <el-select filterable v-model="searchData.status" clearable style="width: 130px">
          <el-option label="已下达" value="已下达"></el-option>
          <el-option label="维修确认" value="维修确认"></el-option>
          <el-option label="维修完成" value="维修完成"></el-option>
          <el-option label="维修失败" value="维修失败"></el-option>
          <el-option label="已取消" value="已取消"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item :label="'故障发现日期'">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.startDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item style="margin-top: 23px;">
        <laber style="margin-left: -9px;font-size: 19px">&#10142</laber>
      </el-form-item>
      <el-form-item  :label="' '">
        <el-date-picker
          style="width: 120px"
          v-model="searchData.endDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item  :label="' '">
        <el-button v-if="!authSearch" @click="getDataList">查询</el-button>
        <el-button v-if="!authSave" @click="saveModal">新增</el-button>
        <download-excel
          :fields="fields()"
          :data="exportData"
          type="xls"
          :name="exportName"
          :header="exportHeader"
          :footer="exportFooter"
          :fetch="createExportData"
          :before-generate="startDownload"
          :before-finish="finishDownload"
          worksheet="导出信息"
          class="el-button el-button--primary el-button--medium">
          {{ "导出" }}
        </download-excel>
      </el-form-item>
    </el-form>

    <el-table
      :height="height"
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        prop="buDesc"
        header-align="center"
        align="center"
        label="BU"
        width="60">
      </el-table-column>
      <el-table-column
        prop="urgency"
        header-align="center"
        align="center"
        label="紧急程度"
        width="70">
        <template slot-scope="scope">
          <div :style="{fontWeight:'bold', color: scope.row.urgency === '特急' ? 'red' : scope.row.urgency === '紧急' ? '#ffa500e0' : scope.row.urgency === '一般' ? '#47B0FF' : ''}">
            {{ scope.row.urgency }}
          </div>
        </template>
      </el-table-column>
      <el-table-column
        v-for="(item,index) in columnList" :key="index"
        :sortable="item.columnSortable"
        :prop="item.columnProp"
        :header-align="item.headerAlign"
        :show-overflow-tooltip="item.showOverflowTooltip"
        :align="item.align"
        :fixed="item.fixed==''?false:item.fixed"
        :min-width="item.columnWidth"
        :label="item.columnLabel">
        <template slot-scope="scope">
          <span v-if="!item.columnHidden">{{ scope.row[item.columnProp] }}</span>
          <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="100"
        label="操作">
        <template slot-scope="scope">
          <a type="text" size="small" v-if="scope.row.status === '已录入' && !authCancel" @click="cancelFeedBack(scope.row)">取消反馈</a>
          <a type="text" size="small" v-if="scope.row.status === '已录入' && !authRelease" @click="createDefectOrderModel(scope.row)">下达</a>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[20, 50, 100, 200, 500]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>

    <!-- 下达 -->
    <el-dialog title="下达维修工单" :close-on-click-modal="false" v-drag :visible.sync="modalFlag" width="570px">
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="计划编码:">
          <el-input v-model="modalData.feedBackID" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="计划描述:">
          <el-input v-model="modalData.feedBackDesc" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item >
          <span slot="label" style="">设备编码</span>
          <el-input v-model="modalData.objectID" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="设备名称:">
          <el-input v-model="modalData.objectDesc" disabled style="width: 120px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item >
          <span slot="label" style="">故障编码</span>
          <el-input v-model="modalData.defectID" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="故障原因:">
          <el-input v-model="modalData.defectDesc" disabled style="width: 120px"></el-input>
        </el-form-item>
        <el-form-item label="计划维修日期:">
          <el-date-picker
            style="width: 120px"
            v-model="modalData.planDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="必选">
          </el-date-picker>
        </el-form-item>
        <el-form-item >
          <span slot="label" style="" @click="getBaseList(201)"><a herf="#">计划执行人员</a></span>
          <el-input v-model="modalData.planOperator" style="width: 120px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button type="primary" @click="saveDefectOrder()">保存</el-button>
        <el-button type="primary" @click="modalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- 新增 -->
    <el-dialog title="设备故障报备" top="25vh" :close-on-click-modal="false" v-drag :visible.sync="saveModalFlag" width="500px">
      <el-form :inline="true" label-position="top" :model="saveModalData" :rules="saveRules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="反馈单号">
          <el-input v-model="saveModalData.feedBackID" disabled style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item label="BU" prop="bu" :rules="saveRules.bu">
          <el-select v-model="saveModalData.bu" placeholder="请选择" :disabled="modalDisableFlag" style="width: 221px">
            <el-option
              v-for = "i in userBuList"
              :key = "i.buNo"
              :label = "i.sitename"
              :value = "i.buNo">
              <span style="float: left;width: 100px">{{ i.sitename }}</span>
              <span style="float: right; color: #8492a6;white-space:nowrap;overflow:hidden;text-overflow:ellipsis; font-size: 11px;width: 60px">
                {{ i.buDesc }}
              </span>
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="saveModalData" :rules="saveRules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item prop="objectId" :rules="saveRules.objectId">
          <span slot="label" @click="getBaseList(200)"><a href="#">设备编码</a></span>
          <el-input v-model="saveModalData.objectID" style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item label="设备名称" prop="objectDesc" :rules="saveRules.objectDesc">
          <el-input v-model="saveModalData.objectDesc" disabled style="width: 221px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="saveModalData" :rules="saveRules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item prop="defectId" :rules="saveRules.defectId">
          <span slot="label" @click="getBaseList(1055)"><a href="#">故障编码</a></span>
          <el-input v-model="saveModalData.defectID" style="width: 221px"></el-input>
        </el-form-item>
        <el-form-item label="故障名称" prop="defectDesc" :rules="saveRules.defectDesc">
          <el-input v-model="saveModalData.defectDesc" disabled style="width: 221px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="saveModalData" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="故障日期">
          <el-date-picker style="width: 221px" v-model="saveModalData.defectDate" type="date" value-format="yyyy-MM-dd" format='yyyy-MM-dd' placeholder="请选择故障日期" :editable=false :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>
        <el-form-item label="故障描述">
          <el-input v-model="saveModalData.feedBackDesc" style="width: 221px"></el-input>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="saveModalData" :rules="saveRules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="紧急程度" prop="urgency" :rules="saveRules.urgency">
          <el-select v-model="saveModalData.urgency" style="width: 221px">
            <el-option label="一般" value="一般"></el-option>
            <el-option label="紧急" value="紧急"></el-option>
            <el-option label="特急" value="特急"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item :label="' '">
          <el-button type="primary" @click="uploadFaultImageModal()">故障图片</el-button>
        </el-form-item>
      </el-form>
      <el-form :inline="true" label-position="top" :model="saveModalData" :rules="saveRules" style="margin-left: 7px;margin-top: -5px;">
        <el-form-item label="备注">
          <el-input v-model="saveModalData.remark" style="width: 456px"></el-input>
        </el-form-item>
      </el-form>
      <el-footer style="height:40px;margin-top: 10px;text-align:center">
        <el-button :loading="saveLoading" type="primary" @click="saveData">保存</el-button>
        <el-button type="primary" @click="saveModalFlag = false">关闭</el-button>
      </el-footer>
    </el-dialog>

    <!-- chooseList -->
    <Chooselist ref="baseList" @getBaseData="getBaseData"></Chooselist>

    <upload-file-list ref="feedBackRef" :folder="uploadData.folder" :title="uploadData.title" :upload-status="true" :label="'反馈单号:'" :file-list.sync="fileData.file" :no="uploadData.feedBackID" :upload-dialog.sync="uploadDialog"></upload-file-list>

  </div>
</template>

<script>
  import {
    eamFeedBackSearch,
    cancelFeedBack,
    saveDefectOrder,
    saveEamGzBbData, // 新增方法
    getSiteAndBuByUserName,
    getFeedBackId, // 获得反馈单号
  } from "@/api/eam/eam.js"
  import {
    getTableDefaultListLanguage,
    getTableUserListLanguage,
  } from "@/api/table.js"
  import Chooselist from '@/views/modules/common/Chooselist_eam'
  import {userFavoriteList, saveUserFavorite, removeUserFavorite} from '@/api/userFavorite.js'
  import {uploadFileList} from '../../../api/base/baseFunction.js';
  import UploadFileList from "../common/uploadFileList.vue";
  export default {
    components: {
      Chooselist,
      UploadFileList
    },
    watch: {

    },
    data () {
      return {
        uploadDialog: false,
        uploadData: {
          folder: '',
          title: '',
          feedBackID: ''
        },
        fileData: {
          file: [],
          orderRef1: '',
          orderRef2: '',
          orderRef3: '',
          orderRef4: '',
          folder: ''
        },
        // 是否收藏
        favorite: false,
        // 导出 start
        exportData: [],
        exportName: "维修反馈" + this.dayjs().format('YYYYMMDDHHmmss'),
        exportHeader: ["维修反馈"],
        exportFooter: [],
        exportList: [],
        // 导出 end
        tagNo: '',
        searchData: {
          site: '',
          userName: this.$store.state.user.name,
          feedBackID: '',
          objectID: '',
          planOperator: '',
          functionType: 'C',
          status: '',
          startDate: '',
          defectDesc: '',
          endDate: '',
          page: 1,
          limit: 10,
          buDesc: '',
          urgency: '',
        },
        height: 200,
        pageIndex: 1,
        pageSize: 50,
        totalPage: 0,
        dataList: [],
        dataListLoading: false,
        dataListSelections: [],
        modalFlag: false,
        modalDisableFlag: false,
        saveModalFlag: false,
        saveModalDisableFlag: false,
        modalData: {
          site: '',
          bu: '',
          feedBackID: '',
          feedBackDesc: '',
          objectID: '',
          objectDesc: '',
          defectID: '',
          defectDesc: '',
          planDate: '',
          planOperator: '',
          userId: '',
        },
        saveModalData: {
          site: '',
          bu: '',
          feedBackID: '',
          feedBackDesc: '',
          objectID: '',
          objectDesc: '',
          defectID: '',
          defectDesc: '',
          defectDate: '',
          remark: '',
          urgency: '',
          status: '',
          createdBy: '',
          updateBy: ''
        },
        departmentList: [],
        // 展示列集
        columnList: [
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1FeedBackID',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'feedBackID',
            headerAlign: "center",
            align: "center",
            columnLabel: '反馈单号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1FeedBackDesc',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'feedBackDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: '反馈描述',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1DefectID',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'defectID',
            headerAlign: "center",
            align: "center",
            columnLabel: '故障代码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1DefectDesc',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'defectDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: '故障原因',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1ObjectID',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'objectID',
            headerAlign: "center",
            align: "center",
            columnLabel: '设备编码',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1ObjectDesc',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'objectDesc',
            headerAlign: "center",
            align: "center",
            columnLabel: '设备名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1Status',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'status',
            headerAlign: "center",
            align: "center",
            columnLabel: '状态',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1PlanOperatorName',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'planOperatorName',
            headerAlign: "center",
            align: "center",
            columnLabel: '计划执行人员',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1ActualOperatorName',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'actualOperatorName',
            headerAlign: "center",
            align: "center",
            columnLabel: '实际执行人员',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1DefectDate',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'defectDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '故障发现日期',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1CreatedDate',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'createdDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '反馈时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1FinishDate',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'finishDate',
            headerAlign: "center",
            align: "center",
            columnLabel: '维修时间',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1CreatedBy',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'createdBy',
            headerAlign: "center",
            align: "center",
            columnLabel: '报修人员账号',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1FeedbackBy',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'feedbackBy',
            headerAlign: "center",
            align: "center",
            columnLabel: '报修人员名称',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
          {
            userId: this.$store.state.user.name,
            functionId: 101004001,
            serialNumber: '101004001Table1Remark',
            tableId: "101004001Table1",
            tableName: "维修反馈表",
            columnProp: 'remark',
            headerAlign: "center",
            align: "center",
            columnLabel: '备注',
            columnHidden: false,
            columnImage: false,
            columnSortable: false,
            sortLv: 0,
            status: true,
            fixed: '',
            columnWidth: 95,
          },
        ],
        pickerOptions: {
          disabledDate(time) {
            let curDate = new Date().getTime()
            let curD = new Date()
            /* 获取当前月份 */
            let curMonth = curD.getMonth()
            /*  生成实际的月份: 由于curMonth会比实际月份小1, 故需加1 */
            curD.setMonth(curMonth + 1)
            /* 将日期设置为0, 这里为什么要这样设置, 我不知道原因, 这是从网上学来的 */
            curD.setDate(0)
            /* 返回当月的天数 */
            let days = curD.getDate()
            let three = days * 24 * 3600 * 1000
            let threeMonths = curDate - three
            return time.getTime() > Date.now()  || time.getTime() < threeMonths
          },
        },
        saveRules: {
          objectId: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          objectDesc: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          defectId: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          defectDesc: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          urgency: [
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ],
          bu:[
            {
              required: true,
              message: ' ',
              trigger: 'change'
            }
          ]
        },
        saveLoading: false,
        userBuList: [],
        authSearch: false,
        authSave: false,
        authCancel: false,
        authRelease: false,
        menuId: this.$route.meta.menuId,
      }
    },

    mounted () {
      this.$nextTick(() => {
        this.height = window.innerHeight - 210
      })
    },

    created () {
      // 按钮控制
      this.getButtonAuthData()
      // 获取用户的 site 和 bu
      this.getSiteAndBuByUserName()
      // 校验用户是否收藏
      this.favoriteIsOk()
      // 动态列
      this.getTableUserColumn(this.$route.meta.menuId+'table1',1)
      if (!this.authSearch) {
        // 获取数据列表
        this.getDataList()
      }
    },

    methods: {
      // 获取用户的bu
      getSiteAndBuByUserName () {
        let tempData = {
          username: this.$store.state.user.name,
        }
        getSiteAndBuByUserName(tempData).then(({data}) => {
          if (data.code === 0) {
            this.userBuList = data.rows
          }
        })
      },

      // 新增模态框
      saveModal () {
        // 获取反馈单号
        getFeedBackId().then(({data}) => {
          if (data.code === 0) {
            this.saveModalData = {
              site: '',
              bu: this.userBuList[0].buNo,
              feedBackID: data.feedBackID,
              feedBackDesc: '',
              objectID: '',
              objectDesc: '',
              defectID: '',
              defectDesc: '',
              defectDate: '',
              remark: '',
              urgency: '',
              status: '已录入',
              createdBy: this.$store.state.user.name,
            }
            this.fileData = {
              file: [],
              orderRef1: '',
              orderRef2: '',
              orderRef3: '',
              orderRef4: '',
              folder: ''
            }
            this.saveModalDisableFlag = false
            this.saveModalFlag = true
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 新增/编辑方法
      saveData () {
        if (this.saveModalData.bu === '' || this.saveModalData.bu == null) {
          this.$message.warning('请选择BU！')
          return
        }
        if (this.saveModalData.objectID === '' || this.saveModalData.objectID == null) {
          this.$message.warning("请选择设备!")
          return;
        }
        if (this.saveModalData.defectID === '' || this.saveModalData.defectID == null) {
          this.$message.warning("请选择故障!")
          return;
        }
        if (this.saveModalData.urgency === '' || this.saveModalData.urgency == null) {
          this.$message.warning("请选择紧急程度!")
          return;
        }
        this.saveLoading = true
        this.fileData.orderRef1 = this.saveModalData.bu.split('_')[0]
        this.fileData.orderRef2 = this.saveModalData.feedBackID
        this.fileData.orderRef3 = this.uploadData.folder
        this.fileData.orderRef4 = this.saveModalData.bu.split('_')[1]
        this.fileData.folder = this.uploadData.folder
        saveEamGzBbData(this.saveModalData).then(({data}) => {
          if (data && data.code === 0) {
            if (this.fileData.file.length > 0) { // 上传文件
              let tempData = new FormData()
              for (let i in this.fileData) {
                if (i === 'file') {
                  for (let j = 0; j < this.fileData.file.length; j++) {
                    tempData.append("file", this.fileData.file[j].raw)
                  }
                  continue
                }
                tempData.append(i, this.fileData[i])
              }
              uploadFileList(tempData).then(({data}) => {
                if (data.code !== 0) {
                  this.$message.warning(data.msg)
                }
              })
            }
            this.getDataList()
            this.saveModalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
          this.saveLoading = false
        })
      },

      // 校验用户是否收藏
      favoriteIsOk () {
        let userFavorite = {
          userId: this.$store.state.user.id,
          languageCode: this.$i18n.locale
        }
        userFavoriteList(userFavorite).then(({data}) => {
          for (let i = 0; i < data.list.length; i++) {
            if(this.$route.meta.menuId === data.list[i].menuId){
              this.favorite = true
            }
          }
        })
      },

      // 收藏 OR 取消收藏
      favoriteFunction () {
        let userFavorite = {
          userId: this.$store.state.user.id,
          functionId: this.$route.meta.menuId,
        }
        if (this.favorite) {
          removeUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = false
          })
        } else {
          // 收藏
          saveUserFavorite(userFavorite).then(({data}) => {
            this.$message.success(data.msg)
            this.favorite = true
          })
        }
      },

      // 获取基础数据列表S
      getBaseList (val,type) {
        this.tagNo = val
        this.$nextTick(() => {
          let strVal = ''
          let conSql = ''
          if (val === 201) {
            strVal = this.modalData.planOperator
            this.$refs.baseList.init(val, strVal)
          }
          if (val === 200) {
            strVal = this.saveModalData.objectID
            if (this.saveModalData.bu === null || this.saveModalData.bu === '') {
              this.$message.warning("请选择BU!")
              return
            } else {
              conSql = " and bu_no = '" + this.saveModalData.bu.split('_')[1] + "'"
              this.$refs.baseList.init(val, strVal, conSql)
            }
          }
          if (val === 1055) {
            strVal = this.saveModalData.defectID
            this.$refs.baseList.init(val, strVal)
          }
        })
      },

      /* 列表方法的回调 */
      getBaseData (val) {
        if (this.tagNo === 201) {
          this.modalData.planOperator = val.username
        }
        if (this.tagNo === 200) {
          this.saveModalData.objectID = val.ObjectID
          this.saveModalData.objectDesc = val.ObjectDesc
        }
        if (this.tagNo === 1055) {
          this.saveModalData.defectID = val.DefectID
          this.saveModalData.defectDesc = val.DefectDesc
        }
      },

      //导出excel
      async createExportData () {
        this.searchData.limit = -1
        this.searchData.page = 1
        await eamFeedBackSearch(this.searchData).then(({data}) => {
          this.exportList= data.page.list
        })
        return this.exportList
      },

      startDownload () {},

      finishDownload () {},

      fields () {
        let json = "{"
        this.columnList.forEach((item, index) => {
          if (index === this.columnList.length - 1) {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\""
          } else {
            json += "\"" + item.columnLabel + "\"" + ":" + "\"" + item.columnProp + "\"" + ","
          }
        })
        json += "}"
        let s = eval("(" + json + ")")
        return s
      },

      // 获取数据列表
      getDataList () {
        this.searchData.limit = this.pageSize
        this.searchData.page = this.pageIndex
        eamFeedBackSearch(this.searchData).then(({data}) => {
          if (data.code === 0) {
            this.dataList = data.page.list
            this.pageIndex = data.page.currPage
            this.pageSize = data.page.pageSize
            this.totalPage = data.page.totalCount
          }
          this.dataListLoading = false
        })
      },

      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },

      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },

      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },

      cancelFeedBack (row) {
        this.$confirm(`是否取消选定反馈单?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          cancelFeedBack(row).then(({data}) => {
            if (data && data.code === 0) {
              this.getDataList()
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {}
              })
            } else {
              this.$alert(data.msg, '错误', {
                confirmButtonText: '确定'
              })
            }
          })
        }).catch(() => {
        })
      },

      // 下达
      createDefectOrderModel (row) {
        this.modalData = {
          site: row.site,
          buNo: row.buNo,
          feedBackID: row.feedBackID,
          feedBackDesc: row.feedBackDesc,
          objectID: row.objectID,
          objectDesc: row.objectDesc,
          defectID: row.defectID,
          defectDesc: row.defectDesc,
          planDate: '',
          planOperator: '',
          userId: row.createdBy,
        }
        this.modalFlag = true
      },

      saveDefectOrder () {
        if (this.modalData.planDate === '' || this.modalData.planDate == null) {
          this.$message.warning('请选择计划维修日期！')
          return
        }
        if (this.modalData.planOperator === '' || this.modalData.planOperator == null) {
          this.$message.warning('请选择计划执行人员！')
          return
        }
        saveDefectOrder(this.modalData).then(({data}) => {
          if (data && data.code === 0) {
            this.getDataList()
            this.modalFlag = false
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {}
            })
          } else {
            this.$alert(data.msg, '错误', {
              confirmButtonText: '确定'
            })
          }
        })
      },

      // 动态列开始 获取 用户保存的 格式列
      async getTableUserColumn(tableId, columnId) {
        let queryTableUser = {
          userId: this.$store.state.user.name,
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          status: true,
          languageCode: this.$i18n.locale
        }
        await getTableUserListLanguage(queryTableUser).then(({data}) => {
          if (data.rows.length > 0) {
            //this.columnList1 = []
            switch (columnId) {
              case 1:
                this.columnList = data.rows
                break;
              // case 2:
              //   this.columnDetailList = data.rows
              //   break;
              // case 3:
              //   this.columnList2 = data.rows
              //   break;
              // case 4:
              //   this.columnList3 = data.rows
              //   break;
            }
          } else {
            this.getColumnList(tableId, columnId)
          }
        })
      },

      // 获取 tableDefault 列
      async getColumnList(tableId, columnId) {
        let queryTable= {
          functionId: this.$route.meta.menuId,
          tableId: tableId,
          languageCode: this.$i18n.locale
        }
        await getTableDefaultListLanguage(queryTable).then(({data}) => {
          if (!data.rows.length == 0) {
            switch (columnId) {
              case 1:
                this.columnList = data.rows
                break;
              // case 2:
              //   this.columnDetailList = data.rows
              //   break;
              // case 3:
              //   this.columnList2 = data.rows
              //   break;
              // case 4:
              //   this.columnList3 = data.rows
              //   break;
            }
          } else {
            // this.showDefault = true.
          }
        })
      },

      //获取按钮的权限数据
      getButtonAuthData () {
        let searchFlag = this.isAuth(this.menuId+":search")
        let saveFlag = this.isAuth(this.menuId+":save")
        let cancelFlag = this.isAuth(this.menuId+":cancel")
        let releaseFlag = this.isAuth(this.menuId+":release")
        //处理页面的权限数据
        this.authSearch = !searchFlag
        this.authSave = !saveFlag
        this.authCancel = !cancelFlag
        this.authRelease = !releaseFlag
      },

      // 上传保修故障图片
      uploadFaultImageModal () {
        this.uploadData = {
          folder: 'feedBack',
          title: '故障保修图片上传',
          feedBackID: this.saveModalData.feedBackID
        }
        this.uploadDialog = true
      },

    }
  }
</script>
