createVisit.js
4.08 KB
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
// packageCustomer/pages/createVisit/createVisit.js
import mapApi from "~/utils/mapapi/mapapi";
import { IMG_URL } from '~/utils/constantData'
Page({
data: {
IMG_URL: IMG_URL,
navHeight: 0,
showTimePicker: false,
timeValue: Date.now(),
minDate: new Date(2000, 0, 1).getTime(),
maxDate: new Date(2100, 0, 1).getTime(),
visitTimeText: "",
contactName: "",
content: "",
contentLength: 0,
fileList: [],
locationName: "",
latitude: null,
longitude: null,
infoData: {}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
onReady() {
this.resultDialog = this.selectComponent('#resultDialog')
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
onNavbarReady(e) {
const { height } = e.detail || {};
this.setData({ navHeight: height || 0 });
},
onContactInput(e) {
this.setData({
'infoData.contactName': e.detail.value
})
},
onContentInput(e) {
const val = e.detail.value || ""
this.setData({
'infoData.content': val,
contentLength: val.length
})
},
copy() {
wx.setClipboardData({
data: 1111,
})
},
// 上传图片
uploadImages() {
let _this = this
wx.chooseImage({
count: 1,
success(res) {
console.log(res)
let [tempFiles] = res.tempFilePaths
let tempFilesList = tempFiles.split('.')
let imgType = tempFilesList[tempFilesList.length - 1]
let type = imgType == 'unknown' ? 'jpg' : imgType
wx.getFileSystemManager().readFile({
filePath: tempFiles, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success(_res) {
wx.$util.showLoading('上传中...')
uploadImg({
file: `${type}@${_res.data}`
}).then(img => {
wx.$util.hideLoading()
let {
code,
data,
message
} = img
if (code == 0) {
_this.setData({
'infoData.attachmentList': data
})
} else {
wx.$util.showToast(message)
}
})
}
})
},
fail(err) {
console.log(err)
}
})
},
// 图片预览
previewImage(e) {
let { url, index } = e.currentTarget.dataset
let imageUrl = url?.map(v => { return v.fileUrl})
wx.previewImage({
urls: imageUrl,
current: imageUrl[index]
})
},
// 删除图片
deleteFile(e) {
let { index } = e.currentTarget.dataset
let { infoData } = this.data
infoData.attachmentList.splice(index, 1)
this.setData({infoData})
},
async getLocation() {
try {
const loc = await wx.getLocation({ type: "gcj02" })
const { latitude, longitude } = loc
const res = await mapApi.detailedAdrress({ location: `${latitude},${longitude}` })
const locationName = res?.result?.address || res?.result?.formatted_addresses?.recommend || "已定位"
this.setData({ latitude, longitude, locationName })
} catch (err) {
wx.showToast({ title: "定位失败,请检查权限", icon: "none" })
}
},
handleCancel() {
if (wx.$router && wx.$router.back) {
wx.$router.back()
} else {
wx.navigateBack({})
}
},
handleConfirm() {
const { infoData } = this.data
if (!infoData.visitTimeText || !infoData.contactName || !infoData.content) return wx.$api.showToast("请输入必填信息")
const res = {code: 1}
const okText = '我知道了'
if (this.resultDialog) {
if (res.code == 0) {
this.resultDialog.open({
type: 'success',
title: '新增拜访记录成功!',
description: '',
okText
})
} else {
this.resultDialog.open({
type: 'fail',
title: '新增拜访记录失败,请稍后重试',
description: '',
okText
})
}
}
},
// 接口请求结果弹窗确认
onDialogOk() {
this.handleCancel()
},
})