receive copy.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. });
  69. const rules = {
  70. name: {
  71. rules: [{ required: true, errorMessage: '请输入收货人姓名' }]
  72. },
  73. mobile,
  74. detailAddress: {
  75. rules: [{ required: true, errorMessage: '请输入详细地址' }]
  76. },
  77. areaName: {
  78. rules: [{ required: true, errorMessage: '请选择您的位置' }]
  79. }
  80. }
  81. // 确认选择地区
  82. const onRegionConfirm = (e) => {
  83. state.model.areaName = `${e.province_name} ${e.city_name} ${e.district_name}`;
  84. state.model.areaId = e.district_id;
  85. state.showRegion = false;
  86. };
  87. // 获得地区数据
  88. const getAreaData = () => {
  89. if (_.isEmpty(uni.getStorageSync('areaData'))) {
  90. AreaApi.getAreaTree().then((res) => {
  91. if (res.code === 0) {
  92. uni.setStorageSync('areaData', res.data);
  93. }
  94. });
  95. }
  96. };
  97. // 获取收货地址
  98. const getAddressList = async () => {
  99. const list = (await AddressApi.getAddressList()).data;
  100. state.addressList = list.map(e => {
  101. return { text: e.areaName, value: e.id, ...e }
  102. })
  103. // state.addressList.push({ value: 9999, text: '使用新地址' })
  104. console.log(list, '收货地址列表', state.addressList)
  105. }
  106. // 保存收货地址
  107. const onSave = async () => {
  108. // 参数校验
  109. const validate = await unref(addressFormRef)
  110. .validate()
  111. .catch((error) => {
  112. console.log('error: ', error);
  113. });
  114. if (!validate) {
  115. return;
  116. }
  117. // // 提交请求
  118. // const formData = {
  119. // ...state.model,
  120. // };
  121. // const { code } =
  122. // state.model.id > 0
  123. // ? await AddressApi.updateAddress(formData)
  124. // : await AddressApi.createAddress(formData);
  125. // if (code === 0) {
  126. // sheep.$router.back();
  127. // }
  128. };
  129. const receiveId = ref()
  130. onLoad(async (options) => {
  131. // 获得地区数据
  132. getAreaData()
  133. // 获取收货地址列表
  134. await getAddressList()
  135. console.log(options, 'receive')
  136. receiveId.value = options.id
  137. });
  138. </script>
  139. <style lang="scss">
  140. :deep() {
  141. .uni-forms-item__label .label-text {
  142. font-size: 28rpx !important;
  143. color: #333333 !important;
  144. line-height: normal !important;
  145. }
  146. .uni-easyinput__content-input {
  147. font-size: 28rpx !important;
  148. color: #333333 !important;
  149. line-height: normal !important;
  150. padding-left: 0 !important;
  151. }
  152. .uni-easyinput__content-textarea {
  153. font-size: 28rpx !important;
  154. color: #333333 !important;
  155. line-height: normal !important;
  156. margin-top: 8rpx !important;
  157. }
  158. .uni-icons {
  159. font-size: 40rpx !important;
  160. }
  161. .is-textarea-icon {
  162. margin-top: 22rpx;
  163. }
  164. .is-disabled {
  165. color: #333333;
  166. }
  167. .uni-data-checklist .checklist-group {
  168. display: block !important;
  169. }
  170. }
  171. .default-box {
  172. width: 100%;
  173. box-sizing: border-box;
  174. height: 100rpx;
  175. .default-box-title {
  176. font-size: 28rpx;
  177. color: #333333;
  178. line-height: normal;
  179. }
  180. }
  181. .footer-box {
  182. .save-btn {
  183. width: 710rpx;
  184. height: 80rpx;
  185. border-radius: 40rpx;
  186. background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
  187. color: $white;
  188. }
  189. .cancel-btn {
  190. width: 710rpx;
  191. height: 80rpx;
  192. border-radius: 40rpx;
  193. background: var(--ui-BG);
  194. }
  195. }
  196. </style>