service.vue 9.0 KB

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