<template>
  <a-modal
    :title="$t('plan.correlate-pfmea.correlate-pfmea')"
    :visible="dialogFormVisible"
    :maskClosable="false"
    @cancel="close"
    :keyboard="false"
    width="100%"
    destroy-on-close
    :footer="false"
    @afterClose="close"
  >
    <a-card class="mb_8">
      <a-form layout="vertical">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
            <a-form-item :label="$t('plan.correlate-pfmea.project-number')">
              <a-select
                :value="queryParam.projectNo"
                :placeholder="
                  $t('plan.correlate-pfmea.please-enter-project-number')
                "
                @change="handleProjectChange"
                @search="getPFMEAMyProjectNoList"
                allowClear
                showSearch
              >
                <a-icon slot="suffixIcon" type="search" />
                <a-select-option
                  v-for="item in projectCodeList"
                  :key="item.projectSn"
                  :value="item.projectNo"
                >
                  {{ item.projectNo }}
                </a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
            <a-form-item :label="$t('plan.correlate-pfmea.pfmea-number')">
              <a-input
                allowClear
                v-model="queryParam.dfmeaCode"
                :placeholder="
                  $t('plan.correlate-pfmea.please-enter-pfmea-number')
                "
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
            <a-form-item
              :label="$t('plan.correlate-pfmea.operation/process-name')"
            >
              <a-input
                allowClear
                v-model="queryParam.name"
                :placeholder="
                  $t(
                    'plan.correlate-pfmea.please-enter-operation/process-name'
                  )
                "
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
            <a-form-item :label="$t('plan.correlate-pfmea.owner')">
              <a-input
                allowClear
                v-model="queryParam.user"
                :placeholder="
                  $t('plan.correlate-pfmea.please-enter-owner-name')
                "
              />
            </a-form-item>
          </a-col>
          <span v-show="advanceExpand">
            <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-item :label="$t('plan.correlate-pfmea.status')">
                <a-select
                  allowClear
                  v-model="queryParam.status"
                  :placeholder="$t('plan.correlate-pfmea.please-select-status')"
                >
                  <a-select-option
                    v-for="(item, index) in DFMEAStateList"
                    :key="index"
                    :value="item.value"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-item :label="$t('plan.correlate-pfmea.fmea-type')">
                <a-select
                  allowClear
                  v-model="queryParam.fmeaType"
                  :placeholder="
                    $t('plan.correlate-pfmea.please-select-fmea-type')
                  "
                >
                  <a-select-option
                    v-for="(item, index) in fmeaTypeList"
                    :key="index"
                    :value="item.value"
                  >
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-item :label="$t('plan.correlate-pfmea.department')">
                <a-select
                  allowClear
                  v-model="queryParam.orgName"
                  :placeholder="
                    $t('plan.correlate-pfmea.please-select-department')
                  "
                  showSearch
                  @change="orgInput"
                  @search="getFuzzyOrg"
                >
                  <a-icon slot="suffixIcon" type="search" />
                  <a-select-option
                    v-for="item in deptList"
                    :key="item.orgId"
                    :value="item.orgName"
                  >
                    {{ item.orgName }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-item :label="$t('plan.correlate-pfmea.version')">
                <a-input
                  allowClear
                  v-model="queryParam.versionDesc"
                  :placeholder="$t('plan.correlate-pfmea.please-enter-version')"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-item :label="$t('plan.correlate-pfmea.whether-prepare')">
                <a-select
                  allowClear
                  v-model="queryParam.isCompile"
                  :placeholder="
                    $t('plan.correlate-pfmea.please-select-whether-prepare')
                  "
                >
                  <a-select-option value="1">
                    {{ $t("global-dict.yes") }}
                  </a-select-option>
                  <a-select-option value="2">
                    {{ $t("global-dict.no") }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
<!--            <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">-->
<!--              <a-form-item-->
<!--                :label="$t('plan.correlate-pfmea.trial-production-schedule')"-->
<!--              >-->
<!--                <a-range-picker-->
<!--                  :value="tg1Date"-->
<!--                  @change="tg1Change"-->
<!--                  style="width:100%;"-->
<!--                />-->
<!--              </a-form-item>-->
<!--            </a-col>-->
            <a-col :xl="6" :lg="8" :md="12" :sm="24" :xs="24">
              <a-form-item
                :label="$t('plan.basic-information.planning-completion-time')"
              >
                <a-range-picker
                  :value="tg2Date"
                  @change="tg2Change"
                  style="width:100%"
                />
              </a-form-item>
            </a-col>
          </span>
          <a-col
            :xl="advanceExpand ? 12 : 24"
            :lg="16"
            :md="24"
            :sm="24"
            :xs="24"
          >
            <a-form-item class="tr" :label="'\xa0'">
              <a @click="toggleAdvance">
                {{
                  advanceExpand ? $t("global.collapse") : $t("global.expand")
                }}
                <a-icon :type="advanceExpand ? 'up' : 'down'" />
              </a>
              <a-button class="ml10" @click="reset">
                {{ $t("global-btn.reset") }}
              </a-button>
              <a-button class="ml10" type="primary" @click="search">
                {{ $t("global-btn.search") }}
              </a-button>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <div class="mt10">
        <a-button type="primary" @click="quotePFMEA">
          {{ $t("global-btn.correlate") }}
        </a-button>
      </div>
    </a-card>
    <a-card>
      <a-table
        :columns="columns"
        :dataSource="tableData"
        size="small"
        :customRow="customRow"
        :rowKey="
          (record, index) => {
            return index;
          }
        "
        :row-selection="{
          fixed: true,
          selectedRowKeys: selectedTableRowKeys,
          onChange: onSelectTableChange
        }"
        bordered
        :scroll="{ x: 2110, y: 400 }"
        :pagination="pagination"
        :loading="tableLoading"
        @change="handleOuterTableChange"
      >
        <template slot="lifeState" slot-scope="text, record">
          <span>{{ lifeStateMap[record.lifeState] || "-" }}</span>
        </template>
        <template slot="action1" slot-scope="text, record">
          <span>
            {{
              record.isDraw == "1"
                ? $t("global-constant.flag-status.yes")
                : record.isDraw == "2"
                ? $t("global-constant.flag-status.no")
                : "-"
            }}
          </span>
        </template>
        <template slot="relationFlag" slot-scope="text, record">
          <span>
            {{
              record.relationFlag == "1"
                ? $t("global-constant.flag-status.yes")
                : record.relationFlag == "0"
                ? $t("global-constant.flag-status.no")
                : "-"
            }}
          </span>
        </template>
        <template slot="approvalInfoList" slot-scope="approvalInfoList">
          <template>
            <span
              v-for="item in approvalInfoList"
              :key="item.approverId"
              :title="approvalInfoList | changeHandleItem"
              class="approverContent"
            >
              {{ item.approverName }}({{ item.approvalTypeDesc }})
            </span>
          </template>
        </template>
        <!-- 序号列 -->
        <template slot="index" slot-scope="text, record, index">
          <span>{{
            (pagination.current - 1) * pagination.pageSize + index + 1
          }}</span>
        </template>
      </a-table>
    </a-card>
  </a-modal>
</template>

<script>
import { stateDict } from "./assets/fmeaData";

const statusMap = {
  0: {
    status: "default",
    text: "关闭"
  },
  1: {
    status: "processing",
    text: "运行中"
  },
  2: {
    status: "success",
    text: "已上线"
  },
  3: {
    status: "error",
    text: "异常"
  }
};

export default {
  name: "PFMEAList",
  components: {},
  props: {
    showPFMEAList: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    showPFMEAList(val) {
      this.dialogFormVisible = val;
    }
  },
  data() {
    return {
      lifeStateMap: {
        "10": this.$t("global-dict.fmea-status.in-preparation"),
        "50": this.$t("global-dict.fmea-status.under-approval"),
        "51": this.$t("global-dict.fmea-status.archive"),
        "60": this.$t("global-dict.fmea-status.abandoned"),
        "1": this.$t("global-dict.fmea-status.disable")
      },
      // 当前页
      pageNo: 1,
      // 每页显示的数据条数
      pageSize: 10,
      // 分页
      pagination: {
        // defaultPageSize: 10,
        current: 1,
        pageNo: 1,
        pageSize: 10, // 默认每页显示数量
        showTotal: total =>
          this.$t("global-constant.table.show-total", [total]), // 显示总数
        showSizeChanger: true, // 显示可改变每页数量
        pageSizeOptions: ["10", "20", "50", "100", "200"], // 每页数量选项
        onShowSizeChange: (current, pageSize) => (this.pageSize = pageSize), // 改变每页数量时更新显示
        // onChange: (page, pageSize) => self.changePage(page, pageSize), //点击页码事件
        total: 0 //总条数
      },
      labelCol: {
        // 24格栅格系统，label所占为 a
        xl: 10, // ≥1600px 响应式栅格
        lg: 8, // ≥992px 响应式栅格
        md: 6, // ≥768px 响应式栅格
        sm: 6,
        xs: 6
      },
      wrapperCol: {
        // 24格栅格系统，label后面内容所占为 24-a
        xl: 14,
        lg: 16,
        md: 18,
        sm: 18,
        xs: 18
      },
      mdl: {},
      // 查询参数
      queryParam: {
        projectNo: undefined,
        dfmeaCode: undefined,
        name: undefined,
        user: undefined,
        status: undefined,
        fmeaType: undefined,
        projectSn: undefined,
        orgId: undefined,
        orgName: undefined,
        versionDesc: undefined,
        isCompile: undefined
      },
      /** TG1时间 */
      tg1Date: [],
      /** TG2时间 */
      tg2Date: [],
      // 表头
      columns: [
        {
          title: () => this.$t("plan.correlate-pfmea.serial-number"),
          width: 50,
          align: "center",
          scopedSlots: {
            customRender: "index"
          },
          ellipsis: true
        },
        {
          title: () => this.$t("plan.correlate-pfmea.pfmea-number"),
          width: 200,
          align: "center",
          dataIndex: "dfmeaCode",
          ellipsis: true
        },
        {
          title: () => this.$t("plan.correlate-pfmea.operation/process-name"),
          width: 220,
          align: "center",
          dataIndex: "partName",
          ellipsis: true
        },
        {
          title: () => this.$t("plan.correlate-pfmea.status"),
          width: 120,
          align: "center",
          dataIndex: "lifeState",
          scopedSlots: {
            customRender: "lifeState"
          },
          ellipsis: true
        },
        {
          title: () => this.$t("plan.correlate-pfmea.owner"),
          width: 100,
          align: "center",
          dataIndex: "dfmeaOwnerName",
          ellipsis: true
        },
        {
          title: () => this.$t("plan.correlate-pfmea.project-number"),
          width: 200,
          align: "center",
          dataIndex: "projectNo",
          ellipsis: true
        },
        {
          title: () => this.$t("plan.correlate-pfmea.department"),
          width: 120,
          align: "center",
          dataIndex: "departmentName",
          ellipsis: true
        },
        {
          title: () => this.$t("plan.correlate-pfmea.process-code"),
          width: 150,
          align: "center",
          dataIndex: "svpps",
          ellipsis: true
        },
        {
          title: () => this.$t("plan.correlate-pfmea.version"),
          width: 100,
          align: "center",
          dataIndex: "version",
          ellipsis: true
        },
        {
          title: () => this.$t("plan.correlate-pfmea.fmea-type"),
          width: 100,
          align: "center",
          dataIndex: "fmeaBusiType",
          ellipsis: true
        },
        {
          title: () => this.$t("plan.correlate-pfmea.whether-prepare"),
          width: 150,
          align: "center",
          scopedSlots: {
            customRender: "action1"
          },
          ellipsis: true
        },
        // {
        //   title: () =>
        //     this.$t("plan.correlate-pfmea.trial-production-schedule"),
        //   width: 200,
        //   dataIndex: "partTg1Time",
        //   align: "center",
        //   ellipsis: true
        // },
        {
          title: () => this.$t("plan.basic-information.planning-completion-time"),
          width: 200,
          align: "center",
          dataIndex: "partTg2Time",
          ellipsis: true
        },
        {
          title: () =>
            this.$t("plan.correlate-pfmea.whether-relate-family-fmea"),
          width: 200,
          align: "center",
          dataIndex: "relationFlag",
          scopedSlots: {
            customRender: "relationFlag"
          },
          ellipsis: true
        }
      ],
      /** 表格Loading */
      tableLoading: false,
      tableData: [],
      selectedRowKeys: [],
      selectedTableRowKeys: [],
      selectedRows: [],
      selectedTableRows: [],
      options: {
        alert: {
          show: true,
          clear: () => {
            this.selectedRowKeys = [];
          }
        },
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys,
          onChange: this.onSelectChange
        }
      },
      optionAlertShow: false,
      // 项目编号字典
      projectCodeList: [],
      // dfmea状态字典
      DFMEAStateList: [],
      // FMEA类型字典
      fmeaTypeList: [],
      // 部门字典
      deptList: [],
      // 项目DFMEA编号字典
      PFMEAList: [],
      // 弹窗传值
      versionFlag: false,
      versionTitle: "",
      tableDataList: null,
      // 参数存储
      fmeaId: "",
      // 按钮权限显示
      searchBtnFlag: false,
      queryBtnFlag: false,
      addBtnFlag: false,
      organizationBtnFlag: false,
      updateBtnFlag: false,
      delBtnFlag: false,
      delayBtnFlag: false,
      tempFormData: {},
      /** 模态框状态 */
      dialogFormVisible: false,
      advanceExpand: false
    };
  },
  filters: {
    statusFilter(type) {
      return statusMap[type].text;
    },
    statusTypeFilter(type) {
      return statusMap[type].status;
    },
    changeHandleItem(value) {
      let result = "";
      value.map(_ => {
        result += `${_.approverName}(${_.approvalTypeDesc}) `;
      });
      return result;
    }
  },
  created() {
    this.tableOption();
    var _this = this;
    document.onkeydown = function(e) {
      //按下回车提交
      let key = window.event.keyCode;
      //事件中keycode=13为回车事件
      if (key == 13) {
        _this.search();
      }
    };
  },
  methods: {
    // 收起/展开
    toggleAdvance() {
      this.advanceExpand = !this.advanceExpand;
    },
    // 重置
    reset() {
      this.queryParam.projectId = undefined;
      this.queryParam.dfmeaCode = undefined;
      this.queryParam.name = undefined;
      this.queryParam.user = undefined;
      this.queryParam.status = undefined;
      this.queryParam.fmeaType = undefined;
      this.queryParam.dept = undefined;
      this.queryParam.isDelay = undefined;
      this.queryParam.isCompile = undefined;
      this.queryParam.tg1_start = undefined;
      this.queryParam.tg1_end = undefined;
      this.queryParam.tg2_start = undefined;
      this.queryParam.tg2_end = undefined;
      this.queryParam.projectNo = undefined;
      this.queryParam.projectSn = undefined;
      this.queryParam.orgId = undefined;
      this.queryParam.orgName = undefined;
      this.queryParam.versionDesc = undefined;
      this.tg1Date = [];
      this.tg2Date = [];
      this.pageNo = 1;
      this.pageSize = 10;
      this.tempFormData = {};
      this.pagination.current = 1;
      this.pagination.pageNo = 1;
      this.pagination.pageSize = 10;
      this.getAllProjectPFMEAPageList();
    },
    toFmea(value) {
      var userList = JSON.parse(localStorage.getItem("userInfo"));
      console.log("value", value);
      if (value.projectDFMEAOperateFlag == "1") {
        console.log("value", value);
        this.$router.push({
          path: "/fmea/pfmea/edit",
          query: {
            // deriveId: value.deriveId,
            fmeaId: value.fmeaId,
            flag: "1",
            ntimet: new Date().getTime()
          }
        });
      } else if (
        value.projectDFMEAOperateFlag == "3" &&
        value.dfmeaOwnerName == userList.name
      ) {
        this.$router.push({
          path: "/fmea/pfmea/edit",
          query: {
            // deriveId: value.deriveId,
            fmeaId: value.fmeaId,
            flag: "1",
            ntimet: new Date().getTime()
          }
        });
      } else if (value.extendsFmeaId) {
        this.$router.push({
          path: "/fmea/pfmea/look",
          query: {
            // deriveId: value.extendsDeriveId ? value.extendsDeriveId : '',
            fmeaId: value.extendsFmeaId ? value.extendsFmeaId : "",
            rfmeaId: value.rfmeaId,
            ntimet: new Date().getTime()
          }
        });
      } else {
        this.$router.push({
          path: "/fmea/pfmea/look",
          query: {
            fmeaId: value.fmeaId,
            rfmeaId: value.rfmeaId,
            ntimet: new Date().getTime()
          }
        });
      }
    },
    newProject() {
      this.$router.push({
        name: "fmea:pfmea:new",
        query: { ntimet: new Date().getTime() }
      });
    },
    tableOption() {
      if (!this.optionAlertShow) {
        this.options = {
          alert: {
            show: true,
            clear: () => {
              this.selectedRowKeys = [];
            }
          },
          rowSelection: {
            selectedRowKeys: this.selectedRowKeys,
            onChange: this.onSelectChange,
            getCheckboxProps: record => ({
              props: {
                disabled: record.no === "No 2", // Column configuration not to be checked
                name: record.no
              }
            })
          }
        };
        this.optionAlertShow = true;
      } else {
        this.options = {
          alert: false,
          rowSelection: null
        };
        this.optionAlertShow = false;
      }
    },

    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectedRows = selectedRows;
    },
    // 工艺数模时间
    tg1Change(date, dateString) {
      this.tg1Date = date;
      this.queryParam.tg1_start = dateString[0] || undefined;
      this.queryParam.tg1_end = dateString[1] || undefined;
    },
    // 正式数模时间
    tg2Change(date, dateString) {
      this.tg2Date = date;
      this.queryParam.tg2_start = dateString[0] || undefined;
      this.queryParam.tg2_end = dateString[1] || undefined;
    },
    // 获取所有项目DFMEA分页列表
    getAllProjectPFMEAPageList() {
      this.tempFormData = { ...this.queryParam };
      let _this = this;
      _this.selectedTableRows = [];
      _this.selectedTableRowKeys = [];
      _this.tableLoading = true;
      console.log("_this.tempFormData", _this.tempFormData);
      let data = {
        delayFlag: _this.tempFormData.isDelay,
        departmentId: _this.tempFormData.orgId,
        dfmeaCode: _this.tempFormData.dfmeaCode,
        dfmeaOwnerName: _this.tempFormData.user,
        drawFlag: _this.tempFormData.isCompile,
        fmeaBusiType: _this.tempFormData.fmeaType,
        lifeState: _this.tempFormData.status,
        pageNo: _this.pageNo,
        pageSize: _this.pageSize,
        partName: _this.tempFormData.name,
        partTg1TimeEnd: _this.tempFormData.tg1_end,
        partTg1TimeStart: _this.tempFormData.tg1_start,
        partTg2TimeEnd: _this.tempFormData.tg2_end,
        partTg2TimeStart: _this.tempFormData.tg2_start,
        projectSn: _this.tempFormData.projectId,
        dfmeaId: _this.fmeaId,
        fmeaId: undefined,
        versionDesc: _this.tempFormData.versionDesc,
        category: _this.$route.query.from === 'master' ? 2 : 1
      };
      this.$api
        .getAllProjectPFMEAPageList(data)
        .then(res => {
          if (!res.flag) {
            this.$notification.error({ message: res.message });
          }
          _this.tableData = res.data.data || [];
          for (let i = 0; i < _this.tableData.length; i++) {
            if (_this.tableData[i].checked == 1) {
              _this.selectedTableRows.push(_this.tableData[i]);
              _this.selectedTableRowKeys.push(i);
            }
          }
          _this.pagination.total = res.data.total || 0;
        })
        .finally(() => {
          _this.tableLoading = false;
        });
    },
    // 项目DFMEA分页列表 - 点击分页中数字触发的方法
    handleOuterTableChange(pagination) {
      this.pageNo = pagination.current;
      this.pageSize = pagination.pageSize;
      this.pagination.current = pagination.current;
      this.pagination.pageSize = pagination.pageSize;
      this.quotePFMEA(2);
    },
    // 搜索
    search() {
      this.pageNo = 1;
      this.pageSize = this.pagination.pageSize;
      this.pagination.current = 1;
      this.getAllProjectPFMEAPageList();
    },
    // 项目编号模糊搜索
    handleProjectChange(value, options) {
      console.log("handleProjectChange", value, options);
      this.queryParam.projectNo = value;
      this.queryParam.projectId = options ? options.data.key : null;
    },
    // 获取项目编号字典
    getPFMEAMyProjectNoList(projectNo) {
      let _this = this;
      let data = {
        projectNo: projectNo
      };
      this.$api.getPFMEAMyProjectNoList(data).then(res => {
        if (!res.flag) {
          this.$notification.error({ message: res.message });
        }
        let hash = {},
          tempData = [];
        if (res.data && res.data.length > 0) {
          tempData = res.data.reduce(function(item, next) {
            hash[next.projectSn]
              ? ""
              : (hash[next.projectSn] = true && item.push(next));
            return item;
          }, []);
        }
        _this.projectCodeList = tempData || [];
      });
    },
    // 获取DFMEA状态字典
    getProjectPFMEAStateDict() {
      let _this = this;
      this.$api.getProjectPFMEAStateDict().then(res => {
        if (!res.flag) {
          this.$notification.error({ message: res.message });
        }
        //过滤编制中、审批中状态
        for (let i in res.data) {
          if (
            res.data[i].value === stateDict.compile.key ||
            res.data[i].value === stateDict.approval.key
          ) {
            _this.DFMEAStateList.push(res.data[i]);
          }
        }
      });
    },
    // 获取FMEA类型字典
    getPFMEABusiTypeDict() {
      let _this = this;
      this.$api.getPFMEABusiTypeDict().then(res => {
        if (!res.flag) {
          this.$notification.error({ message: res.message });
        }
        _this.fmeaTypeList = res.data || [];
      });
    },

    // 获取项目DFMEA编号
    getPFMEAProjectCodeDict() {
      let _this = this;
      this.$api.getProjectPFMEACodeDictIncludeDerive(null).then(res => {
        if (!res.flag) {
          this.$notification.error({ message: res.message });
        }
        _this.PFMEAList = res.data || [];
      });
    },
    orgInput(value, options) {
      this.queryParam.orgName = value;
      this.queryParam.orgId = options ? options.data.key : null;
    },
    getFuzzyOrg(orgName) {
      this.$api
        .post("/DFMEA/fmea/org/getFuzzyOrg.do", { orgName: orgName })
        .then(res => {
          if (res.flag) {
            this.deptList = res.data;
          } else {
            this.deptList = [];
          }
        });
    },
    // 状态下拉改变
    handleStatus(val) {
      this.queryParam.status = val;
    },
    // 类型下拉改变
    handleFmeaType(val) {
      this.queryParam.fmeaType = val;
    },
    delCookie(name) {
      document.cookie = name + "=" + escape("") + ";expires=-1";
    },
    setCookie(name, value) {
      if (value) {
        var days = 1; //定义一天
        var exp = new Date();
        exp.setTime(exp.getTime() + days * 24 * 60 * 60 * 1000);
        // 写入Cookie, toGMTString将时间转换成字符串
        document.cookie =
          name + "=" + escape(value) + ";expires=" + exp.toGMTString;
      }
    },
    // 版本号弹窗
    // versionClick(record) {
    // 	this.versionFlag = true;
    // 	this.versionTitle = '查看历史版本';
    // 	this.tableDataList = record;
    // },
    // 基本信息-项目编号模糊查询
    fpid(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
    // 获取按钮权限
    initBtnRole() {
      let m = localStorage.getItem("menuRoleList") || "[]";
      let menuList = JSON.parse(m);
      let perId = null;
      menuList.map(item => {
        if (item.code.indexOf("fmea-dfmea-list") != -1) {
          perId = item.id;
        }
      });
      let data = {
        perId: perId
      };
      this.$api.initBtnRole(data).then(res => {
        res.map(item => {
          if (item.resCode == "fmea:pfmea:list:search") {
            this.searchBtnFlag = true;
          } else if (item.resCode == "fmea:pfmea:list:view:fe") {
            this.queryBtnFlag = true;
          } else if (item.resCode == "fmea:pfmea:list:create") {
            // 新建
            this.addBtnFlag = true;
          } else if (item.resCode == "fmea:pfmea:list:fe") {
            // 编制
            this.organizationBtnFlag = true;
          } else if (item.resCode == "fmea:pfmea:list:delay") {
            // 延期
            this.delayBtnFlag = true;
          } else if (item.resCode == "fmea:pfmea:list:edit") {
            // 编辑
            this.updateBtnFlag = true;
          } else if (item.resCode == "fmea:pfmea:list:delete") {
            // 删除
            this.delBtnFlag = true;
          }
        });
      });
    },
    hasPermission(v) {
      let b = localStorage.getItem("buttonList") || "[]";
      let buttonList = JSON.parse(b);
      let res = false;
      if (buttonList.length > 0) {
        res = buttonList.includes(v);
      }
      console.log("res", res, v);
      return res;
    },
    /**
     * 复选框改变事件
     */
    onSelectTableChange(selectedRowKeys, row) {
      this.selectedTableRows = row;
      this.selectedTableRowKeys = selectedRowKeys;
    },
    /**
     * 行点击事件
     */
    customRow(record, index) {
      let _that = this;
      return {
        on: {
          // 鼠标单击行
          click: () => {
            if (_that.selectedTableRowKeys.indexOf(index) !== -1) {
              _that.selectedTableRows.splice(
                _that.selectedTableRowKeys.indexOf(index),
                1
              );
              _that.selectedTableRowKeys.splice(
                _that.selectedTableRowKeys.indexOf(index),
                1
              );
            } else {
              _that.selectedTableRowKeys.push(index);
              _that.selectedTableRows.push(record);
            }
          }
        }
      };
    },

    isOwner(row) {
      if (row.drawOperateFlag === "1") {
        return true;
      }
      return false;
    },
    close() {
			this.queryParam.projectId = undefined;
			this.queryParam.dfmeaCode = undefined;
			this.queryParam.name = undefined;
			this.queryParam.user = undefined;
			this.queryParam.status = undefined;
			this.queryParam.fmeaType = undefined;
			this.queryParam.dept = undefined;
			this.queryParam.isDelay = undefined;
			this.queryParam.isCompile = undefined;
			this.queryParam.tg1_start = undefined;
			this.queryParam.tg1_end = undefined;
			this.queryParam.tg2_start = undefined;
			this.queryParam.tg2_end = undefined;
			this.queryParam.projectNo = undefined;
			this.queryParam.projectSn = undefined;
			this.queryParam.orgId = undefined;
			this.queryParam.orgName = undefined;
			this.queryParam.versionDesc = undefined;
			this.tg1Date = [];
			this.tg2Date = [];
			this.pageNo = 1;
			this.pageSize = 10;
			this.tempFormData = {};
			this.pagination.current = 1;
			this.pagination.pageNo = 1;
			this.pagination.pageSize = 10;
      this.$emit("closePFMEAListModal");
    },
    // 关联pfmea
    quotePFMEA(type) {
      let pfmeaIds = [];
      let allPfmeaIds = [];
      this.selectedTableRows.forEach(item => {
        pfmeaIds.push(item.fmeaId);
      });
      this.tableData.forEach(item => {
        allPfmeaIds.push(item.fmeaId);
      });
      this.$api
        .quoteToPFMEA({
          fmeaId: this.$route.query.fmeaId,
          quoteFmeaIds: pfmeaIds,
          allFmeaIds: allPfmeaIds
        })
        .then(res => {
          if (res.flag) {
            if (type == 1) {
              this.close();
            } else {
              this.getAllProjectPFMEAPageList();
            }
          }
        });
    }
  },
  mounted() {
    // this.initBtnRole();
    this.getProjectPFMEAStateDict();
    this.getPFMEABusiTypeDict();
    this.fmeaId = this.$route.query.fmeaId ? this.$route.query.fmeaId : "";
    this.getAllProjectPFMEAPageList();
    this.getPFMEAMyProjectNoList();
    this.getFuzzyOrg();
  }
};
</script>
<style lang="less" scoped>
// 设置model 全屏
/deep/ .ant-modal {
  top: 0 !important;
}

// 设置model 全屏
/deep/ .ant-modal-content {
  height: calc(100vh);
  overflow: auto;
}

// 不加上弹窗就会有滚动条;
/deep/ .ant-modal-wrap {
  overflow: hidden !important;
}

/deep/ .ant-table-tbody {
  .ant-table-row-cell-ellipsis:nth-of-type(3) {
    text-align: left !important;
  }

  .ant-table-row-cell-ellipsis:nth-of-type(4) {
    text-align: left !important;
  }

  .ant-table-row-cell-ellipsis:nth-of-type(7) {
    text-align: left !important;
  }

  .ant-table-row-cell-ellipsis:nth-of-type(9) {
    text-align: left !important;
  }
}
/deep/ .ant-table-fixed-header .ant-table-scroll .ant-table-header {
  overflow: hidden!important;
  margin-bottom: 0!important;
  padding-right: 8px;
  background: rgb(250, 250, 250);
}
</style>
