apply.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <view v-if="!isLoading" class="container">
  3. <!-- 商品详情 -->
  4. <view class="goods-detail b-f dis-flex flex-dir-row">
  5. <view class="left">
  6. <image class="goods-image" :src="goods.goods_image"></image>
  7. </view>
  8. <view class="right dis-flex flex-box flex-dir-column flex-x-around">
  9. <view class="goods-name">
  10. <text class="twoline-hide">{{ goods.goods_name }}</text>
  11. </view>
  12. <view class="dis-flex col-9 f-24">
  13. <view class="flex-box">
  14. <view class="goods-props clearfix">
  15. <view class="goods-props-item" v-for="(props, idx) in goods.goods_props" :key="idx">
  16. <text>{{ props.value.name }}</text>
  17. </view>
  18. </view>
  19. </view>
  20. <text class="t-r">×{{ goods.total_num }}</text>
  21. </view>
  22. </view>
  23. </view>
  24. <!-- 服务类型 -->
  25. <view class="row-service b-f m-top20">
  26. <view class="row-title">服务类型</view>
  27. <view class="service-switch dis-flex">
  28. <view class="switch-item" v-for="(item, index) in RefundTypeEnum.data" :key="index" :class="{ active: formData.type == item.value }"
  29. @click="onSwitchService(item.value)">{{ item.name }}</view>
  30. </view>
  31. </view>
  32. <!-- 申请原因 -->
  33. <view class="row-textarea b-f m-top20">
  34. <view class="row-title">申请原因</view>
  35. <view class="content">
  36. <textarea class="textarea" v-model="formData.content" maxlength="2000" placeholder="请详细填写申请原因,注意保持商品的完好,建议您先与卖家沟通"
  37. placeholderStyle="color:#ccc"></textarea>
  38. </view>
  39. </view>
  40. <!-- 退款金额 -->
  41. <view v-if="formData.type == RefundTypeEnum.RETURN.value" class="row-money b-f m-top20 dis-flex">
  42. <view class="row-title">退款金额</view>
  43. <view class="money col-m">¥{{ goods.total_pay_price }}</view>
  44. </view>
  45. <!-- 上传凭证 -->
  46. <view class="row-voucher b-f m-top20">
  47. <view class="row-title">上传凭证 (最多6张)</view>
  48. <view class="image-list">
  49. <!-- 图片列表 -->
  50. <view class="image-preview" v-for="(image, imageIndex) in imageList" :key="imageIndex">
  51. <text class="image-delete iconfont icon-shanchu" @click="deleteImage(imageIndex)"></text>
  52. <image class="image" mode="aspectFill" :src="image.path"></image>
  53. </view>
  54. <!-- 上传图片 -->
  55. <view v-if="imageList.length < maxImageLength" class="image-picker" @click="chooseImage()">
  56. <text class="choose-icon iconfont icon-camera"></text>
  57. <text class="choose-text">上传图片</text>
  58. </view>
  59. </view>
  60. </view>
  61. <!-- 底部操作按钮 -->
  62. <view class="footer-fixed">
  63. <view class="btn-wrapper">
  64. <view class="btn-item btn-item-main" :class="{ disabled }" @click="handleSubmit()">确认提交</view>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. import { RefundTypeEnum } from '@/common/enum/order/refund'
  71. import * as UploadApi from '@/api/upload'
  72. import * as RefundApi from '@/api/refund'
  73. const maxImageLength = 6
  74. export default {
  75. data() {
  76. return {
  77. // 枚举类
  78. RefundTypeEnum,
  79. // 正在加载
  80. isLoading: true,
  81. // 订单商品id
  82. orderGoodsId: null,
  83. // 订单商品详情
  84. goods: {},
  85. // 表单数据
  86. formData: {
  87. // 图片上传成功的文件ID集
  88. images: [],
  89. // 服务类型
  90. type: 10,
  91. // 申请原因
  92. content: ''
  93. },
  94. // 用户选择的图片列表
  95. imageList: [],
  96. // 最大图片数量
  97. maxImageLength,
  98. // 按钮禁用
  99. disabled: false
  100. }
  101. },
  102. /**
  103. * 生命周期函数--监听页面加载
  104. */
  105. onLoad({ orderGoodsId }) {
  106. this.orderGoodsId = orderGoodsId
  107. // 获取订单商品详情
  108. this.getGoodsDetail()
  109. },
  110. methods: {
  111. // 获取订单商品详情
  112. getGoodsDetail() {
  113. const app = this
  114. app.isLoading = true
  115. RefundApi.goods(app.orderGoodsId)
  116. .then(result => {
  117. app.goods = result.data.goods
  118. app.isLoading = false
  119. })
  120. },
  121. // 切换类型
  122. onSwitchService(value) {
  123. this.formData.type = value
  124. },
  125. // 选择图片
  126. chooseImage() {
  127. const app = this
  128. const oldImageList = app.imageList
  129. // 选择图片
  130. uni.chooseImage({
  131. count: maxImageLength - oldImageList.length,
  132. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  133. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  134. success({ tempFiles }) {
  135. // tempFiles = [{path:'xxx', size:100}]
  136. app.imageList = oldImageList.concat(tempFiles)
  137. }
  138. });
  139. },
  140. // 删除图片
  141. deleteImage(imageIndex) {
  142. this.imageList.splice(imageIndex, 1)
  143. },
  144. // 表单提交
  145. handleSubmit() {
  146. const app = this
  147. const { imageList } = app
  148. // 判断是否重复提交
  149. if (app.disabled === true) return false
  150. // 按钮禁用
  151. app.disabled = true
  152. // 判断是否需要上传图片
  153. if (imageList.length > 0) {
  154. app.uploadFile()
  155. .then(() => app.onSubmit())
  156. .catch(err => {
  157. app.disabled = false
  158. if (err.statusCode !== 0) {
  159. app.$toast(err.errMsg)
  160. }
  161. console.log('err', err)
  162. })
  163. } else {
  164. app.onSubmit()
  165. }
  166. },
  167. // 提交到后端
  168. onSubmit() {
  169. const app = this
  170. RefundApi.apply(app.orderGoodsId, app.formData)
  171. .then(result => {
  172. app.$toast(result.message)
  173. setTimeout(() => {
  174. app.disabled = false
  175. uni.navigateBack()
  176. }, 1500)
  177. })
  178. .catch(err => app.disabled = false)
  179. },
  180. // 上传图片
  181. uploadFile() {
  182. const app = this
  183. const { imageList } = app
  184. // 批量上传
  185. return new Promise((resolve, reject) => {
  186. if (imageList.length > 0) {
  187. UploadApi.image(imageList)
  188. .then(fileIds => {
  189. app.formData.images = fileIds
  190. resolve(fileIds)
  191. })
  192. .catch(reject)
  193. } else {
  194. resolve()
  195. }
  196. })
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. .container {
  203. padding-bottom: constant(env(safe-area-inset-bottom) + 130rpx);
  204. padding-bottom: calc(env(safe-area-inset-bottom) + 130rpx);
  205. }
  206. .row-title {
  207. color: #888;
  208. margin-bottom: 20rpx;
  209. }
  210. // 商品信息
  211. .goods-detail {
  212. padding: 24rpx 20rpx;
  213. .left {
  214. .goods-image {
  215. display: block;
  216. width: 150rpx;
  217. height: 150rpx;
  218. }
  219. }
  220. .right {
  221. padding-left: 20rpx;
  222. }
  223. .goods-props {
  224. margin-top: 14rpx;
  225. height: 40rpx;
  226. color: #ababab;
  227. font-size: 24rpx;
  228. overflow: hidden;
  229. .goods-props-item {
  230. display: inline-block;
  231. margin-right: 14rpx;
  232. padding: 4rpx 16rpx;
  233. border-radius: 12rpx;
  234. background-color: #F5F5F5;
  235. width: auto;
  236. }
  237. }
  238. }
  239. /* 服务类型 */
  240. .row-service {
  241. padding: 24rpx 20rpx;
  242. }
  243. .service-switch {
  244. .switch-item {
  245. padding: 6rpx 30rpx;
  246. margin-right: 25rpx;
  247. border-radius: 10rpx;
  248. border: 1px solid rgb(177, 177, 177);
  249. color: #888;
  250. &.active {
  251. color: #fc1e56;
  252. border: 1px solid #fc1e56;
  253. }
  254. }
  255. }
  256. /* 申请原因 */
  257. .row-textarea {
  258. padding: 24rpx 20rpx;
  259. .textarea {
  260. width: 100%;
  261. height: 220rpx;
  262. padding: 12rpx;
  263. border: 1rpx solid #e8e8e8;
  264. border-radius: 5rpx;
  265. box-sizing: border-box;
  266. font-size: 26rpx;
  267. }
  268. }
  269. /* 退款金额 */
  270. .row-money {
  271. padding: 24rpx 20rpx;
  272. .row-title {
  273. margin-bottom: 0;
  274. margin-right: 30rpx;
  275. }
  276. }
  277. // 上传凭证
  278. .row-voucher {
  279. padding: 24rpx 20rpx;
  280. .image-list {
  281. padding: 0 20rpx;
  282. margin-top: 20rpx;
  283. margin-bottom: -20rpx;
  284. &:after {
  285. clear: both;
  286. content: " ";
  287. display: table;
  288. }
  289. .image {
  290. display: block;
  291. width: 100%;
  292. height: 100%;
  293. }
  294. .image-picker,
  295. .image-preview {
  296. width: 184rpx;
  297. height: 184rpx;
  298. margin-right: 30rpx;
  299. margin-bottom: 30rpx;
  300. float: left;
  301. &:nth-child(3n+0) {
  302. margin-right: 0;
  303. }
  304. }
  305. .image-picker {
  306. display: flex;
  307. flex-direction: column;
  308. justify-content: center;
  309. align-items: center;
  310. border: 1rpx dashed #ccc;
  311. color: #ccc;
  312. .choose-icon {
  313. font-size: 48rpx;
  314. margin-bottom: 6rpx;
  315. }
  316. .choose-text {
  317. font-size: 24rpx;
  318. }
  319. }
  320. .image-preview {
  321. position: relative;
  322. .image-delete {
  323. position: absolute;
  324. top: -15rpx;
  325. right: -15rpx;
  326. height: 42rpx;
  327. width: 42rpx;
  328. line-height: 42rpx;
  329. background: rgba(0, 0, 0, 0.64);
  330. border-radius: 50%;
  331. color: #fff;
  332. font-weight: bolder;
  333. font-size: 22rpx;
  334. z-index: 10;
  335. text-align: center;
  336. }
  337. }
  338. }
  339. }
  340. // 底部操作栏
  341. .footer-fixed {
  342. position: fixed;
  343. bottom: var(--window-bottom);
  344. left: 0;
  345. right: 0;
  346. z-index: 11;
  347. box-shadow: 0 -4rpx 40rpx 0 rgba(151, 151, 151, 0.24);
  348. background: #fff;
  349. // 设置ios刘海屏底部横线安全区域
  350. padding-bottom: constant(safe-area-inset-bottom);
  351. padding-bottom: env(safe-area-inset-bottom);
  352. .btn-wrapper {
  353. height: 120rpx;
  354. display: flex;
  355. align-items: center;
  356. padding: 0 20rpx;
  357. }
  358. .btn-item {
  359. flex: 1;
  360. font-size: 28rpx;
  361. height: 80rpx;
  362. line-height: 80rpx;
  363. text-align: center;
  364. color: #fff;
  365. border-radius: 50rpx;
  366. }
  367. .btn-item-main {
  368. background: linear-gradient(to right, #f9211c, #ff6335);
  369. // 禁用按钮
  370. &.disabled {
  371. background: #ff9779;
  372. }
  373. }
  374. }
  375. </style>