<template>
  <div class="app-container">
    <el-card>
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="88px">
        <el-form-item label="结算日期" prop="timeRange">
          <el-date-picker
            v-model="queryParams.timeRange"
            type="date"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="采购日期" prop="timeRange">
          <el-date-picker
            v-model="queryParams.timeRange"
            type="date"
            value-format="yyyy-MM-dd"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="供应商" prop="supplierName">
          <el-select v-model="queryParams.supplierName" filterable>
            <el-option v-for="item in supplierList" :key="item.supplierName" :value="item.supplierName" :label="item.supplierName"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结算方式" prop="way">
          <el-select v-model="queryParams.way">
            <el-option v-for="item in wayList" :key="item.id" :value="item.id" :label="item.label"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="结算批次" prop="batch">
          <el-input v-model="queryParams.batch"></el-input>
        </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"
            v-hasPermi="['app:test:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDeleteAll"
            v-hasPermi="['app:test:remove']"
          >批量删除</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
    </el-card>
    <br />
    <el-card>
      <el-table border stripe  v-loading="loading" ref="multipleTable" :data="disposalList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" fixed/>
        <el-table-column label="单据编号" align="center" prop="orderNum" width="180" fixed/>
        <el-table-column label="结算日期" align="center" prop="dealReason" width="180" />
        <el-table-column label="采购日期" align="center" prop="dealWay" width="180" />
        <el-table-column label="屠宰日期" align="center" prop="dealWay" width="180"/>
        <el-table-column label="供应商" align="center" prop="supplierName" width="150"/>
        <el-table-column label="结算方式" align="center" prop="supplierName" width="150"/>
        <el-table-column label="批次" align="center" prop="batch" width="180"/>
        <el-table-column label="结算数量" align="center" prop="batch" width="150" />
        <el-table-column label="结算重量" align="center" prop="batch" width="150" />
        <el-table-column label="结算价格" align="center" prop="batch" width="150" />
        <el-table-column label="采购加分" align="center" prop="batch"  width="150"/>
        <el-table-column label="采购减分" align="center" prop="batch" width="150" />
        <el-table-column label="牧场出肉率" align="center" prop="batch" width="150" />
        <el-table-column label="到场出肉率" align="center" prop="batch" width="150" />
        <el-table-column label="平均级别" align="center" prop="batch" width="150" />
        <el-table-column label="预估平均级别" align="center" prop="batch" width="150" />
        <el-table-column label="白毛数" align="center" prop="batch" width="150" />
        <el-table-column label="黑毛数" align="center" prop="batch" width="150" />
        <el-table-column label="平均重量" align="center" prop="batch" width="150" />
        <el-table-column label="预估重量" align="center" prop="batch" width="150"/>
        <el-table-column label="运费" align="center" prop="batch" width="150" />
        <el-table-column label="途亡数" align="center" prop="batch" width="150" />
        <el-table-column label="未到数" align="center" prop="batch" width="150" />
        <el-table-column label="不合格数" align="center" prop="batch" width="150" />
        <el-table-column label="圈亡数" align="center" prop="batch"  width="150"/>
        <el-table-column label="进场扣款" align="center" prop="batch" width="150" />
        <el-table-column label="级别扣款" align="center" prop="batch" width="150" />
        <el-table-column label="重量扣款" align="center" prop="batch"  width="150"/>
        <el-table-column label="采购扣款" align="center" prop="batch"  width="150"/>
        <el-table-column label="其他扣款" align="center" prop="batch" width="150" />
        <el-table-column label="圈亡补款" align="center" prop="batch"  width="150"/>
        <el-table-column label="其他补款" align="center" prop="batch"  width="150"/>
        <el-table-column label="备注" align="center" prop="batch" width="200" />
        <el-table-column label="未到金额" align="center" prop="batch" width="150" fixed="right"/>
        <el-table-column label="已付金额" align="center" prop="batch" width="150" fixed="right" />
        <el-table-column label="结算金额" align="center" prop="batch" width="150" fixed="right" />
        <el-table-column label="单据状态" align="center" prop="batch" width="150"  fixed="right"/>
        <el-table-column label="操作" width="180" align="center" fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="handleView(scope.row)"
            >查看</el-button>
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['app:test:edit']"
              style="margin-right: 8px"
            >修改</el-button>
            <el-popconfirm
              v-hasPermi="['app:test:remove']"
              :title="'确定要删除这条数据吗？'"
              @confirm="handleDelete(scope.row)"
            >
              <el-button
                size="mini"
                type="text"
                slot="reference"
                icon="el-icon-delete"
              >删除</el-button>
            </el-popconfirm>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
    <!-- 添加或修改死淘处理方式对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" size="mini" :disabled="isView" label-width="110px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="单据编号" prop="orderNum">
              <el-input v-model="form.orderNum"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="结算日期" prop="orderNum">
              <el-date-picker
                style="width: 100%"
                v-model="form.timeRange"
                type="date"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="采购日期" prop="orderNum">
              <el-date-picker
                style="width: 100%"
                v-model="form.timeRange"
                type="date"
                value-format="yyyy-MM-dd"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="采购入库单号" prop="orderNum">
              <el-input v-model="form.orderNum"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="供应商" prop="supplierNum">
              <el-select style="width: 100%" filterable v-model="form.supplierNum">
                <el-option v-for="item in supplierList" :key="item.supplierNum" :value="item.supplierNum" :label="item.supplierName"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="结算方式">
              <el-select style="width: 100%" v-model="form.way">
                <el-option v-for="item in wayList" :key="item.id" :value="item.id" :label="item.label"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="结算批次">
              <el-input v-model="form.batch"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="入库数量">
              <decimal-input v-model="form.num" :min="0" :max="999999" placeholder="请输入入库数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="结算数量">
              <decimal-input v-model="form.num" :min="0" :max="999999" placeholder="请输入入库数量" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="毛猪结算单价">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入毛猪结算单价" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="采购扣分">
              <decimal-input v-model="form.num" :min="0" :max="999999" placeholder="请输入采购扣分" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="采购加分">
              <decimal-input v-model="form.num" :min="0" :max="999999" placeholder="请输入采购加分" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="牧场出肉率(%)">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入牧场出肉率" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="预估平均重量">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入预估平均重量" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="平均级别">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入平均级别" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="白毛数量">
              <decimal-input v-model="form.num" :min="0" :max="999999" placeholder="请输入白毛数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="到场出肉率(%)">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入牧场出肉率" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="预估平均重量">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入预估平均重量" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="平均重量">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入平均重量" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="黑毛数量">
              <decimal-input v-model="form.num" :min="0" :max="999999" placeholder="请输入黑毛数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="未到头数">
              <decimal-input v-model="form.num" :min="0" :max="999999" placeholder="请输入未到头数" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="不合格数量">
              <decimal-input v-model="form.num" :min="0" :max="999999" placeholder="请输入不合格数量" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="途亡数量">
              <decimal-input v-model="form.num" :min="0" :max="999999" placeholder="请输入途亡数量" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="圈亡数量">
              <decimal-input v-model="form.num" :min="0" :max="999999" placeholder="请输入圈亡数量" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="进场扣款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入进场扣款" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="级别扣款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入级别扣款" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="重量扣款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入重量扣款" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="采购扣款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入采购扣款" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="其他扣款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入其他扣款" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="运费">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入运费" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="圈亡补款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入圈亡补款" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="其他补款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入其他补款" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="备注">
              <el-input v-model="form.remark"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="已付金额">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入已付金额" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="未付金额">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入未付金额" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="结算金额">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入结算金额" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="业务费用">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入业务费用" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="白胴考核收入">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入白胴考核收入" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="盈亏">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入盈亏" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">报表款项说明</el-divider>
        <el-row>
          <el-col :span="6">
            <el-form-item label="过磅方式">
              <el-select v-model="form.num"></el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="进场扣款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入进场扣款" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="级别扣款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入级别扣款" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="重量扣款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入重量扣款" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item label="采购扣款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入采购扣款" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="其他扣款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入其他扣款" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="圈亡补款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入圈亡补款" />
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="其他扣款">
              <decimal-input v-model="form.num" :min="0" :max="999999" :precision="2" placeholder="请输入其他扣款" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider content-position="left">屠宰列表</el-divider>
        <el-table border stripe>
          <el-table-column label="屠宰日期" align="center" width="180" fixed></el-table-column>
          <el-table-column label="物料编号" align="center" width="180" fixed></el-table-column>
          <el-table-column label="物料名称" align="center" width="180" fixed></el-table-column>
          <el-table-column label="品种" align="center" width="120"></el-table-column>
          <el-table-column label="级别" align="center" width="120"></el-table-column>
          <el-table-column label="数量" align="center" width="120"></el-table-column>
          <el-table-column label="占比" align="center" width="120"></el-table-column>
          <el-table-column label="重量" align="center" width="120"></el-table-column>
          <el-table-column label="头蹄重量" align="center" width="120"></el-table-column>
          <el-table-column label="合计重量" align="center" width="120"></el-table-column>
          <el-table-column label="单价" align="center" width="120"></el-table-column>
          <el-table-column label="金额" align="center" width="120"></el-table-column>
          <el-table-column label="存栏单价" align="center" width="150"></el-table-column>
          <el-table-column label="存栏天数" align="center" width="150"></el-table-column>
          <el-table-column label="存栏加价" align="center" width="150"></el-table-column>
          <el-table-column label="黑毛数" align="center" width="150"></el-table-column>
        </el-table>
        <!--        <el-form-item label="处理方式" prop="dealWay">-->
        <!--          <el-input type="textarea" v-model="form.dealWay" maxlength="50" show-word-limit placeholder="请输入处理方式" />-->
        <!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!isView">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { formatMoney } from "../../../../utils";
import { getSupplierList } from "../../../../api/purchase/supplier";

export default {
  name: "SettleAccounts",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      disposalList: [],
      // 弹出层标题
      title: "",
      isView:false,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        supplierName: null,
        way: 0,
        batch: null,
        timeRange: null,
        startTime: null,
        endTime: null,
      },
      pickerOptions: {
        disabledDate(time) {
          // 获取当前日期
          const today = new Date();
          today.setHours(0, 0, 0, 0); // 将时间设置为当天的 00:00:00

          // 禁用今天之后的日期
          return time.getTime() > today.getTime();
        }
      },
      // 表单参数
      form: {},
      rules: {},
      supplierList: [],
      wayList: [
        {
          id: 1,
          label: '毛猪结算'
        },
        {
          id: 2,
          label: '分级结算'
        },
      ]
    }
  },
  watch: {
    "queryParams.timeRange": {
      handler(newVal) {
        if (newVal) {
          this.queryParams.startTime = newVal[0]
          this.queryParams.endTime = newVal[1]
        } else {
          this.queryParams.startTime = null
          this.queryParams.endTime = null
        }
      },
      deep: true
    },
  },
  created() {
    this.getSupplier()
    this.getList();
  },
  methods: {
    getSupplier() {
      getSupplierList({}).then(res => {
        this.supplierList = res.data
      })
    },
    getMoney(val) {
      return formatMoney(val)
    },
    goNext(event, nextRef) {
      event.preventDefault();
      this.$refs[nextRef].focus();
    },
    /** 查询检验项目列表 */
    getList() {
      // (this.queryParams).then(res => {
      // this.disposalList = res.data.records;
      // this.total = res.data.total;
      //   this.loading = false;
      // })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      // this.resetForm("queryForm");
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        projectName: null,
        supplierName: null,
        way: 0,
        batch: null,
        timeRange: null,
        startTime: null,
        endTime: null,
      }
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isView = false;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id;
      let params = {
        id: id
      }
      // (params).then(res => {
      //   this.form = res.data;
      //   this.open = true;
      //   this.isView = false;
      //   this.title = "编辑"
      // })
    },
    /** 查看按钮操作 */
    handleView(row) {
      this.reset();
      const id = row.id;
      let params = {
        id: id
      }
      // (params).then(res => {
      //   this.form = res.data;
      //   this.open = true;
      //   this.isView = true;
      //   this.title = "查看"
      // })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        // dealReason: null,
        // dealWay: null,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            // 编辑
            // (this.form).then(res => {
            //   this.$modal.msgSuccess("修改成功");
            //   this.open = false;
            //   this.getList();
            // })
          } else {
            // 新增
            // (this.form).then(response => {
            //   this.$modal.msgSuccess("新增成功");
            //   this.open = false;
            //   this.getList();
            // });
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id;
      let params = {
        ids: ids
      }
      // (params).then(res => {
      //   this.getList();
      //   this.$modal.msgSuccess("删除成功");
      // })
    },
    /** 删除按钮操作 */
    handleDeleteAll() {
      const ids = this.ids;
      this.$modal.confirm('确定要删除这条数据吗？').then(() => {
        let params = {
          ids: ids.join(',')
        }
        // (params).then(res => {
        //   this.getList();
        //   this.$modal.msgSuccess("删除成功");
        //   this.$refs.multipleTable.clearSelection();
        // })
      })
    }
  }
}
</script>

<style scoped lang="scss">

</style>

