<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="费用名称,存储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存储id 显示名称 name	对应，t_unitfees f_id，如果选择为毛重，数量" prop="fFeeunitid">
        <el-select v-model="queryParams.fFeeunitid" placeholder="请选择计价单位,t_unitfees f_id存储id 显示名称 name	对应，t_unitfees f_id，如果选择为毛重，数量" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="开始天数,只有为仓储费显示" prop="fFromdays">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.fFromdays"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择开始天数,只有为仓储费显示">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束天数,只有为仓储费显示" prop="fEndays">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.fEndays"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择结束天数,只有为仓储费显示">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="单价,只有为仓储费显示" prop="fPrice">
        <el-input
          v-model="queryParams.fPrice"
          placeholder="请输入单价,只有为仓储费显示"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态，默认 T ,正常T 停用F 下拉选择" prop="fStatus">
        <el-select v-model="queryParams.fStatus" placeholder="请选择状态，默认 T ,正常T 停用F 下拉选择" 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:agreementitems: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:agreementitems: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:agreementitems: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:agreementitems:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="agreementitemsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="状态，默认 T ,正常T 停用F 下拉选择" 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="费用名称,存储id 显示名称	t_fees 中的no或 name，模糊查找选择后，存储f_id，显示name" align="center" prop="fFeeid" />
      <el-table-column label="计价单位,t_unitfees f_id存储id 显示名称 name	对应，t_unitfees f_id，如果选择为毛重，数量" align="center" prop="fFeeunitid" />
      <el-table-column label="开始天数,只有为仓储费显示" align="center" prop="fFromdays" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fFromdays, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结束天数,只有为仓储费显示" align="center" prop="fEndays" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fEndays, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单价,只有为仓储费显示" align="center" prop="fPrice" />
      <el-table-column label="状态，默认 T ,正常T 停用F 下拉选择" 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:agreementitems:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['warehouseBusiness:agreementitems: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="费用名称,存储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存储id 显示名称 name	对应，t_unitfees f_id，如果选择为毛重，数量" prop="fFeeunitid">
          <el-select v-model="form.fFeeunitid" placeholder="请选择计价单位,t_unitfees f_id存储id 显示名称 name	对应，t_unitfees f_id，如果选择为毛重，数量">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="开始天数,只有为仓储费显示" prop="fFromdays">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.fFromdays"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择开始天数,只有为仓储费显示">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束天数,只有为仓储费显示" prop="fEndays">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.fEndays"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择结束天数,只有为仓储费显示">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="单价,只有为仓储费显示" prop="fPrice">
          <el-input v-model="form.fPrice" placeholder="请输入单价,只有为仓储费显示" />
        </el-form-item>
        <el-form-item label="状态，默认 T ,正常T 停用F 下拉选择">
          <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 { listAgreementitems, getAgreementitems, delAgreementitems, addAgreementitems, updateAgreementitems, exportAgreementitems } from "@/api/warehouseBusiness/agreementitems";

export default {
  name: "Agreementitems",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 仓储费明细表表格数据
      agreementitemsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fPid: null,
        fLineno: null,
        fFeeid: null,
        fFeeunitid: null,
        fFromdays: null,
        fEndays: null,
        fPrice: null,
        fStatus: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fPid: [
          { required: true, message: "对应主表id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询仓储费明细表列表 */
    getList() {
      this.loading = true;
      listAgreementitems(this.queryParams).then(response => {
        this.agreementitemsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fId: null,
        fPid: null,
        fLineno: null,
        fFeeid: null,
        fFeeunitid: null,
        fFromdays: null,
        fEndays: null,
        fPrice: 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
      getAgreementitems(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) {
            updateAgreementitems(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAgreementitems(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 delAgreementitems(fIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有仓储费明细表数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportAgreementitems(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
