陈鹏铭 3 mēneši atpakaļ
vecāks
revīzija
eaab6b6777
2 mainītis faili ar 160 papildinājumiem un 149 dzēšanām
  1. 119 119
      src/pages/cityDangerReport/add.vue
  2. 41 30
      src/pages/cityDangerReport/index.vue

+ 119 - 119
src/pages/cityDangerReport/add.vue

@@ -101,137 +101,137 @@
 </template>
 
 <script>
-import { addForApp, getTroubleDetail } from "@/service/api_company.js";
-import { upload } from "@/service/api_upload";
-import { Toast } from "vant";
+import { addForApp, getTroubleDetail } from '@/service/api_company.js'
+import { upload } from '@/service/api_upload'
+import { Toast } from 'vant'
 export default {
-  data() {
-    return {
-      show: false,
-      columns: [
-        { label: "梁溪区", value: 320213, isSelected: false },
-        { label: "锡山区", value: 320205, isSelected: false },
-        { label: "惠山区", value: 320206, isSelected: false },
-        { label: "滨湖区", value: 320211, isSelected: false },
-        { label: "新吴区", value: 320214, isSelected: false },
-        { label: "经开区", value: 320299, isSelected: false },
-        { label: "江阴市", value: 320281, isSelected: false },
-        { label: "宜兴市", value: 320282, isSelected: false },
-      ],
-      form: {
-        createdBy: "10008611",
-      },
-      entryForm: [],
-      fileList: [
-        // { url: 'https://cloud-image', isImage: true },
-      ],
-    };
-  },
-  methods: {
+    data() {
+        return {
+            show: false,
+            columns: [
+                { label: '梁溪区', value: 320213, isSelected: false },
+                { label: '锡山区', value: 320205, isSelected: false },
+                { label: '惠山区', value: 320206, isSelected: false },
+                { label: '滨湖区', value: 320211, isSelected: false },
+                { label: '新吴区', value: 320214, isSelected: false },
+                { label: '经开区', value: 320299, isSelected: false },
+                { label: '江阴市', value: 320281, isSelected: false },
+                { label: '宜兴市', value: 320282, isSelected: false }
+            ],
+            form: {
+                createdBy: '10008611'
+            },
+            entryForm: [],
+            fileList: [
+                // { url: 'https://cloud-image', isImage: true },
+            ]
+        }
+    },
+    methods: {
 
-    async addForm() {
-      console.log(this.fileList);
-      console.log(this.form);
-      if (
-        !this.form.hiddenTroubleDescription ||
+        async addForm() {
+            console.log(this.fileList)
+            console.log(this.form)
+            if (
+                !this.form.hiddenTroubleDescription ||
         this.form.hiddenTroubleDescription.length == 0
-      ) {
-        return Toast("请填写隐患描述");
-      }
-      if (!this.form.reportPeople || this.form.reportPeople.length == 0) {
-        return Toast("请填写联系人");
-      }
-      if (!this.form.reportPeopleTel || this.form.reportPeopleTel.length == 0) {
-        return Toast("请填写联系电话");
-      }
-      if (!this.form.area || this.form.area.length == 0) {
-        return Toast("请选择所在区域");
-      }
-      if (
-        !this.form.hiddenTroubleAddress ||
+            ) {
+                return Toast('请填写隐患描述')
+            }
+            if (!this.form.reportPeople || this.form.reportPeople.length == 0) {
+                return Toast('请填写联系人')
+            }
+            if (!this.form.reportPeopleTel || this.form.reportPeopleTel.length == 0) {
+                return Toast('请填写联系电话')
+            }
+            if (!this.form.area || this.form.area.length == 0) {
+                return Toast('请选择所在区域')
+            }
+            if (
+                !this.form.hiddenTroubleAddress ||
         this.form.hiddenTroubleAddress.length == 0
-      ) {
-        return Toast("请填写隐患位置");
-      }
-      let form = { ...this.form };
-      form.scenePhoto = JSON.stringify(this.entryForm);
-      let data = await addForApp(form);
-      console.log(data);
-      if (data.code == 200) {
-        Toast("提交成功");
-        this.$router.go(-1);
-      }
-    },
-    async getTroubleDetail() {
-      let data = await getTroubleDetail({ id: this.$route.query.id });
-      this.form = data;
-      let index = this.columns.findIndex((e) => e.value == data.area);
-      console.log(this.columns[index]);
-      console.log(JSON.parse(data.scenePhoto));
-      this.entryForm = JSON.parse(data.scenePhoto);
-      this.form.areaName = this.columns[index].label;
-    },
-    uploadImg(file) {
-      const formParam = new FormData(); // 创建form对象
-      formParam.append("file", file.file); // 通过append向form对象添加数据
-      const config = {
-        headers: {
-          "Content-Type": "multipart/form-data",
-          "MVVM-Key": String(new Date().getTime()),
-          xx: "anything",
-        }, // 这里是重点,需要和后台沟通好请求头,Content-Type不一定是这个值
-      }; // 添加请求头
-      return new Promise((resolve, reject) => {
-        upload(formParam, config)
-          .then((response) => {
-            console.log(response);
-            if (response.data) {
-              this.entryForm[this.entryForm.length - 1].url = response.data.msg;
-              this.entryForm[this.entryForm.length - 1].content = null;
-              this.entryForm[this.entryForm.length - 1].name =
-                response.data.name;
+            ) {
+                return Toast('请填写隐患位置')
+            }
+            const form = { ...this.form }
+            form.scenePhoto = JSON.stringify(this.entryForm)
+            const data = await addForApp(form)
+            console.log(data)
+            if (data.code == 200) {
+                Toast('提交成功')
+                this.$router.go(-1)
+            }
+        },
+        async getTroubleDetail() {
+            const data = await getTroubleDetail({ id: this.$route.query.id })
+            this.form = data
+            const index = this.columns.findIndex((e) => e.value == data.area)
+            console.log(this.columns[index])
+            console.log(JSON.parse(data.scenePhoto))
+            this.entryForm = JSON.parse(data.scenePhoto)
+            this.form.areaName = this.columns[index].label
+        },
+        uploadImg(file) {
+            const formParam = new FormData() // 创建form对象
+            formParam.append('file', file.file) // 通过append向form对象添加数据
+            const config = {
+                headers: {
+                    'Content-Type': 'multipart/form-data',
+                    'MVVM-Key': String(new Date().getTime()),
+                    xx: 'anything'
+                } // 这里是重点,需要和后台沟通好请求头,Content-Type不一定是这个值
+            } // 添加请求头
+            return new Promise((resolve, reject) => {
+                upload(formParam, config)
+                    .then((response) => {
+                        console.log(response)
+                        if (response.data) {
+                            this.entryForm[this.entryForm.length - 1].url = response.data.msg
+                            this.entryForm[this.entryForm.length - 1].content = null
+                            this.entryForm[this.entryForm.length - 1].name =
+                response.data.name
 
-              Toast("上传成功");
-              Toast.clear();
-              console.log(this.entryForm);
+                            Toast('上传成功')
+                            Toast.clear()
+                            console.log(this.entryForm)
+                        } else {
+                            Toast('上传失败')
+                            Toast.clear()
+                        }
+                    })
+                    .catch((err, x) => {
+                        reject(err, x)
+                    })
+            })
+        },
+        afterRead(file) {
+            if (file instanceof Array) {
+                file.map((v) => {
+                    this.uploadImg(v)
+                })
             } else {
-              Toast("上传失败");
-              Toast.clear();
+                this.uploadImg(file)
             }
-          })
-          .catch((err, x) => {
-            reject(err, x);
-          });
-      });
-    },
-    afterRead(file) {
-      if (file instanceof Array) {
-        file.map((v) => {
-          this.uploadImg(v);
-        });
-      } else {
-        this.uploadImg(file);
-      }
+        },
+        onConfirm(e) {
+            this.form.area = e.value
+            this.form.areaName = e.label
+            console.log(e)
+            this.show = false
+        },
+        onCancel() {
+            this.show = false
+        }
     },
-    onConfirm(e) {
-      this.form.area = e.value;
-      this.form.areaName = e.label;
-      console.log(e);
-      this.show = false;
-    },
-    onCancel() {
-      this.show = false;
-    },
-  },
-  mounted() {
+    mounted() {
         console.log('this.$route.params', this.$route.params, this.$route.params.openId)
         // alert('openId'+this.$route.params.openId)
         this.form.createdBy = this.$route.params.openId
-    if (this.$route.query.id) {
-      this.getTroubleDetail();
+        if (this.$route.query.id) {
+            this.getTroubleDetail()
+        }
     }
-  },
-};
+}
 </script>
 
 <style lang="scss">

+ 41 - 30
src/pages/cityDangerReport/index.vue

@@ -74,58 +74,67 @@ export default {
             })
         },
         handleAuthorization() {
-             // alert(this.initCode)
-            const _this = this
-            ls.ready(function() {
-                ls.userAuth({
-                    appId: _this.appId // 从开放平台申请到的 appId
-                }, function(res) {
+            let _this= this
+            // fetchUserAccessToken(_this.search).then(res => {
+                // alert('获取用户访问令牌——:' + res)
+            this.getList()
+            // })
+            try {
+                // alert(this.initCode)
+                const _this = this
+                ls.ready(function() {
+                    ls.userAuth({
+                        appId: _this.appId // 从开放平台申请到的 appId
+                    }, function(res) {
                     // alert('res:' + JSON.stringify(res))
-                    if (res.code === 200) {
+                        if (res.code === 200) {
                         // // alert('requestCode:' + res.data.requestCode)
-                        const reqData = {
-                            requestCode: res.data.requestCode
-                        }
-                        fetchUserAccessToken(reqData).then(res => {
+                            const reqData = {
+                                requestCode: res.data.requestCode
+                            }
+                            fetchUserAccessToken(reqData).then(res => {
                             // alert('获取用户访问令牌——:' + res)
-                            getUserInfo({ userAccessToken: res }).then((res) => {
+                                getUserInfo({ userAccessToken: res }).then((res) => {
                                 // alert('用户信息——:' + JSON.stringify(res))
                                 // alert('用户信息1——:' + res.openId)
                                 // eslint-disable-next-line standard/object-curly-even-spacing
                                 // _this.$router.push({ name: urlname, params: { openId: res.openId, realName: res.realName }})
                                 // Toast('登录成功')
 
-                                _this.search.createdBy = res.openId
-                                // 执行下一步
-                                _this.getList()
-                            }).catch(e => {
-                                Toast(e)
+                                    _this.search.createdBy = res.openId
+                                    // 执行下一步
+                                    _this.getList()
+                                }).catch(e => {
+                                    Toast(e)
+                                })
                             })
-                        })
-                    } else if (res.code === 9005) {
+                        } else if (res.code === 9005) {
                         // 认证失败或登录失败
                         // console.log('认证失败或登录失败')
                         // alert('认证失败或登录失败')
                         // 如果在此处调用ls.close()关闭页面,需要延迟0.5秒执行,否则ls.close()会无效。
-                    } else {
+                        } else {
                         // 其余情况
                         // alert('userAuth error')
                         // 如果在此处调用ls.close()关闭页面,需要延迟0.5秒执行,否则ls.close()会无效。
-                    }
+                        }
+                    })
                 })
-            })
 
-            // 失败回调
-            ls.error(function(res) {
+                // 失败回调
+                ls.error(function(res) {
                 // 错误处理
                 // alert('失败回调')
-            })
+                })
 
-            ls.config({
-                debug: false, // 开发时建议把调试模式开启
-                appId: this.appId, // 从开放平台申请到的 appId
-                initCode: this.initCode // 从业务方自己后台请求到 initCode
-            })
+                ls.config({
+                    debug: false, // 开发时建议把调试模式开启
+                    appId: this.appId, // 从开放平台申请到的 appId
+                    initCode: this.initCode // 从业务方自己后台请求到 initCode
+                })
+            } catch (e) {
+                console.log(e)
+            }
         },
         // ===上面是灵锡用的===========================================================================
         toDetail(id) {
@@ -185,6 +194,8 @@ c
   color: rgba(13, 47, 118, 1);
   padding-right: 40px;
   font-size: 36px;
+    display: flex;
+    align-items: center;
 }
 
 .morebox4 {