service.vue 8.0 KB

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