<template> 
  <view class="page"> 
    <view v-if="ready"> 
      <l-input 
        @input="setValue('StuAttendanceLeave.AcademicYearNo', $event)"
        :value="getValue('StuAttendanceLeave.AcademicYearNo')"
        :disabled="!edit"
        title="学年度"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.Semester', $event)"
        :value="getValue('StuAttendanceLeave.Semester')"
        :disabled="!edit"
        title="学期"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.StuNo', $event)"
        :value="getValue('StuAttendanceLeave.StuNo')"
        :disabled="!edit"
        title="学号"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.StuName', $event)"
        :value="getValue('StuAttendanceLeave.StuName')"
        :disabled="!edit"
        title="姓名"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.Grade', $event)"
        :value="getValue('StuAttendanceLeave.Grade')"
        :disabled="!edit"
        title="年级"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.EmpNo', $event)"
        :value="getValue('StuAttendanceLeave.EmpNo')"
        :disabled="!edit"
        title="教师号"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.DeptNo', $event)"
        :value="getValue('StuAttendanceLeave.DeptNo')"
        :disabled="!edit"
        title="系所码"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.DeptName', $event)"
        :value="getValue('StuAttendanceLeave.DeptName')"
        :disabled="!edit"
        title="系名"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.MajorNo', $event)"
        :value="getValue('StuAttendanceLeave.MajorNo')"
        :disabled="!edit"
        title="专业码"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.MajorName', $event)"
        :value="getValue('StuAttendanceLeave.MajorName')"
        :disabled="!edit"
        title="专业名"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.ClassNo', $event)"
        :value="getValue('StuAttendanceLeave.ClassNo')"
        :disabled="!edit"
        title="所在行政班号"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.ClassName', $event)"
        :value="getValue('StuAttendanceLeave.ClassName')"
        :disabled="!edit"
        title="班级名称"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.LessonNo', $event)"
        :value="getValue('StuAttendanceLeave.LessonNo')"
        :disabled="!edit"
        title="课程号"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.LessonName', $event)"
        :value="getValue('StuAttendanceLeave.LessonName')"
        :disabled="!edit"
        title="课程名称"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.LessonSortNo', $event)"
        :value="getValue('StuAttendanceLeave.LessonSortNo')"
        :disabled="!edit"
        title="课程类别码"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.LessonSortName', $event)"
        :value="getValue('StuAttendanceLeave.LessonSortName')"
        :disabled="!edit"
        title="课程类别"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.LessonDate', $event)"
        :value="getValue('StuAttendanceLeave.LessonDate')"
        :disabled="!edit"
        title="原上课日期"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.LessonTime', $event)"
        :value="getValue('StuAttendanceLeave.LessonTime')"
        :disabled="!edit"
        title="上课时间"
      /> 
      <l-input 
        @input="setValue('StuAttendanceLeave.PlanWeek', $event)"
        :value="getValue('StuAttendanceLeave.PlanWeek')"
        :disabled="!edit"
        title="教学周次"
      /> 
      <l-select 
        @input="setValue('StuAttendanceLeave.LeaveType', $event)"
        :value="getValue('StuAttendanceLeave.LeaveType')"
        :disabled="!edit"
        :range="dataSource.StuAttendanceLeave.LeaveType"
        title="请假类型"
      /> 
      <l-textarea 
        @input="setValue('StuAttendanceLeave.Remark', $event)"
        :value="getValue('StuAttendanceLeave.Remark')"
        :readonly="!edit"
        title="备注"
      /> 
      <l-select 
        @input="setValue('StuAttendanceLeave.IsCheck', $event)"
        :value="getValue('StuAttendanceLeave.IsCheck')"
        :disabled="!edit"
        :range="dataSource.StuAttendanceLeave.IsCheck"
        title="下拉框"
      /> 
      <l-textarea 
        @input="setValue('StuAttendanceLeave.TecRemark', $event)"
        :value="getValue('StuAttendanceLeave.TecRemark')"
        :readonly="!edit"
        title="备注"
      /> 
    </view> 
  
    <view v-if="ready" class="bg-white margin-tb padding" style="padding-top: 0; overflow: hidden;"> 
      <l-button v-if="edit" @click="action('save')" size="lg" color="green" class="block margin-top" block> 
        提交保存 
      </l-button> 
      <l-button v-if="!edit && mode !== 'create'" @click="action('edit')" size="lg" line="orange" class="block margin-top" block> 
        编辑本页 
      </l-button> 
      <l-button v-if="edit && mode !== 'create'" @click="action('reset')" size="lg" line="red" class="block margin-top" block> 
        取消编辑 
      </l-button> 
      <l-button v-if="!edit && mode !== 'create'" @click="action('delete')" size="lg" line="red" class="block margin-top" block> 
        删除 
      </l-button> 
    </view> 
  </view> 
</template> 
  
  
<script> 
/* 
 * 版 本 Learun-ADMS V7.0.3 力软敏捷开发框架(http://www.learun.cn) 
 * Copyright (c) 2013-2020 上海力软信息技术有限公司 
 * 创建人：超级管理员 
 * 日  期：2020-10-20 15:34 
 * 描  述：aaa 
 */
  
/** 
 * 本段代码由移动端代码生成器输出，移动端须 2.2.0 版本及以上可以使用 
 * 请在移动端 /pages.json 中的 pages 字段中添加一条记录： 
 * { "path": "pages/EducationalAdministration/StuAttendanceLeave/single", "style": { "navigationBarTitleText": "表单详情页" } } 
 *  
 * （navigationBarTitleText 字段为本页面的标题文本，可以修改） 
 * （必须自行操作该步骤，力软代码生成器不会自动帮您修改 /pages.json 文件） 
 */
  
import get from 'lodash/get'
import set from 'lodash/set'
import moment from 'moment'
import customPageMixins from '@/common/custompage.js'
  
export default { 
  mixins: [customPageMixins], 
  
  data() { 
    return { 
      // 页面相关参数 
      id: null, 
      mode: null, 
      edit: null, 
      ready: false, 
  
      // 表单数据 
      current: {}, 
      origin: {}, 
  
      // 表单项数据结构 
      scheme: { 
        StuAttendanceLeave: { 
          AcademicYearNo: { type: 'text', title: '学年度' }, 
          Semester: { type: 'text', title: '学期' }, 
          StuNo: { type: 'text', title: '学号' }, 
          StuName: { type: 'text', title: '姓名' }, 
          Grade: { type: 'text', title: '年级' }, 
          EmpNo: { type: 'text', title: '教师号' }, 
          DeptNo: { type: 'text', title: '系所码' }, 
          DeptName: { type: 'text', title: '系名' }, 
          MajorNo: { type: 'text', title: '专业码' }, 
          MajorName: { type: 'text', title: '专业名' }, 
          ClassNo: { type: 'text', title: '所在行政班号' }, 
          ClassName: { type: 'text', title: '班级名称' }, 
          LessonNo: { type: 'text', title: '课程号' }, 
          LessonName: { type: 'text', title: '课程名称' }, 
          LessonSortNo: { type: 'text', title: '课程类别码' }, 
          LessonSortName: { type: 'text', title: '课程类别' }, 
          LessonDate: { type: 'text', title: '原上课日期' }, 
          LessonTime: { type: 'text', title: '上课时间' }, 
          PlanWeek: { type: 'text', title: '教学周次' }, 
          LeaveType: { type: 'select', title: '请假类型', itemCode: 'LeaveType', dataSource: '0' }, 
          Remark: { type: 'textarea', title: '备注' }, 
          IsCheck: { type: 'select', title: '下拉框', itemCode: 'LeaveCheck', dataSource: '0' }, 
          TecRemark: { type: 'textarea', title: '备注' }, 
        }, 
  
      }, 
  
      // 数据源 
      dataSource: { 
        StuAttendanceLeave: { 
          LeaveType: Object.values(this.GET_GLOBAL('dataDictionary').LeaveType).map(t => ({ value: t.value, text: t.text })), 
          IsCheck: Object.values(this.GET_GLOBAL('dataDictionary').LeaveCheck).map(t => ({ value: t.value, text: t.text })), 
        }, 
  
      } 
    } 
  }, 
  
  async onLoad({ type, id }) { 
    await this.init(type, id) 
  }, 
  
  methods: { 
    // 页面初始化 
    async init(type, id) { 
      this.LOADING('加载数据中...') 
  
      this.id = id 
      this.mode = type 
      this.edit = ['create', 'edit'].includes(this.mode) 
  
      // 拉取表单数据，同时拉取所有来自数据源的选单数据 
      await Promise.all([ 
  
  
        () => {} 
      ]) 
      await this.fetchForm() 
  
      this.ready = true
      this.HIDE_LOADING() 
    }, 
  
    // 加载表单数据 
    async fetchForm() { 
      if (this.mode === 'create') { 
        this.origin = await this.getDefaultForm() 
      } else { 
        const result = await this.HTTP_GET('learun/adms/EducationalAdministration/StuAttendanceLeave/form', this.id) 
        this.origin = await this.formatFormData(result) 
      } 
      this.current = this.COPY(this.origin) 
    }, 
  
    // 点击 「编辑」、「重置」、「保存」、「删除」 按钮 
    async action(type) { 
      switch (type) { 
        case 'edit': 
          this.edit = true
          break
  
        case 'reset': 
          this.current = this.COPY(this.origin) 
          this.edit = false
          break
  
        case 'save': 
          const verifyResult = this.verifyForm() 
          if (verifyResult.length > 0) { 
            this.CONFIRM('表单验证失败', verifyResult.join('\n')) 
            return
          } 
  
          if (!(await this.CONFIRM('提交确认', '确定要提交本页表单内容吗？', true))) { 
            return
          } 
  
          this.LOADING('正在提交...') 
          const postData = await this.getPostData(this.id) 
  
          this.HTTP_POST('learun/adms/EducationalAdministration/StuAttendanceLeave/save', postData, '表单提交保存失败').then(success => { 
            this.HIDE_LOADING() 
            if (!success) { 
              return
            } 
  
            this.EMIT('EducationalAdministrationStuAttendanceLeave-list-change') 
            this.NAV_BACK() 
            this.TOAST('提交保存成功') 
          }) 
          break
  
        case 'delete': 
          if (!(await this.CONFIRM('删除项目', '确定要删除本项吗？', true))) { 
            return
          } 
  
          this.LOADING('提交删除中...') 
          this.HTTP_POST('learun/adms/EducationalAdministration/StuAttendanceLeave/delete', this.id, '删除失败').then(success => { 
            this.HIDE_LOADING() 
            if (!success) { 
              return
            } 
  
            this.EMIT('EducationalAdministrationStuAttendanceLeave-list-change') 
            this.NAV_BACK() 
            this.this.TOAST('删除成功', 'success') 
          }) 
          break
  
        default: break
      } 
    }, 
  
    // 获取表单值 
    getValue(path) { 
      return get(this.current, path) 
    }, 
  
    // 设置表单值 
    setValue(path, val) { 
      set(this.current, path, val) 
    } 
  } 
} 
</script> 