riku
2022-10-17 eb7366f400867d3f401fe60f06d848d6d1448457
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// pages/m_user/base_c/c_company-info/c_company-info.js
import {companyLedger} from '../../../../data/sceneInfo'
import userservice from '../../../../service/userservice'
import authservice from '../../../../service/authservice'
import ledgerservice from "../../../../service/ledgerservice"
import b_inputCheck from '../../../../base/behaviors/b_inputCheck'
import b_uploadLedger from '../../../m_ledger/behaviors/b_uploadLedger'
import b_loadingToast from '../../../../base/behaviors/b_loadingToast'
 
const app = getApp()
 
Component({
  behaviors: [b_inputCheck, b_uploadLedger, b_loadingToast],
  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {
    submitText: {
      type: String,
      value: '提交'
    },
    sceneType: {
      type: String,
      value: '1'
    },
  },
  /**
   * 页面的初始数据
   */
  data: {
    sceneTypes: [
      {value: '1', name: '餐饮'},
      {value: '7', name: '汽修'},
      {value: '6', name: '工业企业' },
      {value: '2', name: '工地'},
      {value: '3', name: '码头'},
      {value: '4', name: '堆场'},
      {value: '5', name: '搅拌站' },
    ],
    sceneTypeIndex: 0,
    msg: [{
        name: "企业名称",
        id: "ciName",
        input: true,
        value: '',
        noValue: false,
      },
      {
        name: "企业地址",
        id: "ciAddress",
        input: true,
        value: '',
        noValue: false,
      },
      {
        name: "信用代码",
        id: "ciOrgCode",
        input: true,
        value: "",
        noValue: false,
      },
      {
        name: "法人",
        id: "ciJuridicalPerson",
        input: true,
        value: '',
        noValue: false,
      },
      {
        name: "联系人",
        id: "ciContactName",
        input: true,
        value: '',
        noValue: false,
      },
      {
        name: "联系方式",
        id: "ciTelephone",
        input: true,
        value: '',
        noValue: false,
      },
    ],
  },
 
  ready() {
    this.setData({
      loadingText: '上传中',
      loadCompleteText: '上传完成'
    })
 
    this.setData({
      ledger: companyLedger[this.data.sceneType]
    })
    this.getCompanyInfo()
  },
 
  /**
   * 组件的方法列表
   */
  methods: {
    changeSceneType(e) {
      let i = e.detail.value
      this.setData({
        sceneTypeIndex: i
      })
    },
 
    //获取企业信息
    getCompanyInfo() {
      var that = this
      userservice.getBaseInfo(app.globalData.accessToken.userId, {
        success(data) {
          const msg = that.data.msg
          if (data.company != null) {
            const info = data.company
            msg[0].value = info.ciName
            msg[1].value = info.ciAddress
            msg[2].value = info.ciOrgCode
            msg[3].value = info.ciJuridicalPerson
            msg[4].value = info.ciContactName
            msg[5].value = info.ciTelephone
            that.setData({
              msg, info
            })
          }
        }
      }, app.globalData.accessToken.openId)
      ledgerservice.getLedgerDetail(
        app.globalData.accessToken.userId, that.data.ledger.ledgerSubTypeId, that.data.ledger.sceneType, undefined, {
          success(res) {
            if (res.length > 0) {
              let detail = res[0]
              if (detail.upLoad) {
                let imgFiles = [{
                  url: detail.path1[0],
                  loading: false
                }]
                that.setData({
                  imgFiles
                })
              }
            }
          }
        })
    },
 
    //提交企业信息
    _submit() {
      var that = this
      this.setData({loading: true})
      authservice.authCompany(app.globalData.accessToken.openId, this.data.info, {
        success(res) {
          that.submintLedger()
        },
      })
    },
 
    //提交图片信息
    submintLedger() {
      if (this.data.imgFiles.length == 0) {
        this.setData({
          loading: false
        })
        wx.navigateBack({
          delta: 1,
        })
        return
      }
      if (this.data.imgFiles[0].url.indexOf('http') != -1) {
        wx.downloadFile({
          url: this.data.imgFiles[0].url,
          success: (res) => {
            const imgPath = res.tempFilePath
            this.data.imgFiles[0].url = imgPath
            this._uploadLedger()
          }
        })
      } else {
        this._uploadLedger()
      }
    },
 
    //上传完成后,回退
    _success(res) {
      wx.navigateBack({
        delta: 1,
      })
    }
    
  }
})