cm-invice-popup.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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.getStorage()
  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 res = await this.OrderService.updateOrganize({ ...this.invoiceData,...{userId: this.userId }})
  271. this.invoiceText = this.setInvoiceText(this.invoiceData)
  272. this.$emit('handleChoiceaInvoice', this.invoiceData)
  273. this.popupShow = false
  274. } catch (error) {
  275. console.log('error',error)
  276. }
  277. },
  278. // 设置发票文案
  279. setInvoiceText(data){
  280. const map = {
  281. 0:'个人',
  282. 1:'单位'
  283. }
  284. switch (data.type){
  285. case 0:
  286. return `不开发票`
  287. break;
  288. case 1:
  289. return `普票-${map[data.headingType]}(${this.nameFilters(data.invoiceTitle)})`
  290. break;
  291. case 2:
  292. return `专票(${this.nameFilters(data.invoiceTitle)})`
  293. break;
  294. }
  295. },
  296. nameFilters(value) {
  297. if(value && value.length>10){
  298. return value.substring(0,10)+"..."
  299. }else{
  300. return value
  301. }
  302. },
  303. hidePopup() {
  304. this.popupShow = false
  305. }
  306. }
  307. }
  308. </script>
  309. <style lang="scss">
  310. .invoice-template {
  311. width: 100%;
  312. height: auto;
  313. background: #ffffff;
  314. float: left;
  315. margin-top: 24rpx;
  316. .invoice-title {
  317. width: 702rpx;
  318. padding: 0 24rpx;
  319. height: 88rpx;
  320. line-height: 88rpx;
  321. position: relative;
  322. border-bottom: 1px solid #ebebeb;
  323. .text {
  324. font-size: $font-size-28;
  325. color: $text-color;
  326. }
  327. .invoice-text {
  328. font-size: $font-size-28;
  329. color: #F85050;
  330. line-height: 90rpx;
  331. display: inline-block;
  332. float: right;
  333. box-sizing: border-box;
  334. padding-right: 30rpx;
  335. }
  336. .iconfont {
  337. width: 50rpx;
  338. height: 88rpx;
  339. line-height: 88rpx;
  340. color: #999999;
  341. display: block;
  342. position: absolute;
  343. right: 0;
  344. top: 0;
  345. }
  346. }
  347. }
  348. .tui-popup-box {
  349. position: relative;
  350. box-sizing: border-box;
  351. min-height: 220rpx;
  352. padding: 24rpx 24rpx 0 24rpx;
  353. .title {
  354. font-size: $font-size-34;
  355. color: $text-color;
  356. line-height: 88rpx;
  357. text-align: center;
  358. float: left;
  359. width: 100%;
  360. height: 88rpx;
  361. font-weight: bold;
  362. }
  363. .tui-popup-close {
  364. width: 90rpx;
  365. height: 90rpx;
  366. position: absolute;
  367. right: 0;
  368. top: 24rpx;
  369. line-height: 90rpx;
  370. text-align: center;
  371. color: #b2b2b2;
  372. .icon-iconfontguanbi {
  373. font-size: $font-size-40;
  374. }
  375. }
  376. .tui-popup-main {
  377. width: 100%;
  378. float: left;
  379. min-height: 400rpx;
  380. .popup-form {
  381. width: 100%;
  382. height: 112rpx;
  383. box-sizing: border-box;
  384. padding: 23rpx 0;
  385. border-bottom: 1px solid #e1e1e1;
  386. &.none{
  387. border-bottom: none;
  388. }
  389. .label {
  390. width: 140rpx;
  391. float: left;
  392. font-size: $font-size-28;
  393. line-height: 64rpx;
  394. color: #666666;
  395. }
  396. .radio {
  397. height: 64rpx;
  398. padding: 0 28rpx;
  399. line-height: 64rpx;
  400. color: #666666;
  401. text-align: center;
  402. border-radius: 32rpx;
  403. margin: 0 8rpx;
  404. display: inline-block;
  405. background: #f5f5f5;
  406. font-size: $font-size-28;
  407. &.active {
  408. background: #fff4e6;
  409. color: #f3b574;
  410. }
  411. }
  412. .input {
  413. line-height: 64rpx;
  414. height: 64rpx;
  415. color: #333333;
  416. font-size: $font-size-28;
  417. }
  418. }
  419. }
  420. .tui-popup-btn {
  421. width: 100%;
  422. height: auto;
  423. float: left;
  424. }
  425. .tui-modal-flex {
  426. width: 100%;
  427. height: 84rpx;
  428. margin-top: 40rpx;
  429. display: flex;
  430. .tui-modal-button {
  431. flex: 1;
  432. line-height: 84rpx;
  433. font-size: $font-size-28;
  434. text-align: center;
  435. border-radius: 42rpx;
  436. padding: 0;
  437. margin: 0 15rpx;
  438. box-sizing: border-box;
  439. background: $btn-confirm;
  440. color: #ffffff;
  441. &.disabled {
  442. background: #e1e1e1;
  443. border-radius: 42rpx;
  444. }
  445. }
  446. }
  447. }
  448. </style>