<template>
  <div class="edit-add-detail">
    <div class="crumbs">
      <Breadcrumb
        :breadcrumbOpt="breadcrumbOpt"
        svg-name="#icon-model"
        @breadcrumb-click="handleClose"
      />
    </div>
    <div class="form-content">
      <el-form
        ref="formInfo"
        :model="parameter"
        label-width="auto"
        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="matCompanyCode">
              <el-input
                clearable
                v-model="parameter.matCompanyCode"
                placeholder="请输入企业编号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业物料编号" prop="matCode">
              <el-input
                clearable
                v-model="parameter.matCode"
                placeholder="请输入企业物料编号"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="平台物料编号" prop="matPlatcode">
              <el-input
                clearable
                v-model="parameter.matPlatcode"
                placeholder="请输入平台物料编号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料分类" prop="matCategory">
              <el-cascader
                v-model="parameter.matCategory"
                :options="options"
                :props="{
                  value: 'code',
                  label: 'name',
                  checkStrictly: true,
                  emitPath: false
                }"
                clearable
                style="width:100%"
              ></el-cascader>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="物料名称" prop="matName">
              <el-input
                clearable
                v-model="parameter.matName"
                placeholder="请输入物料名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="物料牌号" prop="matMaterial">
              <el-input
                clearable
                v-model="parameter.matMaterial"
                placeholder="请输入物料牌号"
              ></el-input>
            </el-form-item>
          </el-col>
          
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="规格型号" prop="matSpec">
              <el-input
                clearable
                v-model="parameter.matSpec"
                placeholder="请输入规格型号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="计量单位" prop="matUnit">
              <el-input
                clearable
                v-model="parameter.matUnit"
                placeholder="请输入计量单位"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="是否集中采购" prop="matIfPlat">
              <dict-select
                dictCode="cglx-ywlx"
                :hasDefaultOption="true"
                clearable
                style="width:100%"
                v-model="parameter.matIfPlat"
                placeholder="请选择是否集中采购"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="税率" prop="matTaxrate">
              <el-input
                clearable
                v-model="parameter.matTaxrate"
                placeholder="请输入税率"
              ></el-input>
            </el-form-item>
          </el-col>

          
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="品牌" prop="matBrand">
              <el-input
                clearable
                v-model="parameter.matBrand"
                placeholder="请输入品牌"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="基础扩展" prop="matBaseExt">
              <el-input
                clearable
                v-model="parameter.matBaseExt"
                placeholder="请输入基础扩展"
              ></el-input>
            </el-form-item>
          </el-col>
          
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="其他扩展" prop="matOtherExt">
              <el-input
                clearable
                v-model="parameter.matOtherExt"
                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" :loading="saveing" @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: 'domesticDialog',
  components: {Breadcrumb},
  props: {
    editData: Object
  },
  data() {
    return {
      breadcrumbOpt: [{breadcrumbName: '物料数据'}, {breadcrumbName: '新增'}],
      options: [],
      saveing: false,
      rules: {
        matCompanyCode: [
          {
            required: true,
            message: '请输入企业编号',
            trigger: 'blur'
          }
        ],
        matCode: [
          {
            required: true,
            message: '请输入企业物料编号',
            trigger: 'blur'
          }
        ],
        matPlatcode: [
          {
            required: true,
            message: '请输入平台物料编号',
            trigger: 'blur'
          }
        ],
        matIfPlat: [
          {
            required: true,
            message: '请选择是否集中采购',
            trigger: 'blur'
          }
        ],
        matCategory: [
          {
            required: true,
            message: '请选择物料分类',
            trigger: 'blur'
          }
        ],
        matName: [
          {
            required: true,
            message: '请输入平台物料名称',
            trigger: 'blur'
          }
        ],
        matSpec: [
          {
            required: true,
            message: '请输入规格型号',
            trigger: 'blur'
          }
        ],
        matUnit: [
          {
            required: true,
            message: '请输入计量单位',
            trigger: 'blur'
          }
        ],
        matMaterial: [
          {
            required: true,
            message: '请选择物料牌号',
            trigger: 'blur'
          }
        ]
      },
      parameter: {
        matCompanyCode: '',
        matCode: '',
        matPlatcode: '',
        matSpec: '',
        matUnit: '',
        matMaterial: '',
        matCategory: '',
        matIfPlat: '',
        matCompanyId: '',
        matCompanyName: '',
        matStatus: '1'
      }
    }
  },
  created() {
    this.selectTree()
    this.addModifyBtn()
    this.currentUser = JSON.parse(sessionStorage.getItem('currentUserDetail'))
    this.parameter.matCompanyId = this.currentUser.org[0].orgId
    this.parameter.matCompanyName = this.currentUser.org[0].orgName
    // this.parameter.createBy = this.currentUser.user.userId
    // this.parameter.createName = this.currentUser.user.fullname
  },
  mounted() {},
  methods: {
    //查询物料分类树结构
    selectTree() {
      basicData.bizMaterialCategorySelectTree().then(res => {
        this.options = res.value
      })
    },
    //编辑
    addModifyBtn() {
      if (this.$route.query.editRows) {
        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: 'materialManagement',
          params: {
            tabsActiveName: 'itemData',
            pageBean: this.$route.query.pageBean
          }
        })
      } else {
        this.$router.push({
          name: 'materialManagement',
          params: {
            tabsActiveName: 'itemData'
          }
        })
      }
      this.parameter = {}
    },
    // 保存
    handleSave() {
      this.$refs.formInfo.validate(valid => {
        if (valid) {
          this.saveing = true
          basicData.bizMaterialSave(this.parameter).then(res => {
            this.saveing = false
            if (res.state) {
              this.$message.success(res.message)
              if (this.breadcrumbOpt[1].breadcrumbName === '编辑') {
                this.$router.push({
                  name: 'materialManagement',
                  params: {
                    tabsActiveName: 'itemData',
                    pageBean: this.$route.query.pageBean
                  }
                })
              } else {
                this.$router.push({
                  name: 'materialManagement',
                  params: {
                    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>
