<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="对应主表id" prop="fPid">
        <el-input
          v-model="queryParams.fPid"
          placeholder="请输入对应主表id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="行号" prop="fLineno">
        <el-input
          v-model="queryParams.fLineno"
          placeholder="请输入行号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称,t_corps 中的no或 name，模糊查找选择后，存储id，显示name" prop="fCorpid">
        <el-input
          v-model="queryParams.fCorpid"
          placeholder="请输入客户名称,t_corps 中的no或 name，模糊查找选择后，存储id，显示name"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="费用名称,存储id 显示名称,t_fees 中的no或 name，模糊查找选择后，存储f_id，显示name" prop="fFeeid">
        <el-select v-model="queryParams.fFeeid" placeholder="请选择费用名称,存储id 显示名称,t_fees 中的no或 name，模糊查找选择后，存储f_id，显示name" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="计价单位(数据字典),对应，t_unitfees f_id，如果选择为毛重，数量" prop="fFeeunitid">
        <el-select v-model="queryParams.fFeeunitid" placeholder="请选择计价单位(数据字典),对应，t_unitfees f_id，如果选择为毛重，数量" clearable size="small">
          <el-option
            v-for="dict in fFeeunitidOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="数量" prop="fQty">
        <el-input
          v-model="queryParams.fQty"
          placeholder="请输入数量"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单价" prop="fUnitprice">
        <el-input
          v-model="queryParams.fUnitprice"
          placeholder="请输入单价"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="金额,2位小数f_qty* f_amount" prop="fAmount">
        <el-input
          v-model="queryParams.fAmount"
          placeholder="请输入金额,2位小数f_qty* f_amount"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="币别" prop="fCurrency">
        <el-input
          v-model="queryParams.fCurrency"
          placeholder="请输入币别"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="汇率" prop="fExrate">
        <el-input
          v-model="queryParams.fExrate"
          placeholder="请输入汇率"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="税率，显示是 3 6 16 用13%" prop="fTaxrate">
        <el-input
          v-model="queryParams.fTaxrate"
          placeholder="请输入税率，显示是 3 6 16 用13%"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收、付,D:收 C 付" prop="fDc">
        <el-input
          v-model="queryParams.fDc"
          placeholder="请输入收、付,D:收 C 付"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态,N 录入，F审核中，T审核通过，只有录入状态的数据可以修改" prop="fBillstatus">
        <el-select v-model="queryParams.fBillstatus" placeholder="请选择状态,N 录入，F审核中，T审核通过，只有录入状态的数据可以修改" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="对账金额" prop="fAccamount">
        <el-input
          v-model="queryParams.fAccamount"
          placeholder="请输入对账金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结算金额" prop="fStlamount">
        <el-input
          v-model="queryParams.fStlamount"
          placeholder="请输入结算金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发票号" prop="fInvnos">
        <el-input
          v-model="queryParams.fInvnos"
          placeholder="请输入发票号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开票金额" prop="fInvamount">
        <el-input
          v-model="queryParams.fInvamount"
          placeholder="请输入开票金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="申请金额" prop="fAskamount">
        <el-input
          v-model="queryParams.fAskamount"
          placeholder="请输入申请金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="fStatus">
        <el-select v-model="queryParams.fStatus" placeholder="请选择状态" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" 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"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['warehouseBusiness:warehousebillsfees:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['warehouseBusiness:warehousebillsfees:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['warehouseBusiness:warehousebillsfees:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['warehouseBusiness:warehousebillsfees:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="warehousebillsfeesList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="状态" align="center" prop="fId" />
      <el-table-column label="对应主表id" align="center" prop="fPid" />
      <el-table-column label="行号" align="center" prop="fLineno" />
      <el-table-column label="客户名称,t_corps 中的no或 name，模糊查找选择后，存储id，显示name" align="center" prop="fCorpid" />
      <el-table-column label="费用名称,存储id 显示名称,t_fees 中的no或 name，模糊查找选择后，存储f_id，显示name" align="center" prop="fFeeid" />
      <el-table-column label="计价单位(数据字典),对应，t_unitfees f_id，如果选择为毛重，数量" align="center" prop="fFeeunitid" :formatter="fFeeunitidFormat" />
      <el-table-column label="数量" align="center" prop="fQty" />
      <el-table-column label="单价" align="center" prop="fUnitprice" />
      <el-table-column label="金额,2位小数f_qty* f_amount" align="center" prop="fAmount" />
      <el-table-column label="币别" align="center" prop="fCurrency" />
      <el-table-column label="汇率" align="center" prop="fExrate" />
      <el-table-column label="税率，显示是 3 6 16 用13%" align="center" prop="fTaxrate" />
      <el-table-column label="收、付,D:收 C 付" align="center" prop="fDc" />
      <el-table-column label="状态,N 录入，F审核中，T审核通过，只有录入状态的数据可以修改" align="center" prop="fBillstatus" />
      <el-table-column label="对账金额" align="center" prop="fAccamount" />
      <el-table-column label="结算金额" align="center" prop="fStlamount" />
      <el-table-column label="发票号" align="center" prop="fInvnos" />
      <el-table-column label="开票金额" align="center" prop="fInvamount" />
      <el-table-column label="申请金额" align="center" prop="fAskamount" />
      <el-table-column label="状态" align="center" prop="fStatus" />
      <el-table-column label="备注" align="center" prop="remark" />
      <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)"
            v-hasPermi="['warehouseBusiness:warehousebillsfees:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['warehouseBusiness:warehousebillsfees:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改仓库费用明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="对应主表id" prop="fPid">
          <el-input v-model="form.fPid" placeholder="请输入对应主表id" />
        </el-form-item>
        <el-form-item label="行号" prop="fLineno">
          <el-input v-model="form.fLineno" placeholder="请输入行号" />
        </el-form-item>
        <el-form-item label="客户名称,t_corps 中的no或 name，模糊查找选择后，存储id，显示name" prop="fCorpid">
          <el-input v-model="form.fCorpid" placeholder="请输入客户名称,t_corps 中的no或 name，模糊查找选择后，存储id，显示name" />
        </el-form-item>
        <el-form-item label="费用名称,存储id 显示名称,t_fees 中的no或 name，模糊查找选择后，存储f_id，显示name" prop="fFeeid">
          <el-select v-model="form.fFeeid" placeholder="请选择费用名称,存储id 显示名称,t_fees 中的no或 name，模糊查找选择后，存储f_id，显示name">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="计价单位(数据字典),对应，t_unitfees f_id，如果选择为毛重，数量" prop="fFeeunitid">
          <el-select v-model="form.fFeeunitid" placeholder="请选择计价单位(数据字典),对应，t_unitfees f_id，如果选择为毛重，数量">
            <el-option
              v-for="dict in fFeeunitidOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数量" prop="fQty">
          <el-input v-model="form.fQty" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="单价" prop="fUnitprice">
          <el-input v-model="form.fUnitprice" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="金额,2位小数f_qty* f_amount" prop="fAmount">
          <el-input v-model="form.fAmount" placeholder="请输入金额,2位小数f_qty* f_amount" />
        </el-form-item>
        <el-form-item label="币别" prop="fCurrency">
          <el-input v-model="form.fCurrency" placeholder="请输入币别" />
        </el-form-item>
        <el-form-item label="汇率" prop="fExrate">
          <el-input v-model="form.fExrate" placeholder="请输入汇率" />
        </el-form-item>
        <el-form-item label="税率，显示是 3 6 16 用13%" prop="fTaxrate">
          <el-input v-model="form.fTaxrate" placeholder="请输入税率，显示是 3 6 16 用13%" />
        </el-form-item>
        <el-form-item label="收、付,D:收 C 付" prop="fDc">
          <el-input v-model="form.fDc" placeholder="请输入收、付,D:收 C 付" />
        </el-form-item>
        <el-form-item label="状态,N 录入，F审核中，T审核通过，只有录入状态的数据可以修改">
          <el-radio-group v-model="form.fBillstatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="对账金额" prop="fAccamount">
          <el-input v-model="form.fAccamount" placeholder="请输入对账金额" />
        </el-form-item>
        <el-form-item label="结算金额" prop="fStlamount">
          <el-input v-model="form.fStlamount" placeholder="请输入结算金额" />
        </el-form-item>
        <el-form-item label="发票号" prop="fInvnos">
          <el-input v-model="form.fInvnos" placeholder="请输入发票号" />
        </el-form-item>
        <el-form-item label="开票金额" prop="fInvamount">
          <el-input v-model="form.fInvamount" placeholder="请输入开票金额" />
        </el-form-item>
        <el-form-item label="申请金额" prop="fAskamount">
          <el-input v-model="form.fAskamount" placeholder="请输入申请金额" />
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.fStatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="删除状态" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除状态" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWarehousebillsfees, getWarehousebillsfees, delWarehousebillsfees, addWarehousebillsfees, updateWarehousebillsfees, exportWarehousebillsfees } from "@/api/warehouseBusiness/warehousebillsfees";

export default {
  name: "Warehousebillsfees",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 仓库费用明细表格数据
      warehousebillsfeesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 计价单位(数据字典),对应，t_unitfees f_id，如果选择为毛重，数量字典
      fFeeunitidOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fPid: null,
        fLineno: null,
        fCorpid: null,
        fFeeid: null,
        fFeeunitid: null,
        fQty: null,
        fUnitprice: null,
        fAmount: null,
        fCurrency: null,
        fExrate: null,
        fTaxrate: null,
        fDc: null,
        fBillstatus: null,
        fAccamount: null,
        fStlamount: null,
        fInvnos: null,
        fInvamount: null,
        fAskamount: null,
        fStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fCorpid: [
          { required: true, message: "客户名称,t_corps 中的no或 name，模糊查找选择后，存储id，显示name不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("data_unitfees").then(response => {
      this.fFeeunitidOptions = response.data;
    });
  },
  methods: {
    /** 查询仓库费用明细列表 */
    getList() {
      this.loading = true;
      listWarehousebillsfees(this.queryParams).then(response => {
        this.warehousebillsfeesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 计价单位(数据字典),对应，t_unitfees f_id，如果选择为毛重，数量字典翻译
    fFeeunitidFormat(row, column) {
      return this.selectDictLabel(this.fFeeunitidOptions, row.fFeeunitid);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fId: null,
        fPid: null,
        fLineno: null,
        fCorpid: null,
        fFeeid: null,
        fFeeunitid: null,
        fQty: null,
        fUnitprice: null,
        fAmount: null,
        fCurrency: null,
        fExrate: null,
        fTaxrate: null,
        fDc: null,
        fBillstatus: "0",
        fAccamount: null,
        fStlamount: null,
        fInvnos: null,
        fInvamount: null,
        fAskamount: null,
        fStatus: "0",
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.fId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加仓库费用明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fId = row.fId || this.ids
      getWarehousebillsfees(fId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改仓库费用明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fId != null) {
            updateWarehousebillsfees(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWarehousebillsfees(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fIds = row.fId || this.ids;
      this.$confirm('是否确认删除仓库费用明细编号为"' + fIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delWarehousebillsfees(fIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有仓库费用明细数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportWarehousebillsfees(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
