service.vue 9.2 KB

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