<!-- 存储位置列表 -->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item :label="$t('page.system.storageLocation.fzdd') + '：'" prop="location">
        <el-input v-model="queryParams.location" placeholder="" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('page.system.storageLocation.sbmc') + '：'" prop="name">
        <el-input v-model="queryParams.name" placeholder="" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('page.system.storageLocation.fzhj') + '：'" prop="shelfPlacement">
        <el-input v-model="queryParams.shelfPlacement" placeholder="" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item :label="$t('page.system.storageLocation.zt')" prop="status"   >
        <el-select v-model="queryParams.status" :placeholder="$t('form.placeholderSelect')" clearable @change="handleQuery">
          <el-option key="1" :label="$t('page.system.storageLocation.no')" :value="1" />
          <el-option key="10" :label="$t('page.system.storageLocation.yes')" :value="10" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{ $t('form.search')
        }}</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">{{ $t('form.reset') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain @click="handleAdd" v-hasPermi="['business:storageLocation:add']">{{
          $t('page.system.storageLocation.add') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="list">
      <el-table-column :label="$t('page.system.storageLocation.fzdd')" align="center" prop="location" />
      <el-table-column :label="$t('page.system.storageLocation.sbmc')" align="center" prop="name" />
      <el-table-column :label="$t('page.system.storageLocation.fzhj')" align="center" prop="shelfPlacement" />
      <el-table-column :label="$t('page.system.storageLocation.wc')" align="center" prop="compartment" />
      <el-table-column :label="$t('page.system.storageLocation.ssbm')" align="center" prop="deptName" />
      <el-table-column :label="$t('page.system.storageLocation.zt')" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 1">{{ $t('page.system.storageLocation.no') }}</span>
          <span v-if="scope.row.status == 10">{{ $t('page.system.storageLocation.yes') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('form.operate')" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button type="text" @click="handleDetail(scope.row)">{{
            $t('form.detail') }}</el-button>
          <el-button type="text" @click="handleUpdate(scope.row)" v-hasPermi="['business:storageLocation:edit']">{{
            $t('form.edit') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改仪器管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.system.storageLocation.fzdd')" prop="location">
              <el-input v-model="form.location" :placeholder="$t('form.placeholderInput')" maxlength="50" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.system.storageLocation.sbmc')" prop="name">
              <el-input v-model="form.name" :placeholder="$t('form.placeholderInput')" maxlength="50" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.system.storageLocation.fzhj')" prop="shelfPlacement">
              <el-input v-model="form.shelfPlacement" :placeholder="$t('form.placeholderInput')" maxlength="50" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.system.storageLocation.wc')" prop="compartment">
              <BusinessSelect v-model="form.compartment" dictType="business_cctj"></BusinessSelect>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.system.storageLocation.ssbm')" prop="deptId">
              <SelectDept v-model="form.deptId" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('page.system.storageLocation.zt')" prop="status">
              <el-select v-model="form.status" :placeholder="$t('form.placeholderSelect')" style="width: 100%;">
                <el-option key="1" :label="$t('page.system.storageLocation.no')" :value="1" />
                <el-option key="10" :label="$t('page.system.storageLocation.yes')" :value="10" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('form.qmyy')" prop="qmyy">
              <el-input v-model="form.qmyy" disabled :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item :label="$t('form.signer')" prop="qmrmc">
              <el-input v-model="nickName" disabled :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('form.signerPsw')" prop="qmrmm">
              <el-input v-model="form.qmrmm" autocomplete="off" auto-complete="new-password" show-password
                :placeholder="$t('form.placeholderInput')" type="password" maxlength="20" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">{{ $t('form.saveConfirm') }}</el-button>
        <el-button @click="cancel">{{ $t('form.cancel') }}</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { storageLocation_list, storageLocation_add } from '@/api/business/storageLocation/storageLocation'

import BusinessSelect from '@/views/business/comps/select/BusinessSelect';
import SelectDept from '@/views/business/comps/select/SelectDept';
import { mapGetters } from 'vuex'
import SelectStorageLocation from '@/views/business/comps/select/SelectStorageLocation'
export default {
  name: 'StorageLocation',
  components: { BusinessSelect, SelectDept, SelectStorageLocation },

  data() {
    return {
      // 遮罩层
      loading: true,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 列表数据
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        location: null,
        name: null,
        shelfPlacement: null,
      },
      // 表单参数
      form: {
        'qmyy': this.$t('page.form.add')
      },
      // 表单校验
      rules: {
        location: [
          { required: true, message: this.$t('form.notEmpty'), trigger: "change" },
          { min: 0, max: 50, message: this.$t('form.lengthLimit') + '50', trigger: 'blur' }
        ],
        name: [
          { required: true, message: this.$t('form.notEmpty'), trigger: "change" },
          { min: 0, max: 50, message: this.$t('form.lengthLimit') + '50', trigger: 'blur' }
        ],
        shelfPlacement: [
          { required: true, message: this.$t('form.notEmpty'), trigger: "change" },
          { min: 0, max: 50, message: this.$t('form.lengthLimit') + '50', trigger: 'blur' }
        ],
        compartment: [
          { required: true, message: this.$t('form.notEmpty'), trigger: "blur" }
        ],
        deptId: [
          { required: true, message: this.$t('form.notEmpty'), trigger: "change" },
        ],
        status: [
          { required: true, message: this.$t('form.notEmpty'), trigger: "change" },
        ],
        qmrmm: [
          { required: true, message: this.$t('form.signerPsw') + this.$t('form.notEmpty'), trigger: "change" },
          { min: 0, max: 20, message: this.$t('form.signerPsw') + this.$t('form.lengthLimit') + '20', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName', 'name'
    ]),
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      storageLocation_list(this.queryParams).then((response) => {
        this.list = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        mc: null,
        bh: null,
        xh: null,
        ly: null,
        jzrq: null,
        bmId: null,
        wc: null,
        ccwz: null,
        fzdd: null,
        qmyy: this.$t('page.system.storageLocation.addStroageLocation'),
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = this.$t('form.add')
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()

      this.form = row
      this.form.qmyy = this.$t('page.system.storageLocation.editStroageLocation')
      this.open = true
      this.title = this.$t('form.edit')
    },
    handleDetail(row) {
      this.$refs.YqDetail.show(row)
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          if (this.form.id) {
            storageLocation_edit(this.form).then((response) => {
              this.$modal.msgSuccess(this.$t('form.operationSuccess'))
              this.open = false
              this.getList()
            })
          } else {
            storageLocation_add(this.form).then((response) => {
              this.$modal.msgSuccess(this.$t('form.operationSuccess'))
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
  }
}
</script>
