<template>
  <div>
    <xy-dialog ref="dialog" :is-show.sync="isShow" type="form" :title="'审核'" :form="checkform" :rules="rules" @submit="submit">
      <template v-slot:audit_status>
        <div class="xy-table-item">
          <div class="xy-table-item-label">
            <span style="color: red;font-weight: 600;padding-right: 4px;">*</span>状态：
          </div>
          <div class="xy-table-item-content">
              <el-select v-model="checkform.audit_status" placeholder="请选择">
                <el-option
                  v-for="item in statusList"
                  :key="item.id"
                  :label="item.value"
                  :value="item.id">
                </el-option>
              </el-select>
          </div>
        </div>
      </template>

    </xy-dialog>
  </div>
</template>

<script>
import {show,save} from "@/api/activity"
import { Message } from 'element-ui'
    import {replaceAll} from "@/utils/index"

export default {
  components:{
  },
  data() {
    return {
      isShow:false,
      id:'',
      checkform:{
        audit_status:0,

      },
      rules:{
        audit_status:[
          {required:true,message:'请选择状态'}
        ]
      },
      statusList:[{
        id:0,
        value:'待审核'
      },{
        id:1,
        value:'通过'
      },{
        id:2,
        value:'不通过'
      }]
    }
  },
  created(){
  },
  methods: {
    async getDetail(){
      const res = await show({id:this.id})
      this.form = {
        activeName:res.active_name,
        company_ids:res.company_ids?JSON.parse(res.company_ids):[],
        sponsorLogo:res.sponsor_logo,
        sponsorAdvertise:res.sponsor_advertise,
        recommend:res.recommend,
        //slogan:res.slogan,
        date:[`${res.start_date}/${res.start_time}`,`${res.end_date}/${res.end_time}`],
        address:res.address,
        relationName:res.relation_name,
        phoneNumber:res.phone_number,
        group:res.group,
        memberSum:res.member_sum,
        startMemberSum:res.start_member_sum,
        greatServices:res.great_services,
        applyDate:[res.apply_start,res.apply_end],
        // money:Number(res.money),
        activePlaybill:res.active_playbill,
        sort:res.sort,
        content:res?.content,
      }

    },
    submit(){
        save({
          id:this.id,
          audit_status:this.checkform.audit_status,
          active_name:this.form.activeName,
          company_ids:this.form.company_ids,
          shop_id:0,
          sponsor:0,
          sponsor_logo:this.form.sponsorLogo,
          sponsor_advertise:this.form.sponsorAdvertise,
          recommend:this.form.recommend,
          //slogan:this.form.slogan,
          start_date:this.form.date[0]?.split('/')[0],
          start_time:this.form.date[0]?.split('/')[1],
          end_date:this.form.date[1]?.split('/')[0],
          end_time:this.form.date[1]?.split('/')[1],
          address:this.form.address,
          relation_name:this.form.relationName,
          phone_number:this.form.phoneNumber,
          group:this.form.group,
          start_member_sum:this.form.startMemberSum,
          member_sum:this.form.memberSum,
          great_services:this.form.greatServices,
          // money:this.form.money,
          apply_start:this.form.applyDate[0],
          apply_end:this.form.applyDate[1],
          active_playbill:this.form.activePlaybill,
          sort:this.form.sort,
          content: replaceAll(this.form.content,'../storage/files',`${process.env.VUE_APP_BASE_API}storage/files`),
        }).then(res => {
          Message({
            type:'success',
            message:'审核成功'
          })
          this.isShow = false
          this.$emit('refresh')
        })
    }
  },
  watch:{
    isShow(newVal){
      if(newVal){
        this.getDetail()
      }else{
        this.id = ''
        this.$refs['dialog'].reset()
      }
    }
  }

}
</script>

<style scoped lang="scss">
.xy-table-item-label{
  width: 160px;
}
.img__delete{
  transform: scale(0.8,0.8);

  position: absolute;
  top: 4px;
  right: 4px;
}
::v-deep .avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
::v-deep .avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
::v-deep .el-upload--picture-card {
  font-size: 28px;
  color: #8c939d;
  width: 80px !important;
  height: 80px !important;
  line-height: 80px !important;
  text-align: center;
}
::v-deep .avatar-uploader-icon{
  font-size: 28px;
  color: #8c939d;
  width: 80px !important;
  height: 80px !important;
  line-height: 80px !important;
  text-align: center;
}
::v-deep .avatar {
  width: 80px !important;
  display: block;
  border-radius: 6px;
}

::v-deep .xy-table-item-label{
  width: 160px !important;
}

::v-deep .el-date-editor .el-range-separator{
  width: auto !important;
}

::v-deep .el-input-number .el-input__inner{
  text-align: left !important;
}
  .searchCompanys{
    display: flex;
    justify-content: space-between;
    margin-bottom:16px;
    .el-input{
      width:80%
    }
  }
</style>
