<template>
  <div class="app-container">
    <van-nav-bar
      left-arrow
      fixed
      placeholder
      @click-left="$router.back(-1)"
    >
      <template #title>
        <p style="font-weight: bold;">重大事项</p>
      </template>
      <template #right>
        <van-icon name="../../../static/images/icon/icon_flow.png" size="20" @click="goFlow"/>
      </template>
    </van-nav-bar>
    <van-form @submit="getChange" @failed="getError" :show-error-message="false" scroll-to-error validate-first readonly>
      <p class="main_title">基础信息</p>
      <div class="main_box">
        <van-field
          label="事项名称"
          v-model="form.eventName"
          placeholder="事项名称"
          input-align="right"
          label-width="auto"
          required
          :rules="[{ required: true , message:'事项名称' }]"
        />
        <van-field
          readonly
          clickable
          required
          :rules="[{ required: true , message:'发生日期'  }]"
          v-model="form.eventTime"
          label="发生日期"
          placeholder="发生日期"
          input-align="right"
          right-icon="arrow-down"
        />
        <van-popup v-model="showlasj" position="bottom">
          <van-datetime-picker
            v-model="currentDate"
            type="date"
            title="选择年月日"
            :min-date="minDate"
            :max-date="maxDate"
            @confirm="onConfirmLasj"
            @cancel="showlasj = false"
          />
        </van-popup>
      </div>
      <div class="main_box" style="margin-top: 10px;">
        <van-field
          label="事项内容"
          input-align="right"
          label-width="auto"
          readonly
        />
        <van-field
          v-model="form.eventContent"
          type="textarea"
          placeholder="事项内容"
          rows="8"
          required
          :rules="[{ required: true , message:'事项内容'  }]"
        />
<!--        <editor v-model="form.eventContent" :min-height="192"/>-->
<!--        <quill-editors @ChangeText="(text)=>{form.eventContent=text}" :title="title" />-->
      </div>
      <div class="main_box" style="margin-top: 10px;">
        <van-field
          label="备注"
          v-model="form.remark"
          type="textarea"
          placeholder="备注"
          input-align="right"
          rows="3"
          label-width="auto"
        />
      </div>

     <!-- <p class="main_title">上传附件</p>
     <div class="main_box" style="padding: 5px 0 0 8px;">
       <van-uploader v-model="fileList" :after-read="beforeRead" @delete="deleteFile"></van-uploader>
       </div> -->
      <p style="margin-top:20px;padding: 0 10px">附件{{fileList&&fileList.length==0?':暂无可下载文件':''}}</p>
      <van-cell v-for="(item,index) in fileList" :key="index">
        <a :href="item.url" target="_blank">{{index+1}}.{{item.fileName}}</a>
      </van-cell>
    </van-form>
    <div class="main_box examine_box">
      <van-row type="flex" justify="space-between" align="center">
        <van-col span="5">审批<br/>意见</van-col>
        <van-col span="19">
          <van-radio-group v-model="pass" direction="horizontal" :disabled="!isAudit">
            <van-radio name="true">同意</van-radio>
            <van-radio name="false">驳回</van-radio>
          </van-radio-group>
          <van-field :readonly="!isAudit" rows="2" autosize v-model="comment" type="textarea" placeholder="请输入审批意见"/>
        </van-col>
      </van-row>
    </div>

    <div style="margin: 16px 2%;" v-if="isAudit">
      <van-row>
        <van-col span="24" align="center">
          <van-button type="info" native-type="submit" @click="submitForm" class="submitButton">提交</van-button>
        </van-col>
      </van-row>
      <div class="clear"></div>
    </div>
  </div>
</template>

<script>
  import { addMajorevent , getMajorevent , attachmentList , updateMajorevent,approval } from "@/api/onlineHome/bankAgriculture/paymentApproval";
  import request from '@/utils/request';
  import Dialog from "vant/lib/dialog";
  import Editor from '@/components/Editor';
  import {A_auditHistoryDetail} from "@/api/audit/aauditpipeline";
  export default {
    name: "approvalApproval13",
    components: {
      Editor,
    },
    data() {
      return {
        title:false,
        showcapital:false,
        showpayee:false,
        showlasj:false,
        showbankType:false,
        showproject:false,
        showFundType:false,
        showpayer:false,

        buttonType:'a',

        minDate: new Date(2000, 1, 1),
        maxDate: new Date(2050, 12, 31),
        currentDate: new Date(),
        form:{},
        fileList:[],
        capitalExpenditureType:'',
        payee:'',
        bankType:'',

        wfydlxDictionaries:[],
        jglxDictionaries:[],
        sysDictionaries:[],
        capitalExpenditureTypeOptions:[],
        bankTypeDictionaries:[],
        projectList:[],
        projectFundTypeOptions:[],
        projectFundTypeDictionaries:[],
        projectListShow:[],
        payerOptions:[],

        chargeItme:[],
        chargeItmeShow:[],

        payeeList:[],
        // 查询参数
        queryParams: {
          transferType:"",
          orderByColumn: "id",
          isAsc: "desc",
        },
        capitalExpenditureOpen:false,
        projectForm:{
          projectId:null,
          projectName:null,
          projectContractor:null,
          projectAmount:null,
          projectBillNum:null,
          projectFundType:'1',
          outId:null,
          ynType:'2'
        },
        projectFundType:'',
        uploadFiles:[],
        // 审核意见默认值
        pass: "true",
        comment: "同意",
        templateList:[],
      };
    },
    created() {
      this.reset();
      this.getForm();
      this.getFileList();
    },
    methods: {
      // 表单重置
      reset() {
        this.form = {
          id: null,
          upId: null,
          downId: null,
          orderId: null,
          cashierId: null,
          transferType: '3',
          accountType: '2',
          explainSituation: null,
          succeedAmount: null,
          payer: null,
          payerAccount: null,
          operatorCode: null,
          enterpriseCode: null,
          expenditureAmount: null,
          capitalExpenditureType: '1',
          remark: null,
          transferStatus: "0",
          auditStatus: "0",
          paymentState: "1",
          bankPriority: "0",
          clientPriority: "0"
        };
        this.processList = {}
        this.projectForm={
          projectId:null,
          projectName:null,
          projectContractor:null,
          projectAmount:null,
          projectBillNum:null,
          projectFundType:'1',
          outId:null,
          ynType:'1'
        }
      },
      getForm(){
        getMajorevent(this.$route.query.id).then(response => {
          this.form = response.data;
          if(!this.isAudit)
          {
            A_auditHistoryDetail(this.$route.query.taskId).then((resp) => {
              this.pass = resp.data.auditStatus === '3' ? "true" : 'false';
              this.comment = resp.data.auditRemark;
            });
          }
        });
      },
      goFlow(){
        window.location='approvalProcess13?id='+this.$route.query.auditbatchNo;
      },
      getChange(){
        updateMajorevent(this.form).then(response => {
          this.$toast.success('修改成功');
          setTimeout(function(){
            history.go(-1)
          },2000)
        });
      },
      getError(e){
        console.log(e)
        this.$notify({ type: 'danger', message: e.errors[0].message });
      },
      onConfirmLasj(data){
        this.form.eventTime = this.getNowFormatDate(data).substr(0,10);
        this.showlasj = false;
      },
      beforeRead(file) {
        this.uploadFiles.push(file.file);
      },
      deleteFile(file){
        this.uploadFiles.map((response,index) => {
          if(file.file == response){
            this.uploadFiles.splice(index,1)
          }
        })
      },
      getFileList(){
        let oData= {
          tableId: this.$route.query.id,
          tableName: 't_yinnong_majorevent',
          bizPath: "yinnong",
          fileType: "",
        }
        attachmentList(oData).then(res => {
          res.rows.map(r => {
            let baseUrl = location.protocol+"//"+location.host+request.defaults.baseURL
            // this.fileList.push({"url":baseUrl + r.fileUrl,"file":new File([],r.fileName,{})})
            this.fileList.push({"url":baseUrl + r.fileUrl,"file":new File([],r.fileName,{}),"id":r.id,"fileName":r.fileName})
            console.log(r)
          })
        })
      },
      goBack(){
        window.history.go(-1)
      },
      //删除家庭成员
      deleteChargeItme(index){
        this.chargeItme.splice(index,1)
      },
      /** 提交按钮 */
      submitForm() {
        const data = {
          taskId: this.$route.query.taskId,
          auditbatchNo: this.$route.query.auditbatchNo,
          remark: this.comment,
          pass: this.pass === "true",
          deptId: this.form.deptId
        };
        approval(data).then((response) => {
          if(response.code==200){
            this.$toast.success("操作成功");
            setTimeout(function(){
              history.go(-1)
            },2000)
          } else{
            this.$toast.success("操作失败");
          }
        });
      },
    },
    watch: {
      pass: function (val) {
        if(this.isAudit)
          this.comment = val === "true" ? "同意" : "驳回";
      },
    },
    computed: {
      isAudit() {
        return this.$route.query.type != 'done';
      }
    }
  }
</script>

<style scoped lang="scss">
  .app-container {
    padding: 2% 0;
  }
  .main_title{
    font-size: 0.4rem;
    color: #1D6FE9;
    margin: 0.2rem 6%;
    position: relative;
  }
  .main_box{
    width: 96%;
    margin: 0 auto;
    border-radius: 6px;
    box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
    overflow: hidden;
    background-color: #FFF;
  }
  .submitButton{
    width: 96%;
    margin: 0 auto;
  }

  .addFamily{
    position: absolute;
    top: -2px;
    right: 0;
    border-radius: 50%;
  }
  .deleteFamily{
    position: absolute;
    top: 0rem;
    right: 6%;
    z-index: 9;
    border-radius: 50%;
  }
  .examine_box{
    background-color: #1D6FE9!important;
    padding: 0.18rem!important;
    padding-left: 0!important;
    border-radius: 0.15rem!important;
    margin-top: 0.3rem!important;
  }
  .examine_box .van-col:first-child{
    color: #FFF!important;
    font-size: 0.45rem!important;
    text-align: center!important;
  }
  .examine_box .van-col:last-child{
    background-color: #FFF!important;
    border-radius: 0.15rem!important;
    overflow: hidden!important;
    .van-radio-group--horizontal{
      padding: 0.2rem 0;
      border-bottom: 1px solid #eee;
    }
  }
  /deep/.van-radio--horizontal{
    margin-left: 20px;
    margin-right: 0;
  }
</style>
