<template>
  <div class="borderless" v-loading="pageLoading">
    <div class="customer-head">
      <div class="customer-back">
        <el-button type="danger" style="border: none;background: none;color: red" icon="el-icon-arrow-left"
          @click="backToList">返回列表
        </el-button>
      </div>
      <div class="add-customer-btn">
        <el-button type="primary" size="small" :disabled="form.status>0" v-if="detailData.status == 1"
          class="el-button--small-yh " @click.stop="openEdit">编辑
        </el-button>
        <el-button type="primary" @click="editCustomer" :loading="subLoading" v-if="detailData.status != 1"
          size="small">保存数据
        </el-button>
        <el-dropdown style="padding: 0 6px;line-height: 0">
          <el-button type="primary" size="small" :loading="subLoading" :disabled="!form.id">
            审核处理<i class="el-icon-arrow-down el-icon--right"></i>
          </el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item :disabled="form.status>0" @click.native="auditCheck">提交审核</el-dropdown-item>
            <el-dropdown-item :disabled="form.status<1" @click.native="checkScheduleDialog = true">审核进度
            </el-dropdown-item>
            <el-dropdown-item v-if="$route.query.check" :disabled="form.status==3" @click.native="check">审批数据
            </el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </div>
    <div class="customer-main" v-loading="subLoading">
      <trade-card title="基础信息">
        <avue-form ref="form" class="trading-form" v-model="form" :option="option">
          <template slot="corpId">
            <crop-select v-model="form.corpId" corpType="KH" :refresh="false" @getCorpData="getKHData"
              :disabled="form.status > 0"></crop-select>
          </template>
          <template slot="companyId">
            <crop-select v-model="form.companyId" corpType="GS" :refresh="false" @getCorpData="getKHDataTwo"
              :disabled="form.status > 0"></crop-select>
          </template>
        </avue-form>
      </trade-card>
      <el-dialog append-to-body title="审批进度" class="el-dialogDeep" :visible.sync="checkScheduleDialog" width="40%"
        :close-on-click-modal="false" :destroy-on-close="true" :close-on-press-escape="false" v-dialog-drag>
        <check-schedule :checkId="form.id" :batchNo="batchNo" @choceScheduleFun="choceScheduleFun">
        </check-schedule>
      </el-dialog>
      <el-dialog append-to-body title="审批" class="el-dialogDeep" :visible.sync="checkDialog" width="50%"
        :close-on-click-modal="false" :destroy-on-close="true" :close-on-press-escape="false" v-dialog-drag>
        <check :checkData="checkData" :checkDetail="false" :idList="[]" @choceCheckFun="choceCheckFun">
        </check>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { getDetail, submit, checkFinancing } from "@/api/basicData/financing";
import feeInfo from "@/components/fee-info/main";
import checkSchedule from "../../../components/check/checkSchedule";
import uploadFile from "@/components/upload-file/main";
import check from "@/components/check/check";
export default {
  name: "detailsPageEdit",
  data() {
    return {
      checkData: {},
      checkDialog: false,
      form: {},
      checkScheduleDialog: false,
      option: {
        disabled: false,
        menuBtn: false,
        labelWidth: 100,
        column: [
          {
            label: "系统编号",
            prop: "sysNo",
            disabled: true,
            span: 6
          },
          {
            label: "客户",
            prop: "corpId",
            rules: [
              {
                required: true,
                message: "",
                trigger: "blur"
              }
            ],
            span: 6
          },
          {
            label: "通过公司",
            prop: "companyId",
            rules: [{
                required: false,
                message: "",
                trigger: "blur"
            }],
            span: 6
          },
          {
            label: "融资日期",
            prop: "financingDate",
            type: "date",
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
            rules: [{
                required: true,
                message: "",
                trigger: "blur"
            }],
            span: 6
          },
          {
            label: "融资类别",
            prop: "financingType",
            type: "select",
            dataType: 'number',
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            dicData: [],
            rules: [{
                required: true,
                message: "",
                trigger: "blur"
            }],
            span: 6
          },
          {
            label: "融资金额",
            prop: "financingAmount",
            blur:(data)=>{
              if (data.value < 0){
                this.form.financingAmount = 0
              }
            },
            controls:false,
            type:'number',
            rules: [{
                required: true,
                message: "",
                trigger: "blur"
            }],
            span: 6
          },
          {
            label: "状态",
            prop: "status",
            type: "select",
            dataType: 'number',
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            dicData: [],
            disabled: true,
            span: 6
          },
          {
            label: "备注",
            prop: "remarks",
            type: "textarea",
            minRows: 2,
            width: 120,
            span: 24,
          },
        ]

      },
      itemsVOList: [],
      orderFilesList: [],
      subLoading: false,
      pageLoading: false,
      batchNo: '',
      storagetreeList: []
    };
  },
  props: {
    detailData: {
      type: Object
    }
  },
  components: {
    feeInfo,
    checkSchedule,
    uploadFile,
    check
  },
  async created() {
    if (this.detailData.status == 1) {
      this.option.disabled = true;
    }
    if (this.detailData.id) {
      this.getDetail(this.detailData.id);
    }
    this.getWorkDicts("financing_status").then(res => {
      this.findObject(this.option.column, "status").dicData =
        res.data.data;
    });
    this.getWorkDicts("financing_type").then(res => {
      this.findObject(this.option.column, "financingType").dicData =
        res.data.data;
    });
  },
  methods: {
    check() {
      this.checkData = this.$route.query.check
      this.checkDialog = true
    },
    //关闭审核
    choceCheckFun() {
      this.checkDialog = false;
    },
    cellStyle() {
      return "padding:0;height:40px;";
    },
    getKHData(row) {
      this.form.corpName = row.cname
    },
    getKHDataTwo(row) {
      this.form.company = row.cname
    },
    getDetail(id) {
      this.pageLoading = true;
      getDetail(id)
        .then(res => {
          this.form = res.data.data;
        })
        .finally(() => {
          this.pageLoading = false;
        });
    },
    //修改提交触发
    editCustomer(status) {
      this.$refs["form"].validate((valid, done) => {
        done();
        if (valid) {
          this.subLoading = true;
          let data = {
            ...this.form
          };
          submit(data).then(res => {
            console.log(res)
            this.form = res.data.data.data;
            this.$message({
              type: "success",
              message: "保存成功!"
            });
          })
            .finally(() => {
              this.subLoading = false;
            });
        } else {
          return false;
        }
      });
    },
    //请核
    auditCheck() {
      this.$confirm("确定审核此订单?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.subLoading = true
        const data = {
          id: this.form.id,
          checkType: 'rzgl',
          url: '/financing/financingManagement/index',
          pageStatus: "this.$store.getters.entranceXsStatus",
          pageLabel: "融资管理",
          checkFlag: 1,
        }
        checkFinancing(data).then(res => {
          if (res.data.success) {
            this.$message.success("操作成功!")
            this.form.status = 3
            this.option.disabled = true;
          }
        }).finally(() => {
          this.subLoading = false
        })
      })
    },
    //返回列表
    backToList() {
      this.$emit("goBack");
    },
    openEdit() {
      this.detailData.status = 2;
      this.option.disabled = false;
      this.$refs.crud.refreshTable();
    }
  },
  watch: {
  }
};
</script>

<style lang="scss" scoped>
.trading-form ::v-deep .el-form-item {
  margin-bottom: 8px !important;
}

::v-deep .el-form-item__error {
  display: none !important;
}

::v-deep .select-component {
  display: flex !important;
}
</style>
