invoice.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="invoice-form-wrapper">
  3. <image class="invoice-pic" :src="invoiceUrl" mode="widthFix"></image>
  4. <view class="invoice-form">
  5. <view class="form-item">
  6. <view class="form-title"><text class="asterisk">*</text>单位名称:</view>
  7. <input class="form-input" maxlength="30" v-model="invoiceData.companyName" name="input" placeholder="请输入单位名称..." placeholder-class="placeholder"/>
  8. </view>
  9. <view class="form-item">
  10. <view class="form-title"><text class="asterisk">*</text>纳税人识别号:</view>
  11. <input class="form-input" v-model="invoiceData.taxId" name="input" placeholder="请输入纳税人识别号..." placeholder-class="placeholder"/>
  12. </view>
  13. <view class="form-item">
  14. <view class="form-title"><text class="asterisk">*</text>开户银行:</view>
  15. <input class="form-input" v-model="invoiceData.bankName" name="input" placeholder="请输入开户银行..." placeholder-class="placeholder"/>
  16. </view>
  17. <view class="form-item">
  18. <view class="form-title"><text class="asterisk">*</text>银行账号:</view>
  19. <input class="form-input" maxlength="23" v-model="invoiceData.bankNum" @input="inputBankNum(invoiceData.bankNum)" name="input" placeholder="请输入银行账号..." placeholder-class="placeholder"/>
  20. </view>
  21. <view class="form-item">
  22. <view class="form-title"><text class="asterisk">*</text>注册电话:</view>
  23. <input class="form-input" maxlength="11" v-model="invoiceData.phoneNum" name="input" placeholder="请输入注册电话..." placeholder-class="placeholder"/>
  24. </view>
  25. <view class="form-item">
  26. <view class="form-title"><text class="asterisk">*</text>注册地址:</view>
  27. <textarea :class="{iostextarea: isIos}" cols="20" rows="4" class="form-input form-textarea" v-model="invoiceData.address" name="input" placeholder="请输入注册地址..." placeholder-class="placeholder"/>
  28. </view>
  29. </view>
  30. <view class="submit-btn" @click="submitNow">确认</view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. userId: '',
  38. invoiceUrl: 'https://img.caimei365.com/group1/M00/03/81/Cmis214BwaCAPYJ3AAYlpcwPaVo973.png',
  39. invoiceData:{
  40. companyName:'',
  41. taxId:'',
  42. bankName: '',
  43. bankNum:'',
  44. address:'',
  45. phoneNum: ''
  46. },
  47. isIos: false
  48. }
  49. },
  50. onLoad() {
  51. this.$api.getStorage().then((resolve) =>{
  52. this.userId = resolve.userID
  53. this.sendData('init');
  54. let phone = wx.getSystemInfoSync();  //调用方法获取机型
  55.     if (phone.platform == 'ios') {
  56.         this.isIos = true;
  57.     } else if (phone.platform == 'android') {
  58. this.isIos = false;
  59.     }
  60. })
  61. },
  62. methods: {
  63. inputBankNum(val) {
  64. if (/\S{5}/.test(val)) {
  65. this.invoiceData.bankNum = val.replace(/\s/g, '').replace(/(.{4})/g, "$1 ");
  66. }
  67. },
  68. showMsg(text) {
  69. this.$util.msg(text,1000);
  70. },
  71. checkTaxId(taxId) {
  72. var regArr = [/^[\da-z]{10,15}$/i, /^\d{6}[\da-z]{10,12}$/i, /^[a-z]\d{6}[\da-z]{9,11}$/i, /^[a-z]{2}\d{6}[\da-z]{8,10}$/i, /^\d{14}[\dx][\da-z]{4,5}$/i, /^\d{17}[\dx][\da-z]{1,2}$/i, /^[a-z]\d{14}[\dx][\da-z]{3,4}$/i, /^[a-z]\d{17}[\dx][\da-z]{0,1}$/i, /^[\d]{6}[\da-z]{13,14}$/i],
  73. i, j = regArr.length;
  74. for (let i = 0; i < j; i++) {
  75. if (regArr[i].test(taxId)) {
  76. return true;
  77. }
  78. }
  79. //纳税人识别号格式错误
  80. return false;
  81. },
  82. submitNow() {
  83. let {companyName,taxId,
  84. bankName,bankNum,phoneNum,address} = this.invoiceData,
  85. commonRegex = this.$api.regexSets();
  86. if(companyName.trim() == '') {
  87. this.showMsg('请填写单位名称');
  88. return false;
  89. }
  90. if(!commonRegex.companyName.test(companyName.trim())) {
  91. this.showMsg('单位名称格式不正确');
  92. return false;
  93. }
  94. if(taxId.trim() == '') {
  95. this.showMsg('请填写纳税人识别号');
  96. return false;
  97. }
  98. if(!this.checkTaxId(taxId)) {
  99. this.showMsg('纳税人识别号格式不正确');
  100. return false;
  101. }
  102. if(bankName.trim() == '') {
  103. this.showMsg('请填写开户银行');
  104. return false;
  105. }
  106. if(!commonRegex.invalidChar.test(bankName)) {
  107. this.showMsg('开户银行格式不正确');
  108. return false;
  109. }
  110. if(bankNum.trim() == '') {
  111. this.showMsg('请填写银行账号');
  112. return false;
  113. }
  114. if(!commonRegex.bankNum.test(bankNum.replace(/\s*/g,""))) {
  115. this.showMsg('银行账号格式不正确');
  116. return false;
  117. }
  118. if(phoneNum.trim() == '') {
  119. this.showMsg('请填写注册电话');
  120. return false;
  121. }
  122. if(!commonRegex.phoneAndTelephone.test(phoneNum)) {
  123. this.showMsg('注册电话格式不正确');
  124. return false;
  125. }
  126. if(address.trim() == '') {
  127. this.showMsg('请填写注册地址');
  128. return false;
  129. }
  130. this.sendData();
  131. },
  132. sendData(type) {
  133. let self = this,
  134. invoiceData = self.invoiceData,
  135. data = '';
  136. if(type === 'init') {
  137. data = {userId: self.userId};
  138. } else {
  139. const {companyName:invoiceTitle, taxId:corporationTaxNum, bankName: openBank,
  140. bankNum: bankAccountNo, phoneNum:registeredPhone, address:registeredAddress} = invoiceData;
  141. data = {userId: self.userId, invoiceTitle, corporationTaxNum, openBank,
  142. bankAccountNo: bankAccountNo.replace(/\s*/g,""), registeredPhone, registeredAddress};
  143. }
  144. self.$api.post('/personal/invoice', data,
  145. response => {
  146. const code = response.code;
  147. const resData = response.data;
  148. if(code == 1) {
  149. if(type === 'init') {
  150. if(resData) {
  151. invoiceData.companyName = resData.invoiceTitle;
  152. invoiceData.taxId = resData.corporationTaxNum;
  153. invoiceData.bankName = resData.openBank;
  154. invoiceData.phoneNum = resData.registeredPhone;
  155. invoiceData.address = resData.registeredAddress;
  156. self.inputBankNum(resData.bankAccountNo);
  157. }
  158. } else {
  159. self.showMsg('保存成功');
  160. setTimeout(()=>{
  161. uni.navigateBack({
  162. delta: 1
  163. })
  164. },1100)
  165. }
  166. } else {
  167. uni.showToast({
  168. icon: 'none',
  169. title: '网络错误,请稍后重试。',
  170. duration: 3000
  171. })
  172. }
  173. }
  174. )
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss">
  180. page {
  181. .invoice-form-wrapper {
  182. display: flex;
  183. flex-direction: column;
  184. }
  185. .invoice-pic {
  186. width: 100%;
  187. }
  188. .form-item {
  189. align-items: flex-start;
  190. }
  191. .form-item:first-child {
  192. margin-top: 0rpx;
  193. }
  194. .invoice-form {
  195. background: #fff;
  196. padding: 50rpx 48rpx 38rpx 50rpx;
  197. }
  198. .form-input {
  199. height: 45rpx;
  200. line-height: 45rpx;
  201. flex-grow: 1;
  202. }
  203. .form-title {
  204. height: 45rpx;
  205. line-height: 45rpx;
  206. white-space: nowrap;
  207. }
  208. .form-textarea {
  209. width: 100%;
  210. height: 130rpx;
  211. }
  212. .place-holder {
  213. color: #999;
  214. }
  215. .iostextarea {
  216. margin-top: -10rpx;
  217. }
  218. }
  219. </style>