<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>-->
    </van-form>
  </div>
</template>

<script>
  import { addMajorevent , getMajorevent , attachmentList , updateMajorevent } from "@/api/onlineHome/bankAgriculture/paymentApproval";
  import request from '@/utils/request';
  import Dialog from "vant/lib/dialog";
  import Editor from '@/components/Editor';
  export default {
    name: "approvalAdd3",
    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:[],
      };
    },
    created() {
      this.reset();
      this.getForm();
    },
    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;
        });
      },
      goFlow(){
        window.location='approvalProcess13?id='+this.form.instanceId;
      },
      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_transfer",
          bizPath: "upload",
          fileType: "0",
        }
        attachmentList(oData).then(res => {
          console.log(res)
          console.log(location.protocol+"//"+location.host+request.defaults.baseURL)
          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,{})})
            console.log(r)
          })
        })
      },
      goBack(){
        window.history.go(-1)
      },
      //删除家庭成员
      deleteChargeItme(index){
        this.chargeItme.splice(index,1)
      },
    },
  }
</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: 80%;
    margin: 0 auto;
    background-color: #1D6FE9;
  }

  .addFamily{
    position: absolute;
    top: -2px;
    right: 0;
    border-radius: 50%;
  }
  .deleteFamily{
    position: absolute;
    top: 0rem;
    right: 6%;
    z-index: 9;
    border-radius: 50%;
  }
</style>
