123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- const app = getApp();
- const api = app.api;
- import WxValidate from '../../../utils/WxValidate'
- import {pointNum} from "../../../utils/util"
- Page({
-
- data: {
- agreement:true,
- invoiceInfo:null,
- pickerInvoiceKindIndex:0,
- pickerInvoiceKind:[
- {
- name:"个人",
- value:0,
- },
- {
- name:"单位名称",
- value:1,
- }
- ],
- formData: {
- invoiceType:0,
- buyIdNumber:"",
- buyName:"",
- invoiceKind:1,
- invoiceOrderId:null,
-
- },
- rules: {
-
- },
- messages: {
-
- },
- isSubmit:false
- },
-
- onLoad: function (options) {
- const { rules, messages } = this.data;
- this.WxValidate = new WxValidate(rules, messages);
- console.log('WxValidate',this.WxValidate);
- this.setData({
- id:options.id,
- 'formData.invoiceOrderId':options.id||null,
- 'formData.invoiceId':options.invoiceId||null
- })
- wx.hideShareMenu();
- },
-
- onReady: function () {
- },
-
- onShow: function () {
- this.setData({
- invoiceInfo: wx.getStorageSync('invoiceInfo')
- })
- },
- changeAgreement(){
- this.setData({
- agreement:!this.data.agreement
- });
- },
-
- changeInput(e){
- console.log(e);
- const id = e.currentTarget.id;
- const number = e.currentTarget.dataset.number;
- let value = e.detail.value;
- if(number=='pointNum'){
- value=pointNum(value)
- }
- this.setData({
- [id]: value
- });
- },
-
- bindPickerChangeKind: function(e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- pickerInvoiceKindIndex: e.detail.value,
- })
- },
-
- saveData() {
- const {formData,pickerInvoiceKindIndex,agreement,isSubmit} = this.data;
- if(isSubmit){
- return
- }
-
- if(pickerInvoiceKindIndex==0){
- if(formData.buyName==''){
- wx.showToast({
- title: '请输入开票个人姓名',
- icon: 'none',
- duration: 2000
- });
- return false
- }
- }else{
- if(formData.buyName==''){
- wx.showToast({
- title: '请输入开票单位名称',
- icon: 'none',
- duration: 2000
- });
- return false
- }
- if(formData.buyIdNumber==''){
- wx.showToast({
- title: '纳税人识别号',
- icon: 'none',
- duration: 2000
- });
- return false
- }
- }
- if (!this.WxValidate.checkForm(formData)) {
- const error = this.WxValidate.errorList[0];
- wx.showToast({
- title: error.msg,
- icon: 'none',
- duration: 2000
- })
- return false
- }
- if(!agreement){
- wx.showToast({
- title: '请勾选阅读法律申明和免责申明',
- icon: 'none',
- duration: 2000
- })
- return false
- }
- this.setData({
- isSubmit:true
- })
- app.post(api.addInvoice, formData).then(res => {
- wx.showToast({
- title: '服务费开票成功',
- duration: 2000
- });
-
- this.setData({
- isSubmit:false,
- });
- wx.navigateTo({
- url:`/pages/invoice/myInvoice/myInvoice`
- })
-
- }).catch(()=>{
- this.setData({
- isSubmit:false
- })
- })
- },
-
- getAddress(){
- const settingAddress=function(res){
- this.setData({
- 'formData.receiverName':res.userName,
- 'formData.receiverAddress':`${res.provinceName}${res.cityName}${res.countyName}${res.detailInfo}`,
- 'formData.receiverPhoneNumber':res.telNumber,
- })
- }.bind(this);
- wx.chooseAddress({
- success:(res)=>{
-
- settingAddress(res);
- },
- fail:(error)=>{
-
- if(error.errMsg=="chooseAddress:fail auth deny"){
- wx.showModal({
- title: '是否授权通讯地址',
- content: '需要获取您通讯地址,请确认授权,否则获取地址功能将无法使用',
- success: (tip)=> {
- if (tip.confirm) {
- wx.openSetting({
- success: function (data) {
-
- if (data.authSetting["scope.address"] === true) {
- wx.showToast({
- title: '授权成功',
- icon: 'success',
- duration: 1000
- });
-
- wx.chooseAddress({
- success: (res)=> {
- settingAddress(res);
- },
- })
- } else {
- wx.showToast({
- title: '授权失败',
- icon: 'success',
- duration: 1000
- })
- }
- }
- })
- }
- }
- })
- }
- }
- })
- },
-
- onHide: function () {
- },
-
- onUnload: function () {
- },
-
- onPullDownRefresh: function () {
- },
-
- onReachBottom: function () {
- },
-
- onShareAppMessage: function () {
- }
- })
|