<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" >
      <el-form-item prop="选择供应商">
        <el-input
          v-model="queryParams.选择供应商"
          placeholder="请输入选择供应商"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="订单签订日期">
        <el-input
          v-model="queryParams.订单签订日期"
          placeholder="请输入订单签订日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item prop="订单交付日期">
        <el-input
          v-model="queryParams.订单交付日期"
          placeholder="请输入订单交付日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >提交</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table :height="740" v-loading="loading" :data="采购订单List" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="选择供应商" align="center" prop="选择供应商" />
      <el-table-column label="订单签订日期" align="center" prop="订单签订日期" />
      <el-table-column label="采购订单名称" align="center" prop="采购订单名称" />
      <el-table-column label="订单交付日期" align="center" prop="订单交付日期" />
      <el-table-column label="采购负责人" align="center" prop="采购负责人" />
      <el-table-column label="入库仓库" align="center" prop="入库仓库" />
      <el-table-column label="采购原价总额含税" align="center" prop="采购原价总额含税" />
      <el-table-column label="优惠金额" align="center" prop="优惠金额" />
      <el-table-column label="整单折扣率" align="center" prop="整单折扣率" />
      <el-table-column label="采购订单金额含税" align="center" prop="采购订单金额含税" />
      <el-table-column label="采购金额合计不含税" align="center" prop="采购金额合计不含税" />
      <el-table-column label="合同附件上传" align="center" prop="合同附件上传" />
      <el-table-column label="到货地址" align="center" prop="到货地址" />
      <el-table-column label="具体地址" align="center" prop="具体地址" />
      <el-table-column label="结算期限" align="center" prop="结算期限" />
      <el-table-column label="创建时间" align="center" prop="创建时间" />
      <el-table-column label="创建用户" align="center" prop="创建用户" />
      <el-table-column label="最近修改时间" align="center" prop="最近修改时间" />
      <el-table-column label="修改用户" align="center" prop="修改用户" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>

<script>
import { list采购订单, get采购订单, del采购订单, add采购订单, update采购订单 } from "@/api/system/采购订单";

export default {
  name: "Cgddtj",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      采购订单List: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        选择供应商: null,
        订单签订日期: null,
        采购订单名称: null,
        订单交付日期: null,
        采购负责人: null,
        入库仓库: null,
        采购原价总额含税: null,
        优惠金额: null,
        整单折扣率: null,
        采购订单金额含税: null,
        采购金额合计不含税: null,
        合同附件上传: null,
        到货地址: null,
        具体地址: null,
        结算期限: null,
        创建时间: null,
        创建用户: null,
        最近修改时间: null,
        修改用户: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      list采购订单(this.queryParams).then(response => {
        this.采购订单List = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        选择供应商: null,
        订单签订日期: null,
        采购订单名称: null,
        订单交付日期: null,
        采购负责人: null,
        入库仓库: null,
        采购原价总额含税: null,
        优惠金额: null,
        整单折扣率: null,
        采购订单金额含税: null,
        采购金额合计不含税: null,
        合同附件上传: null,
        到货地址: null,
        具体地址: null,
        结算期限: null,
        创建时间: null,
        创建用户: null,
        最近修改时间: null,
        修改用户: null
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.选择供应商)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const 选择供应商 = row.选择供应商 || this.ids
      get采购订单(选择供应商).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.选择供应商 != null) {
            update采购订单(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            add采购订单(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const 选择供应商s = row.选择供应商 || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + 选择供应商s + '"的数据项？').then(function() {
        return del采购订单(选择供应商s);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/采购订单/export', {
        ...this.queryParams
      }, `采购订单_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
