apply.vue 10 KB

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