Przeglądaj źródła

自动计算不行啊

FANGLH 8 lat temu
rodzic
commit
8d80460067

+ 91 - 35
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/erp/activity/oa/ExpenseReimbursementActivity.java

@@ -9,8 +9,6 @@ import android.content.Intent;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
-import android.text.Editable;
-import android.text.TextWatcher;
 import android.util.Log;
 import android.view.Gravity;
 import android.view.LayoutInflater;
@@ -32,6 +30,7 @@ import com.xzjmyk.pm.activity.AppConstant;
 import com.xzjmyk.pm.activity.R;
 import com.xzjmyk.pm.activity.bean.oa.SelectBean;
 import com.xzjmyk.pm.activity.ui.base.BaseActivity;
+import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
 import com.xzjmyk.pm.activity.ui.erp.util.ListUtils;
 import com.xzjmyk.pm.activity.ui.erp.view.NScrollerGridView;
 import com.xzjmyk.pm.activity.ui.tool.MultiImagePreviewActivity;
@@ -62,6 +61,10 @@ public class ExpenseReimbursementActivity extends BaseActivity implements View.O
     private Button btn_save;
     @ViewInject(R.id.gv_details_list)
     private NScrollerGridView gv_details_list;
+    @ViewInject(R.id.sum_money_tv)
+    private TextView sum_money_tv;
+    @ViewInject(R.id.detail_table_ll)
+    private LinearLayout detail_table_ll;
     private MyGridView mGridView;
     private GridViewAdapter mAdapter;
     private ArrayList<String> mPhotoList;
@@ -71,12 +74,9 @@ public class ExpenseReimbursementActivity extends BaseActivity implements View.O
     private static final int SELECT_REIMBURSEMENT_TYPE = 3;
     private static final int SELECT_CURRENCY = 4;
     private PopupWindow setWindow = null;//
-    private List<String> detailsData;  // 要展示的消费明细
-    private List<String> selected_detailsData; //点击后要返回的消费明细
     private GridDataAdapter gAdapter;
     private String[] TypeDatas =  {"类型1","类型2","类型3","类型4","类型5"};
     private String[] CurrencyDatas =  {"币种1","币种2","币种3","币种4","币种5"};
-
     @ViewInject(R.id.details_data_tv)
     private TextView details_data_tv;
     private Boolean initDetailDatas_initialization = false;
@@ -85,8 +85,11 @@ public class ExpenseReimbursementActivity extends BaseActivity implements View.O
     @ViewInject(R.id.table_details_list)
     private MyListView table_details_list;
     private DetailsTableAdapter dtAdapter;
-    private List<String> table_list_type;
-    private List<Double> table_list_money;
+    private List<String> detailsData;  // popwindow要展示的消费明细类型
+    private List<String> selected_detailsData; //点击后要返回的消费明细类型
+    private List<String> table_list_type; //表格里面新增的消费明细类型
+    private List<Double> table_list_money;//表格里面新增的消费明细金额
+    private double sum_money = 0.0; // 最后算的的总金额
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
@@ -112,16 +115,17 @@ public class ExpenseReimbursementActivity extends BaseActivity implements View.O
 
         mGridView = (MyGridView) findViewById(R.id.grid_view);
         findViewById(R.id.add_details_tv).setOnClickListener(this);
+        findViewById(R.id.automatic_calculation_tv).setOnClickListener(this);
         mPhotoList = new ArrayList<String>();
         mAdapter = new GridViewAdapter();
         mGridView.setAdapter(mAdapter);
+
+        detail_table_ll.setVisibility(View.GONE);
     }
 
     @Override
     public void onClick(View v) {
         switch (v.getId()){
-            case R.id.reimbursement_title_fet:
-                break;
             case R.id.reimbursement_type_fet:
                 doSingleSelect(TypeDatas,2,getString(R.string.Reimbursement_type),SELECT_REIMBURSEMENT_TYPE);
                 break;
@@ -131,16 +135,52 @@ public class ExpenseReimbursementActivity extends BaseActivity implements View.O
             case R.id.add_details_tv:
                 showPopupWindow();
                 break;
+            case R.id.automatic_calculation_tv:
+//                doAutoCalculateJudge();
+                break;
             case R.id.btn_save:
+                if (reimbursement_title_fet.testValidity() ){
+
+                }
                 break;
         }
     }
 
+    private void doAutoCalculateJudge() {
+        if (!ListUtils.isEmpty(table_list_money)) table_list_money.clear();
+        for (int i = 0; i < table_list_type.size(); i++) {
+            if (dtAdapter.getTable_list_money().get(i) != null){
+                table_list_money.add(CommonUtil.getTwoPointDouble(Double.valueOf(dtAdapter.getTable_list_money().get(i).toString())));
+            }
+            else {
+                ToastMessage("请输入消费金额");
+                return;
+            }
+        }
+        sum_money = 0.0;
+        if (ListUtils.isEmpty(table_list_money)){
+            ToastMessage("请输入消费金额");
+            return;
+        }
+
+        if (table_list_type.size() > table_list_money.size()){
+            ToastMessage("请输入完整的消费明细金额");
+            return;
+        }
+        Log.i("table_list_money",table_list_money.toString()+"");
+        for (int i = 0; i < table_list_money.size(); i++) {
+            sum_money = sum_money + Double.valueOf(table_list_money.get(i));
+            if (i == (table_list_money.size() - 1)){
+                sum_money_tv.setText(CommonUtil.getTwoPointDouble(sum_money)+"");
+            }
+        }
+    }
+
     private void showPopupWindow() {
         if (setWindow == null) initPopupWindow();
         setWindow.showAtLocation(getWindow().getDecorView().
                 findViewById(android.R.id.content), Gravity.BOTTOM, 0, 0);
-        if (VERSION_CODES  < 24)
+        if (VERSION_CODES  < 24) // API版本太高不断刷新View亮度,会有黑缝隙bug
             DisplayUtil.backgroundAlpha(this, 0.4f);
     }
     private void closePopupWindow() {
@@ -175,10 +215,8 @@ public class ExpenseReimbursementActivity extends BaseActivity implements View.O
             @Override
             public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                 GridDataAdapter.ViewModle modle = (GridDataAdapter.ViewModle) view.getTag();
-//                gAdapter.setSelected(position);
-
                 // TODO 记录当下点击的位置
-                if (selected_detailsData.contains(detailsData.get(position))){
+                if (!ListUtils.isEmpty(selected_detailsData) && selected_detailsData.contains(detailsData.get(position))){
                     selected_detailsData.remove(detailsData.get(position));
                 }else {
                     selected_detailsData.add(detailsData.get(position));
@@ -192,27 +230,29 @@ public class ExpenseReimbursementActivity extends BaseActivity implements View.O
         btn_sure.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
+                closePopupWindow();
                 if (ListUtils.isEmpty(selected_detailsData)) return;
-                details_data_tv.setText(selected_detailsData.toString());
                 for (int i = 0; i < selected_detailsData.size(); i++) {
                     table_list_type.add(selected_detailsData.get(i));
                     detailsData.remove(selected_detailsData.get(i));
                     if (i == (selected_detailsData.size()-1)){
                         dtAdapter.setTable_list_type(table_list_type);
-                        dtAdapter.setTable_list_money(table_list_money);
+//                        dtAdapter.setTable_list_money(table_list_money);
                         dtAdapter.notifyDataSetChanged();
+                        detail_table_ll.setVisibility(View.VISIBLE);
                         Log.i("selected_detailsData",selected_detailsData.toString()+"se");
                         Log.i("detailsData",detailsData.toString()+"de");
                         Log.i("table_list_type",table_list_type.toString()+"tlt");
                     }
                 }
-                closePopupWindow();
+                selected_detailsData.clear();
             }
         });
     }
 
     private void initAddDatas() {
         if (!ListUtils.isEmpty(selected_detailsData)) selected_detailsData.clear();
+        //TODO 接口返回
         if (initDetailDatas_initialization) return;
         for (int i = 0; i < 22; i++) {
             detailsData.add("明细" + i);
@@ -342,31 +382,46 @@ public class ExpenseReimbursementActivity extends BaseActivity implements View.O
                                 @Override
                                 public void onClick(DialogInterface dialog, int which) {
                                    table_list_type.remove(position);
-                                   if (!ListUtils.isEmpty(table_list_money) && table_list_money.get(position) != null){
-                                       table_list_money.remove(position);
+//                                   if (!ListUtils.isEmpty(table_list_money) && table_list_money.get(position) != null){
+//                                       table_list_money.remove(position);
+//                                   }
+                                   if (ListUtils.isEmpty(table_list_type)){
+                                       detail_table_ll.setVisibility(View.GONE);
+                                   }else {
+                                       notifyDataSetChanged();
                                    }
-                                   notifyDataSetChanged();
                                 }
                             }).show();
                 }
             });
-            viewHolder.details_money.addTextChangedListener(new TextWatcher() {
-                @Override
-                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
-
-                }
-
-                @Override
-                public void onTextChanged(CharSequence s, int start, int before, int count) {
-
-                }
-
-                @Override
-                public void afterTextChanged(Editable s) {
-                    double numberstrChche =  Double.parseDouble(s.toString());
-                    table_list_money.add(numberstrChche);
+            /*String s = viewHolder.details_money.getText().toString();
+            if (!StringUtils.isEmpty(s)){
+                double numberstrChche =  Double.parseDouble(s);
+                if (table_list_money == null){
+                    table_list_money.add(position, CommonUtil.getTwoPointDouble(numberstrChche));
+                }else {
+                    table_list_money.remove(position);
+                    table_list_money.add(position,CommonUtil.getTwoPointDouble(numberstrChche));
                 }
-            });
+            }*/
+
+//            viewHolder.details_money.addTextChangedListener(new TextWatcher() {
+//                @Override
+//                public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+//                @Override
+//                public void onTextChanged(CharSequence s, int start, int before, int count) {}
+//                @Override
+//                public void afterTextChanged(Editable s) {
+//                    if (StringUtils.isEmpty(s.toString())) return;
+//                    double numberstrChche =  Double.parseDouble(s.toString());
+//                    if (table_list_money == null){
+//                        table_list_money.add(position, CommonUtil.getTwoPointDouble(numberstrChche));
+//                    }else {
+//                        table_list_money.remove(position);
+//                        table_list_money.add(position,CommonUtil.getTwoPointDouble(numberstrChche));
+//                    }
+//                }
+//            });
             return convertView;
         }
         class ViewHolder{
@@ -513,6 +568,7 @@ public class ExpenseReimbursementActivity extends BaseActivity implements View.O
      * @param requestCode
      */
     private void doSingleSelect(String[] Datas, int type, String title, int requestCode) {
+        //TODO Datas为接口返回
         ArrayList<SelectBean> formBeaan = new ArrayList<>();
         SelectBean selectBean;
         for (int i = 0; i < Datas.length; i++) {

+ 11 - 7
WeiChat/src/main/res/layout/activity_expense_reimbursement.xml

@@ -170,12 +170,16 @@
                     android:layout_height="wrap_content"
                     android:text="如下表格"
                     android:layout_marginLeft="10dp"
+                    android:visibility="gone"
                     />
                 <LinearLayout
                     android:id="@+id/detail_table_ll"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
-                    android:orientation="vertical">
+                    android:orientation="vertical"
+                    android:layout_alignParentTop="true"
+                    android:layout_alignParentLeft="true"
+                    android:layout_alignParentStart="true">
                     <LinearLayout
                         android:id="@+id/detail_table_top_ll"
                         android:layout_width="match_parent"
@@ -195,7 +199,7 @@
                                 android:text="类型"
                                 android:layout_width="0dp"
                                 android:layout_height="wrap_content"
-                                android:layout_weight="1"
+                                android:layout_weight="2"
                                 android:paddingLeft="10dp"
                                 android:layout_gravity="center_vertical"/>
                             <View
@@ -204,7 +208,7 @@
                                 android:text="金额"
                                 android:layout_width="0dp"
                                 android:layout_height="wrap_content"
-                                android:layout_weight="1"
+                                android:layout_weight="2"
                                 android:paddingLeft="10dp"
                                 android:layout_gravity="center_vertical"
                                 />
@@ -215,8 +219,8 @@
                                 android:layout_width="0dp"
                                 android:layout_height="wrap_content"
                                 android:layout_weight="1"
-                                android:paddingLeft="10dp"
-                                android:layout_gravity="center_vertical"/>
+                                android:layout_gravity="center_vertical"
+                                android:gravity="center"/>
                             <View
                                 style="@style/expense_table_v_1dp"
                                 />
@@ -267,7 +271,6 @@
                                 android:layout_height="wrap_content"
                                 android:layout_toLeftOf="@+id/right_view_v"
                                 android:layout_alignParentRight="true"
-                                android:text="9999"
                                 android:layout_marginRight="30dp"
                                 android:layout_centerVertical="true"
                                 android:textColor="@color/red"/>
@@ -277,7 +280,8 @@
                                 android:text="总金额"
                                 android:layout_toLeftOf="@+id/sum_money_tv"
                                 android:layout_centerVertical="true"
-                                android:layout_marginRight="10dp"/>
+                                android:layout_marginRight="10dp"
+                                android:textColor="@color/text_main"/>
                         </RelativeLayout>
                         <View
                             style="@style/expense_table_h_1dp"/>

+ 11 - 7
WeiChat/src/main/res/layout/expense_details_table_item.xml

@@ -16,12 +16,12 @@
             style="@style/expense_table_v_1dp"/>
         <TextView
             android:id="@+id/details_type_tv"
-            android:hint="请输入明细金额"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
-            android:layout_weight="1"
+            android:layout_weight="2"
             android:paddingLeft="10dp"
-            android:layout_gravity="center_vertical"/>
+            android:layout_gravity="center_vertical"
+            android:textColor="@color/text_main"/>
         <View
             style="@style/expense_table_v_1dp"/>
 
@@ -29,22 +29,26 @@
             android:id="@+id/details_money_tv"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
-            android:layout_weight="1"
+            android:layout_weight="2"
             android:background="@null"
             android:hint="请输入明细金额"
             android:layout_gravity="center_vertical"
-            android:textColor="@color/dark_dark_grey"
+            android:textColor="@color/text_main"
             android:textSize="14sp"
             android:maxLength="10"
             android:inputType="number"
-            android:paddingLeft="10dp"/>
+            android:paddingLeft="10dp"
+            whatever:customRegexp="^([0-9](\.[0-9]+)?|10)$"
+            whatever:testType="regexp"
+            whatever:testErrorString="限制输入10位有效双精度数值"
+        />
 
         <View
             style="@style/expense_table_v_1dp"/>
         <ImageView
             android:id="@+id/details_delete_im"
             android:layout_width="0dp"
-            android:layout_height="wrap_content"
+            android:layout_height="20dp"
             android:layout_weight="1"
             android:paddingLeft="10dp"
             android:layout_gravity="center_vertical"