apply.vue 10 KB

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