<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="main">
      <div class="form_all">
        <el-form ref="select" :model="select" label-width="auto">
          <el-row :gutter="10">
            <el-col :span="4">
              <el-form-item label="供应商名称">
                <el-input clearable v-model="select.custName"></el-input>
              </el-form-item>
            </el-col>

            <el-col :span="4">
              <el-button type="primary" @click="getDataList">
                {{ '搜索' }}</el-button
              >
              <el-button type="" @click="reset"> {{ '重置' }}</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="maintop">
        <div class="mainbtn">
          <!-- v-has-buttons="['depositPaymentAdd']" -->
          <el-button
            size="small"
            @click="openDig"
            :disabled="canSub"
            class="addBtn"
            >{{ '添加' }}</el-button
          >
          <!-- v-has-buttons="['depositPaymentDelete']" -->
          <el-button
            size="small"
            @click="handleDelete"
            style="background-color: #c9171d"
            :disabled="single || canSub"
            class="thebtn1"
          >
            {{ '删除' }}</el-button
          >
          <!-- v-has-buttons="['depositPaymentSubmit']" -->
          <el-button
            size="small"
            :disabled="selRow.length == 0 || canSub"
            @click="goQc"
            type="success"
            >{{ '提交' }}</el-button
          >
        </div>
      </div>
      <div class="maintable">
        <el-table
          :data="tableData"
          v-loading="loading"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column align="center" prop="custName" label="供应商名称">
          </el-table-column>
          <el-table-column align="center" prop="shortName" label="供应商简称">
          </el-table-column>
          <el-table-column align="center" prop="legalBody" label="法人姓名">
          </el-table-column>
          <el-table-column align="center" prop="linkMan" :label="'联系人'">
          </el-table-column>
          <el-table-column align="center" prop="phone" label="联系方式">
          </el-table-column>
          <el-table-column
            align="center"
            prop="taxpayerid"
            label="纳税人登记号"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="provinceName"
            :label="'省'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="cityName"
            :label="'市'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="countyName"
            :label="'区/县'"
          >
          </el-table-column>
          <el-table-column align="center" prop="address" :label="'详细地址'">
          </el-table-column>

          <el-table-column align="center" prop="tradeScope" label="经营范围">
          </el-table-column>
          <el-table-column align="center" prop="billDate" label="缴纳日期">
          </el-table-column>
          <el-table-column align="center" prop="saleTypeVal" label="销售类型 ">
          </el-table-column>
          <el-table-column
            align="center"
            prop="approveStatusVal"
            label="审核状态"
          >
          </el-table-column>

          <el-table-column
            align="center"
            prop="creationTime"
            :label="'创建时间'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            :label="'操作'"
            fixed="right"
          >
            <template slot-scope="scope">
              <el-button
                style="color: #6962f6"
                class="button-s"
                type="text"
                size="small"
                :disabled="
                  scope.row.approveStatus == 5 || scope.row.approveStatus == 2
                "
                @click.native.prevent="updateRow(scope.row)"
              >
                {{ '修改' }}
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />

    <el-dialog
      :title="dialogTitle"
      :close-on-click-modal="false"
      :visible.sync="dialogVisible"
      width="40%"
      center
      :before-close="handleClose"
    >
      <el-form ref="form" :rules="rules" :model="form" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="缴纳供应商" prop="pkSupplier">
              <el-select
                clearable
                :placeholder="'请选择'"
                v-model="form.pkSupplier"
              >
                <el-option
                  v-for="item in supplierList"
                  :key="item.pkId"
                  :label="item.custName"
                  :value="item.pkId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="缴纳日期" prop="billDate">
              <el-date-picker
                v-model="form.billDate"
                type="date"
                value-format="yyyy-MM-dd"
                :placeholder="'请选择'"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="销售类型" prop="saleType">
              <el-select
                clearable
                :placeholder="'请选择'"
                v-model="form.saleType"
              >
                <el-option
                  v-for="item in saleTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="销售范围" prop="saleScope">
              <el-select
                clearable
                :placeholder="'请选择'"
                v-model="form.saleScope"
              >
                <el-option
                  v-for="item in saleScopeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人" prop="linkMan">
              <el-input clearable v-model="form.linkMan"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phone">
              <el-input clearable v-model="form.phone"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="保证金金额" prop="margin">
              <el-input
                type="number"
                clearable
                v-model="form.margin"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">{{ '取消' }}</el-button>
        <el-button type="primary" @click="onSubmit('form')">{{
          '确认'
        }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>
    
    <script>
import topBar from "@/components/topBar";
import * as api from "@/api/supply.js";
export default {
  name: "DepositPayment",
  components: {
    topBar,
  },
  data() {
    return {
      creationTime: [],
      select: {},
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
      },
      addOrEdit: "", //true添加false修改
      dialogTitle: "",
      total: 0,
      dialogVisible: false,
      tableData: [],
      loading:false,
      form: {},
      moren: "depositPayment",
      topList: [
        {
          name: "保证金缴纳",
          path: "depositPayment",
        },
      ],
      single: true,
      thepkId: "",
      selRow: [],
      supplierList: [],
      saleTypeList: [],
      saleScopeList: [],
      rules: {
        phone: [
          { required: true, message: '请输入', trigger: "blur" },
        ],
        margin: [
          { required: true, message: '请输入', trigger: "blur" },
        ],
        margin: [
          { required: true, message: '请输入', trigger: "blur" },
        ],
        pkSupplier: [
          { required: true, message: '请选择收货地址', trigger: "change" },
        ],
        billDate: [
          { required: true, message: '请选择收货地址', trigger: "change" },
        ],
        saleType: [
          { required: true, message: '请选择收货地址', trigger: "change" },
        ],
        saleScope: [
          { required: true, message: '请选择收货地址', trigger: "change" },
        ],
      },
      canSub: false,
    };
  },
  mounted() {
    this.getOthers();
    // 获取列表
    this.getDataList();
  },
  methods: {
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let url = "";
          if (this.addOrEdit == true) {
            url = api.addThMargin;
          } else {
            url = api.updateThMargin;
          }
          url(this.form).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: "success",
              });
              this.dialogVisible = false;
              // 获取列表
              this.getDataList();
              this.$refs[formName].resetFields();
            }
          });
        }
      });
    },
    //修改
    updateRow(row) {
      this.dialogTitle = '修改';
      this.addOrEdit = false;
      api.getOneThMargin(row.pkId).then((res) => {
        this.form = res.data;

        this.dialogVisible = true;
      });
    },

    getOthers() {
      api.supplierList().then((res) => {
        this.supplierList = res.rows;
      });
      api.getOrderType().then((res) => {
        this.saleTypeList = res.data;
      });
      api.getSaleScopeList().then((res) => {
        this.saleScopeList = res.data;
      });
    },
    goQc() {
      this.$confirm("是否确认提交", '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then(() => {
        let arr = this.selRow.map((item) => item.pkId);
        let pkIdListStr = arr.join(",");
        api.petitionThMargin({ pkIdListStr: pkIdListStr }).then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.msg,
              type: "success",
            });
            this.getDataList();
          }
        });
      });
    },
    reset() {
      this.select = {};
      this.getDataList();
    },
    // 删除
    handleDelete(id) {
      this.$confirm('确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: "warning",
      }).then(() => {
        api.deleteThMargin(this.thepkId).then((res) => {
          this.getDataList();
        });
      });
    },
    openDig() {
      this.dialogVisible = true;
      this.addOrEdit = true;
      this.dialogTitle = '添加';
      this.$refs[formName].resetFields();
    },
    getDataList() {
      this.loading = true
      api
        .getThMarginList(Object.assign({}, this.queryParams, this.select))
        .then((res) => {
          this.tableData = res.rows;
          this.total = res.total;
          this.loading = false
        });
    },
    handleClose() {
      this.dialogVisible = false;
      this.$refs["form"].clearValidate();
      this.$refs["form"].resetFields();
    },
    handleSelectionChange(val) {
      this.single = val.length !== 1;
      this.thepkId = val[0].pkId;
      this.selRow = val;
      val.forEach((element) => {
        if (element.approveStatus == 5 || element.approveStatus == 2) {
          this.canSub = true;
        } else {
          this.canSub = false;
        }
      });
    },

    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>
    <style scoped lang="scss">
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
.uploadIcon ::v-deep .el-upload--picture-card {
  display: none !important; /* 上传按钮隐藏 */
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    .form_all {
      padding: 0px 20px 0 20px;
      // margin-bottom: 20px;
      background: #fff;
      border-radius: 8px;
    }
    .maintop {
      display: flex;
      padding: 0px 0px;
      justify-content: space-between;
      align-items: center;

      background: #f8f8f8;
      .mainbtn {
        .thebtn1 {
          background: #3181e5;
          color: #ffffff;
        }
        .thebtn2 {
          background: #ffad41;
          color: #ffffff;
        }
      }
      .maintitle {
        font-size: 10px;
        font-family: MicrosoftYaHei;
        color: #999999;
      }
    }
  }
  .tem {
    display: flex;
    align-items: center;
    justify-content: center;
    img {
      width: 28px;
      height: 20px;
      margin-right: 3px;
    }
  }
  .isRed {
    color: #ed1d25;
  }
  .isGreen {
    color: #1ab62b;
  }
  .bgImg {
    width: 48px;
    height: 48px;
  }
}
.openClose {
  text-align: right;
  margin-right: 10px;
  color: #3181e5;
}
.dizhi {
  ::v-deep .el-cascader {
    width: 100%;
  }
}
::v-deep .el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: auto;
}
</style>
    