service.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <view class="list" v-if="info._id">
  6. <view class="list_1">
  7. <text>退款商品</text>
  8. </view>
  9. <view class="list_2">
  10. <view class="l">
  11. <image class="image"
  12. :src="info.goods.file&&info.goods.file.length>0?info.goods.file[0].url:''" mode="">
  13. </image>
  14. </view>
  15. <view class="c">
  16. <view class="name">
  17. {{info.name}}
  18. </view>
  19. </view>
  20. <view class="r">
  21. <view v-if="item.type=='0'" class="price">
  22. ¥{{item.sell_money}}
  23. </view>
  24. <view v-else class="price">
  25. ¥{{item.group_config.money}}
  26. </view>
  27. <view class="num">
  28. ×{{info.buy_num}}
  29. </view>
  30. <view class="money" v-if="moneyInfo.payTotal">
  31. <view class="">商品总价:{{moneyInfo.goodsTotal}}</view>
  32. <view class="">优惠减免:{{moneyInfo.discountTotal}}</view>
  33. <view class="">运费总价:{{moneyInfo.freightTotal}}</view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <view class="two">
  40. <uni-forms ref="form" :rules="rules" :model="form" label-width="auto">
  41. <uni-forms-item label="退款商品" name="goods_id">
  42. <picker class="picker" mode="selector" :range="goodsList" @change="goodsChange"
  43. range-key="name">
  44. <view>{{form.goods_name||'请选择退款商品'}}</view>
  45. </picker>
  46. </uni-forms-item>
  47. <uni-forms-item label="售后类型" name="type" v-if="info._id">
  48. <picker class="picker" mode="selector" :range="typeList" @change="typeChange" range-key="label">
  49. <view>{{form.type_name||'请选择售后类型'}}</view>
  50. </picker>
  51. </uni-forms-item>
  52. <uni-forms-item label="退款金额" name="money" v-if="form.type=='0'||form.type=='1'">
  53. <uni-easyinput type="digit" v-model="form.money" @input="toMoney" placeholder="请输入退款金额" />
  54. <view>
  55. 最大退款金额不能超过{{moneyInfo.payTotal||'暂无'}}
  56. </view>
  57. </uni-forms-item>
  58. <uni-forms-item label="申请理由" name="reason">
  59. <picker class="picker" mode="selector" :range="reasonList" @change="reasonChange"
  60. range-key="label">
  61. <view>{{form.reason_name||'请选择申请理由'}}</view>
  62. </picker>
  63. </uni-forms-item>
  64. <uni-forms-item label="申请售后描述" name="desc">
  65. <uni-easyinput type="textarea" v-model="form.desc" placeholder="请输入申请售后描述" />
  66. </uni-forms-item>
  67. <uni-forms-item label="附件" name="icon">
  68. <upload :list="icon" name="icon" :count="1" @uplSuc="uplSuc" @uplDel="uplDel"></upload>
  69. </uni-forms-item>
  70. <view class="btn">
  71. <button v-if="money_num=='0'" type="primary" size="mini" @click="onSubmit('form')">提交保存</button>
  72. </view>
  73. </uni-forms>
  74. </view>
  75. </view>
  76. </mobile-frame>
  77. </template>
  78. <script>
  79. import upload from '@/components/upload/index.vue';
  80. export default {
  81. components: {
  82. upload
  83. },
  84. data() {
  85. return {
  86. id: '',
  87. user: {},
  88. // 商品详情
  89. info: {},
  90. form: {},
  91. moneyInfo: {},
  92. // 退货商品
  93. goodsList: [],
  94. icon: [],
  95. rules: {
  96. type: {
  97. rules: [{
  98. required: true,
  99. errorMessage: '请选择售后类型',
  100. }]
  101. },
  102. goods_id: {
  103. rules: [{
  104. required: true,
  105. errorMessage: '请选择退款商品',
  106. }]
  107. },
  108. reason: {
  109. rules: [{
  110. required: true,
  111. errorMessage: '请选择申请理由',
  112. }]
  113. },
  114. },
  115. // 售后类型
  116. typeList: [],
  117. // 申请理由
  118. reasonList: [],
  119. money_num: '0'
  120. };
  121. },
  122. onLoad: async function(e) {
  123. const that = this;
  124. that.$set(that, `id`, e && e.id || '');
  125. // 查询其他信息
  126. await that.searchOther();
  127. // 监听用户登录
  128. await that.watchLogin();
  129. },
  130. methods: {
  131. // 退款金额
  132. toMoney(value) {
  133. const that = this;
  134. let money = that.moneyInfo.payTotal;
  135. if (parseFloat(value) > parseFloat(money)) {
  136. uni.showToast({
  137. title: '输入金额不能超过实际支付金额',
  138. icon: 'none'
  139. })
  140. that.$set(that, `money_num`, '1');
  141. } else {
  142. that.$set(that, `money_num`, '0');
  143. }
  144. },
  145. // 选择售后类型
  146. async typeChange(e) {
  147. const that = this;
  148. let data = that.typeList[e.detail.value];
  149. if (data) {
  150. that.$set(that.form, `type`, data.value);
  151. that.$set(that.form, `type_name`, data.label);
  152. }
  153. if (data.value != '2') {
  154. const arr = await that.$api(`/afterSale/cgfr`, 'POST', {
  155. order_detail: that.id,
  156. goods_id: that.info._id
  157. });
  158. if (arr.errcode == '0') {
  159. that.$set(that, `moneyInfo`, arr.data);
  160. } else {
  161. uni.showToast({
  162. title: arr.errmsg,
  163. icon: 'none',
  164. })
  165. }
  166. }
  167. },
  168. // 退款商品
  169. goodsChange(e) {
  170. const that = this;
  171. let data = that.goodsList[e.detail.value];
  172. if (data) {
  173. console.log(data);
  174. that.$set(that, `info`, data);
  175. that.$set(that.form, `goods_id`, data._id);
  176. that.$set(that.form, `goods_name`, data.name);
  177. }
  178. },
  179. // 选择申请理由
  180. reasonChange(e) {
  181. const that = this;
  182. let data = that.reasonList[e.detail.value];
  183. if (data) {
  184. that.$set(that.form, `reason`, data.value);
  185. that.$set(that.form, `reason_name`, data.label);
  186. }
  187. },
  188. // 图片上传
  189. uplSuc(e) {
  190. const that = this;
  191. that.$set(that, `${e.name}`, [...that[e.name], e.data]);
  192. },
  193. // 图片删除
  194. uplDel(e) {
  195. const that = this;
  196. let data = that[e.name];
  197. let arr = data.filter((i, index) => index != e.data.index);
  198. that.$set(that, `${e.name}`, arr)
  199. },
  200. // 提交保存
  201. async onSubmit(ref) {
  202. const that = this;
  203. that.$refs[ref].validate().then(async params => {
  204. if (params.type != '2') {
  205. if (params.money) {
  206. params.file = that.icon;
  207. params.order_detail = that.id;
  208. const arr = await that.$api(`/afterSale`, 'POST', params);
  209. if (arr.errcode == '0') {
  210. uni.showToast({
  211. title: `申请售后成功`,
  212. icon: 'success',
  213. });
  214. uni.navigateBack({
  215. detail: 1
  216. })
  217. } else {
  218. uni.showToast({
  219. title: arr.errmsg,
  220. icon: 'none',
  221. })
  222. }
  223. } else {
  224. uni.showToast({
  225. title: `请输入退款金额`,
  226. icon: 'none',
  227. });
  228. }
  229. } else {
  230. params.file = that.icon;
  231. params.order_detail = that.id;
  232. const arr = await that.$api(`/afterSale`, 'POST', params);
  233. if (arr.errcode == '0') {
  234. uni.showToast({
  235. title: `申请售后成功`,
  236. icon: 'success',
  237. });
  238. uni.navigateBack({
  239. detail: 1
  240. })
  241. } else {
  242. uni.showToast({
  243. title: arr.errmsg,
  244. icon: 'none',
  245. })
  246. }
  247. }
  248. })
  249. },
  250. // 查询其他信息
  251. async searchOther() {
  252. const that = this;
  253. let res;
  254. res = await that.$api(`/dictData`, 'GET', {
  255. code: "afterSale_type"
  256. });
  257. if (res.errcode == '0') {
  258. that.$set(that, `typeList`, res.data)
  259. }
  260. res = await that.$api(`/dictData`, 'GET', {
  261. code: "afterSale_reason"
  262. });
  263. if (res.errcode == '0') {
  264. that.$set(that, `reasonList`, res.data)
  265. }
  266. },
  267. // 监听用户是否登录
  268. watchLogin() {
  269. const that = this;
  270. uni.getStorage({
  271. key: 'token',
  272. success: async function(res) {
  273. let user = that.$jwt(res.data);
  274. if (user) {
  275. that.$set(that, `user`, user);
  276. if (that.id) {
  277. let arr = await that.$api(`/orderDetail/${that.id}`, 'GET')
  278. if (arr.errcode == '0') {
  279. that.$set(that, `goodsList`, arr.data.goods)
  280. }
  281. }
  282. }
  283. },
  284. fail: function(err) {
  285. uni.reLaunch({
  286. url: '/pages/login/index'
  287. })
  288. }
  289. })
  290. },
  291. }
  292. }
  293. </script>
  294. <style lang="scss">
  295. .main {
  296. .one {
  297. .list {
  298. margin: 2vw;
  299. padding: 2vw;
  300. border-radius: 2vw;
  301. border: 1px solid #3333;
  302. .list_1 {
  303. margin: 0 0 1vw 0;
  304. display: flex;
  305. flex-direction: row;
  306. justify-content: space-between;
  307. font-size: var(--font14Size);
  308. font-weight: bold;
  309. }
  310. .list_2 {
  311. margin: 0 0 1vw 0;
  312. display: flex;
  313. .l {
  314. width: 20vw;
  315. .image {
  316. width: 100%;
  317. height: 20vw;
  318. border-radius: 5px;
  319. }
  320. }
  321. .c {
  322. width: 50vw;
  323. padding: 0 2vw;
  324. }
  325. .r {
  326. width: 25vw;
  327. text-align: right;
  328. .money {
  329. color: var(--f85Color);
  330. font-size: var(--font12Size);
  331. }
  332. }
  333. }
  334. .other {
  335. margin: 0 0 2vw 0;
  336. text-align: right;
  337. text {
  338. font-size: 14px;
  339. padding: 0 0 0 2vw;
  340. }
  341. }
  342. .btn {
  343. text-align: right;
  344. margin: 2vw 0 0 0;
  345. border-top: 1px solid #f1fff1;
  346. button {
  347. margin: 2vw 0 0 2vw;
  348. }
  349. }
  350. }
  351. }
  352. .two {
  353. padding: 2vw;
  354. .picker {
  355. border: 1px solid #3333;
  356. border-radius: 5px;
  357. padding: 2vw;
  358. }
  359. .btn {
  360. text-align: center;
  361. button {
  362. width: 30%;
  363. font-size: 14px;
  364. background-color: var(--f35BColor);
  365. }
  366. }
  367. }
  368. }
  369. .uni-forms-item {
  370. margin-bottom: 6vw !important;
  371. display: flex;
  372. flex-direction: row;
  373. }
  374. </style>