<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-view"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="common-page-shadow">
      <el-row class="common-table-container flex searchPanel">
        <el-col :span="24" class="common-table-wrapper">
          <!-- LJ：表格高度自适应需配合样式  btn-pagenation 有按钮有分页  btngroup只有按钮  pagenation只有分页 -->
          <div class="common-table-content btn-pagenation">
            <el-table
              :border="true"
              stripe
              fit
              size="mini"
              height="100%"
              v-loading="tableLoading"
              ref="multipleSelection"
              :data="tableData"
            >
              <el-table-column
                type="index"
                width="55"
                align="center"
                label="序号"
              >
              </el-table-column>
              <el-table-column
                prop="quotationCompanyName"
                min-width="130px"
                label="报价供应商"
                show-overflow-tooltip
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="matPlatcode"
                min-width="120px"
                label="平台物料编号"
                show-overflow-tooltip
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="matName"
                min-width="100px"
                label="物料名称"
                show-overflow-tooltip
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="matSpec"
                min-width="100px"
                label="规格型号"
                show-overflow-tooltip
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="matUnit"
                min-width="100px"
                label="计量单位"
                show-overflow-tooltip
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="planCode"
                show-overflow-tooltip
                min-width="120px"
                align="center"
                label="计划编号"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="pendingTime"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                label="挂账时间"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="acceptanceTime"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                label="承兑时间"
                resizable
              >
              <template slot-scope="scope">
                <div v-if="scope.row.quotationMethod == 2">
                  {{scope.row.acceptanceTime}}
                </div>
              </template>
              </el-table-column>
              <el-table-column
                prop="quotationMethod"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                label="报价方式"
                resizable
              >
                <template slot-scope="scope">
                  <span v-if="scope.row.quotationMethod == 1">现金</span>
                  <span v-if="scope.row.quotationMethod == 2">承兑</span>
                  <span v-if="scope.row.quotationMethod == 3">其他</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="quotationRounds"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                label="报价轮次"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="isTax"
                show-overflow-tooltip
                min-width="100px"
                align="center"
                label="是否含税"
                resizable
              >
                <template slot-scope="scope">
                  <div>
                    {{ scope.row.isTax == 1 ? '含税' : '不含税' }}
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                prop="matNum"
                min-width="100px"
                label="数量"
                show-overflow-tooltip
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="quotationPrice"
                min-width="130px"
                label="报价金额(元)"
                show-overflow-tooltip
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="quotationPrice"
                min-width="130px"
                label="报价总价(元)"
                show-overflow-tooltip
                align="center"
                resizable
              >
                <template slot-scope="scope">
                  <div>
                    {{
                      (scope.row.matNum * scope.row.quotationPrice).toFixed(2)
                    }}
                  </div>
                </template>
              </el-table-column>

              <el-table-column
                prop="taxRate"
                min-width="100px"
                label="税率(%)"
                show-overflow-tooltip
                align="center"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="unloadAddress"
                show-overflow-tooltip
                min-width="130px"
                align="center"
                label="送货地址"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="purNote"
                show-overflow-tooltip
                min-width="130px"
                align="center"
                label="企业补充说明"
                resizable
              >
              </el-table-column>
              <el-table-column
                prop="tenderExplain"
                show-overflow-tooltip
                min-width="130px"
                align="center"
                label="供应商补充说明"
                resizable
              >
              </el-table-column>
              <!-- <el-table-column min-width="20%" align="center" label="操作">
                <template v-slot="{row}">
                  <template>
                    <el-button
                      type="primary"
                      plain
                      size="small"
                      @click="handleQuerys(row)"
                      >报价明细</el-button
                    >
                  </template>
                </template>
              </el-table-column> -->
            </el-table>
          </div>
          <div class="common-pagenation">
            <el-pagination
              ref="paginationPanel"
              background
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="queryParam.pageBean.page"
              :page-sizes="[20, 30, 40, 50]"
              :page-size="queryParam.pageBean.pageSize"
              layout="total, sizes, prev, pager, next, jumper"
              :total="queryParam.pageBean.total"
            >
            </el-pagination>
          </div>
        </el-col>
      </el-row>
    </div>
    <!-- 报价明细详情 -->
    <el-dialog
      :close-on-click-modal="false"
      title="报价明细"
      :visible.sync="showView"
      width="80%"
      :before-close="close"
      top="6vh"
    >
      <el-table
        :border="true"
        stripe
        fit
        size="mini"
        v-loading="loading"
        height="500px"
        ref="multipleSelection"
        :data="detailsList"
      >
        <el-table-column type="index" width="55" align="center" label="序号">
        </el-table-column>
        <!-- <el-table-column
          prop="quotationCompanyName"
          show-overflow-tooltip
          min-width="140px"
          align="center"
          label="报价供应商"
          resizable
        >
        </el-table-column> -->
        <el-table-column
          prop="matCode"
          show-overflow-tooltip
          min-width="110px"
          align="center"
          label="企业物料编号"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="matPlatcode"
          show-overflow-tooltip
          min-width="110px"
          align="center"
          label="平台物料编号"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="matName"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="物料名称"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="matMaterial"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="物料牌号"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="matSpec"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="规格型号"
          resizable
        >
        </el-table-column
        ><el-table-column
          prop="matNum"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="数量"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="matUnit"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="计量单位"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="planCode"
          show-overflow-tooltip
          min-width="120px"
          align="center"
          label="计划编号"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="pendingTime"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="挂账时间"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="acceptanceTime"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="承兑时间"
          resizable
        >
        <template slot-scope="scope">
                <div v-if="scope.row.quotationMethod == 2">
                  {{scope.row.acceptanceTime}}
                </div>
              </template>
        </el-table-column>
        <el-table-column
          prop="quotationMethod"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="报价方式"
          resizable
        >
          <template slot-scope="scope">
            <span v-if="scope.row.quotationMethod == 1">现金</span>
            <span v-if="scope.row.quotationMethod == 2">承兑</span>
            <span v-if="scope.row.quotationMethod == 3">其他</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="quotationRounds"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="报价轮次"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="isTax"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="是否含税"
          resizable
        >
          <template slot-scope="scope">
            <div>
              {{ scope.row.isTax == 1 ? '含税' : '不含税' }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="quotationPrice"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="报价金额(元)"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="quotationAmount"
          show-overflow-tooltip
          min-width="100px"
          align="center"
          label="总额(元)"
          resizable
        >
          <template slot-scope="scope">
            <div>
              {{ (scope.row.quotationPrice * scope.row.matNum).toFixed(2) }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="unloadAddress"
          show-overflow-tooltip
          min-width="130px"
          align="center"
          label="送货地址"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="purNote"
          show-overflow-tooltip
          min-width="130px"
          align="center"
          label="企业补充说明"
          resizable
        >
        </el-table-column>
        <el-table-column
          prop="tenderExplain"
          show-overflow-tooltip
          min-width="130px"
          align="center"
          label="供应商补充说明"
          resizable
        >
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" @click="close">取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import Breadcrumb from '@/components/Breadcrumb/index.vue'
export default {
  name: 'domesticDialog',
  components: {Breadcrumb},
  props: {
    editData: Object,
  },
  data() {
    return {
      breadcrumbOpt: [
        {breadcrumbName: '查看报价'},
        {breadcrumbName: '报价详情'},
      ],
      tableData: [],
      tableLoading: false,
      showView: false,
      loading: false,
      queryParam: {
        pageBean: {
          page: 1,
          pageSize: 20,
          total: 0,
        },
        sorter: [
          {
            direction: 'DESC',
            property: 'quo.QUOTATION_TIME_',
          },
        ],
      },
      querys: [
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'quo.NOTICE_ID_',
          relation: 'AND',
          value: '',
        },
        {
          group: 'main',
          operation: 'EQUAL',
          parentGroup: '',
          property: 'QUOTATION_COMPANY_ID_',
          relation: 'AND',
          value: '',
        },
      ],
      detailsList: [],
      currentUser: {},
    }
  },
  created() {
    console.log(this.$route.query);
    let form = this.$route.query.rows
    this.currentUser = JSON.parse(sessionStorage.getItem('currentUserDetail'))
    if(form.affiliatedOrgId == this.currentUser.org[0].orgId || form.procureOrgId == this.currentUser.org[0].orgId){
      this.querys[1].value = ''
    }else{
      this.querys[1].value = this.currentUser.org[0].orgId
    }
    this.querys[0].value = this.$route.params.ids
    
    this.loadData()
  },
  mounted() {},
  methods: {
    //获取列表
    loadData() {
      this.tableLoading = true
      this.queryParam.querys = []
      if (this.querys[0].value) {
        this.queryParam.querys.push(this.querys[0])
      }
      if (this.querys[1].value) {
        this.queryParam.querys.push(this.querys[1])
      }
      this.$http
        .post(
          '${portal}/bizBiddingQuotation/v1/pageQuoAndMatDetail',
          this.queryParam
        )
        .then((res) => {
          if (res.data.state) {
            this.tableData = res.data.value.rows
            this.tableLoading = false
            this.queryParam.pageBean.page = res.data.value.page
            this.queryParam.pageBean.total = res.data.value.total
            this.queryParam.pageBean.pageSize = res.data.value.pageSize
          }
        })
    },
    // 关闭//面包屑点击
    handleClose() {
      this.$router.push({
        name: 'quotationSite',
        params: {
          tabsActiveName: 'negotiationsList',
          pageBean: this.$route.query.pageBean,
        },
      })
    },
    handleCurrentChange(page) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, page}
      this.loadData(this.queryParam)
    },
    handleSizeChange(pageSize) {
      this.queryParam.pageBean = {...this.queryParam.pageBean, pageSize}
      this.loadData(this.queryParam)
    },
    close() {
      this.showView = false
    },
  },
}
</script>

<style lang="scss" scoped>
.common-page-shadow {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  margin-top: 10px;
  .common-search-container {
    height: 80px;
    div {
      display: flex;
      align-items: center;
    }
  }
  .common-table-container {
    height: calc(100% - 20px);
    .common-table-content {
      height: calc(100% - 60px);
    }
  }
}

.rows {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebebeb;
  margin-bottom: 16px;
  padding: 10px 0;
  .rows-left {
    margin-right: 10px;
    .rows-hr {
      width: 3px;
      height: 18px;
      background-color: #0e6eff;
      border-radius: 2px;
    }
  }
  .rows-title {
    .text-overflow {
      width: 100%;
      font-size: 16px;
    }
  }
}
</style>
