<template>
  <div class="app-container">
    <el-table
      ref="bgfyData"
      :data="bgfyData"
      :span-method="tableJs.mergeColRows"
      border
      stripe
      style="margin-top: 10px"
    >
      <el-table-column type="index" align="center" width="50" label="序号" />
      <el-table-column
        align="center"
        width="50"
        label="检验类别"
        prop="xiangmuleibie"
      />
      <el-table-column
        align="center"
        width="150"
        label="项目"
        prop="jianyanxiang"
      />
      <el-table-column
        align="center"
        width="50"
        label="项目编号"
        prop="jianyanmu"
      />
      <el-table-column align="left" label="检验项目及内容" prop="jianyanneirong" />
      <el-table-column
        align="center"
        prop="jianyanjieguo"
        width="120"
        label="检查结果"
      >
        <template slot-scope="scope">
          <el-select
            v-model="scope.row.jianyanjieguo"
          >
            <el-option
              v-for="item in jyjgList"
              :key="item"
              :label="item"
              :value="item"
            />
          </el-select>
        </template>
      </el-table-column>
      <!-- <el-table-column
        align="center"
        prop="gongzuojianzheng"
        min-width="200"
        label="检验结论"
      >
        <template slot-scope="scope">
          <el-autocomplete
            v-model="scope.row.gongzuojianzheng"
            class="inline-input"
            style="width: 100%"
            :fetch-suggestions="
              (queryString, cb) => {
                querySearchGzjz(queryString, cb, scope.$index);
              }
            "
          />
        </template>
      </el-table-column> -->
    </el-table>
  </div>
</template>
<script>
// import Technical from '@/views/ysjl/3000/common/technical-parameter'

export default {
  name: 'Inspection',
  components: {},
  props: {
    bgfyData: {
      type: Array,
      require: true,
      default: () => []
    }
  },
  data() {
    return {
      jyjgList: ['√', 'X', '/']
    }
  },
  created() {

  },
  mounted() {},
  methods: {
    /**
     * 是否可编辑
     * @param $index
     * @returns {number}
     */
    showXmlb($index) {
      return this.showXmlbIndexListSg.filter((xl) => {
        return xl.index === $index
      }).length
    },

    /**
     * 根据索引找到对应的项目类别选项列表
     * @param $index
     */
    getXmlbList($index) {
      for (let i = 0; i < this.showXmlbIndexListSg.length; i++) {
        const xl = this.showXmlbIndexListSg[i]
        if (xl.index === $index) {
          return xl.xmlb === 'AB'
            ? this.xmlbListAB
            : xl.xmlb === 'AC'
              ? this.xmlbListAC
              : this.xmlbListBC
        }
      }
    },
    /**
     * 修改检验项目关联的检验结果及确认日期为监检日期
     * @param $index  检验项目索引
     */
    changeJyjg($index) {
      // 检查结果为：外协，工作见证为：外协部件监检证书，确认日期为当前日期。检查结果为：无此项，工作见证为：—，确认日期为当前日期。
      const isWcx = this.bgfyData[$index].jianyanjieguo === '无此项'
      const isWx = this.bgfyData[$index].jianyanjieguo === '外协'
      if (isWcx) {
        this.bgfyData[$index].gongzuojianzheng = '—'
      }
      if (isWx) {
        this.bgfyData[$index].gongzuojianzheng = '外协部件监检证书'
      }
      if (isWcx || isWx) {
        this.bgfyData[$index].querenriqi =
          this.formatter.dateFormat('YYYY-MM-dd')
      } else {
        this.bgfyData[$index].gongzuojianzheng = this.dicGzjz[$index].value
        this.bgfyData[$index].querenriqi = this.ysjl.jianyanjieshuriqi
      }
      // 根据索引获取对应关联索引信息
      const jyxm = this.jyxmRelations.filter(
        (jyxm) => jyxm.index === $index
      )[0]
      // 如果不存在关联信息，不进行任何操作
      if (!jyxm) {
        return
      }
      // 遍历关联索引
      // 检查结果改变时，其子项的序号中的检查结果也及工作见证也要随着进行变化。
      jyxm.relationIds.forEach((index) => {
        this.bgfyData[index].jianyanjieguo =
          this.bgfyData[$index].jianyanjieguo
        if (isWcx || isWx) {
          this.bgfyData[index].gongzuojianzheng =
            this.bgfyData[$index].gongzuojianzheng
          this.bgfyData[index].querenriqi = this.bgfyData[$index].querenriqi
        } else {
          this.bgfyData[index].gongzuojianzheng = this.dicGzjz[index].value
          this.bgfyData[index].querenriqi = this.ysjl.jianyanjieshuriqi
        }
      })
    },
    onRowClick(row) {
      this.$refs.bgfyData.toggleRowSelection(row)
    },
    /**
     * 修改检验项目关联的确认日期
     * @param $index  检验项目索引
     */
    changeQrrq: function($index) {
      // 如果是清空当前确认日期，不进行任何操作
      if (!this.bgfyData[$index].querenriqi) {
        return
      }
      // 根据索引获取对应关联索引信息
      const jyxm = this.jyxmRelations.filter(
        (jyxm) => jyxm.index === $index
      )[0]
      // 如果不存在关联信息，不进行任何操作
      if (!jyxm) {
        return
      }
      // 遍历关联索引
      jyxm.relationIds.forEach((index) => {
        // 如果当前确认日期为空，则将其同步关联的确认日期
        if (!this.bgfyData[index].querenriqi) {
          this.bgfyData[index].querenriqi = this.bgfyData[$index].querenriqi
        }
      })
    },
    querySearchGzjz: function(queryString, cb, $index) {
      cb([this.dicGzjz[$index]])
    }
  }
}
</script>
<style scoped>
</style>
<style lang="scss" scoped>
</style>
