Pārlūkot izejas kodu

小程序:首页接口对接

panyong 2 gadi atpakaļ
vecāks
revīzija
eecd91a5d1
1 mainītis faili ar 60 papildinājumiem un 7 dzēšanām
  1. 60 7
      htmldev/wxMini/pages/businessApply/businessApply.js

+ 60 - 7
htmldev/wxMini/pages/businessApply/businessApply.js

@@ -1,6 +1,8 @@
 const uploadJS = require('../../mixin/upload.js')
-const { userApplyShop, mockData } = require('./api/index')
+const { userApplyShop } = require('./api/index')
 const { isMobile } = require('../../utils/validate')
+const { getShopDetail } = require('../../api/common')
+const { fen2Yuan } = require('../../utils/util')
 const app = getApp()
 
 Page({
@@ -24,8 +26,7 @@ Page({
         'address_name': '', // 起点位置名称
         'name': ''
       }, // 店铺地址
-      'shop_remark': '', // 备注
-      ...mockData
+      'shop_remark': '' // 备注
     },
     booLock: false,
     userInfo: {}
@@ -36,7 +37,10 @@ Page({
    * 生命周期函数--监听页面加载
    */
   onLoad(options) {
-
+    this.bindCallBack()
+    app.fetchUserDataCallback = () => {
+      this.bindCallBack()
+    }
   },
 
   /**
@@ -50,9 +54,7 @@ Page({
    * 生命周期函数--监听页面显示
    */
   onShow() {
-    this.setData({
-      userInfo: app.globalData.userInfo
-    })
+
   },
 
   /**
@@ -67,6 +69,57 @@ Page({
    */
   onUnload() {
 
+  },
+  bindCallBack() {
+    this.setData({
+      userInfo: app.globalData.userInfo
+    }, () => {
+      this.fetchShopDetail()
+    })
+  },
+  async fetchShopDetail() {
+    const { user_shop_id } = this.data.userInfo
+    let temp = {}
+
+    if (!user_shop_id) {
+      return
+    }
+
+    try {
+      const { status, data, msg } = await getShopDetail(user_shop_id)
+      if (status) {
+
+        for (let key in data) {
+          let value = data[key]
+          if ((Array.isArray(value) && value.length >= 1) || (Object.prototype.toString.call(value) === '[object Object]') || (typeof value === 'string' && value) || typeof value === 'number') {
+
+            if (key === 'user_code_url' || key === 'shop_img_url') {
+              value = [
+                {
+                  'formkey': key,
+                  'url': value
+                }
+              ]
+            }
+
+            if (key === 'shop_address') {
+              value = JSON.parse(value)
+            }
+
+            if (this.data.form.hasOwnProperty(key)) {
+              temp[`form.${key}`] = value
+            }
+          }
+        }
+
+        this.setData(temp)
+      } else {
+        wx.showToast({
+          title: msg,
+          icon: 'none'
+        })
+      }
+    } catch (err) {}
   },
   ...uploadJS,
   uploadCallBack(res) {