<template>
  <div class="app-container">
    <div v-if="show === 1">
      <!-- 筛选条件 -->
      <div>
        <el-form     ref="screenForm"
        :model="screenForm"
        label-width="70px"
        size="small"
        label-position="left">
          <el-row :gutter="20">
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="存货编码" prop="materialNumber">
                <el-input placeholder="请输入存货编码" v-model="screenForm.materialNumber"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="存货名称" prop="materialName">
                <el-input placeholder="请输入存货名称" v-model="screenForm.materialName"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="存货代码" prop="account">
                <el-input placeholder="请输入存货代码" v-model="screenForm.account"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :lg="6">
              <el-form-item label="生效日期" prop="startDate">
                <el-input placeholder="请输入生效日期"  v-model="screenForm.startDate"></el-input>
              </el-form-item>
            </el-col>

            <el-col :xs="24" :sm="24" :lg="24" class="tr">
              <el-form-item label="">
                <el-button size="small" @click="resetScreenForm"
                  >清空</el-button
                >
                <el-button size="small" type="primary" @click="submitScreenForm"
                  >搜索</el-button
                >
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <!-- 按钮 -->
      <div class="btn-group clearfix">
        <div class="fl">
          <el-button type="primary" size="small" @click="addFn">新增</el-button>
          <el-button type="primary" size="small">编辑</el-button>
          <el-button type="primary" size="small">删除</el-button>
        </div>
        <div class="fr">
          <el-button type="primary" size="small">导入</el-button>
          <el-button type="primary" size="small">导出</el-button>
          <el-button type="primary" size="small">打印</el-button>
        </div>
      </div>
      <div class="mymain-container">
        <!-- 列表 -->
        <div class="table">
          <el-table
            v-loading="listLoading"
            :data="dataList"
            element-loading-text="Loading"
            border
            fit
            highlight-current-row
            stripe
          >
            <el-table-column type="selection" align="center"></el-table-column>
            <el-table-column
              align="center"
              label="单据号"
              prop="billId"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="调价日期"
              prop="modifyPriceDate"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="销售类型"
              prop="saleTypeId"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="产品品类"
              prop="productCategory"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="存货编码"
              prop="billId"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="存货名称"
              prop="materialName"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="规格型号"
              prop="specs"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="计量单位"
              prop="company"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="数量"
              prop="qty"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="批发价"
              prop="batchPrice"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>

            <el-table-column
              align="center"
              label="零售价"
              prop="retailPrice"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="生效日期"
              prop="startDate"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="失效日期"
              prop="endDate"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="是否促销价"
              prop="isPromote"
              min-width="160"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
               <el-tag type="success" v-if="scope.row.isPromote">是</el-tag>
                 <el-tag type="danger" v-else>否</el-tag>
              </template>
            </el-table-column>
            <el-table-column
              align="center"
              label="调价部门"
              prop="modifyPriceDepartment"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="调价业务员"
              prop="operatorName"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="制单日期"
              prop="preparationDate"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="审核人"
              prop="confirmBy"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="审核日期"
              prop="confirmTime"
              min-width="160"
              show-overflow-tooltip
            ></el-table-column>
            <el-table-column
              align="center"
              label="状态"
              prop="billFlag"
              min-width="160"
              show-overflow-tooltip
            >
               <template slot-scope="scope">
               <el-tag type="success" v-if="scope.row.billFlag =='A'">保存</el-tag>
                 <el-tag type="danger" v-else-if="scope.row.billFlag =='B'">提交</el-tag>
                  <el-tag type="danger" v-else>审核</el-tag>
              </template>

            </el-table-column>
            <el-table-column
              align="center"
              label="操作"
              min-width="160"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                 <el-button type="text" class="textColor" @click="approvalFn(scope.row.id)"
                >审批</el-button
              >
              <el-button type="text" class="textColor" @click="detailFn(scope.row.id)"
                >详情</el-button
              >
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 分页 -->
        <div class="fr">
          <el-pagination
              @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="10"
            layout="total, sizes, prev, pager, next, jumper"
            :total="listTotal"
          >
          </el-pagination>
        </div>
      </div>
    </div>
    <ModifyListApply v-else-if="show === 2" />
    <ModifyListApproval v-else-if="show === 3" :detail="detail"/>
    <ModifyListDetail v-else :detail="detail" />
  </div>
</template>

<script>

import ModifyListApply from "./components/modify_list-apply.vue";
import ModifyListApproval from "./components/modify_list-approval.vue";
import ModifyListDetail from "./components/modify_list-detail.vue";
import Mixin from "@/mixin/index";
import {
 getProductRriceAdd,getProductRriceConfirm,getProductRriceDetail,
 getProductRriceEdit,getProductRriceList,getProductRriceRevoke,
 getProductRriceSubmit
} from "@/api/basic_data/material";
import { downloadFiles } from "@/utils/util";
export default {
  mixins: [Mixin],
  data() {
    return {
      show: 3,
      currentPage: 1, // 当前页码
      pageSize: 10, // 每页数量
      listTotal: 0, // 列表总数

      dataList: [
        {
          billNnmber: "00000000121213",
          modifyPriceDate: "2022-03-10",
          saleType: "*一票机*",
          productCategory: "家用空调",
          code: "2022051775",
          name: "夏之凉变频1",
          specs: "KFR-26GW/",
          company: "套",
          number: "500",
          wholesale: "2899",
          retailPrice: "2999",
          effectiveDate: "2022-05-30",
          expiryDate: "2022-06-30",
          promotion: "是",
          modifyPriceDepartment: "销售部",
          modifyPriceSalesman: "张三",
          preparationDate: "2022-05-18",
          examineUser: "admin",
          examineDate: "2022-05-18",
          state: "已通过",
        },
        {
          billNnmber: "00000000121213",
          modifyPriceDate: "2022-03-10",
          saleType: "*一票机*",
          productCategory: "家用空调",
          code: "2022051775",
          name: "夏之凉变频1",
          specs: "KFR-26GW/",
          company: "套",
          number: "500",
          wholesale: "2899",
          retailPrice: "2999",
          effectiveDate: "2022-05-30",
          expiryDate: "2022-06-30",
          promotion: "是",
          modifyPriceDepartment: "销售部",
          modifyPriceSalesman: "张三",
          preparationDate: "2022-05-18",
          examineUser: "admin",
          examineDate: "2022-05-18",
          state: "已通过",
        },
        {
          billNnmber: "00000000121213",
          modifyPriceDate: "2022-03-10",
          saleType: "*一票机*",
          productCategory: "家用空调",
          code: "2022051775",
          name: "夏之凉变频1",
          specs: "KFR-26GW/",
          company: "套",
          number: "500",
          wholesale: "2899",
          retailPrice: "2999",
          effectiveDate: "2022-05-30",
          expiryDate: "2022-06-30",
          promotion: "是",
          modifyPriceDepartment: "销售部",
          modifyPriceSalesman: "张三",
          preparationDate: "2022-05-18",
          examineUser: "admin",
          examineDate: "2022-05-18",
          state: "已通过",
        },
        {
          billNnmber: "00000000121213",
          modifyPriceDate: "2022-03-10",
          saleType: "*一票机*",
          productCategory: "家用空调",
          code: "2022051775",
          name: "夏之凉变频1",
          specs: "KFR-26GW/",
          company: "套",
          number: "500",
          wholesale: "2899",
          retailPrice: "2999",
          effectiveDate: "2022-05-30",
          expiryDate: "2022-06-30",
          promotion: "是",
          modifyPriceDepartment: "销售部",
          modifyPriceSalesman: "张三",
          preparationDate: "2022-05-18",
          examineUser: "admin",
          examineDate: "2022-05-18",
          state: "已通过",
        },
      ],
        searchForm: {
        materialName: "",
        materialNumber: "",
        startDate: "",

      },
      detail:{}
    };
  },
  components: {
    ModifyListApply,
    ModifyListApproval,
    ModifyListDetail,
  },
  methods: {
    addFn() {
      this.show = 2;
    },
    approvalFn() {
  getProductRriceDetail({id}).then(res=>{
        this.detail = res.data
          this.show = 3;
      })

    },
    detailFn(id) {
      getProductRriceDetail({id}).then(res=>{
        this.detail = res.data
        this.show = 4;
      })


    },
    getList() {
      this.listLoading = true;
      let params = {
        pageNum: this.currentPage,
        pageSize: this.pageSize,
        materialName: this.searchForm.materialName,
        materialNumber: this.searchForm.materialNumber,
        startDate: this.searchForm.startDate,

      };
      getProductRriceList(params).then((res) => {
        this.dataList = res.data.records;
        this.listTotal = res.data.total;
        this.listLoading = false;
      });
    },
    editFn(id, row) {
      this.diaLogForm = {
        id,
        composeNumber: row.composeNumber,
        items: row.items === undefined ? [] : row.items,
        materialId: row.materialId,
        orgNumber: row.orgNumber,
        productModel: row.productModel,
        productVolume: row.productVolume,
      };
      this.showDialogForm = true;
    },
    hanleInfo() {
      if (this.type === 1) {
        getProductAdd(this.diaLogForm).then((res) => {
          this.$successMsg("保存成功");
          console.log(params, 123);
          this.getList();
        });
      } else if (this.type === 2) {
        const params = {
          ...this.diaLogForm,
        };
        console.log(params, 123);
        getProductEdit(params).then((res) => {
          this.$successMsg("编辑成功");
          this.getList();
        });
        this.diaLogForm.id = null;
      }
      this.showDialogForm = false;
    },
    hanleDelete(id) {
      this.hanleDeleteAllPromise(id).then((ids) => {
        getProductDel(ids).then((res) => {
          this.$successMsg("删除成功");
        });
      });
    },
        handleExport() {
      let screenData = {
        customerName: this.screenForm.customerName,
        freeDay: this.screenForm.freeDay,
        toll: this.screenForm.toll,
      };
      downloadFiles("/product-compose/export", screenData);
    },
    resetInfo() {
      this.diaLogForm = {
        id: null,
        composeNumber: "",
        id: "",
        items: [],
        materialId: "",
        orgNumber: 0,
        productModel: "",
        productVolume: "",
      };
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-select--small {
  width: 100%;
}
</style>
