123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531 |
- // pages/invoice/editInvoice/editInvoice.js
- const app = getApp();
- const api = app.api;
- import WxValidate from '../../../utils/WxValidate'
- import {pointNum} from "../../../utils/util"
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- saleInfo:null,
- pickerInvoiceKindIndex:0,
- pickerInvoiceKind:[
- {
- name:"增值税普通发票",
- value:0,
- },
- // {
- // name:"增值税开票",
- // value:1,
- // }
- ],
- /* pickerInvoiceKind:[
- {
- name:"普通开票",
- value:0,
- },
- {
- name:"服务费开票",
- value:1,
- }
- ],*/
- pickerServeIndex:"",
- // pickerServe:[
- // '会务服务',
- // '展览展示服务',
- // '文化艺术交流策划',
- // '企业管理咨询',
- // '商务信息咨询',
- // '市场信息咨询与调查',
- // '企业营销策划',
- // '企业形象策划'
- // ],
- pickerServe:[
- '绘画作品',
- '雕塑作品',
- '装置作品',
- '综合作品',
- '摄影作品',
- '新媒体作品',
- '影像作品',
- '陶瓷作品'
- ],
- invoiceBuySearchValue:'',
- invoiceBuyFocus:false,
- invoiceBuyList:[],
- isShowInvoiceBuyList:false,
- searchTimer:null,
- formData: {
- amount:"", //合计开票金额
- buyIdNumber:"", //购买方纳税人识别号
- buyName:"", //购买方
- invoiceKind:0, //0普通开票 1服务费开票
- invoiceOrderId:20, //订单id
- invoiceType:0, //发票类型
- provinceName:"",//
- cityName:"",
- expAreaName:"",
- address:"",
- // receiverAddress:"", //收件人地址
- /* receiverName:"", //收件人姓名
- receiverPhoneNumber:"", //收件人电话*/
- name:"",//收件人姓名
- mobile:"",//收件人姓名
- serviceContentInfo:{
- serverName:"",
- number:1,
- },
- saleId:"", //销售方id
- saleIdNumber:"", //销售方身份证
- saleName:"", //销售方信息
- salePhoneNumber:"", //销售方电话
- },
- rules: {
- invoiceType:{
- required: true,
- },
- myServerName:{
- required: true,
- },
- buyName: {
- required: true
- },
- buyIdNumber: {
- required: true,
- egAndNumber: true,
- },
- amount: {
- required: true,
- number:true,
- },
- invoiceKind:{
- required: true
- },
- address:{
- required: true,
- },
- saleId:{
- required: true
- }
- },
- messages: {
- invoiceType:{
- required: '请选择发票类型',
- },
- myServerName:{
- required: '请选择服务内容',
- },
- amount: {
- required: '请填写开票金额',
- number:"请输入正确的开票金额"
- },
- buyIdNumber: {
- required: '请填写纳税人识别号',
- egAndNumber: '税号只能输入数字和英文'
- },
- buyName: {
- required: '请填写发票抬头'
- },
- invoiceKind:{
- required: '请填写开票种类',
- },
- address:{
- required: '请填写发票收货地址',
- },
- saleId:{
- required: '请选择销售方'
- }
- },
- isValidate:false,
- isSubmit:false
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- const { rules, messages } = this.data;
- this.WxValidate = new WxValidate(rules, messages);
- console.log('WxValidate',this.WxValidate);
- this.setData({
- invoiceId:options.invoiceId||'',
- invoiceOrderId:options.id||'',
- 'formData.invoiceId':options.invoiceId||'',
- 'formData.invoiceOrderId':options.id||''
- },()=>{
- //有提交过发票 未更改状态获取之前记录
- if(options.invoiceId&&options.invoiceId!=""){
- this.getData();
- }
- });
- wx.hideShareMenu();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.getInvoiceBuy(null);
- this.getSaleList();
- },
- /** input change value**/
- 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
- });
- },
- /** pick value**/
- bindPickerChangeKind: function(e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- pickerInvoiceKindIndex: e.detail.value,
- 'formData.invoiceType':e.detail.value
- },()=>{
- this.validateForm()
- })
- },
- bindPickerChangeServe: function(e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- pickerServeIndex: e.detail.value,
- 'formData.myServerName':e.detail.value,
- 'formData.serviceContentInfo.serverName':this.data.pickerServe[e.detail.value]
- },()=>{
- this.validateForm()
- })
- },
- /**已提交获取数据**/
- getData(){
- const {invoiceId,invoiceOrderId}=this.data;
- app.post(api.queryOrderInvoiceInfo,{
- id:invoiceId,
- invoiceOrderId
- }).then(res=>{
- const {
- invoiceType,
- serviceContentInfo,
- saleId,
- saleIdNumber,
- saleName,
- salePhoneNumber,
- buyName,
- buyIdNumber,
- invoiceAmount,
- provinceName,
- cityName,
- expAreaName,
- address,
- mobile,
- name,
- }=res.data;
- this.setData({
- pickerInvoiceKindIndex:invoiceType,
- 'formData.invoiceType':invoiceType,
- 'formData.serviceContentInfo.':{
- serverName:serviceContentInfo.serverName,
- number:1,
- },
- 'formData.myServerName':serviceContentInfo.serverName,
- 'formData.provinceName': provinceName,
- 'formData.cityName': cityName,
- 'formData.expAreaName': expAreaName,
- 'formData.address': address,
- 'formData.mobile':mobile,
- 'formData.name':name,
- 'formData.amount':invoiceAmount/100,
- 'formData.buyName':buyName,
- 'formData.buyIdNumber':buyIdNumber,
- 'formData.saleId':saleId, //销售方id
- 'formData.saleIdNumber':saleIdNumber, //销售方身份证
- 'formData.saleName':saleName, //销售方信息
- 'formData.salePhoneNumber':salePhoneNumber, //销售方电话
- },()=>{
- this.validateForm()
- })
- })
- },
- validateForm(showInfo=false){
- const {formData} = this.data;
- const submitFormData=Object.assign({},formData);
- let flag=true;
- // 传入表单数据,调用验证方法
- if (!this.WxValidate.checkForm(submitFormData)) {
- flag=false
- if(showInfo===true){
- const error = this.WxValidate.errorList[0];
- wx.showToast({
- title: error.msg,
- icon: 'none',
- duration: 2000
- })
- }
- }
- if (submitFormData.amount< 5000){
- flag=false
- if(showInfo===true) {
- wx.showToast({
- title: '开票金额不能小于5000元',
- icon: 'none',
- duration: 2000
- })
- }
- }
- this.setData({
- isValidate:flag
- });
- return flag
- },
- /** 保存数据 **/
- saveData() {
- const {formData,isSubmit} = this.data;
- const submitFormData=Object.assign({},formData)
- if(isSubmit){
- return
- }
- // // 传入表单数据,调用验证方法
- // if (!this.WxValidate.checkForm(submitFormData)) {
- // const error = this.WxValidate.errorList[0];
- // wx.showToast({
- // title: error.msg,
- // icon: 'none',
- // duration: 2000
- // })
- // return false
- // }
- // if (submitFormData.amount< 5000){
- // wx.showToast({
- // title: '开票金额不能小于5000元',
- // icon: 'none',
- // duration: 2000
- // })
- // return false
- // }
- // //console.log(this.WxValidate);
- let flag=this.validateForm(true);
- if(!flag){
- return;
- }
- //元转成分单位
- submitFormData.amount= parseInt(submitFormData.amount*100);
- console.log('转成分',submitFormData.amount)
- this.setData({
- isSubmit:true
- });
- app.post(api.addInvoice, submitFormData).then(res => {
- wx.showToast({
- title: '添加成功',
- duration: 2000
- });
- const {invoiceId,invoiceOrderId}=res.data;
- this.setData({
- isSubmit:false,
- });
- wx.navigateTo({
- url:`/pages/invoice/preview/preview?invoiceId=${invoiceId}&invoiceOrderId=${invoiceOrderId}`
- })
- //wx.navigateBack();
- }).catch(()=>{
- this.setData({
- isSubmit:false
- })
- })
- },
- /** 获取收货地址 **/
- getAddress(){
- const settingAddress=function(res){
- this.setData({
- 'formData.name':res.userName,
- 'formData.provinceName':res.provinceName,
- 'formData.cityName': res.cityName,
- 'formData.expAreaName':res.countyName,
- 'formData.address':res.detailInfo,
- 'formData.mobile':res.telNumber,
- },()=>{
- this.validateForm()
- })
- }.bind(this);
- wx.chooseAddress({
- success:(res)=>{
- // console.log(res);
- settingAddress(res);
- },
- fail:(error)=>{
- //console.log(error);
- if(error.errMsg=="chooseAddress:fail auth deny"){
- wx.showModal({
- title: '是否授权通讯地址',
- content: '需要获取您通讯地址,请确认授权,否则获取地址功能将无法使用',
- success: (tip)=> {
- if (tip.confirm) {
- wx.openSetting({
- success: function (data) {
- //console.log(data);
- if (data.authSetting["scope.address"] === true) {
- wx.showToast({
- title: '授权成功',
- icon: 'success',
- duration: 1000
- });
- //授权成功之后,再调用chooseLocation选择
- wx.chooseAddress({
- success: (res)=> {
- settingAddress(res);
- },
- })
- } else {
- wx.showToast({
- title: '授权失败',
- icon: 'success',
- duration: 1000
- })
- }
- }
- })
- }
- }
- })
- }
- }
- })
- },
- /** 跳转销售方 **/
- goSaleList(){
- wx.navigateTo({
- url:`/pages/invoice/saleList/saleList?id=${this.data.formData.saleId}`
- })
- },
- /**获取销售方信息**/
- getSaleList(){
- const saleInfo=wx.getStorageSync('saleInfo');
- if(saleInfo){
- let {saleId,identityNumber,name,phoneNumber}=saleInfo;
- this.setData({
- 'formData.saleId':saleId, //销售方id
- 'formData.saleIdNumber':identityNumber, //销售方身份证
- 'formData.saleName':name, //销售方信息
- 'formData.salePhoneNumber':phoneNumber, //销售方电话
- },()=>{
- this.validateForm()
- })
- }
- wx.removeStorageSync('saleInfo')
- },
- /**
- * 触发发票抬头列表input
- * */
- changeInputInvoiceBuy(e){
- const {value}=e.detail;
- let {searchTimer}=this.data;
- this.setData({
- 'formData.buyName':value
- },()=>{
- clearInterval(searchTimer)
- searchTimer=setTimeout(()=>{
- this.getInvoiceBuy(value);
- },500);
- this.setData({
- searchTimer:searchTimer
- })
- })
- },
- setInvoiceBuyValue(e){
- const {name,code}=e.currentTarget.dataset;
- console.info(name)
- console.info(code)
- // todo: 税号有时带出不出来 先加一个延时测试一下
- setTimeout(()=>{
- this.setData({
- //invoiceBuySearchValue:value,
- 'formData.buyName':name,
- 'formData.buyIdNumber':code
- },()=>{
- this.validateForm()
- });
- },30)
- },
- showInvoiceBuyList() {
- this.setData({
- isShowInvoiceBuyList:true,
- invoiceBuyFocus:true
- });
- },
- hideInvoiceBuyList() {
- this.setData({
- isShowInvoiceBuyList:false,
- invoiceBuyFocus:false
- },()=>{
- this.validateForm()
- });
- },
- /**
- * 获取发票抬头列表
- * **/
- getInvoiceBuy(name){
- app.post(api.queryInvoiceBuy,{
- buyLike:name, //购买方纳税人识别号
- }).then(res=>{
- this.setData({
- invoiceBuyList:res.data
- });
- })
- },
- /**
- * 返回上一级
- */
- back(){
- wx.navigateBack();
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|