edit1.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <template>
  2. <view class="container">
  3. <scroll-view class="scroll-content" scroll-y>
  4. <!-- 基本信息区域 -->
  5. <view class="section-card">
  6. <!-- 联系人 -->
  7. <view class="form-item">
  8. <view class="label required">姓名</view>
  9. <view class="input-area">
  10. <u-input v-model="formData.shopContacts" placeholder="请输入联系人" border="none" clearable
  11. @blur="validateField('shopContacts')" input-align="right" />
  12. <view class="error-msg" v-if="errors.shopContacts">{{ errors.shopContacts }}</view>
  13. </view>
  14. </view>
  15. <!-- 联系电话 -->
  16. <view class="form-item">
  17. <view class="label required">联系电话</view>
  18. <view class="input-area">
  19. <u-input v-model="formData.shopContactInfo" placeholder="请输入联系电话" border="none" clearable
  20. @blur="validateField('shopContactInfo')" input-align="right" />
  21. <view class="error-msg" v-if="errors.shopContactInfo">{{ errors.shopContactInfo }}</view>
  22. </view>
  23. </view>
  24. <!-- 位置 -->
  25. <view class="form-item time-picker-item" @click="showAreaPicker = true">
  26. <view class="label required">所在省市区</view>
  27. <view class="input-area">
  28. <view class="time-display">
  29. {{ formData.shopLocation || '请选择省市区' }}
  30. <u-icon name="arrow-right" color="#c0c4cc" class="time-arrow"></u-icon>
  31. </view>
  32. <view class="error-msg" v-if="errors.shopLocation">{{ errors.shopLocation }}</view>
  33. </view>
  34. </view>
  35. <!-- 详细地址 -->
  36. <!-- <view class="form-item">
  37. <view class="label">详细地址</view>
  38. <view class="input-area">
  39. <u-input v-model="formData.shopLocationLine" placeholder="请输入详细地址" border="none" clearable
  40. input-align="right" />
  41. </view>
  42. </view> -->
  43. <!-- 详细地址 -->
  44. <view class="upload-section">
  45. <view class="form-label required">详细地址</view>
  46. <u-textarea class="textarea" v-model="formData.goodsOverview" placeholder="请填写详细地址" maxlength="200"
  47. height="160" count></u-textarea>
  48. </view>
  49. </view>
  50. <!-- 占位元素,确保内容不被底部按钮遮挡 -->
  51. <view class="bottom-placeholder"></view>
  52. </scroll-view>
  53. <view class="add-btn-container">
  54. <button class="add-btn" @click="handleSave">
  55. <text class="add-btn-text">保存</text>
  56. </button>
  57. </view>
  58. <!-- 省市区选择器组件 -->
  59. <AreaPickerCustommer :show="showAreaPicker" @update:show="showAreaPicker = $event"
  60. @confirm="handleAreaConfirm" />
  61. </view>
  62. </template>
  63. <script setup>
  64. import {
  65. ref,
  66. reactive,
  67. onMounted
  68. } from 'vue'
  69. import {
  70. onLoad
  71. } from '@dcloudio/uni-app' // 导入 UniApp 的生命周期
  72. import AreaPickerCustommer from '@/components/AreaPickerCustommer.vue';
  73. const tenantId = ref('')
  74. // 表单数据 - 根据UI设计图预填数据
  75. const formData = reactive({
  76. id: '',
  77. shopImage: [],
  78. shopAvatar: undefined,
  79. shopLocation: '',
  80. shopLocationLine: '',
  81. shopContacts: '',
  82. shopContactInfo: '',
  83. wechatId: '',
  84. goodsOverview: '',
  85. approvalType: '0' //0:门店审批 1:无需审批
  86. })
  87. // {
  88. // "locationLng": 112.45,
  89. // "locationLat": 34.61
  90. // }
  91. // 错误信息
  92. const errors = reactive({
  93. shopLocation: '',
  94. shopContacts: '',
  95. shopContactInfo: ''
  96. })
  97. // 头像上传
  98. const avatarList = ref([])
  99. // 海报上传
  100. const posterList = ref([])
  101. // 地区选择器
  102. const showAreaPicker = ref(false);
  103. // 时间选择器
  104. const showTimePicker = ref(false)
  105. const filterNumber = (value) => {
  106. // 移除所有非数字字符,包括小数点(如果不需要小数点可以这样)
  107. // 如果允许小数点,可以使用 /[^\d.]/g,但注意只能有一个小数点
  108. // 这里我们只需要整数,所以移除非数字
  109. formData.value.shopPromotionProportion = value.replace(/\D/g, '');
  110. };
  111. onLoad((option) => {
  112. tenantId.value = option.tenantId
  113. })
  114. onMounted(() => {
  115. getAddressInfo()
  116. })
  117. const getAddressInfo = () => {
  118. const params = {
  119. tenantId: tenantId.value
  120. }
  121. // getAddressApi(params).then(res => {
  122. // if (res.code == 200) {
  123. // if (res.data.length == 0) {
  124. // uni.showToast({
  125. // title: '未查询到店铺信息',
  126. // icon: 'success'
  127. // })
  128. // return
  129. // }
  130. // const shopItemTemp = res.data[0]
  131. // Object.assign(formData, shopItemTemp)
  132. // if (!shopItemTemp.approvalType) {
  133. // formData.approvalType = '0'
  134. // }
  135. // // if (formData.businessHoursStart && formData.businessHoursEnd) {
  136. // // formData.businessHours = `${formData.businessHoursStart}-${formData.businessHoursEnd}`
  137. // // }
  138. // formData.shopAvatar = shopItemTemp.shopAvatar
  139. // if (shopItemTemp.shopAvatarUrl) {
  140. // avatarList.value.push({
  141. // url: shopItemTemp.shopAvatarUrl,
  142. // status: 'success'
  143. // })
  144. // }
  145. // formData.shopImage = []
  146. // const imageIdList = shopItemTemp.shopImage.split(",")
  147. // formData.shopImage = imageIdList
  148. // const imageList = shopItemTemp.shopImageUrl.split(",")
  149. // if (shopItemTemp.shopImageUrl) {
  150. // imageList.map(it => {
  151. // posterList.value.push({
  152. // url: it,
  153. // status: 'success'
  154. // })
  155. // })
  156. // }
  157. // }
  158. // })
  159. }
  160. // 表单验证
  161. const validateField = (field) => {
  162. switch (field) {
  163. case 'shopContacts':
  164. errors.shopContacts = formData.shopContacts.trim() ? '' : '联系人不能为空'
  165. break
  166. case 'shopContactInfo':
  167. if (!formData.shopContactInfo) {
  168. errors.shopContactInfo = '联系电话不能为空'
  169. } else if (!/^1[3-9]\d{9}$/.test(formData.shopContactInfo)) {
  170. errors.shopContactInfo = '请输入正确的手机号码'
  171. } else {
  172. errors.shopContactInfo = ''
  173. }
  174. break
  175. case 'shopLocation':
  176. errors.shopLocation = formData.shopLocation.trim() ? '' : '店铺位置不能为空'
  177. break
  178. }
  179. }
  180. // 时间选择确认
  181. const timeConfirm = (event) => {
  182. const start = event.value[0] ? event.value[0]?.label : '00:00'
  183. const end = event.value[1] ? event.value[1]?.label : '00:00'
  184. formData.businessHoursStart = start
  185. formData.businessHoursEnd = end
  186. formData.businessHours = `${start}-${end}`
  187. showTimePicker.value = false
  188. validateField('businessHours')
  189. }
  190. // 处理地区选择确认
  191. const handleAreaConfirm = (areaData) => {
  192. console.log('选择的地区数据:', areaData);
  193. // 更新表单数据
  194. const district = areaData.district ? areaData.district.name : '';
  195. const province = areaData.province ? areaData.province.name : '';
  196. const city = areaData.city ? areaData.city.name : '';
  197. formData.shopLocation = province + city + district;
  198. // 触发地区字段验证
  199. validateField('shopLocation');
  200. };
  201. //0:门店审批 1:无需审批
  202. const checkApprovalType = (type) => {
  203. formData.approvalType = type
  204. }
  205. // 保存处理
  206. const handleSave = () => {
  207. // 验证所有必填字段
  208. validateField('shopName')
  209. validateField('shopLocation')
  210. validateField('shopContacts')
  211. validateField('shopContactInfo')
  212. validateField('businessHours')
  213. // 检查是否有错误
  214. const hasErrors = Object.values(errors).some(error => error !== '')
  215. if (hasErrors) {
  216. return
  217. }
  218. if (!formData.shopAvatar) {
  219. uni.showToast({
  220. icon: 'none',
  221. title: "请上传店铺头像~"
  222. })
  223. return
  224. }
  225. const params = {
  226. ...formData
  227. }
  228. params.shopImage = params.shopImage.join(",")
  229. editShopInfoApi(params).then(res => {
  230. if (res.code == 200) {
  231. uni.showToast({
  232. title: "修改成功~",
  233. icon: "success"
  234. })
  235. uni.navigateBack()
  236. }
  237. })
  238. }
  239. </script>
  240. <style lang="scss" scoped>
  241. .container {
  242. height: 100vh;
  243. display: flex;
  244. flex-direction: column;
  245. background-color: #F5F7FA;
  246. }
  247. .page-header {
  248. padding: 32rpx;
  249. background-color: #fff;
  250. border-bottom: 1rpx solid #eee;
  251. flex-shrink: 0;
  252. .page-title {
  253. font-size: 36rpx;
  254. font-weight: 600;
  255. color: #333;
  256. }
  257. }
  258. .scroll-content {
  259. flex: 1;
  260. overflow-y: auto;
  261. padding-bottom: 160rpx;
  262. /* 为底部按钮留出空间 */
  263. }
  264. .section-card {
  265. padding: 16rpx;
  266. .form-label {
  267. font-size: 28rpx;
  268. color: #333;
  269. font-weight: 500;
  270. margin-bottom: 20rpx;
  271. }
  272. .form-label.required::before {
  273. content: "*";
  274. color: #fa3534;
  275. margin-right: 8rpx;
  276. }
  277. /* 上传区域样式 */
  278. .upload-section {
  279. background: #FFFFFF;
  280. border-radius: 16rpx;
  281. margin-bottom: 16rpx;
  282. padding: 16rpx;
  283. /* 确保上传的头像预览也是圆形 */
  284. :deep(.u-textarea) {
  285. background-color: #F5F7FA;
  286. border: none;
  287. padding: 16rpx;
  288. font-size: 28rpx;
  289. }
  290. :deep(.u-textarea__count) {
  291. background-color: #F5F7FA;
  292. }
  293. }
  294. .textarea {
  295. background-color: #F5F7FA;
  296. border: none;
  297. padding: 16rpx;
  298. font-size: 28rpx;
  299. }
  300. .column {
  301. display: flex;
  302. flex-direction: column;
  303. background: #FFFFFF;
  304. border-radius: 16rpx;
  305. margin-bottom: 16rpx;
  306. padding: 16rpx;
  307. &:last-child {
  308. border-bottom: none;
  309. }
  310. .label {
  311. width: 260rpx;
  312. font-size: 28rpx;
  313. color: #333;
  314. flex-shrink: 0;
  315. &.required::before {
  316. content: '*';
  317. color: #ff4444;
  318. margin-right: 8rpx;
  319. }
  320. }
  321. }
  322. .form-item {
  323. height: 100rpx;
  324. background: #FFFFFF;
  325. border-radius: 16rpx;
  326. margin-bottom: 16rpx;
  327. padding: 16rpx;
  328. display: flex;
  329. align-items: center;
  330. &:last-child {
  331. border-bottom: none;
  332. }
  333. .label {
  334. width: 260rpx;
  335. font-size: 28rpx;
  336. color: #333;
  337. flex-shrink: 0;
  338. &.required::before {
  339. content: '*';
  340. color: #ff4444;
  341. margin-right: 8rpx;
  342. }
  343. }
  344. .input-area {
  345. flex: 1;
  346. display: flex;
  347. flex-direction: column;
  348. align-items: flex-end;
  349. .error-msg {
  350. font-size: 24rpx;
  351. color: #ff4444;
  352. margin-top: 8rpx;
  353. width: 100%;
  354. text-align: right;
  355. }
  356. }
  357. .textarea {
  358. background-color: #F5F7FA;
  359. border: none;
  360. padding: 16rpx;
  361. font-size: 28rpx;
  362. }
  363. }
  364. .section-title {
  365. font-size: 32rpx;
  366. font-weight: bold;
  367. color: #333;
  368. margin-bottom: 16rpx;
  369. height: 48rpx;
  370. line-height: 48rpx;
  371. }
  372. .upload-desc {
  373. font-size: 24rpx;
  374. color: #999;
  375. margin-top: 16rpx;
  376. }
  377. }
  378. /* 营业时间选择项 - 整个横排可点击 */
  379. .time-picker-item {
  380. cursor: pointer;
  381. .time-display {
  382. display: flex;
  383. align-items: center;
  384. justify-content: flex-end;
  385. width: 100%;
  386. color: #333;
  387. .time-arrow {
  388. margin-left: 16rpx;
  389. }
  390. }
  391. }
  392. .avatar-upload {
  393. display: flex;
  394. justify-content: flex-end;
  395. align-items: center;
  396. }
  397. .upload-avatar-btn {
  398. display: flex;
  399. justify-content: center;
  400. align-items: center;
  401. width: 60rpx;
  402. height: 60rpx;
  403. border: 2rpx dashed #c0c4cc;
  404. /* 圆形头像 */
  405. background-color: #f8f8f8;
  406. /* 确保上传的头像预览也是圆形 */
  407. :deep(.u-upload__wrap) {
  408. .u-upload__wrap__preview {
  409. border-radius: 50%;
  410. overflow: hidden;
  411. }
  412. }
  413. }
  414. .poster-upload-area {
  415. margin-top: 16rpx;
  416. display: flex;
  417. justify-content: flex-start;
  418. }
  419. .upload-poster-btn {
  420. display: flex;
  421. flex-direction: column;
  422. justify-content: center;
  423. align-items: center;
  424. width: 148rpx;
  425. height: 148rpx;
  426. border: 2rpx dashed #c0c4cc;
  427. border-radius: 8rpx;
  428. background-color: #f8f8f8;
  429. .upload-text {
  430. font-size: 24rpx;
  431. color: #999;
  432. margin-top: 12rpx;
  433. }
  434. }
  435. .radio-group {
  436. width: 100%;
  437. display: flex;
  438. flex-direction: column;
  439. margin-top: 16rpx;
  440. .radio-item {
  441. margin-bottom: 24rpx;
  442. width: 100%;
  443. display: flex;
  444. flex-direction: column;
  445. align-items: left;
  446. font-size: 28rpx;
  447. color: #333;
  448. .radio-desc {
  449. font-size: 24rpx;
  450. color: #999;
  451. margin-top: 8rpx;
  452. }
  453. }
  454. }
  455. .bottom-placeholder {
  456. height: 40rpx;
  457. }
  458. .add-btn-container {
  459. padding: 32rpx;
  460. background-color: #fff;
  461. border-top: 1rpx solid #eee;
  462. }
  463. .add-btn {
  464. height: 88rpx;
  465. background: #1B64F0;
  466. border-radius: 44rpx;
  467. }
  468. .add-btn-text {
  469. color: #fff;
  470. font-size: 32rpx;
  471. font-weight: 500;
  472. height: 88rpx;
  473. line-height: 88rpx;
  474. }
  475. /* 按钮激活效果 */
  476. .add-btn:active {
  477. opacity: 0.8;
  478. }
  479. </style>