<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
                readonly
                v-model="parameter.matCompanyCode"
                placeholder="请输入企业编号"
              ></el-input>
            </el-form-item>
          </el-col>
          <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-row>
        <el-row :gutter="24">
          <!-- <el-col :span="12">
            <el-form-item label="设备分类" prop="matCategory">
              <dict-select
                dictCode="xmsblx"
                :hasDefaultOption="true"
                clearable
                style="width: 100%"
                v-model="parameter.matCategory"
                placeholder="请选择设备分类"
              />
            </el-form-item>
          </el-col> -->
          <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="technicalRequirement">
              <el-input
                clearable
                v-model="parameter.technicalRequirement"
                placeholder="请输入技术要求"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          
          <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-col :span="12">
            <el-form-item label="数量" prop="matNum">
              <el-input
                clearable
                type="number"
                v-model="parameter.matNum"
                placeholder="请输入数量"
              ></el-input>
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="不含税单价(元)" prop="price">
              <el-input
                clearable
                type="number"
                v-model="parameter.price"
                placeholder="请输入不含税单价(元)"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="不含税总额(元)" prop="amount">
              <el-input
                clearable
                type="number"
                v-model="parameter.amount"
                placeholder="请输入不含税总额(元)"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="含税单价(元)" prop="taxInprice">
              <el-input
                clearable
                type="number"
                v-model="parameter.taxInprice"
                placeholder="请输入含税单价(元)"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="含税总价(元)" prop="taxInvalue">
              <el-input
                clearable
                type="number"
                v-model="parameter.taxInvalue"
                placeholder="请输入含税总价(元)"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input
                clearable
                v-model="parameter.remark"
                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'
          }
        ],
        matNum: [
          {
            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: '',
        remark:'',
        taxInvalue:0,
        taxInprice:0,
        price:0,
        amount:0,
        technicalRequirement:'',
        matCategory: '',
        matIfPlat: '',
        matCompanyId: '',
        matCompanyName: '',
        matStatus: '1',
        matType:2
      }
    }
  },
  created() {
    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.matCompanyCode = this.currentUser.org[0].orgCode
    // this.parameter.createBy = this.currentUser.user.userId
    // this.parameter.createName = this.currentUser.user.fullname
  },
  mounted() {},
  methods: {
    //编辑
    addModifyBtn() {
      if (this.$route.query.editRows) {
        this.breadcrumbOpt[1].breadcrumbName = '编辑'
        this.modifychoData(this.$route.query.editRows)
      } else {
        this.breadcrumbOpt[1].breadcrumbName = '新增'
      }
    },
    //获取修改回显数据
    modifychoData(val) {
      this.$http.get('${portal}/bizMaterial/v1/selectOne?id='+val.id).then(res=>{
        if(res.data.state){
          this.parameter = res.data.value
        }
      })
    },
    // 关闭//面包屑点击
    handleClose() {
      if (this.breadcrumbOpt[1].breadcrumbName === '编辑') {
        this.$router.push({
          name: 'equipmentLibrary'
        })
      } else {
        this.$router.push({
          name: 'equipmentLibrary',
        })
      }
      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)
              this.handleClose()
            }
          })
        }
      })
    }
  }
}
</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>
