<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-utilize"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="form-content">
      <el-form
        ref="formInfo"
        :model="parameter"
        label-width="80px"
        label-position="right"
        :rules="rules"
      >
        <div class="rows">
          <div class="rows-left">
            <div class="rows-hr"></div>
          </div>
          <div class="rows-title">
            <div class="text-overflow">基本信息</div>
          </div>
        </div>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="父级名称" prop="pcode">
              <el-cascader
                ref="cascader"
                @change="cascaderChange"
                v-model="parameter.pcode"
                :options="treeData"
                :props="{
                  value: 'id',
                  label: 'subjectName',
                  checkStrictly: true,
                  emitPath: false
                }"
                clearable
                style="width:100%"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目名称" prop="subjectName">
              <el-input
                clearable
                v-model="parameter.subjectName"
                placeholder="请输入项目名称"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="排序号" prop="sn">
              <el-input
                clearable
                v-model="parameter.sn"
                placeholder="请输入排序号"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row> -->
        <el-row :gutter="24">
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <el-input
                clearable
                type="textarea"
                :rows="4"
                v-model="parameter.remarks"
                placeholder="请输入备注"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer" class="footer">
      <el-button @click="handleClose">{{ $t('domestic.cancel') }}</el-button>
      <el-button type="primary" @click="handleSave">{{
        $t('domestic.save')
      }}</el-button>
    </div>
  </div>
</template>

<script>
import Breadcrumb from '@/components/Breadcrumb/index.vue'
import basicData from '@/api/basicData'
export default {
  name: 'evaluationManagementDialog',
  components: {Breadcrumb},
  props: {
    editData: Object
  },
  data() {
    return {
      breadcrumbOpt: [{breadcrumbName: '评标项管理'}, {breadcrumbName: '新增'}],
      rules: {
        pcode: [
          {
            required: true,
            message: '请输入父级名称',
            trigger: 'blur'
          }
        ],
        subjectName: [
          {
            required: true,
            message: '请输入项目名称',
            trigger: 'blur'
          }
        ]
      },
      treeData: [], //左边树
      parameter: {
        pname: '',
        pcode: '',
        subjectName: '',
        sn: '',
        remarks: ''
      }
    }
  },
  created() {
    this.selectTree()
    this.addModifyBtn()
  },
  mounted() {},
  methods: {
    cascaderChange(val) {
      this.parameter.pname = this.$refs[
        'cascader'
      ].getCheckedNodes()[0].data.pname
    },
    //查询物料分类树结构
    selectTree() {
      basicData.bizEvaluationItemSelectTree().then(res => {
        this.treeData = res.value
      })
    },
    //编辑
    addModifyBtn() {
      if (this.$route.query.editRows) {
        console.log()
        this.breadcrumbOpt[1].breadcrumbName = '编辑'
        this.modifychoData(this.$route.query.editRows)
      } else {
        this.breadcrumbOpt[1].breadcrumbName = '新增'
      }
    },
    //获取修改回显数据
    modifychoData(val) {
      this.parameter = val
    },
    // 关闭//面包屑点击
    handleClose() {
      if (this.breadcrumbOpt[1].breadcrumbName === '编辑') {
        this.$router.push({
          name: 'evaluationSystem',
          params: {
            routerName: 'evaluationManagement',
            tabsActiveName: 'itemData',
            pageBean: this.$route.query.pageBean
          }
        })
      } else {
        this.$router.push({
          name: 'evaluationSystem',
          params: {
            routerName: 'evaluationManagement',
            tabsActiveName: 'itemData'
          }
        })
      }
      this.parameter = {}
    },
    // 保存
    handleSave() {
      this.$refs.formInfo.validate(valid => {
        if (valid) {
          basicData.bizEvaluationItemSaveItem(this.parameter).then(res => {
            if (res.state) {
              this.$message.success(res.message)
              if (this.breadcrumbOpt[1].breadcrumbName === '编辑') {
                this.$router.push({
                  name: 'evaluationSystem',
                  params: {
                    routerName: 'evaluationManagement',
                    tabsActiveName: 'itemData',
                    pageBean: this.$route.query.pageBean
                  }
                })
              } else {
                this.$router.push({
                  name: 'evaluationSystem',
                  params: {
                    routerName: 'evaluationManagement',
                    tabsActiveName: 'itemData'
                  }
                })
              }
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
// /deep/.el-row {
//   padding: 0 100px;
// }
.rows {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ebebeb;
  margin-bottom: 16px;
  padding: 10px 0;
  .rows-left {
    margin-right: 10px;
    .rows-hr {
      width: 3px;
      height: 18px;
      background-color: #0e6eff;
      border-radius: 2px;
    }
  }
  .rows-title {
    .text-overflow {
      width: 100%;
      font-size: 16px;
    }
  }
}
</style>
