<!--
 * @Description: 修改
 * @Author: wsd
 * @Date: 2022-10-26 14:20:38
 * @LastEditTime: 2022-11-02 21:20:55
 * @LastEditors: wsd
-->
<template>
  <el-dialog
    title="添加修订内容"
    append-to-body
    :visible.sync="dialogVisible"
    width="50%"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <div class="container">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="120px"
        class="demo-ruleForm"
      >
        <el-form-item label="当前版本号:">
          {{ this.rowData.versionNo ? this.rowData.versionNo : '' }}
        </el-form-item>
        <el-form-item label="发布后版本号:">
          {{ this.rowData.versionNoOld }}
        </el-form-item>
        <el-form-item label="代理服务名称:">
          {{ this.rowData.name }}
        </el-form-item>
        <el-form-item label="修订内容描述:" prop="intro">
          <el-input type="textarea" v-model="ruleForm.intro"></el-input>
        </el-form-item>
        <el-form-item align="center">
          <el-button type="primary" @click="submitForm('ruleForm')"
            >立即发布</el-button
          >
          <el-button @click="handleClose()">取消</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-dialog>
</template>
<script>
import { versionQuery } from '@/api/system_manage'
export default {
  name: '',
  components: {},
  props: {
    rowData: {
      type: Object,
      default: () => {}
    },
    visibles: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      ruleForm: {
        version: 'v1',
        versionNo: '',
        versionNoOld: ''
      },
      rules: {
        intro: [
          {
            required: true,
            message: '请输入活动修订内容',
            trigger: ['blur', 'change']
          }
        ]
      },
      dialogVisible: false
    }
  },
  watch: {
    rowData: {
      immediate: true,
      handler: function (val) {
        this.ruleForm = val
      },
      deep: true
    },
    visibles: {
      immediate: true,
      handler: function(val) {
        this.dialogVisible = val
        if (val) {
          console.log(this.ruleForm.status, 'this.ruleForm.status')
          if (this.rowData.status === '已发布') {
            const filters = [
              {
                key: 'proxy_service_id',
                opt: 'LIKE',
                type: 'S',
                value: this.rowData.id
              }
            ]
            versionQuery({
              filters: filters,
              orderby: 'createon',
              pageNum: 1,
              pageSize: 1000,
              sort: 'desc'
            }).then((res) => {
              const obj =
                res.data.list.length > 1 && res.data.list[0]['versionNo']
                  ? res.data.list[0].versionNo
                  : 'v1'
              const objs =
                'v' + (parseInt(obj.split('v')[1]) + 1)
              this.$set(this.ruleForm, 'versionNo', obj)
              this.$set(this.ruleForm, 'versionNoOld', objs)
            })
          } else {
            this.$set(this.ruleForm, 'versionNo', '无')
            this.$set(this.ruleForm, 'versionNoOld', 'v1')
            // this.ruleForm.versionNo = '无'
            // this.ruleForm.versionNoOld = 'v1'
          }
        }
      },
      deep: true
    }
  },
  created() {},
  mounted() {
    console.log(this.rowData, 'rowDataa222')
  },
  methods: {
    handleClose() {
      this.dialogVisible = false
      this.$emit('confirm', false)
    },
    submitForm(formName) {
      console.log(123123123, this.rowData)
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('confirm', this.ruleForm)
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
