| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <template>
- <view class="after-sale">
- <!-- 商品信息 -->
- <view class="product-info">
- <image :src="product.image" mode="aspectFill" class="product-image"></image>
- <view class="product-detail">
- <view class="product-name">{{product.name}}</view>
- <view class="product-spec">{{product.spec}}</view>
- <view class="product-price">¥{{product.price}}</view>
- </view>
- </view>
-
- <!-- 售后表单 -->
- <view class="form-section">
- <u-form :model="form" ref="form">
- <u-form-item label="售后类型" prop="type" required>
- <u-radio-group v-model="form.type">
- <u-radio
- v-for="(item, index) in typeOptions"
- :key="index"
- :name="item.value"
- :label="item.label">
- </u-radio>
- </u-radio-group>
- </u-form-item>
-
- <u-form-item label="申请原因" prop="reason" required>
- <u-select
- v-model="form.reason"
- :list="reasonOptions"
- placeholder="请选择申请原因">
- </u-select>
- </u-form-item>
-
- <u-form-item label="问题描述" prop="description" required>
- <u-textarea
- v-model="form.description"
- placeholder="请详细描述您遇到的问题"
- count
- maxlength="500">
- </u-textarea>
- </u-form-item>
-
- <u-form-item label="上传凭证">
- <u-upload
- :fileList="form.images"
- @afterRead="afterRead"
- @delete="deletePic"
- name="1"
- multiple
- maxCount="9">
- </u-upload>
- </u-form-item>
-
- <u-form-item label="联系人" prop="contact" required>
- <u-input v-model="form.contact" placeholder="请输入联系人姓名" />
- </u-form-item>
-
- <u-form-item label="手机号码" prop="phone" required>
- <u-input v-model="form.phone" placeholder="请输入手机号码" type="number" maxlength="11" />
- </u-form-item>
- </u-form>
- </view>
-
- <!-- 提交按钮 -->
- <view class="submit-btn">
- <u-button type="primary" @click="submit" color="#D93025">提交申请</u-button>
- </view>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- orderId: '',
- productId: '',
- product: {
- image: '',
- name: '',
- spec: '',
- price: ''
- },
- form: {
- type: 'refund',
- reason: '',
- description: '',
- images: [],
- contact: '',
- phone: ''
- },
- typeOptions: [
- { label: '仅退款', value: 'refund' },
- { label: '退货退款', value: 'return' }
- ],
- reasonOptions: [
- { label: '商品质量问题', value: 'quality' },
- { label: '商品损坏', value: 'damaged' },
- { label: '商品与描述不符', value: 'mismatch' },
- { label: '收到错误商品', value: 'wrong' },
- { label: '其他原因', value: 'other' }
- ],
- rules: {
- type: [{
- required: true,
- message: '请选择售后类型',
- trigger: ['change']
- }],
- reason: [{
- required: true,
- message: '请选择申请原因',
- trigger: ['change']
- }],
- description: [{
- required: true,
- message: '请输入问题描述',
- trigger: ['blur']
- }],
- contact: [{
- required: true,
- message: '请输入联系人姓名',
- trigger: ['blur']
- }],
- phone: [{
- required: true,
- message: '请输入手机号码',
- trigger: ['blur']
- }, {
- pattern: /^1[3-9]\d{9}$/,
- message: '请输入正确的手机号码',
- trigger: ['blur']
- }]
- }
- }
- },
- onLoad(options) {
- this.orderId = options.orderId
- this.productId = options.productId
- this.getProductInfo()
- },
- methods: {
- async getProductInfo() {
- try {
- const res = await this.$api.product.detail(this.productId)
- this.product = res.data
- } catch (e) {
- this.$u.toast('获取商品信息失败')
- }
- },
- async afterRead(event) {
- const { file } = event
- const uploadPromises = (Array.isArray(file) ? file : [file]).map(item => {
- return this.uploadFilePromise(item)
- })
- try {
- const urls = await Promise.all(uploadPromises)
- this.form.images = [...this.form.images, ...urls]
- } catch (e) {
- this.$u.toast('上传图片失败')
- }
- },
- uploadFilePromise(file) {
- return new Promise((resolve, reject) => {
- uni.uploadFile({
- url: this.$api.common.uploadUrl,
- filePath: file.url,
- name: 'file',
- success: (res) => {
- const data = JSON.parse(res.data)
- resolve(data.url)
- },
- fail: reject
- })
- })
- },
- deletePic(event) {
- const index = event.index
- this.form.images.splice(index, 1)
- },
- async submit() {
- try {
- await this.$refs.form.validate()
- await this.$api.order.afterSale({
- orderId: this.orderId,
- productId: this.productId,
- ...this.form
- })
- this.$u.toast('提交成功')
- setTimeout(() => {
- uni.navigateBack()
- }, 1500)
- } catch (e) {
- if (e.errors) return
- this.$u.toast('提交失败')
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .after-sale {
- min-height: 100vh;
- background: #f5f5f5;
- padding-bottom: 120rpx;
-
- .product-info {
- background: #fff;
- padding: 30rpx;
- display: flex;
- margin-bottom: 20rpx;
-
- .product-image {
- width: 160rpx;
- height: 160rpx;
- border-radius: 8rpx;
- margin-right: 20rpx;
- }
-
- .product-detail {
- flex: 1;
-
- .product-name {
- font-size: 28rpx;
- color: #333;
- margin-bottom: 10rpx;
- }
-
- .product-spec {
- font-size: 24rpx;
- color: #999;
- margin-bottom: 20rpx;
- }
-
- .product-price {
- font-size: 32rpx;
- color: #D93025;
- font-weight: bold;
- }
- }
- }
-
- .form-section {
- background: #fff;
- padding: 30rpx;
-
- :deep(.u-form-item) {
- padding: 20rpx 0;
- }
- }
-
- .submit-btn {
- position: fixed;
- left: 0;
- right: 0;
- bottom: 0;
- padding: 20rpx 40rpx;
- background: #fff;
- }
- }
- </style>
|