add.vue 7.51 KB
<template>
  <div>
    <el-dialog :title="isEdit=='add'?$t('button.groupAdd'):$t('button.groupEdit')" :visible.sync="isShow" v-if="isShow" :close-on-click-modal='false' class="manage-dialog dialog_lj" :before-close="closeDialog">
      <el-form :model="addForm" label-width="100px" :rules="rules" ref="addForm">
        <el-form-item :label="$t('table.squareName')" prop="mallId">
          <el-select v-model="addForm.mallId" filterable :placeholder="$t('pholder.select')" :disabled="isEdit=='add'?false:true">
              <el-option v-for="item in mallListForTerm" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
          <i class="error-tip">*</i>
        </el-form-item>
        <el-form-item :label="$t('table.monday')" prop="code">
          <el-time-picker v-model="addForm.monStartTime"> </el-time-picker><span>{{$t('dialog.to')}}</span>
          <el-time-picker v-model="addForm.monEndTime"> </el-time-picker>
          <i class="error-tip">*</i>
        </el-form-item>
        <el-form-item :label="$t('table.tuesday')" prop="code">
          <el-time-picker v-model="addForm.tueStartTime"> </el-time-picker><span>{{$t('dialog.to')}}</span>
          <el-time-picker v-model="addForm.tueEndTime"> </el-time-picker>
          <i class="error-tip">*</i>
        </el-form-item>
        <el-form-item :label="$t('table.wednesday')" prop="code">
         <el-time-picker v-model="addForm.wedStartTime"> </el-time-picker><span>{{$t('dialog.to')}}</span>
         <el-time-picker v-model="addForm.wedEndTime"> </el-time-picker>
         <i class="error-tip">*</i>
        </el-form-item>
        <el-form-item :label="$t('table.thursday')" prop="code">
          <el-time-picker v-model="addForm.thuStartTime"> </el-time-picker><span>{{$t('dialog.to')}}</span>
          <el-time-picker v-model="addForm.thuEndTime"> </el-time-picker>
          <i class="error-tip">*</i>
        </el-form-item>

        <el-form-item :label="$t('table.friday')" prop="code">
          <el-time-picker v-model="addForm.friStartTime"> </el-time-picker><span>{{$t('dialog.to')}}</span>
          <el-time-picker v-model="addForm.friEndTime"> </el-time-picker>
          <i class="error-tip">*</i>
        </el-form-item>
        <el-form-item :label="$t('table.saturday')" prop="code">
          <el-time-picker v-model="addForm.satStartTime"> </el-time-picker><span>{{$t('dialog.to')}}</span>
          <el-time-picker v-model="addForm.satEndTime"> </el-time-picker>
          <i class="error-tip">*</i>
        </el-form-item>
        <el-form-item :label="$t('table.sunday')" prop="code">
          <el-time-picker v-model="addForm.sunStartTime"> </el-time-picker><span>{{$t('dialog.to')}}</span>
          <el-time-picker v-model="addForm.sunEndTime"> </el-time-picker>
          <i class="error-tip">*</i>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="closeDialog" class="dialog-btn">{{$t('dialog.cancel')}}</el-button>
        <el-button type="primary" @click="addSubmit('addForm')" class="dialog-btn dialog-confirm-btn">
          {{$t('dialog.confirm')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import moment from 'moment'
  export default {
    data() {
      return {
        isEdit:'add',
        isShow: false,
        addForm: {},
        rules: {
          mallId: [{
            required: true,
            message: this.$t("pholder.input"),
            trigger: 'blur'
          }]
        },
      }
    },
    methods: {
        getMallListForTerm() {
          this.mallListForTerm = [];
          this.$api.base.mall(
              {
                accountId: this.$cookie.get('accountId'),
                status_arr: "1,3"
              },
              null,
              true
            )
            .then(data => {
              let result = data.data;
              if (result.data.length) {
                this.mallListForTerm = result.data;
                this.$forceUpdate()
              }
            })
        },
      dialogInit(type,row) {
        this.getMallListForTerm()
        this.isEdit = type;
        this.isShow = true;
        if(row){
          this.addForm = row
        }else{
          this.addForm = {
            accountId: this.$cookie.get('accountId'),
            mallId: null,
            monStartTime:new Date(2022, 1, 1, 9, 0),
            monEndTime:new Date(2022, 1, 1, 22, 0),
            tueStartTime:new Date(2022, 1, 1, 9, 0),
            tueEndTime:new Date(2022, 1, 1, 22, 0),
            wedStartTime:new Date(2022, 1, 1, 9, 0),
            wedEndTime:new Date(2022, 1, 1, 22, 0),
            thuStartTime:new Date(2022, 1, 1, 9, 0),
            thuEndTime:new Date(2022, 1, 1, 22, 0),
            friStartTime:new Date(2022, 1, 1, 9, 0),
            friEndTime:new Date(2022, 1, 1, 22, 0),
            satStartTime:new Date(2022, 1, 1, 9, 0),
            satEndTime:new Date(2022, 1, 1, 22, 0),
            sunStartTime:new Date(2022, 1, 1, 9, 0),
            sunEndTime:new Date(2022, 1, 1, 22, 0),
          }
        }
        this.$forceUpdate()
      },
      addSubmit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            Object.keys(this.addForm).forEach(key=>{
              if(key != 'mallId' && key != 'accountId' && key != 'id'){
                this.addForm[key] = moment(this.addForm[key]).format('YYYY-MM-DD HH:mm:ss')
              }
            })
            if(this.isEdit=='add'){
              this.$api.queueManagementApi.addOpentime(this.addForm)
                .then((res) => {
                  let result = res.data;
                  if(result.code==200){
                    this.$message({
                      message: result.msg,
                      type: 'success'
                    });
                    this.$parent.getTableData();
                    this.$refs.addForm.resetFields();
                    this.addForm = {}
                    this.isShow = false
                  }else{
                    this.$message({
                      message: result.msg,
                      type: 'error'
                    });
                  }
                })
            }else{
              this.$api.queueManagementApi.updateOpentime(this.addForm).then((res) => {
                  let result = res.data;
                  if(result.code==200){
                    this.$message({
                      message: result.msg,
                      type: 'success'
                    });
                    this.$parent.getTableData();
                    this.$refs.addForm.resetFields();
                    this.addForm = {}
                    this.isShow = false
                  }else{
                    this.$message({
                      message: result.msg,
                      type: 'error'
                    });
                  }
                })
            }
          } else {
            return false;
          }
        });
      },
      closeDialog() {
        this.$refs.addForm.resetFields();
        this.addForm = {}
        this.isShow = false;
      }
    }
  }
</script>
<style lang="less" scoped="scoped">
  .dialog_lj{
    /deep/.el-form-item__label{
      width: 100px;
      text-align:left;
      margin-top: 12px;
    }
    /deep/.el-select{
      width: 100%;
    }
    /deep/.el-date-editor.el-input{
      width: 200px;
    }
    /deep/.el-form-item__label+.el-form-item__content{
        float: none !important;
        line-height:40px !important;
    }
    /deep/.el-form-item__error{
        padding-top: 0px !important;
    }
  }
</style>