afa vor 5 Monaten
Ursprung
Commit
9015299ffe

+ 5 - 0
app/admin/common.php

@@ -57,3 +57,8 @@ if (!function_exists('resp_json')) {
     }
 }
 
+
+function isEnglish($char) {
+    $code = ord($char);
+    return ($code >= 0x00 && $code <= 0x7F); // ASCII码范围
+}

+ 64 - 8
app/admin/controller/user/MoneyLog.php

@@ -23,9 +23,9 @@ class MoneyLog extends Backend
     {
         parent::_initialize();
         $this->model = new MoneyLogModel();
-        //$this->assign('typeList',  site_config('addonsd.money_in_type'));
-        $list = site_config('addonsd.money_out_type');
-        //dump(  $list);die;
+        $this->assign('typeInList',  site_config('addonsd.money_in_type')); //
+        $this->assign('typeOutList',  site_config('addonsd.money_out_type'));
+
         $this->assign('bankList',  site_config('addonsd.bank_account'));
         $this->relationField=['users'];
     }
@@ -55,13 +55,63 @@ class MoneyLog extends Backend
 
     //修改
     #[Route("GET,POST","edit")]
-     public function edit()
+    public function edit(mixed $row=null)
     {
-        if(!$this->request->isPost()){
-            $catelist= site_config('addonsd.money_in_type');
-            $this->assign('parentList', $catelist);
+        $ids = $this->request->get('ids');
+        if(!$row || is_array($row)){
+            $row = $this->model->find($ids);
+        }
+        if (!$row) {
+            $this->error(__('没有找到记录'));
+        }
+        if(count($this->volidateFields)>0){
+            foreach ($this->volidateFields as $field=>$value){
+                if($row[$field]!=$value){
+                    $this->error(__('没有操作权限'));
+                }
+            }
+        }
+        if (false === $this->request->isPost()) {
+            $this->assign('parentList', self::getTypeAllByType($row->type));
+            $this->assign('row', $row);
+            return $this->fetch();
         }
-        return $this->_edit();
+        $params = array_merge($this->request->post("row/a"),$this->postParams);
+        if (empty($params)) {
+            $this->error(__('提交的参数不能为空'));
+        }
+        if(!$this->request->checkToken('__token__',['__token__'=>$this->request->post('__token__')])){
+            $this->error(__('token错误,请刷新页面重试'));
+        }
+        foreach ($params as &$value){
+            if(is_array($value)){
+                $value=implode(',',$value);
+            }
+            if($value===''){
+                $value=null;
+            }
+        }
+        $result = false;
+        Db::startTrans();
+        try {
+            if(isEnglish($params['type_name'])){
+                $arr = self::getTypeAllByType((int)$params['type']);
+                $params['type_name'] = $arr[$params['type_name']];
+            }
+            $result = $row->save($params);
+            if($this->callback){
+                $callback=$this->callback;
+                $callback($row);
+            }
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+        if (false === $result) {
+            $this->error(__('没有数据被更新'));
+        }
+        $this->success();
     }
 
   
@@ -125,4 +175,10 @@ class MoneyLog extends Backend
         return $this->_import();
     }
 
+    //获取分类
+    private static function getTypeAllByType(int $type)
+    {
+       return ($type== 1)?site_config('addonsd.money_in_type'):site_config('addonsd.money_out_type');
+    }
+
 }

+ 76 - 1
app/admin/view/user/money_log/edit.html

@@ -1 +1,76 @@
-{include vue="user/money_log/add" /}
+<template>
+    <el-card shadow="never" style="border: 0;">
+        <yun-form
+            ref="yunform"
+            @render="onFormRender"
+            @submit="onSubmit"
+            @success="onSuccess"
+            @fail="onFail"
+            :data="row"
+            :columns="columns">
+            <template #default>
+                {:token_field()}
+            </template>
+         
+        </yun-form>
+    </el-card>
+</template>
+<script>
+import form from "@components/Form.js";
+export default{
+    components:{
+        'YunForm':form
+    },
+    data:{
+        columns:[
+            {field:"id",title:"ID",edit:"hidden"},
+            {field:"type",title:"记账类型", edit: {form:'radio',change:'changeType'},rules:"required",searchList:{1:"收入", 2:"支出"} },
+            {field: 'type_name',title:__('账变名称'),edit: "select",rules:"required",searchList: Yunqi.data.parentList},
+            {field:"bank_account",title:"记账账户",edit:"radio",rules:"required", searchList: Yunqi.data.bankList},
+            {field:"change",title:"变动金额",edit:"text",rules:"required"},
+            {field:"create_date",title:"记账日期",edit:"date",rules:"required"},
+            {field:"remark",title:"备注",edit:"textarea"},
+        ],
+        row:Yunqi.data.row || {}
+    },
+ 
+    methods: {
+        changeType:function(data,row){
+            //这是监听
+            this.$refs.yunform.setValue('type_name','')
+            if(data == 1){
+            this.$refs.yunform.setField('type_name',  'searchList', Yunqi.data.typeInList);//为表单项设置值
+            }else{
+            this.$refs.yunform.setField('type_name',  'searchList', Yunqi.data.typeOutList);//为表单项设置值
+            }
+        },
+        onSubmit:function(rows){
+            //表单提交前执行,返回false可以阻止表单提交
+            /**
+             * form常用方法
+             * this.$refs.yunform.setError(field,message);//聚焦表单项并显示错误信息
+             * this.$refs.yunform.hideField(field);//隐藏表单项
+             * this.$refs.yunform.showField(field);//显示表单项
+             * this.$refs.yunform.setValue(field,value);//为表单项设置值
+             * this.$refs.yunform.getValue(field);//为获取表单项的值
+             * this.$refs.yunform.setField(field,key,value);//修改表单json的其他属性值,比如rules,title, searchList 等
+             */
+            return true;
+        },
+        onSuccess:function(response){
+            //表单提交成功后执行
+        },
+        onFail:function(err){
+            //表单提交失败后执行
+        },
+
+    },
+            //页面加载完成时执行
+      onShow:function(query){
+
+         
+      },
+}
+</script>
+<style>
+</style>