apply.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. <template>
  2. <view v-if="!isLoading" class="container" :style="appThemeStyle">
  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.tempFilePath"></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. // #ifndef MP-WEIXIN
  131. uni.chooseImage({
  132. count: maxImageLength - oldImageList.length,
  133. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  134. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  135. success({ tempFiles }) {
  136. // tempFiles = [{path:'xxx', size:100}]
  137. app.imageList = oldImageList.concat(tempFiles)
  138. },
  139. fail(err) {
  140. console.log('chooseImage fail', err)
  141. }
  142. })
  143. // #endif
  144. // #ifdef MP-WEIXIN
  145. uni.chooseMedia({
  146. count: maxImageLength - oldImageList.length,
  147. mediaType: ['image'],
  148. sourceType: ['album', 'camera'],
  149. sizeType: ['original', 'compressed'],
  150. success({ tempFiles }) {
  151. // tempFiles = [{tempFilePath:'xxx', size:100}]
  152. app.imageList = oldImageList.concat(tempFiles)
  153. },
  154. fail(err) {
  155. console.log('chooseMedia fail', err)
  156. }
  157. })
  158. // #endif
  159. },
  160. // 删除图片
  161. deleteImage(imageIndex) {
  162. this.imageList.splice(imageIndex, 1)
  163. },
  164. // 表单提交
  165. handleSubmit() {
  166. const app = this
  167. const { imageList } = app
  168. // 判断是否重复提交
  169. if (app.disabled === true) return false
  170. // 表单验证
  171. if (!app.formData.content.trim().length) {
  172. app.$toast('请填写申请原因')
  173. return false
  174. }
  175. // 按钮禁用
  176. app.disabled = true
  177. // 判断是否需要上传图片
  178. if (imageList.length > 0) {
  179. app.uploadFile()
  180. .then(() => app.onSubmit())
  181. .catch(err => {
  182. app.disabled = false
  183. if (err.statusCode !== 0) {
  184. app.$toast(err.errMsg)
  185. }
  186. console.log('err', err)
  187. })
  188. } else {
  189. app.onSubmit()
  190. }
  191. },
  192. // 提交到后端
  193. onSubmit() {
  194. const app = this
  195. RefundApi.apply(app.orderGoodsId, app.formData)
  196. .then(result => {
  197. app.$toast(result.message)
  198. setTimeout(() => {
  199. app.disabled = false
  200. uni.navigateBack()
  201. }, 1500)
  202. })
  203. .catch(err => app.disabled = false)
  204. },
  205. // 上传图片
  206. uploadFile() {
  207. const app = this
  208. const { imageList } = app
  209. // 批量上传
  210. return new Promise((resolve, reject) => {
  211. if (imageList.length > 0) {
  212. UploadApi.image(imageList)
  213. .then(fileIds => {
  214. app.formData.images = fileIds
  215. resolve(fileIds)
  216. })
  217. .catch(reject)
  218. } else {
  219. resolve()
  220. }
  221. })
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss" scoped>
  227. .container {
  228. // 设置ios刘海屏底部横线安全区域
  229. padding-bottom: calc(constant(safe-area-inset-bottom) + 180rpx);
  230. padding-bottom: calc(env(safe-area-inset-bottom) + 180rpx);
  231. }
  232. .row-title {
  233. color: #888;
  234. margin-bottom: 20rpx;
  235. }
  236. // 商品信息
  237. .goods-detail {
  238. padding: 24rpx 20rpx;
  239. .left {
  240. .goods-image {
  241. display: block;
  242. width: 150rpx;
  243. height: 150rpx;
  244. }
  245. }
  246. .right {
  247. padding-left: 20rpx;
  248. }
  249. .goods-props {
  250. margin-top: 14rpx;
  251. color: #ababab;
  252. font-size: 24rpx;
  253. overflow: hidden;
  254. .goods-props-item {
  255. padding: 4rpx 16rpx;
  256. border-radius: 12rpx;
  257. background-color: #fcfcfc;
  258. }
  259. }
  260. }
  261. /* 服务类型 */
  262. .row-service {
  263. padding: 24rpx 20rpx;
  264. }
  265. .service-switch {
  266. .switch-item {
  267. padding: 6rpx 30rpx;
  268. margin-right: 25rpx;
  269. border-radius: 10rpx;
  270. border: 1px solid rgb(177, 177, 177);
  271. color: #888888;
  272. &.active {
  273. color: $main-bg;
  274. border: 1px solid $main-bg;
  275. }
  276. }
  277. }
  278. /* 申请原因 */
  279. .row-textarea {
  280. padding: 24rpx 20rpx;
  281. .textarea {
  282. width: 100%;
  283. height: 220rpx;
  284. padding: 12rpx;
  285. border: 1rpx solid #e8e8e8;
  286. border-radius: 5rpx;
  287. box-sizing: border-box;
  288. font-size: 26rpx;
  289. }
  290. }
  291. /* 退款金额 */
  292. .row-money {
  293. padding: 24rpx 20rpx;
  294. .row-title {
  295. margin-bottom: 0;
  296. margin-right: 30rpx;
  297. }
  298. }
  299. // 上传凭证
  300. .row-voucher {
  301. padding: 24rpx 20rpx;
  302. .image-list {
  303. padding: 0 20rpx;
  304. margin-top: 20rpx;
  305. margin-bottom: -20rpx;
  306. &:after {
  307. clear: both;
  308. content: " ";
  309. display: table;
  310. }
  311. .image {
  312. display: block;
  313. width: 100%;
  314. height: 100%;
  315. }
  316. .image-picker,
  317. .image-preview {
  318. width: 184rpx;
  319. height: 184rpx;
  320. margin-right: 30rpx;
  321. margin-bottom: 30rpx;
  322. float: left;
  323. &:nth-child(3n+0) {
  324. margin-right: 0;
  325. }
  326. }
  327. .image-picker {
  328. display: flex;
  329. flex-direction: column;
  330. justify-content: center;
  331. align-items: center;
  332. border: 1rpx dashed #ccc;
  333. color: #ccc;
  334. .choose-icon {
  335. font-size: 48rpx;
  336. margin-bottom: 6rpx;
  337. }
  338. .choose-text {
  339. font-size: 24rpx;
  340. }
  341. }
  342. .image-preview {
  343. position: relative;
  344. .image-delete {
  345. position: absolute;
  346. top: -15rpx;
  347. right: -15rpx;
  348. height: 42rpx;
  349. width: 42rpx;
  350. background: rgba(0, 0, 0, 0.64);
  351. border-radius: 50%;
  352. color: #fff;
  353. font-weight: bolder;
  354. font-size: 22rpx;
  355. z-index: 10;
  356. display: flex;
  357. justify-content: center;
  358. align-items: center;
  359. }
  360. }
  361. }
  362. }
  363. // 底部操作栏
  364. .footer-fixed {
  365. position: fixed;
  366. bottom: var(--window-bottom);
  367. left: var(--window-left);
  368. right: var(--window-right);
  369. z-index: 11;
  370. // 设置ios刘海屏底部横线安全区域
  371. padding-bottom: constant(safe-area-inset-bottom);
  372. padding-bottom: env(safe-area-inset-bottom);
  373. .btn-wrapper {
  374. height: 140rpx;
  375. display: flex;
  376. align-items: center;
  377. padding: 0 20rpx;
  378. }
  379. .btn-item {
  380. flex: 1;
  381. font-size: 28rpx;
  382. height: 80rpx;
  383. color: #fff;
  384. border-radius: 50rpx;
  385. display: flex;
  386. justify-content: center;
  387. align-items: center;
  388. }
  389. .btn-item-main {
  390. background: linear-gradient(to right, $main-bg, $main-bg2);
  391. color: $main-text;
  392. // 禁用按钮
  393. &.disabled {
  394. opacity: 0.6;
  395. }
  396. }
  397. }
  398. </style>