<template>
<!--  <el-card style="margin: 5px;margin-top: -20px">-->
    <el-form :model="formData" ref="dataForm" :rules="rules" label-width="100px" style="margin-bottom: -15px">
      <el-button-group style="display: flex;margin: 0px 20px 30px 85%; height: 35px;">
        <el-button
          type="primary"
          @click.native="submit()"
        >保存
        </el-button>
      </el-button-group>

      <el-row>
        <el-col :span="12">
          <el-form-item class="query-form-item" label="资产分类:" style="width: 91%">
            <el-select v-model="formData.assetType" style="width: 100%" placeholder="请选择资产分类" >
              <el-option
                v-for="item in dict.type.device_source_type"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <span style="float: left">{{ item.label }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item class="query-form-item" label="国资分类:" style="width: 91%">
            <el-select v-model="formData.sasacType" style="width: 100%" placeholder="请选择国资分类" >
              <el-option
                v-for="item in dict.type.device_source_type"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <span style="float: left">{{ item.label }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="资产助记码:">
            <el-input v-model="formData.assetMnemonicCode" placeholder="请输入资产助记码" style="width: 90%"
                      clearable></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="数量:">
            <el-input-number :min="1"  v-model="formData.number" placeholder="请输入数量" style="width: 90%"
                      clearable></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item class="query-form-item" label="取得方式:" style="width: 91%">
            <el-select v-model="formData.acquisitionMethod" style="width: 100%" placeholder="请选择取得方式" >
              <el-option
                v-for="item in dict.type.device_source_type"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <span style="float: left">{{ item.label }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item class="query-form-item" label="用途:" style="width: 91%">
            <el-select v-model="formData.purpose" style="width: 100%" placeholder="请选择用途" >
              <el-option
                v-for="item in dict.type.device_source_type"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <span style="float: left">{{ item.label }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="5">
          <el-form-item  class="query-form-item"  label="折旧年:">
            <el-input-number :min="0"  v-model="formData.depreciationYear"  style="width: 100%"
                             clearable></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item  class="query-form-item"  label="折旧月:">
            <el-input-number :min="0"  v-model="formData.depreciationMonth" style="width: 100%"
                             clearable></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="2">
          <el-form-item>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item class="query-form-item" label="存储仓库:" style="width: 91%">
            <el-select v-model="formData.purpose" style="width: 100%" placeholder="请选择存储仓库" >
              <el-option
                v-for="item in dict.type.device_source_type"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <span style="float: left">{{ item.label }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="预计总工时:">
            <el-input-number :min="0"  v-model="formData.estimatedTotalHour" placeholder="请输入预计总工时" style="width: 90%"
                             clearable></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="单日工时:">
            <el-input-number :min="0"  v-model="formData.dayHour" placeholder="请输入单日工时" style="width: 90%"
                             clearable></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>


      <el-row>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="单个资产价值:">
            <el-input-number :min="0"  :precision='2' :step='1'  v-model="formData.assetValue" placeholder="请输入单个资产价值" style="width: 90%"
                             clearable></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="自有资金:">
            <el-input-number :min="0"  :precision='2' :step='1'  v-model="formData.ownFund" placeholder="请输入自有资金" style="width: 90%"
                             clearable></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="财政拨款:">
            <el-input-number :min="0"  :precision='2' :step='1'  v-model="formData.financialAppropriation" placeholder="请输入财政拨款" style="width: 90%"
                             clearable></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="科教基金:">
            <el-input-number :min="0"  :precision='2' :step='1'  v-model="formData.educationFund" placeholder="请输入科教基金" style="width: 90%"
                             clearable></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="其他资金:">
            <el-input-number :min="0"  :precision='2' :step='1'  v-model="formData.otherFund" placeholder="请输入其他资金" style="width: 90%"
                             clearable></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12" >
          <el-form-item  class="query-form-item">
            <span slot="label">
      	  <span style="font-size: 11px">非同级财政拨款:</span>
        </span>
            <el-input-number :min="0"  :precision='2' :step='1'  v-model="formData.nonPeerFinancialAppropriation" placeholder="请输入非同级财政拨款" style="width: 90%"
                             clearable></el-input-number>
          </el-form-item>
        </el-col>
      </el-row>




      <el-row>
        <el-col :span="12">
          <el-form-item class="query-form-item" label="管理类别:" style="width: 91%">
            <el-select v-model="formData.managementCategory" style="width: 100%" placeholder="请选择管理类别" >
              <el-option
                v-for="item in dict.type.device_source_type"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <span style="float: left">{{ item.label }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
                    <el-form-item label="使用人:">
                      <el-select v-model="formData.endUser"
                                 placeholder="请输入使用人"
                                 clearable="true"
                                 style="width: 90%"
                      >
                        <el-option v-for="item in userList"
                                   :key="item.employeeName"
                                   :label="item.employeeName"
                                   :value="item.userId">
                          <span>{{ item.employeeName }}</span>
                        </el-option>
                      </el-select>
                    </el-form-item>
        </el-col>
      </el-row>


      <el-row>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="预计残值:" style="font-size: 11px">
            <el-input-number :min="0"  :precision='2' :step='1'  v-model="formData.estimatedResidualValue" placeholder="请输入预计残值" style="width: 90%"
                             clearable></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item class="query-form-item" label="币种:" style="width: 91%">
            <el-select v-model="formData.currencyType" style="width: 100%" placeholder="请选择币种" >
              <el-option
                v-for="item in dict.type.device_source_type"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <span style="float: left">{{ item.label }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item class="query-form-item" label="采购类型:" style="width: 91%">
            <el-select v-model="formData.purType" style="width: 100%" placeholder="请选择采购类型" >
              <el-option
                v-for="item in dict.type.device_source_type"
                :key="item.value"
                :label="item.label"
                :value="item.value">
                <span style="float: left">{{ item.label }}</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="购置日期:">
            <el-date-picker
              style="width: 90%"
              v-model="formData.purchaseDate"
              type="date"
              placeholder="请输入购置日期"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
        </el-col>

      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item  class="query-form-item"  label="添加日期:">
            <el-date-picker
              style="width: 90%"
              v-model="formData.addDate"
              type="date"
              placeholder="请输入添加日期"
              format="yyyy 年 MM 月 dd 日"
              value-format="yyyy-MM-dd">
            </el-date-picker>
          </el-form-item>
        </el-col>

      </el-row>

    </el-form>

</template>

<script>
import {addDeptDevice, saveDeptDevice, updateDeptDevice} from "@/api/dev/deptDevice";
import {isBlank} from "@/utils/strUtil";
import {getDeptListByUser} from "@/api/auth/authDept";
import {getInvListByUser} from "@/api/system/invWarehouse";
import {listDeptUser} from "@/api/system/deptUser";
import {genDeviceCode} from "@/api/dev/deviceInfoApi";

export default {
  props: {
    rowData: {
      type: Object,
      required: true
    },
    editSaveDev: {
      type: Function,
      required: true
    },
    maintainsList: {
      type: Array,
      required: true
    }
  },
  name: "deptDeviceModifyDialog",
  dicts: ['device_source_type'],
  data() {
    return {
      deptList: [],
      invList: [],
      userList: [],
      formData: {},
      rules: {
        // deptCode: [
        //   {required: true, message: '请选择部门', trigger: 'change'}
        // ],
        // invCode: [
        //   {required: true, message: '请选择仓库', trigger: 'change'}
        // ],
        // deviceName: [
        //   {required: true, message: '请输入设备名称', trigger: 'blur'}
        // ],
        // originCode: [
        //   {required: true, message: '请输入原始编码', trigger: 'blur'}
        // ]
      }
    };
  },
  methods: {
    supChange(val) {
      this.formData.supName = this.maintainsList.find(item => item.id == val).name
      this.formData.supId = val
    },
    deptChange() {
      this.formData.invCode = null;
      this.formData.manager = null;
      this.invList = [];
      this.getInvList();
      this.getDeptUserList();
    },
    getDeptList() {
      getDeptListByUser().then((res) => {
        this.deptList = res.data || [];
        this.getInvList();
        this.getDeptUserList();
      });
    },
    getInvList() {
      let params = {deptCode: this.formData.deptCode};
      getInvListByUser(params)
        .then((response) => {
          this.invList = response.data || [];
          this.getList();
        })
        .catch(() => {
        });
    },
    getDeptUserList() {
      this.userList = [];
      let params = {deptId: null};
      this.deptList.forEach((item) => {
        if (item.code === this.formData.deptCode) {
          params.deptId = item.id;
        }
      });
      listDeptUser(params).then((res) => {
        this.userList = res.data.list || [];
      })
    },
    submit() {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          this.$message.error("请完善必填信息");
        } else {
          this.rowData.assetType = this.formData.assetType;
          this.rowData.sasacType = this.formData.sasacType;
          this.rowData.assetMnemonicCode = this.formData.assetMnemonicCode;
          this.rowData.number = this.formData.number;
          this.rowData.acquisitionMethod = this.formData.acquisitionMethod;
          this.rowData.purpose = this.formData.purpose;
          this.rowData.depreciationYear = this.formData.depreciationYear;
          this.rowData.depreciationMonth = this.formData.depreciationMonth;
          this.rowData.invCode = this.formData.invCode;
          this.rowData.estimatedTotalHour = this.formData.estimatedTotalHour;
          this.rowData.dayHour = this.formData.dayHour;
          this.rowData.assetValue = this.formData.assetValue;
          this.rowData.ownFund = this.formData.ownFund;
          this.rowData.financialAppropriation = this.formData.financialAppropriation;
          this.rowData.educationFund = this.formData.educationFund;
          this.rowData.otherFund = this.formData.otherFund;
          this.rowData.nonPeerFinancialAppropriation = this.formData.nonPeerFinancialAppropriation;

          this.rowData.managementCategory = this.formData.managementCategory;
          this.rowData.endUser = this.formData.endUser;
          this.rowData.estimatedResidualValue = this.formData.estimatedResidualValue;
          this.rowData.currencyType = this.formData.currencyType;
          this.rowData.purType = this.formData.purType;
          this.rowData.purchaseDate = this.formData.purchaseDate;
          this.rowData.addDate = this.formData.addDate;

          this.editSaveDev();

        }
      })
    },
    genCode(row) {
      let loading = this.$loading({
        lock: true,
        text: 'Loading',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      });
      genDeviceCode().then(res => {
        loading.close()
        if (res.code != 20000) {
          this.$message.error(res.message)
          return
        }
        this.formData.deviceCode = res.data
      }).catch(e => {
        loading.close()
      })
    },
  },
  created() {
    console.log(this.rowData);
    console.log(this.maintainsList.length);
    this.formData = JSON.parse(JSON.stringify(this.rowData));
    console.log(this.formData);
  },
}
</script>

<style scoped>

</style>
