cm-invice-popup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template name="cm-parameter">
  2. <view class="invoice-template">
  3. <!-- 发票信息 -->
  4. <view class="invoice-title" @tap.stop="handleShowPopup">
  5. <text class="text">发票信息:</text> <text class="invoice-text">{{ invoiceText }}</text>
  6. <text class="iconfont icon-xiangyou"></text>
  7. </view>
  8. <tui-bottom-popup :radius="true" :show="popupShow" @close="hidePopup">
  9. <view class="tui-popup-box clearfix">
  10. <view class="title">发票信息</view>
  11. <view class="tui-popup-close" @click="hidePopup">
  12. <text class="iconfont icon-iconfontguanbi"></text>
  13. </view>
  14. <view class="tui-popup-main">
  15. <view class="popup-form">
  16. <text
  17. class="radio"
  18. v-for="(invoice, index) in invoiceType"
  19. :key="index"
  20. @click="handleTnvoiceType(invoice.type, index)"
  21. :class="invoiceTypeIndex === index ? 'active' : ''"
  22. >
  23. {{ invoice.name }}
  24. </text>
  25. </view>
  26. <view class="popup-form" v-if="invoiceTypeIndex === 1">
  27. <view class="label">抬头类型:</view>
  28. <text
  29. class="radio"
  30. v-for="(title, index) in titleType"
  31. :key="index"
  32. @click="handleTitleType(title.type, index)"
  33. :class="titleIndex === index ? 'active' : ''"
  34. >
  35. {{ title.name }}
  36. </text>
  37. </view>
  38. <view class="popup-form" v-if="invoiceTypeIndex > 0">
  39. <view class="label">发票抬头:</view>
  40. <input
  41. class="input"
  42. type="text"
  43. v-model="invoiceData.invoiceTitle"
  44. placeholder="请输入发票抬头"
  45. maxlength="50"
  46. cursor-spacing="40"
  47. />
  48. </view>
  49. <template v-if="invoiceTypeIndex === 2 || titleIndex === 1">
  50. <view class="popup-form">
  51. <view class="label">单位税号:</view>
  52. <input
  53. class="input"
  54. type="text"
  55. v-model="invoiceData.corporationTaxNum"
  56. placeholder="请输入单位税号"
  57. maxlength="30"
  58. cursor-spacing="40"
  59. />
  60. </view>
  61. <view class="popup-form">
  62. <view class="label">注册地址:</view>
  63. <input
  64. type="text"
  65. class="input"
  66. v-model="invoiceData.registeredAddress"
  67. :placeholder="invoiceTypeIndex === 2 ? '请输入注册地址' : '选填'"
  68. maxlength="50"
  69. cursor-spacing="40"
  70. />
  71. </view>
  72. <view class="popup-form">
  73. <view class="label">注册电话:</view>
  74. <input
  75. type="number"
  76. class="input"
  77. v-model="invoiceData.registeredPhone"
  78. :placeholder="invoiceTypeIndex === 2 ? '请输入注册电话' : '选填'"
  79. maxlength="11"
  80. cursor-spacing="40"
  81. />
  82. </view>
  83. <view class="popup-form">
  84. <view class="label">开户银行:</view>
  85. <input
  86. type="text"
  87. class="input"
  88. v-model="invoiceData.openBank"
  89. :placeholder="invoiceTypeIndex === 2 ? '请输入开户银行' : '选填'"
  90. maxlength="50"
  91. cursor-spacing="40"
  92. />
  93. </view>
  94. <view class="popup-form">
  95. <view class="label">银行账号:</view>
  96. <input
  97. type="number"
  98. class="input"
  99. v-model="invoiceData.bankAccountNo"
  100. :placeholder="invoiceTypeIndex === 2 ? '请输入银行账号' : '选填'"
  101. maxlength="30"
  102. cursor-spacing="40"
  103. />
  104. </view>
  105. </template>
  106. </view>
  107. <view class="tui-popup-btn" :style="{ paddingBottom: isIphoneX ? '68rpx' : '34rpx' }">
  108. <view class="tui-modal-flex">
  109. <button
  110. class="tui-modal-button"
  111. :disabled="disabled"
  112. @click="handleConfirm"
  113. >
  114. 确定
  115. </button>
  116. </view>
  117. </view>
  118. </view>
  119. </tui-bottom-popup>
  120. </view>
  121. </template>
  122. <script>
  123. export default {
  124. name: 'cm-prams-popup',
  125. props: {},
  126. data() {
  127. return {
  128. popupShow: false,
  129. isIphoneX: this.$store.state.isIphoneX,
  130. userId:0,
  131. invoiceTypeIndex: 0,
  132. titleIndex: 0,
  133. invoiceType: [
  134. {
  135. name: '不开发票',
  136. type: 0
  137. },
  138. {
  139. name: '普通发票',
  140. type: 1
  141. },
  142. {
  143. name: '增值税专用发票',
  144. type: 2
  145. }
  146. ],
  147. titleType: [
  148. {
  149. name: '个人',
  150. type: 0
  151. },
  152. {
  153. name: '单位',
  154. type: 1
  155. }
  156. ],
  157. invoiceText: '不开发票',
  158. invoiceData: {
  159. type: 0, //发票类型 0 不开发票 1 普通发票 2 增值税发票
  160. headingType: 0, //抬头类型 0 个人 1 单位
  161. invoiceTitle: '', //发票抬头
  162. corporationTaxNum: '', //单位税号
  163. registeredAddress: '', //单位地址
  164. registeredPhone: '', //注册电话
  165. openBank: '', //开户银行
  166. bankAccountNo: '' //银行账号
  167. }
  168. }
  169. },
  170. created() {
  171. },
  172. computed: {
  173. },
  174. methods: {
  175. // 切换发票类型
  176. handleTnvoiceType(type, index) {
  177. this.invoiceTypeIndex = index
  178. this.invoiceData.type = type
  179. if(this.invoiceTypeIndex === 1){
  180. this.titleIndex = 0
  181. this.invoiceData.headingType = 0
  182. }
  183. },
  184. // 切换抬头类型
  185. handleTitleType(type, index) {
  186. this.titleIndex = index
  187. this.invoiceData.headingType = type
  188. },
  189. // 显示发票弹窗 查询发票信息
  190. handleShowPopup(){
  191. this.getUseFindInvoice()
  192. },
  193. // 确认保存发票
  194. handleConfirm(){
  195. if(this.invoiceTypeIndex === 0){
  196. this.invoiceData = {...this.invoiceData , ...{ type : 0 }}
  197. this.invoiceText = this.setInvoiceText(this.invoiceData)
  198. this.hidePopup()
  199. }else{
  200. this.checkedInput()
  201. }
  202. },
  203. // 校验必填项
  204. checkedInput(){
  205. /**
  206. * 普通发票 个人 仅校验发票抬头
  207. * 普通发票 单位 校验发票抬头 校验单位税号
  208. * 增值税发票 校验全部
  209. * */
  210. if(this.invoiceTypeIndex === 1 && this.titleIndex === 0){
  211. if (!this.invoiceData.invoiceTitle) {
  212. this.$util.msg('请输入发票抬头', 2000)
  213. return
  214. }
  215. }
  216. if(this.invoiceTypeIndex === 1 && this.titleIndex === 1){
  217. if (!this.invoiceData.invoiceTitle) {
  218. this.$util.msg('请输入发票抬头', 2000)
  219. return
  220. }
  221. if (!this.invoiceData.corporationTaxNum) {
  222. this.$util.msg('请输入单位税号', 2000)
  223. return
  224. }
  225. }
  226. if(this.invoiceTypeIndex === 2){
  227. if (!this.invoiceData.invoiceTitle) {
  228. this.$util.msg('请输入发票抬头', 2000)
  229. return
  230. }
  231. if (!this.invoiceData.corporationTaxNum) {
  232. this.$util.msg('请输入单位税号', 2000)
  233. return
  234. }
  235. if (!this.invoiceData.registeredAddress) {
  236. this.$util.msg('请输入注册地址', 2000)
  237. return
  238. }
  239. if (!this.invoiceData.registeredPhone) {
  240. this.$util.msg('请输入注册电话', 2000)
  241. return
  242. }
  243. if (!this.invoiceData.openBank) {
  244. this.$util.msg('请输入开户银行', 2000)
  245. return
  246. }
  247. if (!this.invoiceData.bankAccountNo) {
  248. this.$util.msg('请输入银行账号', 2000)
  249. return
  250. }
  251. }
  252. this.updateInvoiceFn()
  253. },
  254. //获取发票信息
  255. async getUseFindInvoice() {
  256. try {
  257. this.popupShow = true
  258. const resolve = await this.$api.getComStorage('orderUserInfo')
  259. this.userId = resolve.userId
  260. const res = await this.OrderService.GetFindInvoice({ userId: resolve.userId })
  261. this.invoiceData = {...this.invoiceData, ...res.data}
  262. console.log('invoiceData',this.invoiceData)
  263. } catch (error) {
  264. console.log('error',error)
  265. }
  266. },
  267. //保存发票信息
  268. async updateInvoiceFn() {
  269. try {
  270. const resolve = await this.$api.getComStorage('orderUserInfo')
  271. const res = await this.OrderService.updateOrganize({ ...this.invoiceData,...{userId: resolve.userId }})
  272. this.invoiceText = this.setInvoiceText(this.invoiceData)
  273. this.$emit('handleChoiceaInvoice', this.invoiceData)
  274. this.popupShow = false
  275. } catch (error) {
  276. console.log('error',error)
  277. }
  278. },
  279. // 设置发票文案
  280. setInvoiceText(data){
  281. const map = {
  282. 0:'个人',
  283. 1:'单位'
  284. }
  285. switch (data.type){
  286. case 0:
  287. return `不开发票`
  288. break;
  289. case 1:
  290. return `普票-${map[data.headingType]}(${this.nameFilters(data.invoiceTitle)})`
  291. break;
  292. case 2:
  293. return `专票(${this.nameFilters(data.invoiceTitle)})`
  294. break;
  295. }
  296. },
  297. nameFilters(value) {
  298. if(value && value.length>10){
  299. return value.substring(0,10)+"..."
  300. }else{
  301. return value
  302. }
  303. },
  304. hidePopup() {
  305. this.popupShow = false
  306. }
  307. }
  308. }
  309. </script>
  310. <style lang="scss">
  311. .invoice-template {
  312. width: 100%;
  313. height: auto;
  314. background: #ffffff;
  315. float: left;
  316. margin-top: 24rpx;
  317. .invoice-title {
  318. width: 702rpx;
  319. padding: 0 24rpx;
  320. height: 88rpx;
  321. line-height: 88rpx;
  322. position: relative;
  323. border-bottom: 1px solid #ebebeb;
  324. .text {
  325. font-size: $font-size-28;
  326. color: $text-color;
  327. font-weight: bold;
  328. }
  329. .invoice-text {
  330. font-size: $font-size-28;
  331. color: #F85050;
  332. line-height: 90rpx;
  333. display: inline-block;
  334. float: right;
  335. box-sizing: border-box;
  336. padding-right: 40rpx;
  337. }
  338. .iconfont {
  339. width: 50rpx;
  340. height: 88rpx;
  341. line-height: 88rpx;
  342. color: #999999;
  343. display: block;
  344. position: absolute;
  345. right: 0;
  346. top: 0;
  347. }
  348. }
  349. }
  350. .tui-popup-box {
  351. position: relative;
  352. box-sizing: border-box;
  353. min-height: 220rpx;
  354. padding: 24rpx 24rpx 0 24rpx;
  355. .title {
  356. font-size: $font-size-34;
  357. color: $text-color;
  358. line-height: 88rpx;
  359. text-align: center;
  360. float: left;
  361. width: 100%;
  362. height: 88rpx;
  363. font-weight: bold;
  364. }
  365. .tui-popup-close {
  366. width: 90rpx;
  367. height: 90rpx;
  368. position: absolute;
  369. right: 0;
  370. top: 24rpx;
  371. line-height: 90rpx;
  372. text-align: center;
  373. color: #b2b2b2;
  374. .icon-iconfontguanbi {
  375. font-size: $font-size-40;
  376. }
  377. }
  378. .tui-popup-main {
  379. width: 100%;
  380. float: left;
  381. min-height: 400rpx;
  382. .popup-form {
  383. width: 100%;
  384. height: 112rpx;
  385. box-sizing: border-box;
  386. padding: 23rpx 0;
  387. border-bottom: 1px solid #e1e1e1;
  388. &.none{
  389. border-bottom: none;
  390. }
  391. .label {
  392. width: 140rpx;
  393. float: left;
  394. font-size: $font-size-28;
  395. line-height: 64rpx;
  396. color: #666666;
  397. }
  398. .radio {
  399. height: 64rpx;
  400. padding: 0 28rpx;
  401. line-height: 64rpx;
  402. color: #666666;
  403. text-align: center;
  404. border-radius: 32rpx;
  405. margin: 0 8rpx;
  406. display: inline-block;
  407. background: #f5f5f5;
  408. font-size: $font-size-28;
  409. &.active {
  410. background: #fff4e6;
  411. color: #f3b574;
  412. }
  413. }
  414. .input {
  415. line-height: 64rpx;
  416. height: 64rpx;
  417. color: #333333;
  418. font-size: $font-size-28;
  419. }
  420. }
  421. }
  422. .tui-popup-btn {
  423. width: 100%;
  424. height: auto;
  425. float: left;
  426. }
  427. .tui-modal-flex {
  428. width: 100%;
  429. height: 84rpx;
  430. margin-top: 40rpx;
  431. display: flex;
  432. .tui-modal-button {
  433. flex: 1;
  434. line-height: 84rpx;
  435. font-size: $font-size-28;
  436. text-align: center;
  437. border-radius: 42rpx;
  438. padding: 0;
  439. margin: 0 15rpx;
  440. box-sizing: border-box;
  441. background: $btn-confirm;
  442. color: #ffffff;
  443. &.disabled {
  444. background: #e1e1e1;
  445. border-radius: 42rpx;
  446. }
  447. }
  448. }
  449. }
  450. </style>