receive.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <!-- 奖品领取 -->
  2. <template>
  3. <s-layout title="奖品领取">
  4. <uni-data-checkbox v-model="state.radio" :wrap="true" :localdata="state.addressList"></uni-data-checkbox>
  5. <uni-forms
  6. v-if="state.radio === 9999"
  7. ref="addressFormRef"
  8. v-model="state.model"
  9. :rules="rules"
  10. validateTrigger="bind"
  11. labelWidth="160"
  12. labelAlign="left"
  13. border
  14. :labelStyle="{ fontWeight: 'bold' }"
  15. >
  16. <view class="bg-white form-box ss-p-x-30">
  17. <uni-forms-item name="name" label="收货人" class="form-item">
  18. <uni-easyinput v-model="state.model.name" placeholder="请填写收货人姓名" :inputBorder="false" placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal"/>
  19. </uni-forms-item>
  20. <uni-forms-item name="mobile" label="手机号" class="form-item">
  21. <uni-easyinput v-model="state.model.mobile" type="number" placeholder="请输入手机号" :inputBorder="false" placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal"/>
  22. </uni-forms-item>
  23. <uni-forms-item name="areaName" label="省市区" @tap="state.showRegion = true" class="form-item">
  24. <uni-easyinput v-model="state.model.areaName" disabled :inputBorder="false"
  25. :styles="{ disableColor: '#fff', color: '#333' }" placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal" placeholder="请选择省市区">
  26. <template v-slot:right>
  27. <uni-icons type="right" />
  28. </template>
  29. </uni-easyinput>
  30. </uni-forms-item>
  31. <uni-forms-item name="detailAddress" label="详细地址" :formItemStyle="{ alignItems: 'flex-start' }" :labelStyle="{ lineHeight: '5em' }" class="textarea-item">
  32. <uni-easyinput :inputBorder="false" type="textarea" v-model="state.model.detailAddress" placeholderStyle="color:#BBBBBB;font-size:30rpx;font-weight:400;line-height:normal" placeholder="请输入详细地址" clearable/>
  33. </uni-forms-item>
  34. </view>
  35. </uni-forms>
  36. <su-fixed bottom :opacity="false" bg="" placeholder :noFixed="false" :index="10">
  37. <view class="footer-box ss-flex-col ss-row-between ss-p-20">
  38. <view class="ss-m-b-20">
  39. <button class="ss-reset-button save-btn ui-Shadow-Main" @tap="onSave">领取</button>
  40. </view>
  41. </view>
  42. </su-fixed>
  43. <!-- 省市区弹窗 -->
  44. <su-region-picker :show="state.showRegion" @cancel="state.showRegion = false" @confirm="onRegionConfirm"/>
  45. </s-layout>
  46. </template>
  47. <script setup>
  48. import { ref, reactive, unref } from 'vue';
  49. import sheep from '@/sheep';
  50. import { onLoad } from '@dcloudio/uni-app';
  51. import _ from 'lodash-es';
  52. import { mobile } from '@/sheep/validate/form';
  53. import AreaApi from '@/sheep/api/system/area';
  54. import AddressApi from '@/sheep/api/member/address';
  55. const addressFormRef = ref(null);
  56. const state = reactive({
  57. showRegion: false,
  58. model: {
  59. name: '',
  60. mobile: '',
  61. detailAddress: '',
  62. defaultStatus: false,
  63. areaName: '',
  64. },
  65. rules: {},
  66. radio: 0,
  67. addressList: [
  68. { text: '请选择收货地址', value: 0 },
  69. { text: '收货地址1', value: 1 },
  70. { text: '收货地址2', value: 2 },
  71. { text: '收货地址3', value: 3 },
  72. { text: '收货地址4', value: 4 },
  73. ],
  74. });
  75. const rules = {
  76. name: {
  77. rules: [{ required: true, errorMessage: '请输入收货人姓名' }]
  78. },
  79. mobile,
  80. detailAddress: {
  81. rules: [{ required: true, errorMessage: '请输入详细地址' }]
  82. },
  83. areaName: {
  84. rules: [{ required: true, errorMessage: '请选择您的位置' }]
  85. }
  86. }
  87. // 确认选择地区
  88. const onRegionConfirm = (e) => {
  89. state.model.areaName = `${e.province_name} ${e.city_name} ${e.district_name}`;
  90. state.model.areaId = e.district_id;
  91. state.showRegion = false;
  92. };
  93. // 获得地区数据
  94. const getAreaData = () => {
  95. if (_.isEmpty(uni.getStorageSync('areaData'))) {
  96. AreaApi.getAreaTree().then((res) => {
  97. if (res.code === 0) {
  98. uni.setStorageSync('areaData', res.data);
  99. }
  100. });
  101. }
  102. };
  103. // 获取收货地址
  104. const getAddressList = async () => {
  105. const list = (await AddressApi.getAddressList()).data;
  106. state.addressList = [...list, { id: 9999, label: '使用新地址' }]
  107. }
  108. // 保存收货地址
  109. const onSave = async () => {
  110. // 参数校验
  111. const validate = await unref(addressFormRef)
  112. .validate()
  113. .catch((error) => {
  114. console.log('error: ', error);
  115. });
  116. if (!validate) {
  117. return;
  118. }
  119. // // 提交请求
  120. // const formData = {
  121. // ...state.model,
  122. // };
  123. // const { code } =
  124. // state.model.id > 0
  125. // ? await AddressApi.updateAddress(formData)
  126. // : await AddressApi.createAddress(formData);
  127. // if (code === 0) {
  128. // sheep.$router.back();
  129. // }
  130. };
  131. const receiveId = ref()
  132. onLoad(async (options) => {
  133. console.log('==============================')
  134. // 获得地区数据
  135. getAreaData()
  136. // 获取收货地址列表
  137. await getAddressList()
  138. console.log(options, 'receive')
  139. receiveId.value = options.id
  140. });
  141. </script>
  142. <style lang="scss">
  143. :deep() {
  144. .uni-forms-item__label .label-text {
  145. font-size: 28rpx !important;
  146. color: #333333 !important;
  147. line-height: normal !important;
  148. }
  149. .uni-easyinput__content-input {
  150. font-size: 28rpx !important;
  151. color: #333333 !important;
  152. line-height: normal !important;
  153. padding-left: 0 !important;
  154. }
  155. .uni-easyinput__content-textarea {
  156. font-size: 28rpx !important;
  157. color: #333333 !important;
  158. line-height: normal !important;
  159. margin-top: 8rpx !important;
  160. }
  161. .uni-icons {
  162. font-size: 40rpx !important;
  163. }
  164. .is-textarea-icon {
  165. margin-top: 22rpx;
  166. }
  167. .is-disabled {
  168. color: #333333;
  169. }
  170. .uni-data-checklist .checklist-group {
  171. display: block !important;
  172. }
  173. }
  174. .default-box {
  175. width: 100%;
  176. box-sizing: border-box;
  177. height: 100rpx;
  178. .default-box-title {
  179. font-size: 28rpx;
  180. color: #333333;
  181. line-height: normal;
  182. }
  183. }
  184. .footer-box {
  185. .save-btn {
  186. width: 710rpx;
  187. height: 80rpx;
  188. border-radius: 40rpx;
  189. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  190. color: $white;
  191. }
  192. .cancel-btn {
  193. width: 710rpx;
  194. height: 80rpx;
  195. border-radius: 40rpx;
  196. background: var(--ui-BG);
  197. }
  198. }
  199. </style>