<template>
  <view>
    <u-popup :show="show" mode="bottom" @open="open" :customStyle="{width:'100vw'}" round="6" safeAreaInsetBottom>
      <view class="popCss">
        <view class="padding-top text-lg text-center">
          {{title}}
        </view>
        <view class="padding" style="padding-bottom: 0px!important;" v-if="title=='同意'&& publishStatus=='PENDING_LEVEL_2_AUDIT'">
          <u-radio-group
            v-model="invoiceYearType"
            placement="row"
            @change="groupChange"
          >
            <u-radio
              :customStyle="{marginRight: '8px'}"
              v-for="(item, index) in radiolist1"
              :key="index"
              :label="item.name"
              :name="item.name"
              @change="radioChange"
            >
            </u-radio>
          </u-radio-group>
        </view>
        <view class="padding">
          <u-textarea v-model="textarea" placeholder="请简单描述原因"></u-textarea>
        </view>
        <view class="flex justify-between">
          <view class="w50" @click="close">
            <u-button>取消</u-button>
          </view>
          <view class="w50" @click="confirm">
            <u-button :customStyle="{color:'#CF000D'}">确定</u-button>
          </view>
        </view>
      </view>
    </u-popup>
  </view>
</template>

<script>
  import {
    submitAuditOne,
    submitAuditTwo,
    submitModificationOne,
    submitModificationTwo
  } from '@/api/charge.js'
  export default {
    name: "popUpComponent",
    props: {
      title: {
        type: String,
        default: "同意"
      },
      publishID: {
        type: Number,
      },
      publishStatus: {
        type: String,
        default: ""
      },
      modificationStatus: {
        type: String,
        default: ""
      },
    },
    data() {
      return {
        radiolist1:[
          {
            name:'往年应收'
          },
          {
            name:'本年新增'
          }
        ],
        invoiceYearType:'往年应收',
        textarea: "",
        show: false,
      };
    },
    methods: {
      groupChange(value){
        console.log('打印value',value)
      },
      radioChange(value){
        console.log('打印value',value)
      },
      open() {
        this.invoiceYearType = '往年应收';
        this.show = true;
      },
      close() {
        this.show = false;
      },
      async confirm() {
        let that = this;
        let data = {
          "id": this.publishID,
          "status": this.title === '同意' ? 'Y' : 'N',
          "remarks": this.textarea
        }
        console.log("审批状态", this.publishStatus);
        if (this.publishStatus === 'PENDING_LEVEL_1_AUDIT') {
          const result = await submitAuditOne(data);
          if (result.code === 200) {
            uni.$u.toast(`${this.title}成功`)
            setTimeout(()=>{
              that.$emit('getList');
            },300)
          } else {
            uni.$u.toast(result.msg)
          }
        }

        if (this.publishStatus === 'PENDING_LEVEL_2_AUDIT') {
          if(this.title == '同意'){
            data= {
              ...data,
              invoiceYearType:this.invoiceYearType
            }
            console.log('打印data',data)
          }
          const result = await submitAuditTwo(data);
          if (result.code === 200) {
            uni.$u.toast(`${this.title}成功`);
            setTimeout(()=>{
              that.$emit('getList');
            },300)
          } else {
            uni.$u.toast(result.msg)
          }
        }

        if (this.publishStatus === 'APPROVED' && this.modificationStatus === 'PENDING_LEVEL_1_AUDIT') {
          const result = await submitModificationOne(data);
          if (result.code === 200) {
            that.$emit('getList');
            uni.$u.toast(`${this.title}成功`)
          } else {
            uni.$u.toast(result.msg)
          }
        }

        if (this.publishStatus === 'APPROVED' && this.modificationStatus === 'PENDING_LEVEL_2_AUDIT') {
          const result = await submitModificationTwo(data);
          if (result.code === 200) {
            that.$emit('getList');
            uni.$u.toast(`${this.title}成功`)
          } else {
            uni.$u.toast(result.msg)
          }
        }
        console.log("审批data", data);
        this.show = false;
        this.textarea = "";
      }
    }
  }
</script>

<style lang="scss">
  .popCss {
    // text-align: center;
  }
</style>
