invoiceInfor.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. // pages/invoiceInfor/invoiceInfor.js
  2. var invoiceContList = ["日用品", "家居用品", "食品", "酒/饮料", "服饰","化妆品"];
  3. var invoiceTypeList = ["纸质普通发票","增值税专用发票"];
  4. var invoiceList = [];
  5. Page({
  6. data: {
  7. invoiceTypeFlag: 0,//发票类型标志值(记录最后一次保存时的状态)
  8. invoiceType : "", //发票类型
  9. invoiceTypeName : '',
  10. isClick : 0,
  11. invoiceTitle : '',//个人发票抬头
  12. condition : false,//发票内容选择开关
  13. conditionType : false, //发票类型选择开关
  14. condBg : false,
  15. contNum : 0,
  16. invoiceContList: invoiceContList,
  17. invoiceCont: '明细',//默认发票内容
  18. contTypeNum : 0,
  19. invoiceTypeList: invoiceTypeList,
  20. invoiceTypeList: invoiceTypeList[0],//默认发票类型
  21. price:0,//金额
  22. takeName : '',//收货姓名
  23. takeTelphone : '',//收货人联系方式
  24. takeAddress : '',//收货人地址
  25. //所有input值
  26. userName: "", //请输入个人或姓名'
  27. companyName: "",//请输入单位名称
  28. sbNum: "",//纳税人识别号
  29. address: "",//注册地址
  30. telphone: "",//注册电话
  31. brandName: "",//开户银行
  32. brandNum: "",//银行账户
  33. // takeName: '',//发票收货人
  34. // takeTelphone: '',//发票收货人联系方式
  35. // takeAddress: '',//发票收货地址
  36. invoiceInfor : [], //发票回值数组
  37. hiddenmodal: true, //弹窗
  38. modalCont: '',
  39. invoiceList: invoiceList,
  40. invoiceData : [], //加载时接收数组
  41. hidden : false,
  42. province: '',
  43. city: '',
  44. area: '',
  45. adress: '',
  46. consignee: '',
  47. phone: '',
  48. },
  49. onLoad: function (options){
  50. var that = this;
  51. that.data.price = options.total1;
  52. that.setData({
  53. price: options.total1
  54. })
  55. var host = getApp().globalData.servsers;
  56. var un_id = getApp().globalData.un_id;
  57. if (un_id != undefined && un_id != '' && un_id != null){
  58. //查询是否有默认地址,如有则直接返回默认地址所有信息
  59. wx.request({
  60. url: host + "adressapi/adressview",//收货地址
  61. data: {
  62. user_id: un_id
  63. },
  64. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  65. header: {
  66. 'Accept': 'application/json'
  67. },
  68. success: function (res) {
  69. that.setData({
  70. addressAll: res.data.rows
  71. });
  72. var len = that.data.addressAll.length;
  73. for (var i = 0; i < len; i++) {
  74. if (that.data.addressAll[i].adress_flag == 1) {
  75. that.setData({
  76. consignee: that.data.addressAll[i].consignee,
  77. phone: that.data.addressAll[i].phone,
  78. province: that.data.addressAll[i].province,
  79. city: that.data.addressAll[i].city,
  80. area: that.data.addressAll[i].area,
  81. adress: that.data.addressAll[i].adress
  82. })
  83. }
  84. }
  85. if (res == null || res.data == null) {
  86. console.error('网络请求失败');
  87. return;
  88. }
  89. wx.hideNavigationBarLoading(//加载完成后显示页面
  90. that.setData({
  91. hidden: ''
  92. })
  93. )
  94. }
  95. });
  96. wx.request({
  97. url: host + "invoiceapi/adressview",
  98. data: {
  99. //user_id: getApp().globalData.open_id,
  100. user_id: un_id,
  101. // getApp().globalData.open_id
  102. // 'op1_x0EUt7BWyNwip4PI8q8e_2ek'
  103. },
  104. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  105. header: {
  106. 'Accept': 'application/json'
  107. },
  108. success: function (res) {
  109. that.setData({
  110. invoiceData: res.data.rows
  111. })
  112. if (res.data.rows.length > 0) {
  113. wx.showNavigationBarLoading(
  114. that.setData({
  115. hidden: true
  116. })
  117. )
  118. var dataLength = res.data.rows.length;
  119. that.setData({
  120. userName: res.data.rows[0].invoice_name, //请输入个人或姓名'
  121. companyName: res.data.rows[0].invoice_company_name,//请输入单位名称
  122. sbNum: res.data.rows[0].invoice_number,//纳税人识别号
  123. address: res.data.rows[0].invoice_address,//注册地址
  124. telphone: res.data.rows[0].invoice_telphone,//注册电话
  125. brandName: res.data.rows[0].invoice_brandName,//开户银行
  126. brandNum: res.data.rows[0].invoice_brandNum,//银行账户
  127. invoiceCont: '明细',//纸质发票内容
  128. price: that.data.price,//金额
  129. invoiceTypeFlag: res.data.rows[0].invoice_flag
  130. })
  131. var flag = that.data.invoiceTypeFlag;
  132. if (flag == 0) {//纸质 - 个人
  133. that.setData({
  134. isClick: 0,
  135. contTypeNum: 0
  136. })
  137. } else if (flag == 1) {//纸质 - 单位
  138. that.setData({
  139. isClick: 1,
  140. contTypeNum: 0
  141. })
  142. } else {
  143. that.setData({
  144. isClick: 1,
  145. contTypeNum: 1
  146. })
  147. }
  148. }
  149. if (res == null || res.data == null) {
  150. console.error('网络请求失败');
  151. return;
  152. }
  153. wx.hideNavigationBarLoading(
  154. that.setData({
  155. hidden: false
  156. })
  157. )
  158. }
  159. })
  160. }
  161. // that.setData({
  162. // takeName: options.consignee,
  163. // takeTelphone: options.phone,
  164. // takeAddress: options.province + options.city + options.area + options.adress
  165. // })
  166. },
  167. titleClick: function (options){
  168. var that = this;
  169. var id = options.currentTarget.dataset.id;
  170. that.setData({
  171. isClick : id,
  172. invoiceTypeFlag : id
  173. })
  174. },
  175. contShow:function(e){
  176. var that = this;
  177. that.setData({
  178. condition: !that.data.condition,
  179. condBg: !that.data.condBg
  180. })
  181. },
  182. typeopen:function(){
  183. var that = this;
  184. that.setData({
  185. conditionType: !that.data.conditionType,
  186. condBg: !that.data.condBg
  187. })
  188. },
  189. //选择发票内容
  190. invoiceContChoose: function (options){
  191. var that = this;
  192. var id = options.currentTarget.dataset.id;
  193. that.setData({
  194. contNum: id
  195. })
  196. },
  197. //选择发票内容-确定
  198. invoiceContSure: function(options){
  199. var that = this;
  200. var id = options.currentTarget.dataset.id;
  201. that.setData({
  202. contNum: id,
  203. invoiceCont: invoiceContList[id],
  204. condition: !that.data.condition,
  205. condBg: false
  206. })
  207. },
  208. //选择发票类型
  209. invoiceTypeChoose: function (options){
  210. var that = this;
  211. var id = options.currentTarget.dataset.id;
  212. that.setData({
  213. contTypeNum: id
  214. })
  215. },
  216. //选择发票类型-确定
  217. invoiceTypeSure: function (options){
  218. var that = this;
  219. var id = options.currentTarget.dataset.id;
  220. var isClick = that.data.isClick;
  221. if (id == 0 && isClick == 0) {
  222. that.setData({
  223. contTypeNum: 0,
  224. invoiceTypeFlag: 0,
  225. conditionType: false,
  226. condBg: !that.data.condBg
  227. })
  228. } else if (id == 0 && isClick == 1) {
  229. that.setData({
  230. contTypeNum: 0,
  231. invoiceTypeFlag: 1,
  232. conditionType: false,
  233. condBg: !that.data.condBg
  234. })
  235. } else {
  236. that.setData({
  237. contTypeNum: 1,
  238. invoiceTypeFlag: 2,
  239. conditionType: false,
  240. condBg: !that.data.condBg
  241. })
  242. }
  243. },
  244. //点击遮罩层,关闭弹层
  245. showState:function(){
  246. var that = this;
  247. that.setData({
  248. condition : false,
  249. conditionType : false,
  250. condBg: !that.data.condBg
  251. })
  252. },
  253. //请输入个人或姓名'
  254. userNameInput: function (e){
  255. this.setData({
  256. userName: e.detail.value
  257. })
  258. },
  259. clearuserName:function(){
  260. this.setData({
  261. userName: ""
  262. })
  263. },
  264. //请输入单位名称
  265. companyNameInput: function (e) {
  266. this.setData({
  267. companyName: e.detail.value
  268. })
  269. },
  270. clearcompanyName: function () {
  271. this.setData({
  272. companyName: ""
  273. })
  274. },
  275. //纳税人识别号
  276. sbNumInput: function (e) {
  277. this.setData({
  278. sbNum: e.detail.value
  279. })
  280. },
  281. clearsbNum: function (e) {
  282. this.setData({
  283. sbNum: ""
  284. })
  285. },
  286. //注册地址
  287. addressInput: function (e) {
  288. this.setData({
  289. address: e.detail.value
  290. })
  291. },
  292. clearaddress: function () {
  293. this.setData({
  294. address: ""
  295. })
  296. },
  297. //注册电话
  298. telphoneInput: function (e) {
  299. this.setData({
  300. telphone: e.detail.value
  301. })
  302. },
  303. cleartelphone: function () {
  304. this.setData({
  305. telphone: ""
  306. })
  307. },
  308. //开户银行
  309. brandNameInput: function (e) {
  310. this.setData({
  311. brandName: e.detail.value
  312. })
  313. },
  314. clearbrandName: function () {
  315. this.setData({
  316. brandName: ""
  317. })
  318. },
  319. //银行账户
  320. brandNumInput: function (e) {
  321. this.setData({
  322. brandNum: e.detail.value
  323. })
  324. },
  325. clearbrandNum: function () {
  326. this.setData({
  327. brandNum: ""
  328. })
  329. },
  330. //保存
  331. save:function(){
  332. var that = this;
  333. let invoiceInfor = this.data.invoiceInfor;
  334. var typeFlag = this.data.invoiceTypeFlag;
  335. var isClick = this.data.isClick;
  336. if (typeFlag == 2) {//增值税专用发票
  337. var invoiceType = "增值税专用发票";
  338. var title = "单位";
  339. var companyName = this.data.companyName;//单位名称
  340. if (companyName == '' || companyName == undefined || companyName == null){
  341. that.setData({
  342. hiddenmodal: false,
  343. modalCont: '请填写单位名称'
  344. })
  345. setTimeout(function () {
  346. that.setData({
  347. hiddenmodal: true
  348. })
  349. }, 1000)
  350. return false;
  351. }
  352. var sbNum = this.data.sbNum;//纳税人识别号
  353. if (sbNum == '' || sbNum == undefined || sbNum == null) {
  354. that.setData({
  355. hiddenmodal: false,
  356. modalCont: '请填写纳税人识别号'
  357. })
  358. setTimeout(function () {
  359. that.setData({
  360. hiddenmodal: true
  361. })
  362. }, 1000)
  363. return false;
  364. }
  365. var address = this.data.address;//注册地址
  366. if (address == '' || address == undefined || address == null) {
  367. that.setData({
  368. hiddenmodal: false,
  369. modalCont: '请填写注册地址'
  370. })
  371. setTimeout(function () {
  372. that.setData({
  373. hiddenmodal: true
  374. })
  375. }, 1000)
  376. return false;
  377. }
  378. var telphone = this.data.telphone;//注册电话
  379. if (telphone == '' || telphone == undefined || telphone == null) {
  380. that.setData({
  381. hiddenmodal: false,
  382. modalCont: '请填写注册电话'
  383. })
  384. setTimeout(function () {
  385. that.setData({
  386. hiddenmodal: true
  387. })
  388. }, 1000)
  389. return false;
  390. }
  391. var brandName = this.data.brandName;//开户银行
  392. if (brandName == '' || brandName == undefined || brandName == null) {
  393. that.setData({
  394. hiddenmodal: false,
  395. modalCont: '请填写开户银行'
  396. })
  397. setTimeout(function () {
  398. that.setData({
  399. hiddenmodal: true
  400. })
  401. }, 1000)
  402. return false;
  403. }
  404. var brandNum = this.data.brandNum;//银行账户
  405. if (brandNum == '' || brandNum == undefined || brandNum == null) {
  406. that.setData({
  407. hiddenmodal: false,
  408. modalCont: '请填写银行账户'
  409. })
  410. setTimeout(function () {
  411. that.setData({
  412. hiddenmodal: true
  413. })
  414. }, 1000)
  415. return false;
  416. }
  417. var invoiceCompCont = "明细";//发票内容
  418. var price = "¥" + this.data.price;//发票金额
  419. } else if (typeFlag == 0) {//纸质发票
  420. var invoiceType = "纸质普通发票";
  421. var title = "个人";
  422. var userName = this.data.userName;//个人或姓名
  423. if (userName == '' || userName == undefined || userName == null) {
  424. that.setData({
  425. hiddenmodal: false,
  426. modalCont: '请填写发票姓名'
  427. })
  428. setTimeout(function () {
  429. that.setData({
  430. hiddenmodal: true
  431. })
  432. }, 1000)
  433. return false;
  434. }
  435. var invoiceCont = '明细';//发票内容
  436. var price = "¥" + this.data.price;//发票金额
  437. }else{
  438. var invoiceType = "纸质普通发票";
  439. var title = "单位";
  440. var companyName = this.data.companyName;//单位名称
  441. if (companyName == '' || companyName == undefined || companyName == null) {
  442. that.setData({
  443. hiddenmodal: false,
  444. modalCont: '请填写单位名称'
  445. })
  446. setTimeout(function () {
  447. that.setData({
  448. hiddenmodal: true
  449. })
  450. }, 1000)
  451. return false;
  452. }
  453. var sbNum = this.data.sbNum;//纳税人识别号
  454. if (sbNum == '' || sbNum == undefined || sbNum == null) {
  455. that.setData({
  456. hiddenmodal: false,
  457. modalCont: '请填写纳税人识别号 '
  458. })
  459. setTimeout(function () {
  460. that.setData({
  461. hiddenmodal: true
  462. })
  463. }, 1000)
  464. return false;
  465. }
  466. var invoiceCont = '明细';//发票内容
  467. var price = "¥" + this.data.price;//发票金额
  468. }
  469. var pages = getCurrentPages();
  470. var currPage = pages[pages.length - 1]; //当前页面
  471. var prevPage = pages[pages.length - 2]; //上一个页面
  472. var host = getApp().globalData.servsers;
  473. var un_id = getApp().globalData.un_id;
  474. var dataLen = that.data.invoiceData.length;
  475. if (un_id != undefined && un_id != '' && un_id != null){
  476. if (dataLen == 0) {
  477. wx.request({
  478. url: host + "invoiceapi/insertadd",
  479. data: {
  480. user_id: un_id,
  481. invoice_flag: typeFlag,//发票类型
  482. invoice_type_name: invoiceType,//发票类型名称
  483. invoice_name: that.data.userName,//个人名字
  484. invoice_content: '明细',//纸质发票内容
  485. invoice_company_name: that.data.companyName,//发票公司名字(纸质单位和增值单位的公司名称相同)
  486. invoice_number: that.data.sbNum, //纳税人识别号
  487. invoice_address: that.data.address,//注册地址
  488. invoice_telphone: that.data.telphone,//注册电话
  489. invoice_brandName: that.data.brandName,//开户银行
  490. invoice_brandNum: that.data.brandNum,//银行账户
  491. invoice_company_content: '明细',//增值发票内容
  492. invoice_price: that.data.price,//发票金额
  493. invoice_title: title,//纸质个人发票抬头
  494. invoice_company_title: '单位',//纸质单位和增值发票抬头
  495. invoice_takeName: that.data.consignee,//收货姓名
  496. invoice_takeTelphone: that.data.phone,//收货人联系方式
  497. invoice_takeAddress: that.data.province + that.data.city + that.data.area + that.data.adress
  498. },
  499. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  500. header: {
  501. 'Accept': 'application/json'
  502. },
  503. success: function (res) {
  504. if (that.data.invoiceTypeFlag == 0) {//纸质普通发票 - 个人
  505. prevPage.setData({
  506. invoice: true,//勾选我要开发票
  507. checked: true,
  508. value: 1,
  509. invoice_flag: 0,
  510. invCont: '纸质普通发票',
  511. invoice_type_name: '纸质普通发票',
  512. invoice_title: '个人',
  513. invoice_name: that.data.userName,//个人姓名
  514. invoice_content: '明细',//发票内容
  515. invoice_price: price//金额
  516. })
  517. } else if (that.data.invoiceTypeFlag == 1) {//纸质 - 单位
  518. prevPage.setData({
  519. invoice: true,//勾选我要开发票
  520. checked: true,
  521. value: 1,
  522. invoice_flag: 1,
  523. invCont: '纸质普通发票',
  524. invoice_type_name: '纸质普通发票',
  525. invoice_company_title: '单位',
  526. invoice_company_name: that.data.companyName,//单位名称
  527. invoice_number: that.data.sbNum,//纳税人识别号
  528. invoice_content: '明细',//发票内容
  529. invoice_price: price //金额
  530. })
  531. } else {//增值税专用发票
  532. prevPage.setData({
  533. invoice: true,//勾选我要开发票
  534. checked: true,
  535. value: 1,
  536. invoice_flag: 2,
  537. invCont: '增值税专用发票',
  538. invoice_type_name: '增值税专用发票',
  539. invoice_company_title: '单位',
  540. invoice_company_name: that.data.companyName,//单位名称
  541. invoice_number: that.data.sbNum,//纳税人识别号
  542. invoice_address: that.data.address,//注册地址
  543. invoice_telphone: that.data.telphone,//注册电话
  544. invoice_brandName: that.data.brandName,//开户银行
  545. invoice_brandNum: that.data.brandNum,//银行账户
  546. invoice_company_content: '明细',//发票内容
  547. invoice_price: price, //金额
  548. invoice_takeName: that.data.consignee,//收货姓名
  549. invoice_takeTelphone: that.data.phone,//收货人联系方式
  550. invoice_takeAddress: that.data.province + that.data.city + that.data.area + that.data.adress
  551. });
  552. }
  553. wx.navigateBack({})//回到上一页
  554. if (res == null || res.data == null) {
  555. console.error('网络请求失败');
  556. return;
  557. }
  558. }
  559. })
  560. } else {
  561. wx.request({
  562. url: host + "invoiceapi/update",
  563. data: {
  564. user_id: un_id,
  565. invoice_flag: typeFlag,//发票类型
  566. invoice_type_name: invoiceType,//发票类型名称
  567. invoice_name: that.data.userName,//个人名字
  568. invoice_content: '明细',//纸质发票内容
  569. invoice_company_name: that.data.companyName,//发票公司名字(纸质单位和增值单位的公司名称相同)
  570. invoice_number: that.data.sbNum, //纳税人识别号
  571. invoice_address: that.data.address,//注册地址
  572. invoice_telphone: that.data.telphone,//注册电话
  573. invoice_brandName: that.data.brandName,//开户银行
  574. invoice_brandNum: that.data.brandNum,//银行账户
  575. invoice_company_content: '明细',//增值发票内容
  576. invoice_price: that.data.price,//发票金额
  577. invoice_title: '个人',//纸质个人发票抬头
  578. invoice_company_title: '单位',//纸质单位和增值发票抬头
  579. invoice_takeName: that.data.consignee,//收货姓名
  580. invoice_takeTelphone: that.data.phone,//收货人联系方式
  581. invoice_takeAddress: that.data.province + that.data.city + that.data.area + that.data.adress//收货人地址
  582. },
  583. method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
  584. header: {
  585. 'Accept': 'application/json'
  586. },
  587. success: function (res) {
  588. if (that.data.invoiceTypeFlag == 0) {//纸质普通发票 - 个人
  589. prevPage.setData({
  590. invoice: true,//勾选我要开发票
  591. checked: true,
  592. value: 1,
  593. invoice_flag: 0,
  594. invCont: '纸质普通发票',
  595. invoice_type_name: '纸质普通发票',
  596. invoice_title: '个人',
  597. invoice_name: that.data.userName,//个人姓名
  598. invoice_content: '明细',//发票内容
  599. invoice_price: price//金额
  600. })
  601. } else if (that.data.invoiceTypeFlag == 1) {//纸质 - 单位
  602. prevPage.setData({
  603. invoice: true,//勾选我要开发票
  604. checked: true,
  605. value: 1,
  606. invoice_flag: 1,
  607. invCont: '纸质普通发票',
  608. invoice_type_name: '纸质普通发票',
  609. invoice_company_title: '单位',
  610. invoice_company_name: that.data.companyName,//单位名称
  611. invoice_number: that.data.sbNum,//纳税人识别号
  612. invoice_content: '明细',//发票内容
  613. invoice_price: price //金额
  614. })
  615. } else {//增值税专用发票
  616. prevPage.setData({
  617. invoice: true,//勾选我要开发票
  618. checked: true,
  619. value: 1,
  620. invoice_flag: 2,
  621. invCont: '增值税专用发票',
  622. invoice_type_name: '增值税专用发票',
  623. invoice_company_title: '单位',
  624. invoice_company_name: that.data.companyName,//单位名称
  625. invoice_number: that.data.sbNum,//纳税人识别号
  626. invoice_address: that.data.address,//注册地址
  627. invoice_telphone: that.data.telphone,//注册电话
  628. invoice_brandName: that.data.brandName,//开户银行
  629. invoice_brandNum: that.data.brandNum,//银行账户
  630. invoice_company_content: '明细',//发票内容
  631. invoice_price: price, //金额
  632. invoice_takeName: that.data.consignee,
  633. invoice_takeTelphone: that.data.phone,
  634. invoice_takeAddress: that.data.province + that.data.city + that.data.area + that.data.adress
  635. });
  636. }
  637. wx.navigateBack({})//回到上一页
  638. if (res == null || res.data == null) {
  639. console.error('网络请求失败');
  640. return;
  641. }
  642. }
  643. })
  644. }
  645. }
  646. }
  647. })