123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712 |
- var invoiceContList = ["日用品", "家居用品", "食品", "酒/饮料", "服饰","化妆品"];
- var invoiceTypeList = ["纸质普通发票","增值税专用发票"];
- var invoiceList = [];
- Page({
- data: {
- invoiceTypeFlag: 0,
- invoiceType : "",
- invoiceTypeName : '',
- isClick : 0,
- invoiceTitle : '',
- condition : false,
- conditionType : false,
- condBg : false,
- contNum : 0,
- invoiceContList: invoiceContList,
- invoiceCont: '明细',
- contTypeNum : 0,
- invoiceTypeList: invoiceTypeList,
- invoiceTypeList: invoiceTypeList[0],
- price:0,
- takeName : '',
- takeTelphone : '',
- takeAddress : '',
-
- userName: "",
- companyName: "",
- sbNum: "",
- address: "",
- telphone: "",
- brandName: "",
- brandNum: "",
-
-
-
- invoiceInfor : [],
- hiddenmodal: true,
- modalCont: '',
- invoiceList: invoiceList,
- invoiceData : [],
- hidden : false,
- province: '',
- city: '',
- area: '',
- adress: '',
- consignee: '',
- phone: '',
- },
- onLoad: function (options){
- var that = this;
- that.data.price = options.total1;
- that.setData({
- price: options.total1
- })
- var host = getApp().globalData.servsers;
- var un_id = getApp().globalData.un_id;
- if (un_id != undefined && un_id != '' && un_id != null){
-
- wx.request({
- url: host + "adressapi/adressview",
- data: {
- user_id: un_id
- },
- method: 'GET',
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- that.setData({
- addressAll: res.data.rows
- });
- var len = that.data.addressAll.length;
- for (var i = 0; i < len; i++) {
- if (that.data.addressAll[i].adress_flag == 1) {
- that.setData({
- consignee: that.data.addressAll[i].consignee,
- phone: that.data.addressAll[i].phone,
- province: that.data.addressAll[i].province,
- city: that.data.addressAll[i].city,
- area: that.data.addressAll[i].area,
- adress: that.data.addressAll[i].adress
- })
- }
- }
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- wx.hideNavigationBarLoading(
- that.setData({
- hidden: ''
- })
- )
- }
- });
- wx.request({
- url: host + "invoiceapi/adressview",
- data: {
-
- user_id: un_id,
-
-
- },
- method: 'GET',
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- that.setData({
- invoiceData: res.data.rows
- })
- if (res.data.rows.length > 0) {
- wx.showNavigationBarLoading(
- that.setData({
- hidden: true
- })
- )
- var dataLength = res.data.rows.length;
- that.setData({
- userName: res.data.rows[0].invoice_name,
- companyName: res.data.rows[0].invoice_company_name,
- sbNum: res.data.rows[0].invoice_number,
- address: res.data.rows[0].invoice_address,
- telphone: res.data.rows[0].invoice_telphone,
- brandName: res.data.rows[0].invoice_brandName,
- brandNum: res.data.rows[0].invoice_brandNum,
- invoiceCont: '明细',
- price: that.data.price,
- invoiceTypeFlag: res.data.rows[0].invoice_flag
- })
- var flag = that.data.invoiceTypeFlag;
- if (flag == 0) {
- that.setData({
- isClick: 0,
- contTypeNum: 0
- })
- } else if (flag == 1) {
- that.setData({
- isClick: 1,
- contTypeNum: 0
- })
- } else {
- that.setData({
- isClick: 1,
- contTypeNum: 1
- })
- }
- }
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- wx.hideNavigationBarLoading(
- that.setData({
- hidden: false
- })
- )
- }
- })
- }
-
-
-
-
-
-
-
- },
- titleClick: function (options){
- var that = this;
- var id = options.currentTarget.dataset.id;
- that.setData({
- isClick : id,
- invoiceTypeFlag : id
- })
- },
- contShow:function(e){
- var that = this;
- that.setData({
- condition: !that.data.condition,
- condBg: !that.data.condBg
- })
- },
- typeopen:function(){
- var that = this;
- that.setData({
- conditionType: !that.data.conditionType,
- condBg: !that.data.condBg
- })
- },
-
- invoiceContChoose: function (options){
- var that = this;
- var id = options.currentTarget.dataset.id;
- that.setData({
- contNum: id
- })
- },
-
- invoiceContSure: function(options){
- var that = this;
- var id = options.currentTarget.dataset.id;
- that.setData({
- contNum: id,
- invoiceCont: invoiceContList[id],
- condition: !that.data.condition,
- condBg: false
- })
- },
-
- invoiceTypeChoose: function (options){
- var that = this;
- var id = options.currentTarget.dataset.id;
- that.setData({
- contTypeNum: id
- })
- },
-
- invoiceTypeSure: function (options){
- var that = this;
- var id = options.currentTarget.dataset.id;
- var isClick = that.data.isClick;
- if (id == 0 && isClick == 0) {
- that.setData({
- contTypeNum: 0,
- invoiceTypeFlag: 0,
- conditionType: false,
- condBg: !that.data.condBg
- })
- } else if (id == 0 && isClick == 1) {
- that.setData({
- contTypeNum: 0,
- invoiceTypeFlag: 1,
- conditionType: false,
- condBg: !that.data.condBg
- })
- } else {
- that.setData({
- contTypeNum: 1,
- invoiceTypeFlag: 2,
- conditionType: false,
- condBg: !that.data.condBg
- })
- }
- },
-
- showState:function(){
- var that = this;
- that.setData({
- condition : false,
- conditionType : false,
- condBg: !that.data.condBg
- })
- },
-
- userNameInput: function (e){
- this.setData({
- userName: e.detail.value
- })
- },
- clearuserName:function(){
- this.setData({
- userName: ""
- })
- },
-
- companyNameInput: function (e) {
- this.setData({
- companyName: e.detail.value
- })
- },
- clearcompanyName: function () {
- this.setData({
- companyName: ""
- })
- },
-
- sbNumInput: function (e) {
- this.setData({
- sbNum: e.detail.value
- })
- },
- clearsbNum: function (e) {
- this.setData({
- sbNum: ""
- })
- },
-
- addressInput: function (e) {
- this.setData({
- address: e.detail.value
- })
- },
- clearaddress: function () {
- this.setData({
- address: ""
- })
- },
-
- telphoneInput: function (e) {
- this.setData({
- telphone: e.detail.value
- })
- },
- cleartelphone: function () {
- this.setData({
- telphone: ""
- })
- },
-
- brandNameInput: function (e) {
- this.setData({
- brandName: e.detail.value
- })
- },
- clearbrandName: function () {
- this.setData({
- brandName: ""
- })
- },
-
- brandNumInput: function (e) {
- this.setData({
- brandNum: e.detail.value
- })
- },
- clearbrandNum: function () {
- this.setData({
- brandNum: ""
- })
- },
-
- save:function(){
- var that = this;
- let invoiceInfor = this.data.invoiceInfor;
- var typeFlag = this.data.invoiceTypeFlag;
- var isClick = this.data.isClick;
- if (typeFlag == 2) {
- var invoiceType = "增值税专用发票";
- var title = "单位";
- var companyName = this.data.companyName;
-
- if (companyName == '' || companyName == undefined || companyName == null){
- that.setData({
- hiddenmodal: false,
- modalCont: '请填写单位名称'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- }
- var sbNum = this.data.sbNum;
- if (sbNum == '' || sbNum == undefined || sbNum == null) {
- that.setData({
- hiddenmodal: false,
- modalCont: '请填写纳税人识别号'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- }
- var address = this.data.address;
- if (address == '' || address == undefined || address == null) {
- that.setData({
- hiddenmodal: false,
- modalCont: '请填写注册地址'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- }
- var telphone = this.data.telphone;
- if (telphone == '' || telphone == undefined || telphone == null) {
- that.setData({
- hiddenmodal: false,
- modalCont: '请填写注册电话'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- }
- var brandName = this.data.brandName;
- if (brandName == '' || brandName == undefined || brandName == null) {
- that.setData({
- hiddenmodal: false,
- modalCont: '请填写开户银行'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- }
- var brandNum = this.data.brandNum;
- if (brandNum == '' || brandNum == undefined || brandNum == null) {
- that.setData({
- hiddenmodal: false,
- modalCont: '请填写银行账户'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- }
- var invoiceCompCont = "明细";
- var price = "¥" + this.data.price;
-
- } else if (typeFlag == 0) {
- var invoiceType = "纸质普通发票";
- var title = "个人";
- var userName = this.data.userName;
- if (userName == '' || userName == undefined || userName == null) {
- that.setData({
- hiddenmodal: false,
- modalCont: '请填写发票姓名'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- }
- var invoiceCont = '明细';
- var price = "¥" + this.data.price;
- }else{
- var invoiceType = "纸质普通发票";
- var title = "单位";
- var companyName = this.data.companyName;
- if (companyName == '' || companyName == undefined || companyName == null) {
- that.setData({
- hiddenmodal: false,
- modalCont: '请填写单位名称'
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- }
- var sbNum = this.data.sbNum;
- if (sbNum == '' || sbNum == undefined || sbNum == null) {
- that.setData({
- hiddenmodal: false,
- modalCont: '请填写纳税人识别号 '
- })
- setTimeout(function () {
- that.setData({
- hiddenmodal: true
- })
- }, 1000)
- return false;
- }
- var invoiceCont = '明细';
- var price = "¥" + this.data.price;
- }
- var pages = getCurrentPages();
- var currPage = pages[pages.length - 1];
- var prevPage = pages[pages.length - 2];
- var host = getApp().globalData.servsers;
- var un_id = getApp().globalData.un_id;
- var dataLen = that.data.invoiceData.length;
- if (un_id != undefined && un_id != '' && un_id != null){
- if (dataLen == 0) {
- wx.request({
- url: host + "invoiceapi/insertadd",
- data: {
- user_id: un_id,
- invoice_flag: typeFlag,
- invoice_type_name: invoiceType,
- invoice_name: that.data.userName,
- invoice_content: '明细',
- invoice_company_name: that.data.companyName,
- invoice_number: that.data.sbNum,
- invoice_address: that.data.address,
- invoice_telphone: that.data.telphone,
- invoice_brandName: that.data.brandName,
- invoice_brandNum: that.data.brandNum,
- invoice_company_content: '明细',
- invoice_price: that.data.price,
- invoice_title: title,
- invoice_company_title: '单位',
- invoice_takeName: that.data.consignee,
- invoice_takeTelphone: that.data.phone,
- invoice_takeAddress: that.data.province + that.data.city + that.data.area + that.data.adress
- },
- method: 'GET',
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- if (that.data.invoiceTypeFlag == 0) {
- prevPage.setData({
- invoice: true,
- checked: true,
- value: 1,
- invoice_flag: 0,
- invCont: '纸质普通发票',
- invoice_type_name: '纸质普通发票',
- invoice_title: '个人',
- invoice_name: that.data.userName,
- invoice_content: '明细',
- invoice_price: price
- })
- } else if (that.data.invoiceTypeFlag == 1) {
- prevPage.setData({
- invoice: true,
- checked: true,
- value: 1,
- invoice_flag: 1,
- invCont: '纸质普通发票',
- invoice_type_name: '纸质普通发票',
- invoice_company_title: '单位',
- invoice_company_name: that.data.companyName,
- invoice_number: that.data.sbNum,
- invoice_content: '明细',
- invoice_price: price
- })
- } else {
- prevPage.setData({
- invoice: true,
- checked: true,
- value: 1,
- invoice_flag: 2,
- invCont: '增值税专用发票',
- invoice_type_name: '增值税专用发票',
- invoice_company_title: '单位',
- invoice_company_name: that.data.companyName,
- invoice_number: that.data.sbNum,
- invoice_address: that.data.address,
- invoice_telphone: that.data.telphone,
- invoice_brandName: that.data.brandName,
- invoice_brandNum: that.data.brandNum,
- invoice_company_content: '明细',
- invoice_price: price,
- invoice_takeName: that.data.consignee,
- invoice_takeTelphone: that.data.phone,
- invoice_takeAddress: that.data.province + that.data.city + that.data.area + that.data.adress
- });
- }
- wx.navigateBack({})
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- })
- } else {
- wx.request({
- url: host + "invoiceapi/update",
- data: {
- user_id: un_id,
- invoice_flag: typeFlag,
- invoice_type_name: invoiceType,
- invoice_name: that.data.userName,
- invoice_content: '明细',
- invoice_company_name: that.data.companyName,
- invoice_number: that.data.sbNum,
- invoice_address: that.data.address,
- invoice_telphone: that.data.telphone,
- invoice_brandName: that.data.brandName,
- invoice_brandNum: that.data.brandNum,
- invoice_company_content: '明细',
- invoice_price: that.data.price,
- invoice_title: '个人',
- invoice_company_title: '单位',
- invoice_takeName: that.data.consignee,
- invoice_takeTelphone: that.data.phone,
- invoice_takeAddress: that.data.province + that.data.city + that.data.area + that.data.adress
- },
- method: 'GET',
- header: {
- 'Accept': 'application/json'
- },
- success: function (res) {
- if (that.data.invoiceTypeFlag == 0) {
- prevPage.setData({
- invoice: true,
- checked: true,
- value: 1,
- invoice_flag: 0,
- invCont: '纸质普通发票',
- invoice_type_name: '纸质普通发票',
- invoice_title: '个人',
- invoice_name: that.data.userName,
- invoice_content: '明细',
- invoice_price: price
- })
- } else if (that.data.invoiceTypeFlag == 1) {
- prevPage.setData({
- invoice: true,
- checked: true,
- value: 1,
- invoice_flag: 1,
- invCont: '纸质普通发票',
- invoice_type_name: '纸质普通发票',
- invoice_company_title: '单位',
- invoice_company_name: that.data.companyName,
- invoice_number: that.data.sbNum,
- invoice_content: '明细',
- invoice_price: price
- })
- } else {
- prevPage.setData({
- invoice: true,
- checked: true,
- value: 1,
- invoice_flag: 2,
- invCont: '增值税专用发票',
- invoice_type_name: '增值税专用发票',
- invoice_company_title: '单位',
- invoice_company_name: that.data.companyName,
- invoice_number: that.data.sbNum,
- invoice_address: that.data.address,
- invoice_telphone: that.data.telphone,
- invoice_brandName: that.data.brandName,
- invoice_brandNum: that.data.brandNum,
- invoice_company_content: '明细',
- invoice_price: price,
- invoice_takeName: that.data.consignee,
- invoice_takeTelphone: that.data.phone,
- invoice_takeAddress: that.data.province + that.data.city + that.data.area + that.data.adress
- });
- }
- wx.navigateBack({})
- if (res == null || res.data == null) {
- console.error('网络请求失败');
- return;
- }
- }
- })
- }
- }
-
- }
- })
|