service.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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=='2'">
  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. params.file = that.icon;
  202. params.order_detail = that.id;
  203. const arr = await that.$api(`/afterSale`, 'POST', params);
  204. if (arr.errcode == '0') {
  205. uni.showToast({
  206. title: `申请售后成功`,
  207. icon: 'success',
  208. });
  209. uni.navigateBack({
  210. detail: 1
  211. })
  212. } else {
  213. uni.showToast({
  214. title: arr.errmsg,
  215. icon: 'none',
  216. })
  217. }
  218. })
  219. },
  220. // 查询其他信息
  221. async searchOther() {
  222. const that = this;
  223. let res;
  224. res = await that.$api(`/dictData`, 'GET', {
  225. code: "afterSale_type"
  226. });
  227. if (res.errcode == '0') {
  228. that.$set(that, `typeList`, res.data)
  229. }
  230. res = await that.$api(`/dictData`, 'GET', {
  231. code: "afterSale_reason"
  232. });
  233. if (res.errcode == '0') {
  234. that.$set(that, `reasonList`, res.data)
  235. }
  236. },
  237. // 监听用户是否登录
  238. watchLogin() {
  239. const that = this;
  240. uni.getStorage({
  241. key: 'token',
  242. success: async function(res) {
  243. let user = that.$jwt(res.data);
  244. if (user) {
  245. that.$set(that, `user`, user);
  246. if (that.id) {
  247. let arr = await that.$api(`/orderDetail/${that.id}`, 'GET')
  248. if (arr.errcode == '0') {
  249. that.$set(that, `goodsList`, arr.data.goods)
  250. }
  251. }
  252. }
  253. },
  254. fail: function(err) {
  255. uni.reLaunch({
  256. url: '/pages/login/index'
  257. })
  258. }
  259. })
  260. },
  261. }
  262. }
  263. </script>
  264. <style lang="scss">
  265. .main {
  266. .one {
  267. .list {
  268. margin: 2vw;
  269. padding: 2vw;
  270. border-radius: 2vw;
  271. border: 1px solid #3333;
  272. .list_1 {
  273. margin: 0 0 1vw 0;
  274. display: flex;
  275. flex-direction: row;
  276. justify-content: space-between;
  277. font-size: var(--font14Size);
  278. font-weight: bold;
  279. }
  280. .list_2 {
  281. margin: 0 0 1vw 0;
  282. display: flex;
  283. .l {
  284. width: 20vw;
  285. .image {
  286. width: 100%;
  287. height: 20vw;
  288. border-radius: 5px;
  289. }
  290. }
  291. .c {
  292. width: 50vw;
  293. padding: 0 2vw;
  294. }
  295. .r {
  296. width: 25vw;
  297. text-align: right;
  298. .money {
  299. color: var(--f85Color);
  300. font-size: var(--font12Size);
  301. }
  302. }
  303. }
  304. .other {
  305. margin: 0 0 2vw 0;
  306. text-align: right;
  307. text {
  308. font-size: 14px;
  309. padding: 0 0 0 2vw;
  310. }
  311. }
  312. .btn {
  313. text-align: right;
  314. margin: 2vw 0 0 0;
  315. border-top: 1px solid #f1fff1;
  316. button {
  317. margin: 2vw 0 0 2vw;
  318. }
  319. }
  320. }
  321. }
  322. .two {
  323. padding: 2vw;
  324. .picker {
  325. border: 1px solid #3333;
  326. border-radius: 5px;
  327. padding: 2vw;
  328. }
  329. .btn {
  330. text-align: center;
  331. button {
  332. width: 30%;
  333. font-size: 14px;
  334. background-color: var(--f35BColor);
  335. }
  336. }
  337. }
  338. }
  339. .uni-forms-item {
  340. margin-bottom: 6vw !important;
  341. display: flex;
  342. flex-direction: row;
  343. }
  344. </style>