edit.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <!-- 收货地址的新增/编辑 -->
  2. <template>
  3. <!-- {{ru}} -->
  4. <s-layout :title="state.model.id ? '编辑发票抬头' : '新增发票抬头'">
  5. <uni-forms ref="invoiceFormRef" v-model="state.model" :rules="rules" validateTrigger="bind" labelWidth="160"
  6. labelAlign="left" border :labelStyle="{ fontWeight: 'bold' }">
  7. <view class="bg-white form-box ss-p-x-30">
  8. <uni-forms-item name="invoiceType" label="发票类型">
  9. <radio-group @change="invoiceType">
  10. <radio value="1" :checked="state.model.invoiceType == 1" color="var(--ui-BG-Main)"
  11. class="radio ss-m-r-30" style="transform: scale(0.9)">纸质普票
  12. </radio>
  13. <radio value="2" :checked="state.model.invoiceType == 2" color="var(--ui-BG-Main)" class="radio"
  14. style="transform: scale(0.9)">专用发票</radio>
  15. </radio-group>
  16. </uni-forms-item>
  17. <!-- 当为专用发票时,不用选择抬头类型 -->
  18. <uni-forms-item name="invoiceTitleType" label="抬头类型" class="form-item" v-if="state.model.invoiceType == 1">
  19. <radio-group class="uni-flex uni-row radio-group" @change="invoiceTitleType">
  20. <radio value="1" :checked="state.model.invoiceTitleType == 1" color="var(--ui-BG-Main)"
  21. class="radio ss-m-r-30" style="transform: scale(0.9)">个人
  22. </radio>
  23. <radio value="2" :checked="state.model.invoiceTitleType == 2" color="var(--ui-BG-Main)"
  24. style="transform: scale(0.9)" class="radio">单位</radio>
  25. </radio-group>
  26. </uni-forms-item>
  27. <uni-forms-item name="invoiceTitle" label="发票抬头" class="form-item">
  28. <uni-easyinput v-model="state.model.invoiceTitle" placeholder="请输入发票抬头"
  29. :inputBorder="false"
  30. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal">
  31. </uni-easyinput>
  32. </uni-forms-item>
  33. <template v-if="state.model.invoiceTitleType == 2">
  34. <uni-forms-item name="taxIDNumber" label="单位税号" class="form-item">
  35. <uni-easyinput v-model="state.model.taxIDNumber" type="number" placeholder="请输入单位税号"
  36. :inputBorder="false"
  37. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal">
  38. </uni-easyinput>
  39. </uni-forms-item>
  40. <uni-forms-item name="invoiceTitle" label="注册地址" class="form-item">
  41. <uni-easyinput v-model="state.model.invoiceTitle" type="number" placeholder="选填"
  42. :inputBorder="false"
  43. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal">
  44. </uni-easyinput>
  45. </uni-forms-item>
  46. <uni-forms-item name="invoiceTitle" label="注册电话" class="form-item">
  47. <uni-easyinput v-model="state.model.invoiceTitle" type="number" placeholder="选填"
  48. :inputBorder="false"
  49. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal">
  50. </uni-easyinput>
  51. </uni-forms-item>
  52. <uni-forms-item name="invoiceTitle" label="开户银行" class="form-item">
  53. <uni-easyinput v-model="state.model.invoiceTitle" type="number" placeholder="选填"
  54. :inputBorder="false"
  55. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal">
  56. </uni-easyinput>
  57. </uni-forms-item>
  58. <uni-forms-item name="invoiceTitle" label="银行账号" class="form-item">
  59. <uni-easyinput v-model="state.model.invoiceTitle" type="number" placeholder="选填"
  60. :inputBorder="false"
  61. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal">
  62. </uni-easyinput>
  63. </uni-forms-item>
  64. </template>
  65. <template v-if="state.model.invoiceType == 2">
  66. <uni-forms-item name="taxIDNumber" label="单位税号" class="form-item">
  67. <uni-easyinput v-model="state.model.taxIDNumber" type="number" placeholder="请输入单位税号"
  68. :inputBorder="false"
  69. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal">
  70. </uni-easyinput>
  71. </uni-forms-item>
  72. <uni-forms-item name="invoiceTitle" label="注册地址" class="form-item">
  73. <uni-easyinput v-model="state.model.invoiceTitle" type="number" placeholder="必填"
  74. :inputBorder="false"
  75. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal">
  76. </uni-easyinput>
  77. </uni-forms-item>
  78. <uni-forms-item name="invoiceTitle" label="注册电话" class="form-item">
  79. <uni-easyinput v-model="state.model.invoiceTitle" type="number" placeholder="必填"
  80. :inputBorder="false"
  81. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal">
  82. </uni-easyinput>
  83. </uni-forms-item>
  84. <uni-forms-item name="invoiceTitle" label="开户银行" class="form-item">
  85. <uni-easyinput v-model="state.model.invoiceTitle" type="number" placeholder="必填"
  86. :inputBorder="false"
  87. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal">
  88. </uni-easyinput>
  89. </uni-forms-item>
  90. <uni-forms-item name="invoiceTitle" label="银行账号" class="form-item">
  91. <uni-easyinput v-model="state.model.invoiceTitle" type="number" placeholder="必填"
  92. :inputBorder="false"
  93. placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal">
  94. </uni-easyinput>
  95. </uni-forms-item>
  96. </template>
  97. </view>
  98. <view class="ss-m-y-20 bg-white ss-p-x-30 ss-flex ss-row-between ss-col-center default-box" v-if="state.model.invoiceType == 2">
  99. <view class="default-box-title" :class="{ shake: currentProtocol }">
  100. <label class="radio ss-flex ss-col-center" @tap="onChange">
  101. <radio :checked="state.protocol" color="var(--ui-BG-Main)" style="transform: scale(0.8)"
  102. @tap.stop="onChange" />
  103. <view class="agreement-text ss-flex ss-col-center ss-m-l-8">
  104. 我已阅读并同意
  105. <view class="tcp-text" @tap.stop="onProtocol('专用发票抬头确认书')">
  106. 《专用发票抬头确认书》
  107. </view>
  108. </view>
  109. </label>
  110. </view>
  111. </view>
  112. </uni-forms>
  113. <su-fixed bottom :opacity="false" bg="" placeholder :noFixed="false" :index="10">
  114. <view class="footer-box ss-flex-col ss-row-between ss-p-20">
  115. <view class="ss-m-b-20">
  116. <button class="ss-reset-button save-btn ui-Shadow-Main" @tap="onSave">保存</button>
  117. </view>
  118. <button v-if="state.model.id" class="ss-reset-button cancel-btn" @tap="onDelete">
  119. 删除
  120. </button>
  121. </view>
  122. </su-fixed>
  123. </s-layout>
  124. </template>
  125. <script setup>
  126. import {
  127. ref,
  128. reactive,
  129. unref
  130. } from 'vue';
  131. import sheep from '@/sheep';
  132. import {
  133. onLoad
  134. } from '@dcloudio/uni-app';
  135. import _ from 'lodash';
  136. import {
  137. mobile
  138. } from '@/sheep/validate/form';
  139. import AreaApi from '@/sheep/api/system/area';
  140. import AddressApi from '@/sheep/api/member/address';
  141. import $helper from '@/sheep/helper';
  142. const invoiceFormRef = ref(null);
  143. const currentProtocol = ref(false)
  144. const state = reactive({
  145. showRegion: false,
  146. model: {
  147. invoiceType: 1,
  148. invoiceTitleType: 1,
  149. invoiceTitle: '',
  150. taxIDNumber: ''
  151. },
  152. rules: {},
  153. protocol: false,
  154. });
  155. // 勾选协议
  156. function onChange() {
  157. state.protocol = !state.protocol;
  158. }
  159. // 查看协议
  160. function onProtocol(title) {
  161. sheep.$router.go('/pages/public/richtext', {
  162. title,
  163. });
  164. }
  165. const rules = {
  166. invoiceType: {
  167. rules: [{
  168. required: true,
  169. errorMessage: '请选择发票类型'
  170. }]
  171. },
  172. invoiceTitleType: {
  173. rules: [{
  174. required: true,
  175. errorMessage: '请选择抬头类型'
  176. }]
  177. },
  178. invoiceTitle: {
  179. rules: [{
  180. required: true,
  181. errorMessage: '请输入发票抬头'
  182. }]
  183. },
  184. taxIDNumber: {
  185. rules: [{
  186. required: true,
  187. errorMessage: '请输入单位税号'
  188. }]
  189. },
  190. };
  191. const invoiceType = (e) => {
  192. state.model.invoiceType = e.detail.value
  193. state.model.invoiceTitleType = 1
  194. }
  195. const invoiceTitleType = (e) => {
  196. state.model.invoiceTitleType = e.detail.value
  197. }
  198. // 保存收货地址
  199. const onSave = async () => {
  200. // 参数校验
  201. const validate = await unref(invoiceFormRef)
  202. .validate()
  203. .catch((error) => {
  204. console.log('error: ', error);
  205. });
  206. if (!validate) {
  207. return;
  208. }
  209. if(!state.protocol){
  210. currentProtocol.value = true
  211. setTimeout(function(){
  212. currentProtocol.value = false
  213. },500)
  214. return
  215. }
  216. // 提交请求
  217. const formData = {
  218. ...state.model
  219. }
  220. const {
  221. code
  222. } = state.model.id > 0 ? await AddressApi.updateAddress(formData) :
  223. await AddressApi.createAddress(formData);
  224. if (code === 0) {
  225. sheep.$router.back();
  226. }
  227. };
  228. // 删除收货地址
  229. const onDelete = () => {
  230. uni.showModal({
  231. title: '提示',
  232. content: '确认删除此收货地址吗?',
  233. success: async function(res) {
  234. if (!res.confirm) {
  235. return;
  236. }
  237. const {
  238. code
  239. } = await AddressApi.deleteAddress(state.model.id);
  240. if (code === 0) {
  241. sheep.$router.back();
  242. }
  243. },
  244. });
  245. };
  246. onLoad(async (options) => {
  247. // // 情况一:基于 id 获得收件地址
  248. // if (options.id) {
  249. // let {
  250. // code,
  251. // data
  252. // } = await AddressApi.getAddress(options.id);
  253. // if (code !== 0) {
  254. // return;
  255. // }
  256. // // console.log(data)
  257. // state.model = data;
  258. // }
  259. });
  260. </script>
  261. <style lang="scss" scoped>
  262. .shake {
  263. animation: shake 0.05s linear 4 alternate;
  264. }
  265. @keyframes shake {
  266. from {
  267. transform: translateX(-10rpx);
  268. }
  269. to {
  270. transform: translateX(10rpx);
  271. }
  272. }
  273. :deep() {
  274. .uni-forms-item__label .label-text {
  275. font-size: 28rpx !important;
  276. color: #333333 !important;
  277. line-height: normal !important;
  278. }
  279. .uni-forms-item__content {
  280. display: flex;
  281. align-items: center;
  282. }
  283. .uni-easyinput__content-input {
  284. font-size: 28rpx !important;
  285. color: #333333 !important;
  286. line-height: normal !important;
  287. padding-left: 0 !important;
  288. }
  289. .uni-easyinput__content-textarea {
  290. font-size: 28rpx !important;
  291. color: #333333 !important;
  292. line-height: normal !important;
  293. margin-top: 8rpx !important;
  294. }
  295. .uni-icons {
  296. font-size: 40rpx !important;
  297. }
  298. .is-textarea-icon {
  299. margin-top: 22rpx;
  300. }
  301. .is-disabled {
  302. color: #333333;
  303. }
  304. }
  305. .default-box {
  306. width: 100%;
  307. box-sizing: border-box;
  308. height: 100rpx;
  309. .default-box-title {
  310. font-size: 28rpx;
  311. color: #333333;
  312. line-height: normal;
  313. }
  314. }
  315. .tcp-text {
  316. color: var(--ui-BG-Main);
  317. }
  318. .footer-box {
  319. .save-btn {
  320. width: 710rpx;
  321. height: 80rpx;
  322. border-radius: 40rpx;
  323. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  324. color: $white;
  325. }
  326. .cancel-btn {
  327. width: 710rpx;
  328. height: 80rpx;
  329. border-radius: 40rpx;
  330. background: var(--ui-BG);
  331. }
  332. }
  333. </style>