<template>
  <div>
    <el-dialog
      title="修改商品名称"
      :close-on-click-modal="false"
	  draggable
      width="500px"
      @close="close"
      append-to-body
      v-model="visible">
      <div style="height: calc(100% - 80px);">
        <el-form style="margin-top: 30px" ref="inputForm" :model="inputForm"  @submit.native.prevent>
          <!-- 搜索框-->
          <el-row :gutter="26">
            <el-col :span="24">
              <el-form-item prop="tradeName" :rules="[
                        {required: true, message: '商品名称不能为空', trigger: 'blur'}
                      ]">
                <el-input v-model="inputForm.tradeName" placeholder="请输入商品名称" ></el-input>
              </el-form-item>
            </el-col>
          </el-row>

        </el-form>
      </div>
		<template #footer>
			<span class="dialog-footer">
			  <el-button @click="close()" icon="el-icon-circle-close">关闭</el-button>
			  <el-button type="primary" @click="submit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
			</span>
		</template>
    </el-dialog>
  </div>
</template>

<script>
  import WareHouseService from '@/api/materialManagement/WareHouseService'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        dataList: [],
        inputForm: {
          tradeName: ''
        },
        oldTradeName: '',
        type: '',
        typeName: ''
      }
    },
    wareHouseService: null,
    created () {
      this.wareHouseService = new WareHouseService()
    },
    components: {
    },
    methods: {
      init (tradeName, type, typeName) {
        this.visible = true
        this.inputForm.tradeName = tradeName
        this.type = type
        this.typeName = typeName
        this.oldTradeName = tradeName
      },
      // 表单提交
      submit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.$confirm('确定将 [' + this.typeName + '] 商品 ”' + this.oldTradeName + '“ 全部改为 ”' + this.inputForm.tradeName + '“ 吗？', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              this.loading = true
              this.wareHouseService.saveTradeName(this.oldTradeName, this.inputForm.tradeName, this.type).then(({data}) => {
                this.$message.success(data)
                this.close()
                this.$emit('refreshList')
                this.loading = false
              }).catch(() => {
                this.$refs.inputForm.resetFields()
                this.loading = false
              })
            })
          }
        })
      },
      close () {
        this.$refs.inputForm.resetFields()
        this.inputForm = {
          tradeName: ''
        }
        this.visible = false
      }
    }
  }
</script>
<style scoped>
  /deep/ .el-dialog__body {
    padding-top: 0px;
    padding-bottom: 15px;
  }
</style>
