invoice.vue 6.9 KB

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