<template>
  <div>
    <template v-if="!addOrUpdateVisible">
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="queryData()"
      >
        <el-form-item label="项目名称">
          <el-input
            v-model="dataForm.projectName"
            placeholder="请输入项目名称"
            clearable
          />
        </el-form-item>
        <el-form-item label="部门">
          <org-component v-model="dataForm.orgId" />
        </el-form-item>
        <el-form-item>
          <el-button @click="queryData()">查询</el-button>
          <el-button
            v-if="isAuth('quoted:insert')"
            type="primary"
            @click="addOrUpdateHandle(0)"
            >新建</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        style="width: 100%"
      >
        <el-table-column
          label="序号"
          type="index"
          width="50"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="priceCode"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="报价编码"
        >
        </el-table-column>
        <el-table-column
          prop="projectName"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="项目名称"
        >
        </el-table-column>
        <el-table-column
          prop="type"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="项目类别"
        >
          <template slot-scope="scope">
            {{productTypeOption.find(t => t.value === scope.row.type).label}}
          </template>
        </el-table-column>
        <el-table-column
          prop="materialCost"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="报价小计"
        >
        </el-table-column>
        <el-table-column
          prop="mouldPrice"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="模具费"
        >
        </el-table-column>
        <el-table-column
          prop="managePrice"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="管理费"
        >
        </el-table-column>
        <el-table-column
          prop="ratePrice"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="税率"
        >
        </el-table-column>
        <el-table-column
          prop="totalPrice"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="总价"
        >
        </el-table-column>
        <el-table-column
          prop="precisionMaterialCost"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="精准报价小计"
        >
        </el-table-column>
        <el-table-column
          prop="precisionMouldPrice"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="精准模具费"
        >
        </el-table-column>
        <el-table-column
          prop="precisionManagePrice"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="精准管理费"
        >
        </el-table-column>
        <el-table-column
          prop="precisionRatePrice"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="精准税率"
        >
        </el-table-column>
        <el-table-column
          prop="precisionTotalPrice"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="精准总价"
        >
        </el-table-column>
        <el-table-column
          prop="remark"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="备注"
        >
        </el-table-column>
        <el-table-column
          prop="creatorName"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="负责人"
        >
        </el-table-column>
        <el-table-column
          prop="orgName"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="部门"
        >
        </el-table-column>
        <el-table-column
          prop="state"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="项目状态"
        >
          <template slot-scope="scope">
            {{projectStateOption.find(t => t.value === scope.row.state).label}}
          </template>
        </el-table-column>
        <el-table-column
          prop="approveState"
          header-align="center"
          align="center"
          min-width="140"
          :show-tooltip-when-overflow="true"
          label="项目评估状态"
        >
          <template slot-scope="scope">
            {{approveStateOption.find(t => t.value === scope.row.approveState).label}}
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          header-align="center"
          align="center"
          min-width="340"
          width="340"
          label="操作"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              @click="showDetail(scope.row.programId)"
              >查看</el-button
            >
            <el-button
              v-if="isAuth('quoted:update')"
              type="text"
              size="small"
              @click="showDetail"
              >编辑</el-button
            >
            <el-button
              v-if="isAuth('quoted:revoke')"
              type="text"
              size="small"
              @click="showDetail"
              >撤回</el-button
            >
            <el-button
              v-if="isAuth('quoted:first')"
              type="text"
              size="small"
              @click="showDetail"
              >报价</el-button
            >
            <el-button
              v-if="isAuth('quoted:two')"
              type="text"
              size="small"
              @click="showDetail"
              >精准报价</el-button
            >
            <el-button
              v-if="isAuth('quoted:two')"
              type="text"
              size="small"
              @click="showDetail"
              >通知报价</el-button
            >
            <el-button
              v-if="isAuth('quoted:restart')"
              type="text"
              size="small"
              @click="showDetail"
              >重新报价</el-button
            >
            <el-button
              v-if="isAuth('quoted:accredit')"
              type="text"
              size="small"
              @click="showDetail"
              >授权</el-button
            >
            <el-button
              v-if="isAuth('quoted:result')"
              type="text"
              size="small"
              @click="showDetail"
              >报价结果</el-button
            >
            <el-button
              v-if="isAuth('quoted:result')"
              type="text"
              size="small"
              @click="showDetail"
              >导出</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </template>
    <quoted-add-or-update ref="addOrUpdate" v-if="addOrUpdateVisible" @onChose="onChose"></quoted-add-or-update>
  </div>
</template>

<script>
import OrgComponent from '../common/org-component'
import {getList} from '@/api/quoted'
import QuotedAddOrUpdate from './quoted-add-or-update'
import { productTypeOption, approveStateOption, projectStateOption } from '@/utils/enums'
export default {
  name: 'cus-quoted',
  components: { OrgComponent, QuotedAddOrUpdate },
  data () {
    return {
      addOrUpdateVisible: false,
      detailVisible: false,
      productTypeOption: productTypeOption,
      approveStateOption: approveStateOption,
      projectStateOption: projectStateOption,
      dataForm: {},
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false
    }
  },
  created () {
    this.getDataList()
  },
  methods: {
    onChose () {
      this.addOrUpdateVisible = false
      this.detailVisible = false
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
      // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    queryData () {
      this.pageIndex = 1
      this.getDataList()
    },
    getDataList () {
      this.dataListLoading = true
      let param = {
        current: this.pageIndex,
        size: this.pageSize,
        ...this.dataForm
      }
      getList(param).then(({data}) => {
        if (data && data.code === '200') {
          this.dataList = data.data.records
          this.totalPage = Number(data.data.total)
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    showDetail () {}
  }
}
</script>

<style scoped>
</style>