invoice.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. this.form.contractId = parseInt(option.id)
  113. this.form.contractCode = option.code
  114. },
  115. methods: {
  116. getOptions() {
  117. Promise.all([this.getDicts('invoice_type')])
  118. .then(([collectionType]) => {
  119. this.collectionTypeOption = collectionType.data.values || []
  120. this.collectionTypeOption.forEach(item => item.name = item.value)
  121. })
  122. .catch((err) => console.log(err))
  123. },
  124. closeMoveInModel() {
  125. },
  126. confirmCalendar(val) {
  127. this.form.invoiceDate = val[0]
  128. this.show = false
  129. },
  130. selectClick(val) {
  131. this.form.invoiceType = val.key
  132. this.form.invoiceName = val.value
  133. this.showPicker = false
  134. },
  135. async save() {
  136. let params = {
  137. ...this.form
  138. }
  139. delete params.invoiceName
  140. params.invoiceAmount = parseInt(params.invoiceAmount)
  141. this.$refs.form.validate().then(async valid => {
  142. if (valid) {
  143. const [err, res] = await to(api.addInvoice(params))
  144. if (err) return
  145. this.$refs.uToast.show({
  146. type: 'success',
  147. message: '创建成功',
  148. complete: () => {
  149. this.goBack()
  150. },
  151. })
  152. }
  153. }).catch(errors => {})
  154. },
  155. goBack() {
  156. uni.navigateBack({
  157. //关闭当前页面,返回上一页面或多级页面。
  158. delta: 1,
  159. })
  160. },
  161. },
  162. }
  163. </script>
  164. <style lang="scss" scoped>
  165. .home {
  166. padding-top: 188rpx;
  167. .nav {
  168. position: absolute;
  169. left: 0;
  170. top: 0;
  171. width: 100%;
  172. height: 284rpx;
  173. background: #3e7ef8;
  174. .title {
  175. position: relative;
  176. text-align: center;
  177. font-size: 32rpx;
  178. font-weight: bold;
  179. color: #ffffff;
  180. .back {
  181. position: absolute;
  182. top: 0;
  183. bottom: 0;
  184. margin: auto;
  185. left: 70rpx;
  186. display: flex;
  187. }
  188. }
  189. }
  190. .main {
  191. position: absolute;
  192. width: 100%;
  193. height: calc(100vh - 280rpx);
  194. background: #ffffff;
  195. border-radius: 31rpx 31rpx 0 0;
  196. padding: 0 32rpx;
  197. overflow: auto;
  198. padding-bottom: 64rpx;
  199. .form-label {
  200. font-size: 32rpx;
  201. font-weight: bold;
  202. color: #323232;
  203. padding-bottom: 18rpx;
  204. .label-tag {
  205. width: 15rpx;
  206. height: 15rpx;
  207. background: #ff4d4f;
  208. border-radius: 50%;
  209. margin-right: 10rpx;
  210. }
  211. }
  212. .save {
  213. position: fixed;
  214. bottom: 0;
  215. left: 0;
  216. width: 100%;
  217. height: 92rpx;
  218. background: #3e7ef8;
  219. border-radius: 31rpx 31rpx 0 0;
  220. margin: 116rpx auto 0;
  221. font-size: 32rpx;
  222. color: #ffffff;
  223. text-align: center;
  224. line-height: 92rpx;
  225. }
  226. }
  227. }
  228. </style>