invoice.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <!-- 新建发票 -->
  3. <view class="home">
  4. <view class="nav">
  5. <view :style="{ paddingTop }">
  6. <view class="title" :style="[{ height }, { lineHeight: height }]">
  7. <view class="back" @click="goBack()">
  8. <u-icon name="arrow-left" color="#ffffff" size="22"></u-icon>
  9. </view>
  10. <text>新建发票</text>
  11. </view>
  12. </view>
  13. </view>
  14. <view class="main">
  15. <u-form :model="form" :rules="rules" ref="form" label-width="0">
  16. <u-form-item prop="contractCode">
  17. <view class="form-label flex_l">
  18. <view class="label-tag"></view>
  19. 合同编号
  20. </view>
  21. <u-input v-model="form.contractCode" disabled />
  22. </u-form-item>
  23. <u-form-item prop="invoiceAmount">
  24. <view class="form-label flex_l">
  25. <view class="label-tag"></view>
  26. 开票金额
  27. </view>
  28. <u-input v-model.number="form.invoiceAmount" placeholder="请输入开票金额"/>
  29. </u-form-item>
  30. <u-form-item prop="invoiceDate" @click="show = true">
  31. <view class="form-label flex_l">
  32. <view class="label-tag"></view>
  33. 开票日期
  34. </view>
  35. <u--input v-model="form.invoiceDate" disabled disabledColor="#ffffff" placeholder="请选择开票日期"></u--input>
  36. </u-form-item>
  37. <u-form-item prop="invoiceType" @click="showPicker = true">
  38. <view class="form-label flex_l">
  39. <view class="label-tag"></view>
  40. 开票类型
  41. </view>
  42. <u-input v-model="form.invoiceName" disabled disabledColor="#ffffff" placeholder="请选择开票类型" />
  43. </u-form-item>
  44. <u-form-item prop="remark">
  45. <view class="form-label flex_l">
  46. <view class="label-tag"></view>
  47. 备注
  48. </view>
  49. <u-textarea fontSize="26rpx" v-model="form.remark" placeholder="输入备注" height="180" :count="true"
  50. maxlength="300"></u-textarea>
  51. </u-form-item>
  52. </u-form>
  53. <view class="save" @click="save">保存</view>
  54. </view>
  55. <u-calendar :show="show" @confirm="confirmCalendar" @close="show = false" minDate="1990-1-1"></u-calendar>
  56. <u-action-sheet :actions="collectionTypeOption" @select="selectClick" :show="showPicker"></u-action-sheet>
  57. <u-toast ref="uToast"></u-toast>
  58. </view>
  59. </template>
  60. <script>
  61. import api from '@/api/contract'
  62. import to from 'await-to-js'
  63. export default {
  64. data() {
  65. return {
  66. height: '',
  67. paddingTop: '',
  68. form: {
  69. invoiceDate: '', //开票日期
  70. contractCode: '', //合同编号
  71. contractId: null, //合同id
  72. invoiceAmount: '', //开票金额
  73. invoiceType: '', //开票类型
  74. invoiceName: '', //开票类型名称
  75. remark: '', //备注
  76. },
  77. rules: {
  78. contractCode: [{
  79. required: true,
  80. trigger: 'blur',
  81. message: '请选择合同'
  82. }],
  83. invoiceAmount: [{
  84. type:'number',
  85. required: true,
  86. trigger: 'blur',
  87. message: '请输入开票金额'
  88. }],
  89. invoiceDate: [{
  90. required: true,
  91. trigger: 'change',
  92. message: '请选择开票日期'
  93. }],
  94. invoiceType: [{
  95. required: true,
  96. trigger: 'chgange',
  97. message: '请输入开票类型'
  98. }],
  99. },
  100. show: false,
  101. showPicker: false,
  102. collectionTypeOption: []
  103. }
  104. },
  105. created() {
  106. const navData = uni.getMenuButtonBoundingClientRect()
  107. this.height = navData.height + 'px'
  108. this.paddingTop = navData.top + 'px'
  109. this.getOptions()
  110. },
  111. onLoad(option) {
  112. console.log(option.id) //打印出上个页面传递的参数。
  113. this.form.contractId = parseInt(option.id)
  114. this.form.contractCode = option.code
  115. },
  116. methods: {
  117. getOptions() {
  118. Promise.all([this.getDicts('invoice_type')])
  119. .then(([collectionType]) => {
  120. this.collectionTypeOption = collectionType.data.values || []
  121. this.collectionTypeOption.forEach(item => item.name = item.value)
  122. })
  123. .catch((err) => console.log(err))
  124. },
  125. closeMoveInModel() {
  126. },
  127. confirmCalendar(val) {
  128. this.form.invoiceDate = val[0]
  129. this.show = false
  130. },
  131. selectClick(val) {
  132. this.form.invoiceType = val.key
  133. this.form.invoiceName = val.value
  134. this.showPicker = false
  135. },
  136. async save() {
  137. let params = {
  138. ...this.form
  139. }
  140. delete params.invoiceName
  141. params.invoiceAmount = parseInt(params.invoiceAmount)
  142. this.$refs.form.validate().then(async valid => {
  143. if (valid) {
  144. console.log(valid);
  145. const [err, res] = await to(api.addInvoice(params))
  146. if (err) return
  147. this.$refs.uToast.show({
  148. type: 'success',
  149. message: '创建成功',
  150. complete: () => {
  151. this.goBack()
  152. },
  153. })
  154. }
  155. }).catch(errors => {})
  156. },
  157. goBack() {
  158. uni.navigateBack({
  159. //关闭当前页面,返回上一页面或多级页面。
  160. delta: 1,
  161. })
  162. },
  163. },
  164. }
  165. </script>
  166. <style lang="scss" scoped>
  167. .home {
  168. padding-top: 188rpx;
  169. .nav {
  170. position: absolute;
  171. left: 0;
  172. top: 0;
  173. width: 100%;
  174. height: 284rpx;
  175. background: #3e7ef8;
  176. .title {
  177. position: relative;
  178. text-align: center;
  179. font-size: 32rpx;
  180. font-weight: bold;
  181. color: #ffffff;
  182. .back {
  183. position: absolute;
  184. top: 0;
  185. bottom: 0;
  186. margin: auto;
  187. left: 70rpx;
  188. display: flex;
  189. }
  190. }
  191. }
  192. .main {
  193. position: absolute;
  194. width: 100%;
  195. height: calc(100vh - 280rpx);
  196. background: #ffffff;
  197. border-radius: 31rpx 31rpx 0 0;
  198. padding: 0 32rpx;
  199. overflow: auto;
  200. padding-bottom: 64rpx;
  201. .form-label {
  202. font-size: 32rpx;
  203. font-weight: bold;
  204. color: #323232;
  205. padding-bottom: 18rpx;
  206. .label-tag {
  207. width: 15rpx;
  208. height: 15rpx;
  209. background: rgba(62, 126, 248, 0.6);
  210. border-radius: 50%;
  211. margin-right: -4rpx;
  212. }
  213. }
  214. .save {
  215. position: fixed;
  216. bottom: 0;
  217. left: 0;
  218. width: 100%;
  219. height: 92rpx;
  220. background: #3e7ef8;
  221. border-radius: 31rpx 31rpx 0 0;
  222. margin: 116rpx auto 0;
  223. font-size: 32rpx;
  224. color: #ffffff;
  225. text-align: center;
  226. line-height: 92rpx;
  227. }
  228. }
  229. }
  230. </style>