cuilei
5 天以前 ba77fdc6a30c9ad0941e40319f8c4f6fe6fdf9f1
src/views/mdc/base/modules/shift/ShiftInfoModel.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,400 @@
<template>
  <a-modal :title="title" :width="800" :visible="visible" :confirmLoading="confirmLoading"
           @ok="handleOk" @cancel="handleCancel" cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="班制名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input :disabled="true" :readOnly="true" allow-clear placeholder="请输入班制名称"
                       v-decorator="['shiftName',validatorRules.shiftName]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="班次名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-input allow-clear placeholder="请输入班次名称" v-decorator="['shiftSubName',validatorRules.shiftSubName]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="开始时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-time-picker :disabled="disableSubmit" :readOnly="disableSubmit" allow-clear
                             v-decorator="['startDate',validatorRules.startDate]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="结束时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-time-picker :disabled="disableSubmit" :readOnly="disableSubmit"
                             v-decorator="['endDate',validatorRules.endDate]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="开始休息时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-time-picker :disabled="disableSubmit" :readOnly="disableSubmit" allow-clear
                             v-decorator="['sleepStartDate',validatorRules.sleepStartDate]"/>
            </a-form-item>
          </a-col>
          <a-col :span="12">
            <a-form-item label="结束休息时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-time-picker :disabled="disableSubmit" :readOnly="disableSubmit" allow-clear
                             v-decorator="['sleepEndDate',validatorRules.sleepEndDate]"/>
            </a-form-item>
          </a-col>
        </a-row>
        <a-row :gutter="24">
          <a-col :span="12">
            <a-form-item label="是否跨天" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <a-switch v-model="isDaySpan" checked-children="是" un-checked-children="否"/>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>
<script>
  import moment from 'moment'
  import pick from 'lodash.pick'
  import {
    getAction,
    postAction,
    requestPut
  } from '@/api/manage'
  import {
    duplicateCheck
  } from '@/api/api'
  import {
    JeecgListMixin
  } from '@/mixins/JeecgListMixin'
  export default {
    name: 'ShiftInfoModel',
    mixins: [JeecgListMixin],
    components: {},
    props: {},
    data() {
      return {
        title: '',
        isDaySpan: false,
        visible: false,
        show: false,
        model: {},
        checked: false,
        labelCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 6
          }
        },
        wrapperCol: {
          xs: {
            span: 24
          },
          sm: {
            span: 18
          }
        },
        confirmLoading: false,
        form: this.$form.createForm(this),
        validatorRules: {
          shiftSubName: {
            rules: [
              {
                required: true,
                message: '请输入班次名称'
              }
            ]
          },
          startDate: {
            rules: [
              {
                required: true,
                message: '请选择开始时间'
              }
            ]
          },
          endDate: {
            rules: [
              {
                required: true,
                message: '请选择结束时间'
              }
            ]
          }
        },
        url: {
          add: '/mdc/mdcShiftSub/addShiftSub',
          edit: '/mdc/mdcShiftSub/editMdcShiftSub',
          list: '/mdc/mdcMdcShift/queryPageList'
        },
        disableSubmit: true
      }
    },
    created() {
      // this.checkshiftSuName();
    },
    methods: {
      //自定义校验函数,要求名字不能重复  value是表单的值,callback是回调函数   å¿…须调用才可验证
      checkshiftSuName(rule, value, callback) {
        if (!value) {
          alert('不能为空!')
          return
        }
        // debugger
        // let NameSelf = value;
        this.loadData()
        // console.log(dataSource);
        callback()
      },
      loadData() {
        if (!this.url.list) {
          this.$message.error('请设置url.list属性!')
          return
        }
        //加载数据 è‹¥ä¼ å…¥å‚æ•°1则加载第一页的内容
        // if (arg === 1) {
        //   this.ipagination.current = 1;
        // }
        var params = this.getQueryParams()//查询条件
        //
        // if(!params){
        //   return false;
        // }
        // this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            // console.log(res)
            //update-begin---author:zhangyafei    Date:20201118  for:适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result
            // if(res.result.total)
            // {
            //   this.ipagination.total = res.result.total;
            // }else{
            //   this.ipagination.total = 0;
            // }
            //update-end---author:zhangyafei    Date:20201118  for:适配不分页的数据列表------------
          } else {
            // this.$message.warning(res.message)
            this.$notification.warning({
              message: '消息',
              description: res.message
            })
          }
        }).finally(() => {
          this.loading = false
        })
      },
      add(record) {
        let _this = this
        this.visible = true
        this.form.resetFields()
        this.model = { shiftId: record.id, shiftName: record.shiftName }
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'shiftName'))
          this.isDaySpan = false
        })
      },
      edit(record) {
        this.form.resetFields()
        this.model = Object.assign({}, record)
        this.visible = true
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model, 'shiftName', 'shiftSubName', 'startDate', 'endDate', 'sleepStartDate', 'sleepEndDate'))
          this.form.setFieldsValue({
            startDate: moment(this.model.startDate, 'HH:mm:ss'),
            endDate: moment(this.model.endDate, 'HH:mm:ss')
          })
          if (this.model.sleepStartDate) {
            this.form.setFieldsValue({
              sleepStartDate: moment(this.model.sleepStartDate, 'HH:mm:ss')
            })
          }
          if (this.model.sleepStartDate) {
            this.form.setFieldsValue({
              sleepEndDate: moment(this.model.sleepEndDate, 'HH:mm:ss')
            })
          }
          if (record.isDaySpan == 'true') {
            this.isDaySpan = true
          } else {
            this.isDaySpan = false
          }
        })
      },
      close() {
        this.$emit('close')
        this.visible = false
        this.show = false
      },
      handleOk() {
        const that = this
        // è§¦å‘表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            // debugger
            that.confirmLoading = true
            let formData = Object.assign(this.model, values)
            formData.isDaySpan = that.isDaySpan
            console.log(formData.isDaySpan)
            formData.startDate = moment(formData.startDate).format('HH:mm:ss')
            formData.endDate = moment(formData.endDate).format('HH:mm:ss')
            if (formData.sleepStartDate) formData.sleepStartDate = moment(formData.sleepStartDate).format('HH:mm:ss')
            if (formData.sleepEndDate) formData.sleepEndDate = moment(formData.sleepEndDate).format('HH:mm:ss')
            if (formData.isDaySpan == false) {
              let startTimeOne = formData.startDate.replace(/:/g, '')
              let endTimeOne = formData.endDate.replace(/:/g, '')
              if (startTimeOne > endTimeOne) {
                // that.$message.warning("非跨天班次结束时间不能小于等于开始时间!")
                that.$notification.warning({
                  message: '消息',
                  description: '非跨天班次结束时间不能小于等于开始时间!'
                })
                that.confirmLoading = false
                that.close()
              } else {
                formData.shiftSubStatus = 1
                let obj
                if (!this.model.id) {
                  obj = postAction(this.url.add, formData)
                } else {
                  obj = requestPut(this.url.edit, formData, {
                    id: this.model.id
                  })
                }
                obj.then((res) => {
                  if (res.success) {
                    // that.$message.success("保存成功")
                    that.$notification.success({
                      message: '消息',
                      description: '保存成功'
                    })
                    that.$emit('ok', res.result)
                  } else {
                    // that.$message.warning(res.message)
                    that.$notification.warning({
                      message: '消息',
                      description: res.message
                    })
                  }
                }).finally(() => {
                  that.confirmLoading = false
                  that.close()
                })
              }
            } else {
              formData.shiftSubStatus = 1
              let obj
              if (!this.model.id) {
                obj = postAction(this.url.add, formData)
              } else {
                obj = requestPut(this.url.edit, formData, {
                  id: this.model.id
                })
              }
              obj.then((res) => {
                if (res.success) {
                  // that.$message.success
                  that.$notification.success({
                    message: '消息',
                    description: '保存成功'
                  })
                  that.$emit('ok', res.result)
                } else {
                  // that.$message.warning(res.message)
                  that.$notification.warning({
                    message: '消息',
                    description: res.message
                  })
                }
              }).finally(() => {
                that.confirmLoading = false
                that.close()
              })
            }
          }
        })
      },
      handleCancel() {
        this.close()
      },
      loadCascade() {
        getAction(this.url.loadCascadeData).then((res) => {
          if (res.success) {
            this.partCategoryCascade = res.result
          }
        })
      },
      //验证 ç¼–码
      validateNum(rule, value, callback) {
        var params = {
          tableName: 'lxmes_base_part',
          fieldName: 'num',
          fieldVal: value,
          dataId: this.model.id,
          //数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false å‡åˆ é™¤ï¼štrue
          delFlag: 'true'
        }
        duplicateCheck(params).then((res) => {
          if (res.success) {
            callback()
          } else {
            callback('存货编码已存在!')
          }
        })
      },
      checkboxChange(e) {
        this.checked = e.target.checked
      }
      //验证 åç§°
      // validateName(rule, value, callback) {
      //   var params = {
      //     tableName: 'mes_base_part',
      //     fieldName: 'name',
      //     fieldVal: value,
      //     dataId: this.model.id,
      //     //数据库中存在字段del_flag并使用该字段作为未删除策略,真删除:false å‡åˆ é™¤ï¼štrue
      //     delFlag: 'true',
      //   };
      //   duplicateCheck(params).then((res) => {
      //     if (res.success) {
      //       callback();
      //     } else {
      //       callback("产品名称已存在!");
      //     }
      //   })
      // },
    }
  }
</script>
<style scoped>
  .ant-btn {
    padding: 0 10px;
    margin-left: 3px;
  }
  .ant-form-item-control {
    line-height: 0px;
  }
  /** ä¸»è¡¨å•行间距 */
  .ant-form .ant-form-item {
    margin-bottom: 10px;
  }
  /** Tab页面行间距 */
  .ant-tabs-content .ant-form-item {
    margin-bottom: 0px;
  }
</style>