张延森 4 gadus atpakaļ
vecāks
revīzija
6db0bd57d3
2 mainītis faili ar 71 papildinājumiem un 21 dzēšanām
  1. 66
    21
      src/pages/shop/edit/index.jsx
  2. 5
    0
      src/pages/shop/index.jsx

+ 66
- 21
src/pages/shop/edit/index.jsx Parādīt failu

@@ -1,5 +1,5 @@
1 1
 import React, { useEffect, useState } from "react";
2
-import Taro from "@tarojs/taro";
2
+import Taro, { useRouter } from "@tarojs/taro";
3 3
 import { View, Input, Text, Image } from "@tarojs/components";
4 4
 import Layout from "../../../layout/index";
5 5
 import Tab from "../../../compents/tab/index";
@@ -7,12 +7,16 @@ import Container from "../../../compents/container/index";
7 7
 import uploadicon from "../../../assets/uploadicon.png";
8 8
 import "./index.scss";
9 9
 import request, { uploadFiles } from "../../../util/request";
10
+import getQueryValue from "../../../util/getQueryValue";
10 11
 import IsLogin from "../../../layout/IsLogin";
11 12
 
12 13
 const index = props => {
14
+  const [shopInfo, setShopInfo] = useState({});
13 15
   const [name, setName] = useState("");
14 16
   const [imgUrl, setImgUrl] = useState("");
15
-  useEffect(() => {}, []);
17
+  const queryParams = getQueryValue() || {}
18
+  
19
+  const shopId = queryParams.id
16 20
 
17 21
   const editShopKeeper = () => {
18 22
     if (!name) {
@@ -31,28 +35,54 @@ const index = props => {
31 35
       });
32 36
       return;
33 37
     }
34
-    request({
35
-      url: "/taShop",
36
-      data: { name: name, logo: imgUrl },
37
-      method: "post"
38
-    }).then(res => {
39
-      Taro.showModal({
40
-        title: "新增成功",
41
-        content: "点击确认按钮,返回上级菜单",
42
-        showCancel: false,
43
-        success: function(res) {
44
-          if (res.confirm) {
45
-            console.log("用户点击确定");
46 38
 
47
-            Taro.navigateBack({
48
-              delta: 1
49
-            });
50
-          } else if (res.cancel) {
51
-            console.log("用户点击取消");
39
+    if (!shopId) {
40
+      request({
41
+        url: "/taShop",
42
+        data: { name: name, logo: imgUrl },
43
+        method: "post"
44
+      }).then(res => {
45
+        Taro.showModal({
46
+          title: "新增成功",
47
+          content: "点击确认按钮,返回上级菜单",
48
+          showCancel: false,
49
+          success: function(res) {
50
+            if (res.confirm) {
51
+              console.log("用户点击确定");
52
+  
53
+              Taro.navigateBack({
54
+                delta: 1
55
+              });
56
+            } else if (res.cancel) {
57
+              console.log("用户点击取消");
58
+            }
52 59
           }
53
-        }
60
+        });
54 61
       });
55
-    });
62
+    } else {
63
+      request({
64
+        url: `/taShop/${shopId}`,
65
+        data: { shopId, name: name, logo: imgUrl },
66
+        method: "put"
67
+      }).then(res => {
68
+        Taro.showModal({
69
+          title: "更新成功",
70
+          content: "点击确认按钮,返回上级菜单",
71
+          showCancel: false,
72
+          success: function(res) {
73
+            if (res.confirm) {
74
+              console.log("用户点击确定");
75
+  
76
+              Taro.navigateBack({
77
+                delta: 1
78
+              });
79
+            } else if (res.cancel) {
80
+              console.log("用户点击取消");
81
+            }
82
+          }
83
+        });
84
+      });
85
+    }
56 86
   };
57 87
   function handNameChange(e) {
58 88
     setName(e.detail.value);
@@ -70,6 +100,21 @@ const index = props => {
70 100
     });
71 101
   };
72 102
 
103
+  useEffect(() => {
104
+    if (shopId) {
105
+      request({
106
+        url: `/taShop/${shopId}`,
107
+        method: "get"
108
+      }).then(res => {
109
+        console.log('--------->', res)
110
+        const data = res.data.data
111
+        setShopInfo(data)
112
+        setName(data.name)
113
+        setImgUrl(data.logo)
114
+      });
115
+    }
116
+  }, [shopId])
117
+
73 118
   return (
74 119
     <IsLogin>
75 120
       <View className="addnewhouse">

+ 5
- 0
src/pages/shop/index.jsx Parādīt failu

@@ -93,6 +93,11 @@ const account = props => {
93 93
           >
94 94
             店主
95 95
           </Text>
96
+          <Text onClick={() => {
97
+              Taro.navigateTo({
98
+                url: `/pages/shop/edit/index?id=${list[index].shopId}`
99
+              })
100
+            }}>编辑</Text>
96 101
           <Text onClick={() => onDelete(list[index].shopId)}>删除</Text>
97 102
         </View>
98 103
       </ContainerLayout>