金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

436 lines
11 KiB

  1. <template>
  2. <view id="order-apply">
  3. <view class="title">选择类型</view>
  4. <view class="content">
  5. <text>服务类型</text>
  6. <picker :value="selectedIndex" :range="list" @change="change" range-key="name">
  7. <!--<view class="picker">{{list[selectedIndex]}}</view>-->
  8. <input type="text" placeholder="选择售后服务类型" disabled :value="list[selectedIndex].name"></input>
  9. </picker>
  10. </view>
  11. <view class="title">退款信息</view>
  12. <view class="list">
  13. <view class="list-detail">
  14. <text>申请数量</text>
  15. <view class="num">
  16. <view class="subtraction" @tap="plus">+</view>
  17. <view class="text-number">{{applyNum}}</view>
  18. <view class="plus" @tap="minus">-</view>
  19. </view>
  20. <!--<input type="range" />-->
  21. </view>
  22. <view class="content">
  23. <text>退换原因</text>
  24. <picker :value="reasonIndex" :range="reason" range-key="name" @change="changeCause" mode = selector>
  25. <!--<view class="picker">{{list[selectedIndex]}}</view>-->
  26. <input type="text" placeholder="选择退换原因" disabled :value="reason[reasonIndex].name"></input>
  27. </picker>
  28. </view>
  29. <view class="list-detail">
  30. <text>退款金额</text>
  31. <view class="right"><input type="text" @input="changeValue" :value="amount" :placeholder="'最多可退' + availableAmount + '元'"></input></view>
  32. </view>
  33. </view>
  34. <view class="title">
  35. 问题描述
  36. </view>
  37. <view class="text-area">
  38. <textarea @input="changeDetail" :value="qestionDetail" contenteditable="true"></textarea>
  39. </view>
  40. <view class="title">
  41. 上传凭证
  42. </view>
  43. <view class="content btn-box">
  44. <view class="imgContainer" v-for="(img, index) in imgList" :key="index">
  45. <image :src="img"></image>
  46. <view class="delete" :data-index="index" @tap="deleteImg">X</view>
  47. </view>
  48. <view class="append" @tap="selectImage" v-if="imgList.length<5">
  49. +
  50. </view>
  51. </view>
  52. <view class="submit" :style="'background: ' + config.mainColor" @tap="submitApplication">
  53. 提交
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import {pageLogin, getUrl,config,is} from '@/common/js/utils.js';
  59. export default {
  60. data() {
  61. return {
  62. list: [{
  63. name:'',
  64. value:''
  65. }],
  66. // 最大的申请数量
  67. maxNum: "",
  68. selectedIndex:0,
  69. // 申请数量
  70. applyNum: 1,
  71. // 退款金额
  72. amount: "",
  73. // 问题描述
  74. qestionDetail: "",
  75. // 可退的金额
  76. availableAmount: "",
  77. reason: [{
  78. name:'',
  79. value:''
  80. }],
  81. reasonIndex:0,
  82. imgList: [],
  83. order_id: "",
  84. order_item_id: "",
  85. good: {
  86. money: "",
  87. number: ""
  88. },
  89. config: ''
  90. };
  91. },
  92. onLoad(e) {
  93. // 第三方平台配置颜色
  94. var config = this.$cookieStorage.get('globalConfig') || '';
  95. this.setData({
  96. config: config
  97. });
  98. var id = e.id,
  99. no = e.no;
  100. this.setData({
  101. order_id: no,
  102. order_item_id: id
  103. });
  104. pageLogin(getUrl(), () => {
  105. this.queryRefundBaseInfo(id);
  106. this.queryCauseList();
  107. });
  108. },
  109. onShow() {// let app =getApp();
  110. // app.isBirthday().then(()=>{
  111. // if(this.$cookieStorage.get("birthday_gift")){
  112. // var giftData=this.$cookieStorage.get("birthday_gift").data;
  113. // new app.ToastPannel().__page.showText(giftData);
  114. // }
  115. // });
  116. },
  117. methods: {
  118. changeValue(e) {
  119. let amount = e.detail.value;
  120. if (!amount) {
  121. amount = '';
  122. } else if (/\S*$/.test(amount)) {
  123. amount = amount.replace(/[^\d\.]|^\./g, '').replace(/\.{2}/g, '.').replace(/^([1-9]\d*|0)(\.\d{1,2})(\.|\d{1})?$/, '$1$2').replace(/^0\d{1}/g, '0');
  124. }
  125. if (Number(amount) > this.availableAmount) {
  126. amount = this.availableAmount;
  127. }
  128. this.setData({
  129. amount: amount
  130. });
  131. },
  132. changeDetail(e) {
  133. var str = e.detail.value;
  134. if (e.detail.value.length > 150) {
  135. wx.showModal({
  136. title: '提示',
  137. content: '超出字数限制'
  138. });
  139. str = str.slice(0, 150);
  140. }
  141. this.setData({
  142. qestionDetail: str
  143. });
  144. },
  145. setAmount(i) {
  146. this.setData({
  147. availableAmount: (this.good.money / this.good.number * i).toFixed(2)
  148. });
  149. },
  150. change(e) {
  151. console.log(e);
  152. // 修改选中项文案
  153. this.setData({
  154. selectedIndex: e.detail.value
  155. });
  156. console.log('this.selectedIndex',this.selectedIndex)
  157. },
  158. changeCause: function (e) {
  159. this.setData({
  160. reasonIndex: e.detail.value
  161. });
  162. },
  163. getValue: function (e) {
  164. console.log(e.detail.value);
  165. },
  166. deleteImg(e) {
  167. var i = e.currentTarget.dataset.index;
  168. var arr = this.imgList;
  169. arr.splice(i, 1);
  170. this.setData({
  171. imgList: arr
  172. });
  173. },
  174. selectImage() {
  175. uni.chooseImage({
  176. count: 1,
  177. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  178. sourceType: ['album'], //从相册选择
  179. success: res => {
  180. var tempFilePaths = res.tempFilePaths;
  181. var token = this.$cookieStorage.get('user_token');
  182. /* this.$http.uploadFile({
  183. header: {
  184. 'content-type': 'multipart/form-data',
  185. Authorization: token
  186. },
  187. api: 'api/users/upload/avatar',
  188. //仅为示例,非真实的接口地址
  189. filePath: tempFilePaths[0],
  190. name: 'avatar_file'
  191. }).then(res => {
  192. var result = JSON.parse(res.data);
  193. var arr = this.imgList;
  194. arr.push(result.data.url); // this.imgList.push();
  195. this.setData({
  196. imgList: arr
  197. });
  198. }); */
  199. uni.uploadFile({
  200. header: {
  201. Authorization: token
  202. },
  203. url: config.GLOBAL.baseUrl + 'api/users/upload/avatar',
  204. filePath: tempFilePaths[0],
  205. fileType: 'image',
  206. name: 'avatar_file',
  207. success: res => {
  208. var result = JSON.parse(res.data);
  209. var arr = this.imgList;
  210. arr.push(result.data.url); // this.imgList.push();
  211. this.setData({
  212. imgList: arr
  213. });
  214. }
  215. })
  216. }
  217. });
  218. },
  219. submitApplication() {
  220. var applyItem = {
  221. order_no: this.order_id,
  222. order_item_id: parseInt(this.order_item_id),
  223. quantity: parseInt(this.applyNum),
  224. images: this.imgList,
  225. amount: parseFloat(this.amount),
  226. content: this.qestionDetail,
  227. type: this.list[this.selectedIndex].value,
  228. reason:this.reason[this.reasonIndex].value
  229. },
  230. message = null;
  231. if (!is.has(applyItem.type)) {
  232. message = "请选择售后类型";
  233. } else if (!is.has(applyItem.reason)) {
  234. message = '请填写退换原因';
  235. } else if (!is.has(applyItem.amount)) {
  236. message = '请填写退款金额';
  237. }
  238. /* else if (!is.has(applyItem.content)) {
  239. message = "请输入问题描述";
  240. } */
  241. if (message) {
  242. wx.showModal({
  243. title: '提示',
  244. content: message,
  245. showCancel: false
  246. });
  247. } else {
  248. applyItem.type = parseInt(applyItem.type);
  249. this.applyretreat(applyItem);
  250. }
  251. },
  252. applyretreat(data) {
  253. wx.showLoading({
  254. mask: true,
  255. title: '正在申请'
  256. });
  257. this.$http.post({
  258. api: "api/refund/apply",
  259. data: data,
  260. header: {
  261. Authorization: this.$cookieStorage.get('user_token')
  262. }
  263. }).then(res => {
  264. if (res.statusCode == 200) {
  265. res = res.data;
  266. if (res.status) {
  267. wx.showToast({
  268. title: "申请成功请等待审核",
  269. duration: 1500,
  270. success: () => {
  271. setTimeout(() => {
  272. wx.redirectTo({
  273. url: '/pages/afterSales/detail/detail?no=' + res.data.refund_no
  274. });
  275. }, 1500);
  276. }
  277. });
  278. } else {
  279. wx.showModal({
  280. content: res.message || '申请失败',
  281. showCancel: false
  282. });
  283. }
  284. wx.hideLoading();
  285. } else {
  286. wx.showModal({
  287. content: '申请失败',
  288. showCancel: false
  289. });
  290. wx.hideLoading();
  291. }
  292. });
  293. },
  294. plus() {
  295. var num = this.applyNum;
  296. num++;
  297. if (num > this.maxNum) return;
  298. this.setData({
  299. applyNum: num
  300. });
  301. this.setAmount(num);
  302. },
  303. minus() {
  304. var num = this.applyNum;
  305. if (num <= 1) return;
  306. num--;
  307. this.setData({
  308. applyNum: num
  309. });
  310. this.setAmount(num);
  311. },
  312. queryRefundBaseInfo(id) {
  313. this.$http.get({
  314. api: "api/refund/base_info",
  315. header: {
  316. Authorization: this.$cookieStorage.get('user_token')
  317. },
  318. data: {
  319. order_item_id: id
  320. }
  321. }).then(res => {
  322. var store = res.data.data;
  323. var meta = res.data.meta.type;
  324. var list = [];
  325. meta.forEach(v => {
  326. list.push({
  327. name: v.value,
  328. value: String(v.key)
  329. });
  330. });
  331. /*var list=[{
  332. name: meta[0].value,
  333. value: meta[0].key
  334. }];*/
  335. this.setData({
  336. 'good.money': store.total / 100,
  337. 'good.number': store.quantity,
  338. availableAmount: (store.total / 100 / store.quantity).toFixed(2),
  339. maxNum: store.quantity,
  340. list: list
  341. });
  342. });
  343. },
  344. queryServiceList(status, distribution_status) {
  345. this.$http.get({
  346. api: 'api/users/BankAccount/show-bank',
  347. header: {
  348. Authorization: this.$cookieStorage.get('user_token')
  349. }
  350. }).then(res => {
  351. res = res.data;
  352. });
  353. },
  354. queryCauseList(type = 'order_refund_reason') {
  355. this.$http.get({
  356. api: 'api/system/settings',
  357. header: {
  358. Authorization: this.$cookieStorage.get('user_token')
  359. },
  360. data: {
  361. type: type
  362. }
  363. }).then(res => {
  364. res = res.data;
  365. var list = [];
  366. res.data.forEach(v => {
  367. if (v.is_enabled != 0) {
  368. list.push({
  369. name: v.value,
  370. value: String(v.key)
  371. });
  372. }
  373. });
  374. this.setData({
  375. reason: list
  376. });
  377. });
  378. },
  379. setData: function (obj) {
  380. let that = this;
  381. let keys = [];
  382. let val, data;
  383. Object.keys(obj).forEach(function (key) {
  384. keys = key.split('.');
  385. val = obj[key];
  386. data = that.$data;
  387. keys.forEach(function (key2, index) {
  388. if (index + 1 == keys.length) {
  389. that.$set(data, key2, val);
  390. } else {
  391. if (!data[key2]) {
  392. that.$set(data, key2, {});
  393. }
  394. }
  395. data = data[key2];
  396. });
  397. });
  398. }
  399. },
  400. computed: {},
  401. watch: {}
  402. };
  403. </script>
  404. <style rel="stylesheet/less" lang="less">
  405. @import "apply";
  406. </style>