apply.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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="twolist-hidden">{{ 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: 100rpx;
  204. }
  205. .row-title {
  206. color: #888;
  207. margin-bottom: 20rpx;
  208. }
  209. // 商品信息
  210. .goods-detail {
  211. padding: 24rpx 20rpx;
  212. .left {
  213. .goods-image {
  214. display: block;
  215. width: 150rpx;
  216. height: 150rpx;
  217. }
  218. }
  219. .right {
  220. padding-left: 20rpx;
  221. }
  222. .goods-props {
  223. margin-top: 14rpx;
  224. height: 40rpx;
  225. color: #ababab;
  226. font-size: 24rpx;
  227. overflow: hidden;
  228. .goods-props-item {
  229. display: inline-block;
  230. margin-right: 14rpx;
  231. padding: 4rpx 16rpx;
  232. border-radius: 12rpx;
  233. background-color: #F5F5F5;
  234. width: auto;
  235. }
  236. }
  237. }
  238. /* 服务类型 */
  239. .row-service {
  240. padding: 24rpx 20rpx;
  241. }
  242. .service-switch {
  243. .switch-item {
  244. padding: 6rpx 30rpx;
  245. margin-right: 25rpx;
  246. border-radius: 10rpx;
  247. border: 1px solid rgb(177, 177, 177);
  248. color: #888;
  249. &.active {
  250. color: #fc1e56;
  251. border: 1px solid #fc1e56;
  252. }
  253. }
  254. }
  255. /* 申请原因 */
  256. .row-textarea {
  257. padding: 24rpx 20rpx;
  258. .textarea {
  259. width: 100%;
  260. height: 220rpx;
  261. padding: 12rpx;
  262. border: 1rpx solid #e8e8e8;
  263. border-radius: 5rpx;
  264. box-sizing: border-box;
  265. font-size: 26rpx;
  266. }
  267. }
  268. /* 退款金额 */
  269. .row-money {
  270. padding: 24rpx 20rpx;
  271. .row-title {
  272. margin-bottom: 0;
  273. margin-right: 30rpx;
  274. }
  275. }
  276. // 上传凭证
  277. .row-voucher {
  278. padding: 24rpx 20rpx;
  279. .image-list {
  280. padding: 0 20rpx;
  281. margin-top: 20rpx;
  282. margin-bottom: -20rpx;
  283. &:after {
  284. clear: both;
  285. content: " ";
  286. display: table;
  287. }
  288. .image {
  289. display: block;
  290. width: 100%;
  291. height: 100%;
  292. }
  293. .image-picker,
  294. .image-preview {
  295. width: 184rpx;
  296. height: 184rpx;
  297. margin-right: 30rpx;
  298. margin-bottom: 30rpx;
  299. float: left;
  300. &:nth-child(3n+0) {
  301. margin-right: 0;
  302. }
  303. }
  304. .image-picker {
  305. display: flex;
  306. flex-direction: column;
  307. justify-content: center;
  308. align-items: center;
  309. border: 1rpx dashed #ccc;
  310. color: #ccc;
  311. .choose-icon {
  312. font-size: 48rpx;
  313. margin-bottom: 6rpx;
  314. }
  315. .choose-text {
  316. font-size: 24rpx;
  317. }
  318. }
  319. .image-preview {
  320. position: relative;
  321. .image-delete {
  322. position: absolute;
  323. top: -15rpx;
  324. right: -15rpx;
  325. height: 42rpx;
  326. width: 42rpx;
  327. line-height: 42rpx;
  328. background: rgba(0, 0, 0, 0.64);
  329. border-radius: 50%;
  330. color: #fff;
  331. font-weight: bolder;
  332. font-size: 22rpx;
  333. z-index: 10;
  334. text-align: center;
  335. }
  336. }
  337. }
  338. }
  339. // 底部操作栏
  340. .footer-fixed {
  341. position: fixed;
  342. bottom: var(--window-bottom);
  343. left: 0;
  344. right: 0;
  345. height: 96rpx;
  346. z-index: 11;
  347. box-shadow: 0 -4rpx 40rpx 0 rgba(144, 52, 52, 0.1);
  348. background: #fff;
  349. .btn-wrapper {
  350. height: 100%;
  351. display: flex;
  352. align-items: center;
  353. padding: 0 20rpx;
  354. }
  355. .btn-item {
  356. flex: 1;
  357. font-size: 28rpx;
  358. height: 72rpx;
  359. line-height: 72rpx;
  360. text-align: center;
  361. color: #fff;
  362. border-radius: 50rpx;
  363. }
  364. .btn-item-main {
  365. background: linear-gradient(to right, #f9211c, #ff6335);
  366. // 禁用按钮
  367. &.disabled {
  368. background: #ff9779;
  369. }
  370. }
  371. }
  372. </style>