<template>
  <div class="app-container contentBox">
    <el-row>
      <el-col>
        <div class="grid-content bg-purple">
          <el-form
            ref="formInline"
            :model="formInline"
            :rules="rules"
            :inline="true"
            class="width-80"
            :disabled="writeJurisdictionBool"
          >
            <el-row
              :span="24"
              style="border:1px solid #49a2fa;font-size:14px"
              class="width-c54 bgc"
            >
              <el-col :span="6" v-for="value in status" :key="value.id">
                <span>
                  <span
                    class="el-button-border el-button-all"
                    :class="{'on':value.check}"
                  >{{value.name}}</span>
                </span>
                <!-- @click="changeStatus(value)" -->
              </el-col>
              <!-- <el-col :span="6">
                <span>
                  <el-button size="small" class="el-button-border el-button-all">6月</el-button>
                </span>
              </el-col>
              <el-col :span="6">
                <span>
                  <el-button size="small" class="el-button-border el-button-all">9月</el-button>
                </span>
              </el-col>
              <el-col :span="6">
                <span>
                  <el-button size="small" class="el-button-border el-button-all">12月</el-button>
                </span>
              </el-col>-->
            </el-row>
            <!-- <el-row class="title-box clearable h3Parent width-c54">
              <el-col :span="24">
                <h3 class="titleUseStyle">基本信息</h3>
              </el-col>
            </el-row>-->
            <div>
              <el-row>
                <el-col :span="24">
                  <div class="grid-content bg-purple">
                    <el-form-item label="主管部门">
                      <el-input
                        v-model="formInline.projectName"
                        resize="none"
                        placeholder="-"
                        :disabled="true"
                      ></el-input>
                    </el-form-item>
                  </div>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <div class="grid-content bg-purple">
                    <el-form-item label="资金总额">
                      <el-input
                        v-model="formInline.projectContent"
                        resize="none"
                        placeholder="-"
                        :disabled="true"
                      ></el-input>
                    </el-form-item>
                  </div>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <div class="grid-content bg-purple">
                    <el-form-item label="项目负责人电话">
                      <el-input
                        v-model="formInline.annualTarget"
                        resize="none"
                        placeholder="-"
                        :disabled="true"
                      ></el-input>
                    </el-form-item>
                  </div>
                </el-col>
              </el-row>
              <el-row :gutter="2">
                <el-col :span="12">
                  <div class="grid-content bg-purple">
                    <el-form-item label="财政拨款" prop="expenditureProgress">
                      <el-input
                        v-model="formInline.expenditureProgress"
                        autocomplete="off"
                        placeholder="-"
                        :disabled="true"
                      ></el-input>
                    </el-form-item>
                  </div>
                </el-col>
                <el-col :span="12">
                  <div class="grid-content bg-purple">
                    <el-form-item label="其它资金">
                      <el-input
                        v-model="formInline.projectCompletionSchedule"
                        resize="none"
                        placeholder="-"
                        :disabled="true"
                      ></el-input>
                    </el-form-item>
                  </div>
                </el-col>
                <!-- <el-col :span="12">
                  <div class="grid-content bg-purple">
                    <el-form-item label="填写日期">
                      <el-date-picker
                        v-model="formInline.fillDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        style="width:100%"
                        :disabled="true"
                      ></el-date-picker>
                    </el-form-item>
                  </div>
                </el-col> -->
              </el-row>
              <v-comtab ref="getData1"></v-comtab>
              <el-row>
                <el-col :span="24">
                  <div class="grid-content bg-purple">
                    <el-form-item label="审核意见" prop="auditOpinions">
                      <el-input
                        v-model="formInline.auditOpinions"
                        type="textarea"
                        :rows="3"
                        @change="limitLength"
                        resize="none"
                        placeholder="请输入内容"
                      ></el-input>
                    </el-form-item>
                  </div>
                </el-col>
              </el-row>
              <el-row :gutter="2">
                <el-col :span="12">
                  <div class="grid-content bg-purple">
                    <!-- <el-form-item label="审核结果">
                      <el-radio-group v-model="formInline.findingsAudit">
                        <el-radio label="审核通过"></el-radio>
                        <el-radio label="驳回"></el-radio>
                      </el-radio-group>
                    </el-form-item>-->
                    <el-form-item label="审核结果" prop="findingsAuditValue">
                      <el-radio-group
                        v-model="findingsAuditValue"
                        @change="findingsAuditChange(findingsAuditValue)"
                      >
                        <el-radio
                          v-for="(item,index) in findingsAuditObj"
                          :key="index"
                          :label="item.value"
                          :value="item.code"
                        ></el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </div>
                </el-col>
                <el-col :span="12">
                  <div class="grid-content bg-purple">
                    <el-form-item label="审核人">
                      <el-input v-model="formInline.auditor" autocomplete="off" :disabled="true"></el-input>
                    </el-form-item>
                  </div>
                </el-col>
              </el-row>
              <el-row :gutter="2">
                <el-col :span="12">
                  <div class="grid-content bg-purple">
                    <el-form-item label="审核日期">
                      <el-date-picker
                        v-model="formInline.auditDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        style="width:100%"
                        :disabled="true"
                      ></el-date-picker>
                    </el-form-item>
                  </div>
                </el-col>
              </el-row>
            </div>
          </el-form>
          <el-row class="saveCancel">
            <el-col :span="24">
              <div class="grid-content bg-purple">
                <el-button
                  type="primary"
                  class="iconfont icontijiao"
                  style="margin-left: 8px;"
                  @click="submissionInfo('formInline')"
                > 提交</el-button>
                <el-button
                  class="iconfont iconquxiao"
                  type="primary"
                  style="margin-left: 8px;"
                  @click="cancel"
                > 取消</el-button>
              </div>
            </el-col>
          </el-row>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
// budgetPerformanceManagementSave
import {
  budgetPerformanceManagementSave,
  budgetPerformanceManagementModify,
  budgetPerformanceManagementSubmission,
  budgetPerformanceManagementAudit1
} from "@/api/budgetPerformanceManagement/index";
import comtab from '@/views/financialManagement/budgetPerformanceManagement/comtab.vue'
export default {
  data() {
    var validatePass = (rule, value, callback) => {
      if (this.findingsAuditValue == "") {
        callback(new Error("请选择审核结果"));
      } else {
        callback();
      }
    };
    return {
      findingsAuditValue: "",
      //状态
      findingsAuditObj: [
        {
          value: "通过",
          code: "300"
        },
        {
          value: "驳回",
          code: "400"
        }
      ],
      modulName: "3月",
      status: [
        {
          id: 0,
          name: "3月",
          check: false
        },
        {
          id: 1,
          name: "6月",
          check: false,
          statusC: "CO"
        },
        {
          id: 2,
          name: "9月",
          check: false,
          statusC: "OP"
        },
        {
          id: 3,
          name: "12月",
          check: false,
          statusC: "DC"
        }
      ],
      rules: {
        findingsAuditValue: [
          { validator: validatePass, trigger: "change" }
        ],
        auditOpinions: [
          { required: true, message: "请填写审核意见", trigger: "blur" },
          { min: 1, max: 200, message: '长度在 1 到 200 个字符', trigger: 'blur' }
        ],
        expenditureProgress:[{
          validator:(rule,value,callback)=>{
            if(value !=='' && value){
              if((/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/).test(value) == false){
                callback(new Error("请填写大于0的数字"));
              }else if(Number(value)>100){
                callback(new Error("请填写小于等于100的数字"));
              }
            }
            callback();
          },
          trigger:'blur'
        }],
      },
      findingsAudit:'',
      formInline: {
        projectName: "", //项目名称
        projectContent: "", //项目内容
        annualTarget: "", //年度目标
        projectCompletionSchedule: "", //项目进度
        expenditureProgress: null, //支出进度
        fillDate: "", //填写日期
        auditOpinions: "", //审核意见
        auditor: "", //审核人
        auditDate: "", //审核日期
        findingsAudit: "" //审核结果
      },
      writeJurisdictionBool: false,
      //总体目标
      targetContentArr: [
        {
          targetContent:"",
          isAdd:true
        },
          {
          targetContent:"",
           isAdd:true
        }
      ],

      // 产出指标二级指标数据
      outputIndexArr:[],

      // 效益指标二级指标数据
      benefitIndexArr:[],

      // 满意度指标二级指标数据
      satisfactionIndexArr:[],
      propertiesList:[
        {
          label:"定量",
          value:'定量'
        },
        {
          label:"定性",
          value:'定性'
        }
      ],
    };
  },
  methods: {
    limitLength(val){
      if(val.length > 200){
        this.formInline.auditOpinions = val.substring(0,200)
      }
    },
    findingsAuditChange(val) {
      if (val == "通过") {
        if(this.formInline.departmentsCodes !== '内蒙古自治区粮食和物资储备局601001'){
          if(this.formInline.findingsAudit == "待二级单位财务审核"){
            this.formInline.findingsAudit = "待单位负责人审核"
            this.formInline.status = 2;
          }else
          if(this.formInline.findingsAudit == "待单位负责人审核"){
            this.formInline.findingsAudit = "待规划财务处工作人员审核"
            this.formInline.status = 3;
          }else
          if(this.formInline.findingsAudit == "待规划财务处工作人员审核"){
            this.formInline.findingsAudit = "待规划财务处处长审核"
            this.formInline.status = 4;
          }else
          if(this.formInline.findingsAudit == "待规划财务处处长审核"){
            this.formInline.findingsAudit = "通过"
            this.formInline.status = 5;
          }
        }else{
          if(this.formInline.findingsAudit == "处室处长审核"){
            this.formInline.findingsAudit = "办公室财务人员审核"
            this.formInline.status = 2;
          }else
          if(this.formInline.findingsAudit == "办公室财务人员审核"){
            this.formInline.findingsAudit = "办公室财务处长审核"
            this.formInline.status = 3;
          }else
          if(this.formInline.findingsAudit == "办公室财务处长审核"){
            this.formInline.findingsAudit = "规划财务处人员审核"
            this.formInline.status = 4;
          }else
          if(this.formInline.findingsAudit == "规划财务处人员审核"){
            this.formInline.findingsAudit = "规划财务处处长审核"
            this.formInline.status = 5;
          }else
          if(this.formInline.findingsAudit == "规划财务处处长审核"){
            this.formInline.findingsAudit = "审核通过"
            this.formInline.status = 6;
          }
        }
        // this.formInline.findingsAudit = "30";
        // this.formInline.findingsAudit = "办公室财务处长审核"
      } else if (val == "驳回") {
        this.formInline.findingsAudit = "驳回";
        this.formInline.status = 0;
      } else if(val == "驳回到上级"){
        if(this.formInline.findingsAudit == "待单位负责人审核"){
          this.formInline.findingsAudit = "待二级单位财务审核"
          this.formInline.status = 1;
        }else
        if(this.formInline.findingsAudit == "待规划财务处工作人员审核"){
          this.formInline.findingsAudit = "待单位负责人审核"
          this.formInline.status = 2;
        }else
        if(this.formInline.findingsAudit == "待规划财务处处长审核"){
          this.formInline.findingsAudit = "待规划财务处工作人员审核"
          this.formInline.status = 3;
        }
      }
    },
    statusFun(month) {
      if (month >= 1 && month <= 3) {
        this.status[0].check = true;
      } else if (month >= 4 && month <= 6) {
        this.status[1].check = true;
      } else if (month >= 7 && month <= 9) {
        this.status[2].check = true;
      } else {
        this.status[3].check = true;
      }
    },
    cancel() {
      this.$router.push({ path: "examine" });
    },
    info(id) {
      budgetPerformanceManagementModify(id).then(response => {
        if (response.infoCode === 200) {
          this.formInline = response.data;
          if(response.data.departmentsCodes !== '内蒙古自治区粮食和物资储备局601001' && this.formInline.findingsAudit !== "待二级单位财务审核"){
            this.findingsAuditObj = [
              {
                value: "通过",
                code: "30"
              },
              {
                value: "驳回",
                code: "40"
              },
              {
                value: "驳回到上级",
                code: "50"
              }
            ];
          }
          // var date = new Date();
          // var month = date.getMonth() + 1;
          // this.formInline.expenditureProgress = (month / 12) * 100;
          // this.formInline.fillDate = date;
          if (this.$route.query.state == "update") {
            var date = new Date();
            this.formInline.auditDate = date;
            let tokenMsg = window.sessionStorage.getItem('TOKENL')
            let msg1 = tokenMsg.split('.')[1]
            let base64 = require('js-base64').Base64;
            let userInfo = JSON.parse(base64.decode(msg1));
            this.formInline.auditor = userInfo.userName;
            // this.formInline.auditor = sessionStorage.getItem("userName");
          }
          if(this.formInline.expenditureProgress == 'null'){
            this.formInline.expenditureProgress = null
          }
          this.findingsAudit = this.formInline.findingsAudit

          let resData1 = {
            "outputIndexArr": this.formInline.outputIndex,
            "benefitIndexArr": this.formInline.benefitIndex,
            "satisfactionIndexArr": this.formInline.satisfactionIndex,
            "targetContentArr": this.formInline.overallObjective
          };
          this.$refs.getData1.getValue(resData1);
        } else {
          this.$message({
            type: "error",
            message: response.msg
          });
        }
      });
    },
    changeStatus(cur) {
      for (var i = 0; i < this.status.length; i++) {
        this.status[i].check = false;
      }
      this.modulName = cur.name;
      //   state.statusC = cur.statusC;
      //   state.bkList.items = [];
      //   this.hasMore = true;
      this.status[cur.id].check = true;
      // cur.check = true;
      //   state.orderStatus = cur.id;
    },
    submissionInfo(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          if(this.findingsAudit == '规划财务处人员审核'){
            if(!this.formInline.expenditureProgress){
              this.$message.info("请填写支出进度")
              return
            }
          }else{
            // if(!this.formInline.expenditureProgress){
            //   this.formInline.expenditureProgress = 'null'
            // }
          }
          let row = {
            departmentsCodes:this.formInline.departmentsCodes,
            findingsAudit:this.formInline.findingsAudit,
            id:this.formInline.id,
            message :this.formInline.auditOpinions ,
            status :this.formInline.status ,
            auditor :this.formInline.auditor ,
            auditDate :this.formInline.auditDate ,
            expenditureProgress:this.formInline.expenditureProgress,
          }
          budgetPerformanceManagementAudit1(row).then(response => {
            if (response.infoCode === 200) {
              this.$message.success("提交成功")
              this.$router.push({ path: "examine" });
            } else {
              this.$message({
                type: "error",
                message: response.msg
              });
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
    // open(month, day) {
    //   this.$notify({
    //     title: "填写权限",
    //     message: "您可以填写",
    //     type: "success",
    //     duration: 2000,
    //     position: "bottom-right"
    //   });
    // },
    // writeJurisdiction(month, day) {
    //   if (month == 3) {
    //     if (day <= 26) {
    //       this.writeJurisdictionBool = false;
    //       this.open(month, day);
    //     } else {
    //       this.writeJurisdictionBool = true;
    //     }
    //   } else if (month == 6) {
    //     if (day <= 25) {
    //       this.writeJurisdictionBool = false;
    //       this.open(month, day);
    //     } else {
    //       this.writeJurisdictionBool = true;
    //     }
    //   } else if (month == 9) {
    //     if (day <= 25) {
    //       this.writeJurisdictionBool = false;
    //       this.open(month, day);
    //     } else {
    //       this.writeJurisdictionBool = true;
    //     }
    //   } else if (month == 12) {
    //     if (day <= 26) {
    //       this.writeJurisdictionBool = false;
    //       this.open(month, day);
    //     } else {
    //       this.writeJurisdictionBool = true;
    //     }
    //   } else {
    //     this.writeJurisdictionBool = true;
    //   }
    // }
  },
  created() {
    var date = new Date();
    var month = date.getMonth() + 1;
    // var month = 3;
    var day = date.getDate();
    // var day = 24;
    this.statusFun(month);
    // this.writeJurisdiction(month, day);
    this.info(JSON.parse(this.$route.query.row));
    // var date = new Date();
    // var month = date.getMonth() + 1;
    // this.formInline.expenditureProgress = (month / 12) * 100;
    // this.formInline.fillDate = date;
  },
  components: {
    "v-comtab": comtab,
  }
};
</script>
<style>
@import "common.css";
.el-message--error {
  display: none !important;
}
.font-color {
  height: 34px;
  font-size: 18px;
  font-weight: 600;
}
.width-c54 {
  width: calc(100% - 50px);
  margin-bottom: 20px;
}
.table-from table {
  width: calc(100% - 50px);
  border: 1px solid #dcdfe6;
  text-align: center;
  margin-bottom: 20px;
}
.on {
  background: #49a2fa;
  color: white;
}
/* .on:hover {
  background: #49a2fa;
  color: white;
} */
.el-button-all {
  display: block;
  height: 28px;
  line-height: 28px;
  text-align: center;
  width: 100%;
  border: 0px;
  border-radius: 0;
  font-size: 14px;
}
.el-button-border {
  height: 28px;
  border-left: 1px solid #49a2fa;
}
.bgc {
  background-color: #a79c9c4a;
}
</style>