<!--
 * @Author: zhp
 * @Date: 2023-07-14 13:44:46
 * @LastEditTime: 2023-07-19 16:58:46
 * @LastEditors: zhp
 * @Description: 
-->
<template>
  <div>
    <el-dialog close-on-press-escape :title="$t('configuration')" :append-to-body="true" :visible.sync="innerDrawer">
      <el-divider content-position="center">项目清单详情</el-divider>
      <el-table style="width: 100%" :data="getValues" :show-header="false">
        <el-table-column v-for="(item, index) in getHeaders" :key="index" :prop="item">
        </el-table-column>
      </el-table>
      <el-divider content-position="center">修订记录</el-divider>
      <el-table style="width: 100%" :data="getReviseValues" :show-header="false">
        <el-table-column v-for="(item, index) in getReviseHeaders" :key="index" :prop="item">
        </el-table-column>
      </el-table>
      <el-divider content-position="center">更改记录</el-divider>
      <el-table style="width: 100%" :data="getChangeValues" :show-header="false">
        <el-table-column v-for="(item, index) in getChangeHeaders" :key="index" :prop="item">
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import i18n from "@/i18n"
// import basicAdd from "@/mixins/basic-add"
// import debounce from "lodash/debounce"

export default {
  // mixins: [basicAdd],
    data() {
      return {
        urlOptions: {
          getReviseDataListURL: '/customerquality/qmsCustomerQualityProjectListRevisionRecord/page',
          getChangeDataListURL: '/customerquality/qmsCustomerQualityProjectListChangeRecord/page',
          submitURL: "/customerquality/knowledgeBaseRequirementListData",
          getDictDataDetail: '/mutual/qmsDataDictionaryDetail/page'
        },
        headers: [
          {
            prop: 'productCode',
            label: '产品编码',
          },
          {
            prop: 'productName',
            label: '产品名称',
          },
          {
            prop: 'customerCode',
            label: '客户编码',
          },
          {
            prop: 'customerName',
            label: '客户名称',
          },
          {
            prop: 'author',
            label: '作者',
          },
          {
            prop: 'releaser',
            label: '发布人',
          }
        ],
        reviseHeaders: [
          {
            prop: 'item',
            label: 'Item/Section',
          },
          {
            prop: 'revision',
            label: 'revision',
          },
          {
            prop: 'essential',
            label: 'Essential Changes',
          },
          {
            prop: 'date',
            label: 'date',
          },
        ],
        reviseTableData: [],
        changeHeaders: [
          {
            prop: 'name',
            label: 'name',
          },
          {
            prop: 'changeHistory',
            label: 'Change History of this PPAP record',
          },
          {
            prop: 'date',
            label: 'date',
          },
        ],
        changeTableData: [],
        tableData: [],
        innerDrawer: false,
        listQuery: {
          limit: 3,
          page: 1,
          customerQualityProjectListId:null
        },
        categoryList:[],
        requirementList: [],
        knowledgeBaseList:[],
      }
  },
  computed: {
    getHeaders() {
      return this.tableData.reduce((pre, cur, index) => pre.concat(`value${index}`), ['title'])
    },
    getValues() {
      return this.headers.map(item => {
        return this.tableData.reduce((pre, cur, index) => Object.assign(pre, { ['value' + index]: cur[item.prop] }), { 'title': item.label, });
      });
    },
    getReviseHeaders() {
      return this.reviseTableData.reduce((pre, cur, index) => pre.concat(`value${index}`), ['title'])
    },
    getReviseValues() {
      return this.reviseHeaders.map(item => {
        return this.reviseTableData.reduce((pre, cur, index) => Object.assign(pre, { ['value' + index]: cur[item.prop] }), { 'title': item.label, });
      });
    },
    getChangeHeaders() {
      return this.changeTableData.reduce((pre, cur, index) => pre.concat(`value${index}`), ['title'])
    },
    getChangeValues() {
      return this.changeHeaders.map(item => {
        return this.changeTableData.reduce((pre, cur, index) => Object.assign(pre, { ['value' + index]: cur[item.prop] }), { 'title': item.label, });
      });
    }
  },
  mounted () {
    // this.getDict()
    // this.getAccessPath()
  },
    methods: {
      init(obj) {
        // this.dataForm.knowledgeBaseRequirementListId = obj.knowledgeBaseRequirementListId || ''
        // this.dataForm.knowledgeBaseRequirementListId = obj.knowledgeBaseRequirementListId || ''
        this.id = obj.id || ''
        this.listQuery.customerQualityProjectListId = obj.id
        this.tableData.push(obj)
        this.innerDrawer = true
        this.$nextTick(() => {
          // this.$refs["dataForm"].resetFields()
          // if (this.dataForm.id) {
            this.getInfo()
          // } else {
            // this.getCode()
          // }
        })
      },
      getInfo() {
        this.$http
          .get(this.urlOptions.getReviseDataListURL, {
            params: this.listQuery,
          })
          .then(({ data: res }) => {
            // this.dataListLoading = false;
            if (res.code !== 0) {
              this.tableData = [];
              // this.listQuery.total = 0;
              return this.$message.error(res.msg);
            }
            this.reviseTableData = res.data.list;
            this.listQuery.total = res.data.total;
          })
        this.$http
          .get(this.urlOptions.getChangeDataListURL, {
            params: this.listQuery,
          })
          .then(({ data: res }) => {
            // this.dataListLoading = false;
            if (res.code !== 0) {
              this.tableData = [];
              // this.listQuery.total = 0;
              return this.$message.error(res.msg);
            }
            this.changeTableData = res.data.list;
            this.listQuery.total = res.data.total;
          })
      },
      // getDict() {
      //   this.$http
      //     .get(this.urlOptions.getDictDataDetail, {
      //       params: {
      //         limit: 999,
      //         page: 1,
      //         dataDictionaryId: '1679670942635122690',
      //       }
      //     })
      //     .then(({ data: res }) => {
      //       // this.dataListLoading = false;
      //       if (res.code === 0) {
      //         this.categoryList = res.data.list
      //       }
      //     })
      // },

      // 表单提交
      // dataFormSubmit() {
      //   this.$refs["dataForm"].validate((valid) => {
      //     if (!valid) {
      //       return false;
      //     }
      //     this.$http[!this.dataForm.id ? "post" : "put"](this.urlOptions.submitURL, this.dataForm)
      //       .then(({ data: res }) => {
      //         if (res.code !== 0) {
      //           return this.$message.error(res.msg);
      //         }
      //         this.$message({
      //           message: this.$t("prompt.success"),
      //           type: "success",
      //           duration: 500,
      //           onClose: () => {
      //             this.innerDrawer = false;
      //             this.$emit("refreshDataList");
      //           },
      //         });
      //       })
      //       .catch(() => { });
      //   });
      // },
    },
  }
</script>

<style lang="scss" scoped>

</style>
