invoice.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <view class="invoice">
  3. <view class="box bg-white">
  4. <!-- 发票类型 -->
  5. <view class="item flex row-between" @click="handleOpenInvoiceType">
  6. <view class="label">发票类型</view>
  7. <view class="content flex-1 flex row-right">
  8. <text>{{ type == 0 ? '增值税电子普通发票' : '增值税专用发票' }}</text>
  9. <u-icon name="arrow-right" size="22" v-if="formData.header_type == 1"></u-icon>
  10. </view>
  11. </view>
  12. <!-- 抬头类型 -->
  13. <view class="item flex row-between">
  14. <view class="label">抬头类型</view>
  15. <view class="content flex-1 flex row-right">
  16. <u-radio-group v-model="formData.header_type">
  17. <u-radio v-for="(item, index) in list" :key="index" :name="item.header_type"
  18. :disabled="item.disabled" :active-color="colorConfig.primary">
  19. {{item.name}}
  20. </u-radio>
  21. </u-radio-group>
  22. </view>
  23. </view>
  24. <!-- 发票抬头 -->
  25. <view class="item flex row-between">
  26. <view class="label">发票抬头</view>
  27. <view class="content">
  28. <u-input v-model="formData.name" input-align="right" placeholder="填写需要开具发票的姓名" />
  29. </view>
  30. </view>
  31. <!-- 税号 -->
  32. <view class="item flex row-between" v-show="formData.header_type === 1">
  33. <view class="label">税号</view>
  34. <view class="content flex-1 flex row-right">
  35. <u-input v-model="formData.duty_number" input-align="right" placeholder="纳税人识别号" />
  36. </view>
  37. </view>
  38. <!-- 邮箱 -->
  39. <view class="item flex row-between">
  40. <view class="label">邮箱</view>
  41. <view class="content flex-1 flex row-right">
  42. <u-input v-model="formData.email" input-align="right" placeholder="您的联系邮箱" />
  43. </view>
  44. </view>
  45. <!-- 企业地址 -->
  46. <view class="item flex row-between" v-show="type == 1 && formData.header_type == 1">
  47. <view class="label">企业地址</view>
  48. <view class="content flex-1 flex row-right">
  49. <u-input v-model="formData.address" input-align="right" placeholder="必填" />
  50. </view>
  51. </view>
  52. <!-- 企业电话 -->
  53. <view class="item flex row-between" v-show="type == 1 && formData.header_type == 1">
  54. <view class="label">企业电话</view>
  55. <view class="content flex-1 flex row-right">
  56. <u-input v-model="formData.mobile" input-align="right" placeholder="必填" />
  57. </view>
  58. </view>
  59. <!-- 开户银行 -->
  60. <view class="item flex row-between" v-show="type == 1 && formData.header_type == 1">
  61. <view class="label">开户银行</view>
  62. <view class="content flex-1 flex row-right">
  63. <u-input v-model="formData.bank" input-align="right" placeholder="必填" />
  64. </view>
  65. </view>
  66. <!-- 银行账号 -->
  67. <view class="item flex row-between" v-show="type == 1 && formData.header_type == 1">
  68. <view class="label">银行账号</view>
  69. <view class="content flex-1 flex row-right">
  70. <u-input v-model="formData.bank_account" input-align="right" placeholder="必填" />
  71. </view>
  72. </view>
  73. </view>
  74. <view class="footer">
  75. <view class="" v-if="order_id && shop_id">
  76. <button class="submit-btn br60 white btn" size="lg" @click="handleInvoiceAdd">提交申请</button>
  77. </view>
  78. <view class="" v-if="invoice_id && shop_id">
  79. <button class="submit-btn br60 white btn" size="lg" @click="handleInvoiceEdit">提交编辑</button>
  80. </view>
  81. <view class="" v-if="shop_id && !invoice_id && !order_id">
  82. <button class="submit-btn br60 white btn" size="lg" @click="handleConfirm">确定</button>
  83. </view>
  84. <view class="m-t-40">
  85. <button class="cancel-btn br60 white btn" size="lg" @click="handleCancel">不开发票</button>
  86. </view>
  87. </view>
  88. <!-- 发票类型选择 -->
  89. <u-popup v-model="showCoupon" border-radius="14" mode="bottom" closeable :safe-area-inset-bottom="true" @open="type=formData.type" @close="handleCloseInvoiceType">
  90. <view class="p-30 bg-body">
  91. <view class="text-center">发票类型选择</view>
  92. </view>
  93. <view class="invoice-type bg-body">
  94. <!-- 普票 -->
  95. <view class="invoice-type--item bg-white flex row-between" @click="type=0">
  96. <view>
  97. <view class="nr black">增值税电子普通发票</view>
  98. <view class="xs lighter m-t-14">默认发送至所提供的电子邮件</view>
  99. </view>
  100. <u-checkbox :value="type==0" shape="circle"
  101. name="0"></u-checkbox>
  102. </view>
  103. <!-- 专票 -->
  104. <view class="invoice-type--item bg-white flex row-between" @click="type=1" v-show="spec_invoice">
  105. <view>
  106. <view class="nr black">增值税专用发票</view>
  107. <view class="xs lighter m-t-14">纸质发票开出后将以邮寄形式交付</view>
  108. </view>
  109. <u-checkbox :value="type==1" shape="circle"
  110. name="1"></u-checkbox>
  111. </view>
  112. <!-- 底部确认按钮 -->
  113. <view class="invoice-type-confirm-btn">
  114. <button class="confirm br60 white btn" size="lg" @click="handleChoise">确定</button>
  115. </view>
  116. </view>
  117. </u-popup>
  118. </view>
  119. </template>
  120. <script>
  121. import {
  122. getInvoiceSetting,
  123. apiInvoiceAdd,
  124. apiInvoiceEdit,
  125. apiInvoiceDetail
  126. } from "@/api/shop.js"
  127. import { invoiceType } from "@/utils/type.js"
  128. export default {
  129. data() {
  130. return {
  131. shop_id: '', // 商家ID
  132. invoice_id: '', // 发票ID (编辑时
  133. order_id: '', // 订单ID (添加时
  134. showCoupon: false,
  135. list: [{
  136. name: '个人',
  137. header_type: 0,
  138. disabled: false
  139. },
  140. {
  141. name: '企业',
  142. header_type: 1,
  143. disabled: false
  144. }
  145. ],
  146. formData: {
  147. id: '', // 必填 int 发票id
  148. order_id: '', // 必填 int 订单id
  149. type: 0, // 必填 int 发票类型 0-普通 1-专用
  150. header_type: 0, // 必填 int 抬头类型 0-个人 1-企业
  151. name: '', // 必填 string 抬头名称
  152. duty_number: '',// 否 string 税号
  153. email: '', // 否 string 邮箱
  154. mobile: '', // 否 string 企业电话
  155. address: '', // 否 string 企业地址
  156. bank: '', // 否 string 开户行
  157. bank_account: ''// 否 string 银行账号
  158. },
  159. type: 0, //
  160. open_invoice: 0, // 发票开关 0- 关闭 1-开启
  161. spec_invoice: 0 // 是否支持专票 0-不支持 1-支持
  162. };
  163. },
  164. methods: {
  165. // 初始化发票
  166. initInvoiceSetting() {
  167. getInvoiceSetting({
  168. shop_id: this.shop_id,
  169. }).then(res => {
  170. this.spec_invoice = res.data.spec_invoice
  171. if ( res.data.open_invoice ) this.open_invoice = res.data.open_invoice
  172. else this.$toast({ title: '当前店铺暂未开启发票' })
  173. })
  174. },
  175. // 获取发票详情
  176. getInvoiceDetail() {
  177. apiInvoiceDetail({ id: this.invoice_id }).then(res => {
  178. for (const key in res.data) {
  179. if (!this.formData.hasOwnProperty(key)) continue
  180. this.formData[key] = res.data[key]
  181. }
  182. })
  183. },
  184. initRules() {
  185. const form = this.formData
  186. if(!this.open_invoice) {
  187. this.$toast({title: '当前店铺暂未开启发票'})
  188. return false
  189. }
  190. if(!form.name) {
  191. this.$toast({title: '请输入发票抬头'})
  192. return false
  193. }
  194. if(!form.duty_number && form.header_type == 1) {
  195. this.$toast({title: '请输入税号'})
  196. return false
  197. }
  198. if(!form.email) {
  199. this.$toast({title: '请输入邮箱地址'})
  200. return false
  201. }
  202. if(!/^[0-9a-zA-Z_.-]+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+){1,2}$/.test(form.email)) {
  203. this.$toast({title: '邮箱输入有误,请重新输入'})
  204. return false
  205. }
  206. if(!form.address && form.header_type == 1 && form.type == 1) {
  207. this.$toast({title: '请输入企业地址'})
  208. return false
  209. }
  210. if(!form.mobile && form.type == 1) {
  211. this.$toast({title: '请输入手机号码'})
  212. return false
  213. }
  214. if(!form.bank && form.header_type == 1 && form.type == 1) {
  215. this.$toast({title: '请输入开户银行'})
  216. return false
  217. }
  218. if(!form.bank_account && form.header_type == 1 && form.type == 1) {
  219. this.$toast({title: '请输入银行账号'})
  220. return false
  221. }
  222. return true
  223. },
  224. // 打开发票类型选择
  225. handleOpenInvoiceType() {
  226. if( this.formData.header_type == 0 ) return
  227. this.showCoupon=true
  228. },
  229. // 关闭发票类型选择
  230. handleCloseInvoiceType() {
  231. if( this.type != this.formData.type ) {
  232. this.type = this.type == 1 ? 0 : 1
  233. }
  234. },
  235. // 选择发票类型
  236. handleChoise() {
  237. this.formData.type = this.type
  238. this.showCoupon = false
  239. },
  240. // 确定发票(订单下单时
  241. handleConfirm() {
  242. if(!this.initRules()) return
  243. uni.$emit('invoice', {...this.formData, shop_id: this.shop_id});
  244. uni.navigateBack()
  245. },
  246. // 确认添加
  247. handleInvoiceAdd() {
  248. if(!this.initRules()) return
  249. apiInvoiceAdd({...this.formData, order_id: this.order_id}).then(res => {
  250. if(res.code == 1) {
  251. setTimeout(() => {
  252. uni.navigateBack()
  253. }, 500)
  254. }
  255. })
  256. },
  257. // 确认编辑
  258. handleInvoiceEdit() {
  259. if(!this.initRules()) return
  260. apiInvoiceEdit({...this.formData}).then(res => {
  261. if(res.code == 1) {
  262. setTimeout(() => {
  263. uni.navigateBack()
  264. }, 500)
  265. }
  266. })
  267. },
  268. // 不开发票
  269. handleCancel() {
  270. if ( !this.order_id && !this.invoice_id ) {
  271. uni.$emit('invoice', {del: true, shop_id: this.shop_id});
  272. }
  273. uni.navigateBack()
  274. }
  275. },
  276. onLoad() {
  277. const query = this.$Route.query;
  278. switch (query.type * 1) {
  279. case invoiceType['SETTLEMENT']:
  280. this.shop_id = query.shop_id || ''
  281. if( query.invoice != '{}') {
  282. this.formData = JSON.parse(query.invoice)
  283. this.type = this.formData.type
  284. }
  285. break;
  286. case invoiceType['ORDERDETAILEdit']:
  287. this.invoice_id = query.invoice_id || ''
  288. this.shop_id = query.shop_id || ''
  289. this.getInvoiceDetail()
  290. break;
  291. case invoiceType['ORDERDETAILADD']:
  292. this.order_id = query.order_id || ''
  293. this.shop_id = query.shop_id || ''
  294. break;
  295. }
  296. // 初始化发票
  297. this.initInvoiceSetting()
  298. }
  299. };
  300. </script>
  301. <style lang="scss">
  302. .invoice {
  303. height: calc(100vh - env(safe-area-inset-bottom));
  304. padding: 24rpx;
  305. position: relative;
  306. .box {
  307. padding: 20rpx 0;
  308. border-radius: 16rpx;
  309. .item {
  310. padding: 16rpx 30rpx;
  311. .label {
  312. font-size: 28rpx;
  313. color: $-color-black;
  314. }
  315. .content {
  316. min-width: 440rpx;
  317. }
  318. }
  319. }
  320. .footer {
  321. left: 0;
  322. bottom: 0;
  323. width: 100%;
  324. padding: 24rpx;
  325. position: absolute;
  326. .btn {
  327. height: 88rpx;
  328. }
  329. .submit-btn {
  330. color: $-color-white;
  331. background-color: #E39B37;
  332. }
  333. .cancel-btn {
  334. color: #E39B37;
  335. background-color: $-color-white;
  336. }
  337. }
  338. .invoice-type {
  339. padding: 40rpx;
  340. padding-bottom: 0;
  341. .invoice-type--item {
  342. padding: 28rpx 36rpx;
  343. border-radius: 40rpx;
  344. margin-bottom: 30rpx;
  345. }
  346. .invoice-type-confirm-btn {
  347. padding: 90rpx 0 50rpx 0;
  348. .confirm {
  349. background-color: #FF9E1E;
  350. }
  351. }
  352. }
  353. }
  354. </style>