edit.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <s-layout :title="state.model.id ? '编辑发票' : '添加发票'">
  3. <uni-forms
  4. ref="invoiceFormRef"
  5. v-model="state.model"
  6. :rules="state.rules"
  7. validateTrigger="bind"
  8. labelWidth="160"
  9. labelAlign="left"
  10. border
  11. :labelStyle="{ fontWeight: 'bold' }"
  12. >
  13. <view class="bg-white form-box ss-p-x-30">
  14. <uni-forms-item name="type" label="发票类型">
  15. <view class="ss-flex ss-col-center ss-h-100">
  16. <radio-group @change="onChange" class="ss-flex ss-col-center">
  17. <label class="radio" v-for="item in invoiceTypeList" :key="item.value">
  18. <view class="ss-flex ss-col-center ss-m-r-32">
  19. <radio
  20. :value="item.value"
  21. color="var(--ui-BG-Main)"
  22. style="transform: scale(0.8)"
  23. :checked="item.value === state.model.type"
  24. />
  25. <view class="radio-name">
  26. {{ item.name }}
  27. </view>
  28. </view>
  29. </label>
  30. </radio-group>
  31. </view>
  32. </uni-forms-item>
  33. <view v-if="state.model.type === 'person'">
  34. <uni-forms-item name="name" label="姓名">
  35. <uni-easyinput
  36. v-model="state.model.name"
  37. type="text"
  38. placeholder="请输入您的姓名(必填)"
  39. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal"
  40. :inputBorder="false"
  41. ></uni-easyinput>
  42. </uni-forms-item>
  43. <uni-forms-item name="mobile" label="手机号">
  44. <uni-easyinput
  45. v-model="state.model.mobile"
  46. type="number"
  47. placeholder="请输入手机号(必填)"
  48. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal"
  49. :inputBorder="false"
  50. ></uni-easyinput>
  51. </uni-forms-item>
  52. </view>
  53. <view v-if="state.model.type === 'company'">
  54. <uni-forms-item name="name" label="单位名称">
  55. <uni-easyinput
  56. v-model="state.model.name"
  57. type="text"
  58. placeholder="请输入单位名称(必填)"
  59. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal"
  60. :inputBorder="false"
  61. ></uni-easyinput>
  62. </uni-forms-item>
  63. <uni-forms-item name="mobile" label="手机号">
  64. <uni-easyinput
  65. v-model="state.model.mobile"
  66. type="number"
  67. placeholder="请输入手机号(必填)"
  68. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal"
  69. :inputBorder="false"
  70. ></uni-easyinput>
  71. </uni-forms-item>
  72. <uni-forms-item name="tax_no" label="税号">
  73. <uni-easyinput
  74. v-model="state.model.tax_no"
  75. type="text"
  76. placeholder="请输入单位税号(必填)"
  77. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal"
  78. :inputBorder="false"
  79. ></uni-easyinput>
  80. </uni-forms-item>
  81. <uni-forms-item name="bank_name" label="开户银行">
  82. <uni-easyinput
  83. v-model="state.model.bank_name"
  84. type="text"
  85. placeholder="请输入对公账户开户银行"
  86. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal"
  87. :inputBorder="false"
  88. ></uni-easyinput>
  89. </uni-forms-item>
  90. <uni-forms-item name="bank_no" label="银行账号">
  91. <uni-easyinput
  92. v-model="state.model.bank_no"
  93. type="text"
  94. placeholder="请输入对公账户银行账号"
  95. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal"
  96. :inputBorder="false"
  97. ></uni-easyinput>
  98. </uni-forms-item>
  99. <uni-forms-item
  100. name="address"
  101. label="详细地址"
  102. :formItemStyle="{ alignItems: 'flex-start' }"
  103. :labelStyle="{ lineHeight: '5em' }"
  104. class="textarea-item"
  105. >
  106. <uni-easyinput
  107. :inputBorder="false"
  108. type="textarea"
  109. v-model="state.model.address"
  110. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal"
  111. placeholder="请输入详细地址"
  112. clearable
  113. ></uni-easyinput>
  114. </uni-forms-item>
  115. </view>
  116. </view>
  117. </uni-forms>
  118. <su-fixed bottom :opacity="false" bg="" placeholder :noFixed="false" :index="10">
  119. <view class="footer-box ss-flex-col ss-row-between ss-p-20">
  120. <view class="ss-m-b-20">
  121. <button class="ss-reset-button save-btn ui-Shadow-Main" @tap="onSave">保存</button>
  122. </view>
  123. <button v-if="state.model.id" class="ss-reset-button cancel-btn" @tap="onDelete">
  124. 删除
  125. </button>
  126. </view>
  127. </su-fixed>
  128. </s-layout>
  129. </template>
  130. <script setup>
  131. import { computed, watch, ref, reactive, unref } from 'vue';
  132. import sheep from '@/sheep';
  133. import { onLoad, onPageScroll } from '@dcloudio/uni-app';
  134. import _ from 'lodash';
  135. import { realName, mobile, taxNo, taxName } from '@/sheep/validate/form';
  136. const invoiceFormRef = ref(null);
  137. const invoiceTypeList = [
  138. {
  139. name: '个人',
  140. value: 'person',
  141. },
  142. {
  143. name: '企/事业单位',
  144. value: 'company',
  145. },
  146. ];
  147. const state = reactive({
  148. model: {
  149. type: '',
  150. name: '',
  151. mobile: '',
  152. tax_no: '',
  153. bank_name: '',
  154. bank_no: '',
  155. address: '',
  156. },
  157. rules: {
  158. name: taxName,
  159. mobile,
  160. tax_no: taxNo,
  161. },
  162. });
  163. //发票
  164. function onChange(e) {
  165. state.model.type = e.detail.value;
  166. }
  167. const onSave = async () => {
  168. const validate = await unref(invoiceFormRef)
  169. .validate()
  170. .catch((error) => {
  171. console.log('error: ', error);
  172. });
  173. if (!validate) return;
  174. let res = null;
  175. if (state.model.id) {
  176. res = await sheep.$api.user.invoice.update(state.model.id, state.model);
  177. } else {
  178. res = await sheep.$api.user.invoice.create(state.model);
  179. }
  180. if (res.error === 0) {
  181. sheep.$router.back();
  182. }
  183. };
  184. const onDelete = () => {
  185. uni.showModal({
  186. title: '提示',
  187. content: '确认删除此发票信息吗?',
  188. success: async function (res) {
  189. if (res.confirm) {
  190. const { error } = await sheep.$api.user.invoice.delete(state.model.id);
  191. if (res.error === 0) {
  192. sheep.$router.back();
  193. }
  194. }
  195. },
  196. });
  197. };
  198. onLoad(async (options) => {
  199. if (options.id) {
  200. let res = await sheep.$api.user.invoice.detail(options.id);
  201. if (res.error === 0) {
  202. state.model = {
  203. ...state.model,
  204. ...res.data,
  205. };
  206. }
  207. } else {
  208. state.model.type = 'person';
  209. }
  210. if (options.data) {
  211. let data = JSON.parse(options.data);
  212. state.model = {
  213. ...state.model,
  214. ...data,
  215. };
  216. }
  217. });
  218. </script>
  219. <style lang="scss" scoped>
  220. :deep() {
  221. .uni-forms-item__label .label-text {
  222. font-size: 28rpx !important;
  223. color: #333333 !important;
  224. line-height: normal !important;
  225. }
  226. .uni-easyinput__content-input {
  227. font-size: 28rpx !important;
  228. color: #333333 !important;
  229. line-height: normal !important;
  230. padding-left: 0 !important;
  231. }
  232. .uni-easyinput__content-textarea {
  233. font-size: 28rpx !important;
  234. color: #333333 !important;
  235. line-height: normal !important;
  236. margin-top: 4rpx;
  237. }
  238. .uni-icons {
  239. font-size: 40rpx !important;
  240. }
  241. .is-textarea-icon {
  242. margin-top: 14rpx;
  243. }
  244. .is-disabled {
  245. color: #333333;
  246. }
  247. }
  248. .footer-box {
  249. .save-btn {
  250. width: 710rpx;
  251. height: 80rpx;
  252. border-radius: 40rpx;
  253. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  254. color: $white;
  255. }
  256. .cancel-btn {
  257. width: 710rpx;
  258. height: 80rpx;
  259. border-radius: 40rpx;
  260. background: var(--ui-BG);
  261. }
  262. }
  263. </style>