95 lines
2.4 KiB
TypeScript
95 lines
2.4 KiB
TypeScript
import RepairPage from '@/pages/repair/repair';
|
|
import Taro from '@tarojs/taro';
|
|
import pt from '@/plain-text';
|
|
import wechatUser, { UserInfo } from '@/wechat';
|
|
import { defaultAvatar, tmplIds } from '@/common';
|
|
import { getUrl } from '.';
|
|
|
|
const relaunchInterval = 1000;
|
|
|
|
export function submitTicket(that: RepairPage) {
|
|
that.setState({
|
|
isLoading: true,
|
|
});
|
|
if (!wechatUser.getAccess()) {
|
|
const userInfo = wechatUser.getInfo();
|
|
if (userInfo.name == '' || userInfo.phone == '') {
|
|
Taro.request({
|
|
url: getUrl('/user/update'),
|
|
method: 'POST',
|
|
data: {
|
|
token: 'token_test',
|
|
name: that.state.owner,
|
|
phone: that.state.phone,
|
|
},
|
|
})
|
|
.then(() => {
|
|
const userTicketInfo: UserInfo = {
|
|
name: that.state.owner,
|
|
phone: that.state.phone,
|
|
avatar: defaultAvatar,
|
|
};
|
|
wechatUser.setInfo(userTicketInfo);
|
|
})
|
|
.catch((err) => {
|
|
console.log(err);
|
|
Taro.atMessage({
|
|
message: pt.get().button.submitText.error + err.toString(),
|
|
type: 'error',
|
|
});
|
|
});
|
|
}
|
|
}
|
|
Taro.request({
|
|
url: getUrl('/tickets/create'),
|
|
method: 'POST',
|
|
data: {
|
|
token: 'token_test',
|
|
type: that.state.type,
|
|
device: that.state.device,
|
|
deviceModel: that.state.deviceModel,
|
|
owner: that.state.owner,
|
|
phone: that.state.phone,
|
|
description: that.state.description,
|
|
accessories: that.state.checkedList,
|
|
},
|
|
})
|
|
.then((res) => {
|
|
console.log(res.data);
|
|
that.setState({
|
|
isLoading: false,
|
|
});
|
|
Taro.atMessage({
|
|
message: pt.get().button.submitText.success,
|
|
type: 'success',
|
|
});
|
|
Taro.requestSubscribeMessage({
|
|
tmplIds: tmplIds,
|
|
success: function (re) {
|
|
console.log(re);
|
|
},
|
|
fail: function (err) {
|
|
console.log(err);
|
|
},
|
|
complete: function () {
|
|
setTimeout(() => {
|
|
Taro.reLaunch({
|
|
url: '/pages/repair/repair',
|
|
});
|
|
}, relaunchInterval);
|
|
},
|
|
entityIds: tmplIds,
|
|
});
|
|
})
|
|
.catch((err) => {
|
|
console.log(err);
|
|
that.setState({
|
|
isLoading: false,
|
|
});
|
|
Taro.atMessage({
|
|
message: pt.get().button.submitText.error + err.toString(),
|
|
type: 'error',
|
|
});
|
|
});
|
|
}
|