index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <div class="invoice-add">
  3. <div class="invoice-add__header">
  4. <el-breadcrumb separator="/">
  5. <el-breadcrumb-item
  6. v-for="(item, index) in $route.matched"
  7. :key="index"
  8. :to="{ path: item.path }"
  9. >{{ item.name }}</el-breadcrumb-item
  10. >
  11. </el-breadcrumb>
  12. </div>
  13. <div class="invoice-add__body">
  14. <el-form
  15. :rules="rules"
  16. class="invoice-content"
  17. ref="form"
  18. :model="form"
  19. label-width="120px"
  20. >
  21. <div class="invoice-content__header">
  22. <el-form-item label="选择订单:" prop="orderGoodsIds"
  23. ><el-select
  24. required
  25. @change="changeSelect"
  26. class="select"
  27. v-model="form.orderGoodsIds"
  28. clearable
  29. multiple
  30. placeholder="请选择"
  31. >
  32. <el-option
  33. v-for="item in orderList"
  34. :key="item.orderGoodsId"
  35. :label="
  36. '商品名称:' +
  37. item.goodsName +
  38. ',订单编号:' +
  39. item.orderSn +
  40. ',价格:¥' +
  41. item.goodsPrice
  42. "
  43. :value="item.orderGoodsId"
  44. >
  45. </el-option>
  46. </el-select>
  47. </el-form-item>
  48. <el-form-item label="合计金额:">
  49. <div class="total">
  50. <span class="note">¥{{ total }}</span>
  51. </div>
  52. </el-form-item>
  53. </div>
  54. <div class="invoice-content__header">
  55. <el-form-item label="发票类型:" required prop="type">
  56. <el-radio-group v-model="form.type" @change="changeType">
  57. <el-radio label="1">普通发票</el-radio>
  58. <el-radio label="2">增值税发票</el-radio>
  59. </el-radio-group>
  60. </el-form-item>
  61. <el-form-item label="申请主体:" required prop="type">
  62. <template v-if="form.type == 2">
  63. <el-radio v-model="form.subject" label="2">企业</el-radio>
  64. </template>
  65. <template v-else>
  66. <el-radio v-model="form.subject" label="1">个人</el-radio>
  67. <el-radio v-model="form.subject" label="2">企业</el-radio>
  68. </template>
  69. </el-form-item>
  70. </div>
  71. <div class="invoice-content__body">
  72. <el-form-item label="发票抬头:" required prop="invoiceTitle">
  73. <el-input v-model="form.invoiceTitle"></el-input>
  74. </el-form-item>
  75. <template v-if="form.subject == 2">
  76. <el-form-item
  77. label="纳税登记号:"
  78. required
  79. prop="taxRegistryNumber"
  80. >
  81. <el-input v-model="form.taxRegistryNumber"></el-input>
  82. </el-form-item>
  83. </template>
  84. <template v-if="form.type == 2">
  85. <el-form-item label="单位地址:" required prop="companyAddress">
  86. <el-input v-model="form.companyAddress"></el-input>
  87. </el-form-item>
  88. <el-form-item label="电话号码:" required prop="phone">
  89. <el-input v-model="form.phone"></el-input>
  90. </el-form-item>
  91. <el-form-item label="开户银行:" required prop="bankName">
  92. <el-input v-model="form.bankName"></el-input>
  93. </el-form-item>
  94. <el-form-item label="银行账号:" required prop="bankAccount">
  95. <el-input v-model="form.bankAccount"></el-input>
  96. </el-form-item>
  97. <el-form-item label="收件地址:" required prop="receivingAddress">
  98. <el-input v-model="form.receivingAddress"></el-input>
  99. </el-form-item>
  100. <el-form-item label="收件人:" required prop="receivingName">
  101. <el-input v-model="form.receivingName"></el-input>
  102. </el-form-item>
  103. <el-form-item label="收件手机:" required prop="receivingTel">
  104. <el-input v-model="form.receivingTel"></el-input>
  105. </el-form-item>
  106. </template>
  107. </div>
  108. <div class="invoice-content__footer">
  109. <div class="invoice-price">
  110. 本次申请开票金额(元):
  111. <span class="note">{{ total }}</span>
  112. </div>
  113. <div class="btns">
  114. <el-button type="primary" plain round class="cancel" @click="cancel"
  115. >取消</el-button
  116. >
  117. <el-button
  118. type="primary"
  119. class="ok"
  120. :loading="loading"
  121. @click="submit"
  122. >提交申请</el-button
  123. >
  124. </div>
  125. </div>
  126. </el-form>
  127. </div>
  128. </div>
  129. </template>
  130. <script>
  131. export default {
  132. name: "MyInvoice",
  133. data() {
  134. return {
  135. form: {
  136. type: "1",
  137. subject: "1",
  138. invoiceTitle: "",
  139. taxRegistryNumber: "",
  140. companyAddress: "",
  141. phone: "",
  142. bankName: "",
  143. bankAccount: "",
  144. receivingAddress: "",
  145. receivingName: "",
  146. receivingTel: "",
  147. orderGoodsIds: [],
  148. },
  149. radio1: "",
  150. radio2: "",
  151. orderList: [],
  152. total: 0,
  153. rules: {
  154. receivingTel: [
  155. {
  156. required: true,
  157. message: "请输入收件手机",
  158. // 可以单个或者同时写两个触发验证方式
  159. trigger: ["change", "blur"],
  160. },
  161. {
  162. validator: (rule, value, callback) => {
  163. var reg_tel =
  164. /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
  165. if (reg_tel.test(value)) {
  166. return callback();
  167. } else {
  168. return callback(new Error("手机号码格式不正确"));
  169. }
  170. },
  171. // 触发器可以同时用blur和change
  172. trigger: ["change", "blur"],
  173. },
  174. ],
  175. type: [
  176. {
  177. required: true,
  178. message: "请选择发票类型",
  179. // 可以单个或者同时写两个触发验证方式
  180. trigger: ["change", "blur"],
  181. },
  182. ],
  183. subject: [
  184. {
  185. required: true,
  186. message: "请选择申请主体",
  187. // 可以单个或者同时写两个触发验证方式
  188. trigger: ["change", "blur"],
  189. },
  190. ],
  191. invoiceTitle: [
  192. {
  193. required: true,
  194. message: "请输入发票抬头",
  195. // 可以单个或者同时写两个触发验证方式
  196. trigger: ["change", "blur"],
  197. },
  198. ],
  199. taxRegistryNumber: [
  200. {
  201. required: true,
  202. message: "请输入纳税登记号",
  203. // 可以单个或者同时写两个触发验证方式
  204. trigger: ["change", "blur"],
  205. },
  206. {
  207. validator: (rule, value, callback) => {
  208. var reg = /(^[0-9A-Z]{15,20}$)/;
  209. if (reg.test(value)) {
  210. return callback();
  211. } else {
  212. return callback(new Error("纳税登记号格式不正确"));
  213. }
  214. },
  215. // 触发器可以同时用blur和change
  216. trigger: ["change", "blur"],
  217. },
  218. ],
  219. companyAddress: [
  220. {
  221. required: true,
  222. message: "请输入单位地址",
  223. // 可以单个或者同时写两个触发验证方式
  224. trigger: ["change", "blur"],
  225. },
  226. ],
  227. phone: [
  228. {
  229. required: true,
  230. message: "请输入电话号码",
  231. // 可以单个或者同时写两个触发验证方式
  232. trigger: ["change", "blur"],
  233. },
  234. ],
  235. bankName: [
  236. {
  237. required: true,
  238. message: "请输入开户银行",
  239. // 可以单个或者同时写两个触发验证方式
  240. trigger: ["change", "blur"],
  241. },
  242. {
  243. validator: (rule, value, callback) => {
  244. var reg = /[\u4E00-\u9FA5]+/;
  245. if (reg.test(value)) {
  246. return callback();
  247. } else {
  248. return callback(new Error("开户银行名称不正确"));
  249. }
  250. },
  251. trigger: ["change", "blur"],
  252. },
  253. ],
  254. bankAccount: [
  255. {
  256. required: true,
  257. message: "请输入银行账号",
  258. // 可以单个或者同时写两个触发验证方式
  259. trigger: ["change", "blur"],
  260. },
  261. {
  262. validator: (rule, value, callback) => {
  263. // 上面有说,返回true表示校验通过,返回false表示不通过
  264. var reg = /^[1-9]{1}(\d{15}|\d{18})$/;
  265. if (reg.test(value)) {
  266. return callback();
  267. } else {
  268. return callback(new Error("银行卡号格式不正确"));
  269. }
  270. },
  271. // 触发器可以同时用blur和change
  272. trigger: ["change", "blur"],
  273. },
  274. ],
  275. receivingAddress: [
  276. {
  277. required: true,
  278. message: "请输入收件地址",
  279. // 可以单个或者同时写两个触发验证方式
  280. trigger: ["change", "blur"],
  281. },
  282. ],
  283. receivingName: [
  284. {
  285. required: true,
  286. message: "请输入收件人",
  287. // 可以单个或者同时写两个触发验证方式
  288. trigger: ["change", "blur"],
  289. },
  290. ],
  291. orderGoodsIds: [
  292. {
  293. required: true,
  294. message: "请选择订单",
  295. // 可以单个或者同时写两个触发验证方式
  296. trigger: ["change", "blur"],
  297. },
  298. ],
  299. },
  300. loading: false,
  301. };
  302. },
  303. mounted() {
  304. this.orderInvoiceCanInvoiceList();
  305. },
  306. methods: {
  307. changeType(e) {
  308. if (this.form.type == "2") {
  309. this.form.subject = "2";
  310. } else {
  311. this.form.subject = "1";
  312. }
  313. },
  314. changeSelect(e) {
  315. let total = 0;
  316. this.form.orderGoodsIds.forEach((id) => {
  317. let orderItem = this.orderList.find((item) => item.orderGoodsId == id);
  318. if (orderItem) {
  319. total += orderItem.goodsPrice;
  320. }
  321. });
  322. this.total = total;
  323. },
  324. cancel() {
  325. this.$router.go(-1);
  326. },
  327. submit() {
  328. this.$refs.form.validate((valid) => {
  329. if (valid) {
  330. if (this.total > 10000) {
  331. this.$message({
  332. type: "warning",
  333. message:
  334. "您所选的订单总开票金额,大于10000元,超出单张发票的开票额度,请修改开票订单",
  335. });
  336. return;
  337. }
  338. this.loading = true;
  339. let data = JSON.parse(JSON.stringify(this.form));
  340. data.amount = this.total;
  341. if (data.subject == "1") {
  342. data.taxRegistryNumber = "";
  343. data.companyAddress = "";
  344. data.phone = "";
  345. data.bankName = "";
  346. data.bankAccount = "";
  347. data.receivingAddress = "";
  348. data.receivingName = "";
  349. data.receivingTel = "";
  350. }
  351. this.$request
  352. .orderInvoice(data)
  353. .then((res) => {
  354. this.loading = false;
  355. this.orderInvoiceCanInvoiceList();
  356. this.form = {
  357. type: "1",
  358. subject: "1",
  359. invoiceTitle: "",
  360. orderGoodsIds: [],
  361. taxRegistryNumber: "",
  362. companyAddress: "",
  363. phone: "",
  364. bankName: "",
  365. bankAccount: "",
  366. receivingAddress: "",
  367. receivingName: "",
  368. receivingTel: "",
  369. };
  370. this.total = 0;
  371. const confirmText = [
  372. "您本次的发票申请已经提交成功!",
  373. "机构将在3-7个工作日内进行处理,处理结果会在【发票记录】显示,请留意进度。",
  374. ];
  375. const newDatas = [];
  376. const h = this.$createElement;
  377. for (const i in confirmText) {
  378. newDatas.push(h("p", null, confirmText[i]));
  379. }
  380. this.$confirm(h("div", null, newDatas), "操作提示", {
  381. confirmButtonText: "知道了",
  382. closeOnClickModal: false,
  383. showCancelButton: false,
  384. closeOnPressEscape: false,
  385. distinguishCancelAndClose: false,
  386. showClose: false,
  387. })
  388. .then((_) => {})
  389. .catch((_) => {
  390. console.log(_);
  391. });
  392. })
  393. .catch((err) => {
  394. this.loading = false;
  395. this.$message({
  396. type: "error",
  397. message: err.msg,
  398. });
  399. });
  400. }
  401. });
  402. },
  403. /**
  404. * 获取可开发票的订单
  405. */
  406. orderInvoiceCanInvoiceList() {
  407. this.$request.orderInvoiceCanInvoiceList().then((res) => {
  408. this.orderList = res.rows;
  409. });
  410. },
  411. },
  412. };
  413. </script>
  414. <!-- Add "scoped" attribute to limit CSS to this component only -->
  415. <style scoped lang="scss">
  416. .invoice-add {
  417. overflow: hidden;
  418. &__header {
  419. border-bottom: 1px solid #eee;
  420. margin-top: 24px;
  421. padding-bottom: 20px;
  422. }
  423. &__body {
  424. .invoice-content {
  425. &__header {
  426. margin-top: 20px;
  427. width: 1110px;
  428. padding: 10px 12px;
  429. background: #fafbfc;
  430. border: 1px solid #eeeeee;
  431. box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
  432. border-radius: 8px;
  433. .select {
  434. width: 100%;
  435. }
  436. .total {
  437. font-size: 14px;
  438. .note {
  439. color: #ff3b30;
  440. }
  441. }
  442. }
  443. &__body {
  444. margin-top: 20px;
  445. width: 1110px;
  446. padding: 10px 12px;
  447. background: #fafbfc;
  448. border: 1px solid #eeeeee;
  449. box-shadow: 0px 0px 7px 1px rgba(0, 0, 0, 0.04);
  450. border-radius: 8px;
  451. }
  452. &__footer {
  453. margin-top: 20px;
  454. padding-bottom: 40px;
  455. .invoice-price {
  456. border-top: 1px solid #eee;
  457. border-bottom: 1px solid #eee;
  458. line-height: 50px;
  459. font-size: 18px;
  460. font-family: Microsoft YaHei;
  461. font-weight: 400;
  462. color: #333333;
  463. .note {
  464. font-size: 18px;
  465. color: #ff3b30;
  466. font-weight: bold;
  467. margin-left: 10px;
  468. }
  469. }
  470. .btns {
  471. margin-top: 20px;
  472. .cancel {
  473. padding: 0;
  474. display: inline-block;
  475. margin: 0 10px;
  476. cursor: pointer;
  477. width: 122px;
  478. height: 32px;
  479. border-radius: 16px;
  480. text-align: center;
  481. font-size: 16px;
  482. line-height: 30px;
  483. }
  484. .ok {
  485. padding: 0;
  486. display: inline-block;
  487. margin: 0 10px;
  488. cursor: pointer;
  489. width: 122px;
  490. height: 32px;
  491. border-radius: 16px;
  492. text-align: center;
  493. line-height: 32px;
  494. font-size: 16px;
  495. }
  496. }
  497. }
  498. }
  499. }
  500. }
  501. </style>