<template> 
  <view class="page"> 
    <view v-if="ready"> 
      <l-input 
        @input="setValue('StuConsumption.ID', $event)"
        :value="getValue('StuConsumption.ID')"
        :disabled="!edit"
        title="记录序号"
      /> 
      <l-input 
        @input="setValue('StuConsumption.ECODE', $event)"
        :value="getValue('StuConsumption.ECODE')"
        :disabled="!edit"
        title="企业代码"
      /> 
      <l-input 
        @input="setValue('StuConsumption.NOTECASE', $event)"
        :value="getValue('StuConsumption.NOTECASE')"
        :disabled="!edit"
        title="钱包类型"
      /> 
      <l-input 
        @input="setValue('StuConsumption.CUSTOMERID', $event)"
        :value="getValue('StuConsumption.CUSTOMERID')"
        :disabled="!edit"
        title="一卡通账号"
      /> 
      <l-input 
        @input="setValue('StuConsumption.OUTID', $event)"
        :value="getValue('StuConsumption.OUTID')"
        :disabled="!edit"
        title="学工号"
      /> 
      <l-input 
        @input="setValue('StuConsumption.CARDSN', $event)"
        :value="getValue('StuConsumption.CARDSN')"
        :disabled="!edit"
        title="持卡序号"
      /> 
      <l-input 
        @input="setValue('StuConsumption.OPCOUNT', $event)"
        :value="getValue('StuConsumption.OPCOUNT')"
        :disabled="!edit"
        title="消费卡操作计数"
      /> 
      <l-date-picker 
        @input="setValue('StuConsumption.OPDT', $event)"
        :value="getValue('StuConsumption.OPDT')"
        :disabled="!edit"
        title="操作时间"
      /> 
      <l-input 
        @input="setValue('StuConsumption.ODDFARE', $event)"
        :value="getValue('StuConsumption.ODDFARE')"
        :disabled="!edit"
        title="余额"
      /> 
      <l-input 
        @input="setValue('StuConsumption.OPFARE', $event)"
        :value="getValue('StuConsumption.OPFARE')"
        :disabled="!edit"
        title="操作额"
      /> 
      <l-input 
        @input="setValue('StuConsumption.MNGFARE', $event)"
        :value="getValue('StuConsumption.MNGFARE')"
        :disabled="!edit"
        title="管理费"
      /> 
      <l-input 
        @input="setValue('StuConsumption.ACCCODE', $event)"
        :value="getValue('StuConsumption.ACCCODE')"
        :disabled="!edit"
        title="科目代码"
      /> 
      <l-input 
        @input="setValue('StuConsumption.DSCRP', $event)"
        :value="getValue('StuConsumption.DSCRP')"
        :disabled="!edit"
        title="科目描述"
      /> 
      <l-input 
        @input="setValue('StuConsumption.TERMID', $event)"
        :value="getValue('StuConsumption.TERMID')"
        :disabled="!edit"
        title="终端编号"
      /> 
      <l-input 
        @input="setValue('StuConsumption.RECNO', $event)"
        :value="getValue('StuConsumption.RECNO')"
        :disabled="!edit"
        title="终端记录流水号"
      /> 
      <l-input 
        @input="setValue('StuConsumption.UPLOADDATE', $event)"
        :value="getValue('StuConsumption.UPLOADDATE')"
        :disabled="!edit"
        title="上传时间"
      /> 
      <l-input 
        @input="setValue('StuConsumption.SAMCARDNO', $event)"
        :value="getValue('StuConsumption.SAMCARDNO')"
        :disabled="!edit"
        title="SAM卡号"
      /> 
      <l-input 
        @input="setValue('StuConsumption.SAMTRADENO', $event)"
        :value="getValue('StuConsumption.SAMTRADENO')"
        :disabled="!edit"
        title="SAM卡交易流水号"
      /> 
      <l-input 
        @input="setValue('StuConsumption.TRADECARDTYPE', $event)"
        :value="getValue('StuConsumption.TRADECARDTYPE')"
        :disabled="!edit"
        title="交易卡类型"
      /> 
      <l-input 
        @input="setValue('StuConsumption.TAC', $event)"
        :value="getValue('StuConsumption.TAC')"
        :disabled="!edit"
        title="验证码"
      /> 
      <l-input 
        @input="setValue('StuConsumption.ASN', $event)"
        :value="getValue('StuConsumption.ASN')"
        :disabled="!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-16 15:16 
 * 描  述：学生消费信息 
 */
  
/** 
 * 本段代码由移动端代码生成器输出，移动端须 2.2.0 版本及以上可以使用 
 * 请在移动端 /pages.json 中的 pages 字段中添加一条记录： 
 * { "path": "pages/EducationalAdministration/StuConsumption/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: { 
        StuConsumption: { 
          ID: { type: 'text', title: '记录序号' }, 
          ECODE: { type: 'text', title: '企业代码' }, 
          NOTECASE: { type: 'text', title: '钱包类型' }, 
          CUSTOMERID: { type: 'text', title: '一卡通账号' }, 
          OUTID: { type: 'text', title: '学工号' }, 
          CARDSN: { type: 'text', title: '持卡序号' }, 
          OPCOUNT: { type: 'text', title: '消费卡操作计数' }, 
          OPDT: { type: 'datetime', title: '操作时间', dateformat: '0' }, 
          ODDFARE: { type: 'text', title: '余额' }, 
          OPFARE: { type: 'text', title: '操作额' }, 
          MNGFARE: { type: 'text', title: '管理费' }, 
          ACCCODE: { type: 'text', title: '科目代码' }, 
          DSCRP: { type: 'text', title: '科目描述' }, 
          TERMID: { type: 'text', title: '终端编号' }, 
          RECNO: { type: 'text', title: '终端记录流水号' }, 
          UPLOADDATE: { type: 'text', title: '上传时间' }, 
          SAMCARDNO: { type: 'text', title: 'SAM卡号' }, 
          SAMTRADENO: { type: 'text', title: 'SAM卡交易流水号' }, 
          TRADECARDTYPE: { type: 'text', title: '交易卡类型' }, 
          TAC: { type: 'text', title: '验证码' }, 
          ASN: { type: 'text', title: '卡应用序列号' }, 
        }, 
  
      }, 
  
      // 数据源 
      dataSource: { 
        StuConsumption: { 
        }, 
  
      } 
    } 
  }, 
  
  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('/EducationalAdministration/StuConsumption/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('/EducationalAdministration/StuConsumption/save', postData, '表单提交保存失败').then(success => { 
            this.HIDE_LOADING() 
            if (!success) { 
              return
            } 
  
            this.EMIT('EducationalAdministrationStuConsumption-list-change') 
            this.NAV_BACK() 
            this.TOAST('提交保存成功') 
          }) 
          break
  
        case 'delete': 
          if (!(await this.CONFIRM('删除项目', '确定要删除本项吗？', true))) { 
            return
          } 
  
          this.LOADING('提交删除中...') 
          this.HTTP_POST('/EducationalAdministration/StuConsumption/delete', this.id, '删除失败').then(success => { 
            this.HIDE_LOADING() 
            if (!success) { 
              return
            } 
  
            this.EMIT('EducationalAdministrationStuConsumption-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> 