<!--
 * @Author: zhp
 * @Date: 2023-06-08 14:29:46
 * @LastEditTime: 2023-07-19 16:58:37
 * @LastEditors: zhp
 * @Description: 
-->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__user">
      <SearchBar :formConfigs="formConfig" ref="ruleForm" @headBtnClick="buttonClick">
        <!-- <el-badge :value="2" class="item">
          <el-button type="primary" size="small" @click="conditionSearch">条件搜索</el-button>
        </el-badge> -->
      </SearchBar>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item :label="$t('customerquality.previousVersionCode')">
                <span>{{ props.row.previousVersionCode }}</span>
              </el-form-item>
              <el-form-item :label="$t('customerquality.ppapGrade')">
                <span>{{ props.row.ppapGradeName }}</span>
              </el-form-item>
              <el-form-item :label="$t('customerquality.description')">
                <span>{{ props.row.description }}</span>
              </el-form-item>
              <el-form-item label="nda">
                <span>{{ props.row.nda ===0? '错号' : '对号'}}</span>
              </el-form-item>
              <el-form-item :label="$t('customerquality.amendment')">
                <span>{{ props.row.amendment }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column :label="$t('customerquality.productName')" prop="productName">
        </el-table-column>
        <el-table-column :label="$t('customerquality.customerName')" prop="customerName">
        </el-table-column>
        <el-table-column :formatter="timeFormatter" :label="$t('customerquality.qualityAcceptanceDate')"
          prop="qualityAcceptanceDate">
        </el-table-column>
        <el-table-column :formatter="timeFormatter" :label="$t('customerquality.confirmDeliveryDate')"
          prop="confirmDeliveryDate">
        </el-table-column>
        <el-table-column :formatter="timeFormatter" :label="$t('customerquality.deliveryRequiredDate')"
          prop="deliveryRequiredDate">
        </el-table-column>
        <el-table-column :label="$t('customerquality.status')" prop="status">
          <template slot-scope="slot">
            <!-- <el-button type="text" @click="start(slot.row)">启动</el-button> -->
            <el-tag v-if="slot.row.status == 0" type="success"> 待审核</el-tag>
            <el-tag v-if="slot.row.status == 1" type="success"> 已完成</el-tag>
            <el-tag v-if="slot.row.status == 2" type="success"> 交付退回</el-tag>
            <el-tag v-if="slot.row.status == 3" type="success"> 审核拒绝</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="160" prop="desc">
          <template slot-scope="slot">
            <!-- <el-button type="text" @click="start(slot.row)">启动</el-button> -->
            <el-button type="text" @click="handleEdit(slot.row)">
              <i class="el-icon-edit"></i>
            </el-button>
            <el-button type="text" @click="handleDelete(slot.row)" style="color: red">
              <i class="el-icon-delete"></i>
            </el-button>
            <el-button type="text" @click="handleShow(slot.row)">
              {{ $t('configuration')}}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination :limit.sync="listQuery.limit" :page.sync="listQuery.page" :total="listQuery.total"
        @pagination="getDataList" />
      <!-- 弹窗, 新增 / 修改 -->
      <customerQualityProjectList-add v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList">
      </customerQualityProjectList-add>
      <qualityProjectList-show v-if="qualityProjectListShow" ref="qualityProjectListShow"
        @refreshDataList="getDataList">
      </qualityProjectList-show>
      <!-- <el-row slot="footer" type="flex" justify="end"> </el-row> -->
      <!-- </base-dialog> -->
      <!-- <baseConfig ref="baseConfigOrList" v-if="baseConfigShow"></baseConfig> -->
      <!-- <base-dialog :dialogTitle="searchOrEditTitle" :dialogVisible="searchOrUpdateVisible" @cancel="handleSearchCancel"
        @confirm="handleSearchConfirm" :before-close="handleSearchCancel">
        <projectType-search ref="searchOrUpdate" @successSubmit="conditionSearchSubmit">
          </projectType-search>
          <el-row slot="footer" type="flex" justify="end">
            <el-col :span="12">
              <el-button size="small" type="primary" plain class="btnTextStyle" @click="handleSearchCancel">
                {{ $t("close") }}
              </el-button>
              <el-button size="small" class="btnTextStyle" type="primary" plain @click="handleSearchReset">{{
                $t("reset")
                }}</el-button>
              <el-button type="primary" size="small" class="btnTextStyle" @click="handleSearchConfirm">
                {{ $t("search") }}
              </el-button>
            </el-col>
          </el-row>
      </base-dialog> -->
    </div>
  </el-card>
</template>

<script>
// import basicPage from "@/mixins/basic-page"
// import basicSearch from "@/mixins/basic-search"
// import projectTypeSearch from "./components/projectTypeSearch.vue"
// import customerquality from '@/filters/customerquality'
import customerQualityProjectListAdd from "./components/customerQualityProjectList-add.vue"
// import baseConfig from "./components/baseConfig"
import qualityProjectListShow from "./components/qualityProjectList-show.vue"
import { timeFormatter } from '@/filters'
import i18n from "@/i18n"
// import i18n from "@/i18n";
const tableBtn = [
  {
    type: "edit",
    btnName: i18n.t('edit'),
  },
  {
    type: "delete",
    btnName: i18n.t('delete'),
  },
  // {
  //   type: "configuration",
  //   btnName: i18n.t('configuration'),
  // }
];
export default {
  // mixins: [basicPage],
  data() {
    return {
      urlOptions: {
        getDataListURL: "/customerquality/qmsCustomerQualityProjectList/page",
        deleteURL: "/customerquality/qmsCustomerQualityProjectList",
        exportURL: '/customerquality/qmsCustomerQualityProjectList/export'
      },
      tableData:[],
      productData: {},
      listQuery:{
        limit: 999,
        page: 1,
        total:0
      },
      timeFormatter,
      baseConfigShow:false,
      searchOrEditTitle: "",
      searchOrUpdateVisible: false,
      productOrEditTitle: "",
      addOrEditTitle: '',
      addOrUpdateVisible: false,
      productOrUpdateVisible: false,
      qualityProjectListShow:false,
      formConfig: [
        {
          type: "button",
          btnName: i18n.t('search'),
          name: "search",
          color: "primary",
          // plain: true,
        },
        {
          type: "button",
          btnName: i18n.t('add'),
          name: "add",
          color: "success",
          plain:true
        }
      ],
    };
  },
  components: {
    customerQualityProjectListAdd,
    qualityProjectListShow
    // baseConfig
  },
  mounted () {
    this.getDataList();
  },
  methods: {
    //search-bar点击
    getDataList() {
      this.dataListLoading = true;
      this.$http
        .get(this.urlOptions.getDataListURL, {
          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.tableData = res.data.list;
          this.listQuery.total = res.data.total;
        })
        .catch(() => {
          this.dataListLoading = false;
        })
    },
    handleProductCancel() {
      this.productOrUpdateVisible = false;
      this.productOrEditTitle = "";
    },
    handleCurrentChange(val) {
      console.log(val);
      this.productData = val.newVal ? val.newVal : {}
    },
    setCurrent(index) {
      this.$refs.palletTable1.setCurrent("palletTable", index);
    },
    // handleSearchCancel() {
    //   this.searchOrEditTitle = "";
    //   this.searchOrUpdateVisible = false;
    // },
    conditionSearch() {
      this.searchOrEditTitle = "搜索";
      this.searchOrUpdateVisible = true;
      this.$nextTick(() => {
        this.$refs.searchOrUpdate.init();
      });
    },
    // handleConfirm() {
    //   this.$refs.addOrUpdate.dataFormSubmitHandle();
    // },
    // conditionSearchSubmit() {},
    conditionSearchSubmit(dataForm) {
      // console.log(key);
      // console.log(key);
      this.listQuery.page = 1;
      this.getDataList();
      this.searchOrUpdateVisible = false;
      // console.log(11111);
      // this.conditionSearchSubmit();
    },
    exportHandle() {
      this.$http.get(this.urlOptions.exportURL, { responseType: 'blob' }, {
        ...this.dataForm
      }).then((res) => {
        console.log(res)
        // if (res !== 0) {
        //   return this.$message.error(res.msg) 
        // }
        let fileName = ''
        const contentDisposition = res.headers['content-disposition']
        if (contentDisposition) {
          const temp = res.headers['content-disposition']
            .split(';')[1]
            .split('=')[1]
          // 对文件名乱码转义--【Node.js】使用iconv-lite解决中文乱码
          fileName = decodeURI(temp)
          console.log(temp)
        }
        const blob = new Blob([res.data])
        const reader = new FileReader()
        reader.readAsDataURL(blob)
        reader.onload = (e) => {
          const a = document.createElement('a')
          a.download = fileName
          a.href = e.target.result
          document.body.appendChild(a)
          a.click()
          document.body.removeChild(a)
        }
      }).catch(() => { })
    },
    handleDelete(val) {
        this.$confirm(`确定对[名称${val.productName}]进行删除操作?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.$http.delete(this.urlOptions.deleteURL, { data: [val.id] }).then(({ data }) => {
              if (data && data.code === 0) {
                this.$message({
                  message: "操作成功",
                  type: "success",
                  duration: 1500,
                  onClose: () => {
                    this.getDataList();
                  },
                });
              } else {
                this.$message.error(data.msg);
              }
            });
          })
          .catch(() => { });
    },
    handleEdit(val) {
      this.addOrUpdateVisible = true
      this.addOrEditTitle = this.$t('edit')
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(val.id);
      })
    },
    handleShow(val) {
      this.qualityProjectListShow = true
      this.$nextTick(() => {
        this.$refs.qualityProjectListShow.init(val)
      })
    },
    // addOrUpdateHandle(productData) {
    //   this.addOrUpdateVisible = true;
    //   this.$nextTick(() => {
    //     this.$refs.addOrUpdate.init(productData);
    //   });
    // },
    buttonClick(val) {
      console.log(val);
      switch (val.btnName) {
        case "search":
          // this.listQuery.paramCode = val.paramCode;
          // console.log(i18n);
          this.listQuery.page = 1
          this.getDataList()
          break;
        case "export":
         this.exportHandle()
          break;
        case "add":
          this.addOrUpdateVisible = true
          this.$nextTick(() => {
            this.$refs.addOrUpdate.init()
          })
          break;
        default:
      }
    },
  },
};
</script>
