use.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. var _request = require('../../../../../utils/request.js')
  2. Page({
  3. data: {
  4. address: null,
  5. order_id: 0,
  6. tabLeft: '0',
  7. tabLeft1: '0',
  8. tabwidth: '0',
  9. show: false,
  10. showModal: false,
  11. angle: 0,
  12. curTab: 'sell',
  13. orderInfo: {},
  14. saleCount: 1,
  15. selfCount: 1,
  16. confirmCount: 0,
  17. selfPage: 1,
  18. selfMore: true,
  19. selfList: [],
  20. updateSelfList: [],
  21. saleOrderInfo: {},
  22. saleOrders: [],
  23. opt: '',
  24. per_page: 10,
  25. confirmLock: false,
  26. showRule: false,
  27. backcount:'',
  28. nowtime: Date.parse(new Date()) / 1000
  29. },
  30. onLoad: function (options) {
  31. this.data.order_id = options.order_id
  32. if (options.tab === 'sell') {
  33. this.sellClick()
  34. } else if (options.tab === 'return') {
  35. this.returnClick()
  36. } else if (options.tab === 'mine') {
  37. this.mineClick()
  38. } else if (options.tab === 'mine1') {
  39. this.mineClick1()
  40. } else {
  41. this.sellClick()
  42. }
  43. this.getOrderInfo()
  44. this.getSaleInfo()
  45. this.getSelfUseOrders()
  46. this.getDefaultAddress()
  47. },
  48. onShow: function () {
  49. this.getDefaultAddress()
  50. },
  51. sellClick () {
  52. var that = this
  53. that.setData({
  54. tabLeft: '0',
  55. tabLeft1: '0',
  56. curTab: 'sell'
  57. })
  58. },
  59. returnClick () {
  60. var that = this
  61. that.setData({
  62. tabLeft: '33.3%',
  63. curTab: 'return'
  64. })
  65. },
  66. mineClick () {
  67. var that = this
  68. that.setData({
  69. tabLeft: '66.6%',
  70. curTab: 'mine'
  71. })
  72. },
  73. mineClick1 () {
  74. var that = this
  75. that.setData({
  76. tabLeft1: '50%',
  77. curTab: 'mine'
  78. })
  79. },
  80. review () {
  81. var that = this
  82. that.data.show = !that.data.show
  83. if (that.data.show) {
  84. that.data.angle = 180
  85. } else {
  86. that.data.angle = 0
  87. }
  88. that.setData({
  89. show: that.data.show,
  90. angle: that.data.angle
  91. })
  92. },
  93. setDefaultAddress () {
  94. // wx.redirectTo({
  95. // url: '/packageUser/pages/user/address/address'
  96. // })
  97. wx.navigateTo({
  98. url: '/packageUser/pages/user/address/address'
  99. })
  100. },
  101. addDefalutAddress () {
  102. wx.navigateTo({
  103. url: '/packageUser/pages/user/newAddress/newAddress'
  104. })
  105. },
  106. toTuiGuang () {
  107. wx.navigateTo({
  108. url: '/packageUser/pages/user/invite/invite'
  109. })
  110. },
  111. getSaleInfo () {
  112. var that = this
  113. var url = "v1/user/granary/" + that.data.order_id + "/sale/order/info"
  114. var params = {}
  115. var success = function (val) {
  116. if (val.data) {
  117. that.setData({
  118. saleOrderInfo: val.data.sale_order,
  119. saleOrders: val.data.orders
  120. })
  121. }
  122. }
  123. _request.$get(url, params, success)
  124. },
  125. saleCreate () {
  126. var that = this
  127. var url = "v1/user/granary/" + that.data.order_id + "/sale/order/operate"
  128. var params = {
  129. opt: that.data.opt,
  130. count: that.data.saleCount
  131. }
  132. var success = function (val) {
  133. if (val.data !== null) {
  134. // wx.navigateTo({
  135. // url: '/packageUser/pages/user/granary/granary'
  136. // })
  137. wx.showToast({
  138. title: '已提交',
  139. icon: 'none',
  140. duration: 3000
  141. })
  142. that.cancelModal()
  143. that.getOrderInfo()
  144. that.getSaleInfo()
  145. }
  146. }
  147. _request.$post(url, params, success)
  148. },
  149. getDefaultAddress: function () {
  150. var that = this
  151. var url = "v1/user/address/default";
  152. var params = {}
  153. var success = function (val) {
  154. if (val.data !== null) {
  155. that.setData({
  156. address: val.data
  157. })
  158. }
  159. }
  160. _request.$get(url, params, success)
  161. },
  162. changeSaleCount: function (val) {
  163. var count = val.detail.value
  164. var leftcount
  165. if (!this.data.orderInfo.self_use_count) {
  166. leftcount = this.data.orderInfo.left_count - this.data.orderInfo.self_use_min
  167. } else {
  168. leftcount = this.data.orderInfo.left_count - (this.data.orderInfo.self_use_min - this.data.orderInfo.self_use_count)
  169. }
  170. if (count <= 0) {
  171. this.setData({
  172. count: 1
  173. })
  174. } else if (count > leftcount) {
  175. this.setData({
  176. count: leftcount,
  177. saleCount: leftcount
  178. })
  179. } else {
  180. this.setData({
  181. count: count,
  182. saleCount: count
  183. })
  184. }
  185. },
  186. changeSelfCount: function (val) {
  187. var count = val.detail.value
  188. if (count <= 0) {
  189. this.setData({
  190. count: 1
  191. })
  192. } else if (count > this.data.orderInfo.valid_count) {
  193. this.setData({
  194. count: this.data.orderInfo.valid_count,
  195. selfCount: this.data.orderInfo.valid_count
  196. })
  197. } else {
  198. this.setData({
  199. count: count,
  200. selfCount: count
  201. })
  202. }
  203. },
  204. getOrderInfo () {
  205. var that = this
  206. var url = "v1/user/granary/" + that.data.order_id
  207. var params = {
  208. cache: false
  209. }
  210. var success = function (val) {
  211. // if (val.data.buyback_min === 0) {
  212. // that.setData({
  213. // backcount: 1,
  214. // orderInfo: val.data
  215. // })
  216. // } else {
  217. that.setData({
  218. orderInfo: val.data,
  219. backcount: val.data.buyback_min
  220. })
  221. // }
  222. if (val.data.buyback_max) {
  223. that.setData({
  224. tabwidth: "33.3%"
  225. })
  226. } else {
  227. that.setData({
  228. tabwidth: "50%"
  229. })
  230. }
  231. }
  232. _request.$get(url, params, success)
  233. },
  234. getSelfUseOrders () {
  235. var that = this
  236. var url = "v1/user/granary/" + that.data.order_id + "/selfuse/orders";
  237. var params = {
  238. page: this.data.selfPage,
  239. per_page: this.data.per_page
  240. }
  241. var success = function (res) {
  242. var result = that.data.selfList.concat(res.data.list || [])
  243. that.setData({
  244. selfList: result
  245. })
  246. var listMore = res.data.list_count > that.data.selfList.length
  247. that.setData({
  248. selfMore: listMore
  249. })
  250. }
  251. _request.$get(url, params, success)
  252. },
  253. secondConfirm (e) {
  254. var that = this
  255. that.data.opt = e.currentTarget.dataset.opt
  256. if (that.data.curTab === 'sell') {
  257. that.setData({
  258. confirmCount: that.data.selfCount
  259. })
  260. } else if (that.data.curTab === 'mine') {
  261. that.setData({
  262. confirmCount: that.data.selfCount
  263. })
  264. }
  265. if (that.data.curTab === 'mine') {
  266. if (that.data.address && that.data.address.id) {
  267. that.setData({
  268. showModal: true
  269. })
  270. } else {
  271. wx.showToast({
  272. title: '请先填写地址~',
  273. icon: 'none',
  274. duration: 3000
  275. })
  276. }
  277. } else {
  278. that.setData({
  279. showModal: true
  280. })
  281. }
  282. },
  283. cancelModal () {
  284. var that = this
  285. that.data.showModal = !that.data.showModal
  286. that.setData({
  287. showModal: that.data.showModal
  288. })
  289. },
  290. cancelModal1 () {
  291. var that = this
  292. that.data.showModal = !that.data.showModal
  293. that.setData({
  294. showModal: that.data.showModal
  295. })
  296. that.getOrderInfo()
  297. },
  298. selfConfirm: function () {
  299. var that = this
  300. var url = "v1/user/granary/" + that.data.order_id + "/selfuse/order/create";
  301. var params = {
  302. count: that.data.selfCount,
  303. address_id: that.data.address.id
  304. }
  305. var success = function (val) {
  306. if (val.data) {
  307. that.cancelModal()
  308. wx.showToast({
  309. title: '已自用',
  310. icon: 'none',
  311. duration: 3000
  312. })
  313. that.data.confirmLock = false
  314. // that.data.page = 1
  315. // that.getSelfUseOrders()
  316. var obj = {
  317. count: val.data.count,
  318. paied_at: val.data.paied_at,
  319. contact: val.data.contact,
  320. tel: val.data.tel,
  321. address: val.data.address
  322. }
  323. that.data.selfList.unshift(obj)
  324. that.setData({
  325. selfList: that.data.selfList
  326. })
  327. that.getOrderInfo()
  328. }
  329. }
  330. if (!that.data.confirmLock) {
  331. _request.$post(url, params, success)
  332. that.data.confirmLock = true
  333. }
  334. },
  335. saleCountPlus () {
  336. var that = this
  337. that.data.saleCount = Number(that.data.saleCount) + 1
  338. var leftcount
  339. if (!that.data.orderInfo.self_use_count) {
  340. leftcount = that.data.orderInfo.left_count - that.data.orderInfo.self_use_min
  341. } else {
  342. leftcount = that.data.orderInfo.left_count - (that.data.orderInfo.self_use_min - that.data.orderInfo.self_use_count)
  343. }
  344. if (that.data.saleCount <= leftcount) {
  345. that.setData({
  346. saleCount: that.data.saleCount
  347. })
  348. } else {
  349. wx.showToast({
  350. title: '代销数量不能大于剩余数量哦~',
  351. icon: 'none',
  352. duration: 3000
  353. })
  354. that.setData({
  355. saleCount: leftcount
  356. })
  357. }
  358. },
  359. selfCountPlus () {
  360. var that = this
  361. that.data.selfCount = Number(that.data.selfCount) + 1
  362. if (that.data.selfCount <= that.data.orderInfo.valid_count) {
  363. that.setData({
  364. selfCount: that.data.selfCount
  365. })
  366. } else {
  367. wx.showToast({
  368. title: '自用数量不能大于剩余数量哦~',
  369. icon: 'none',
  370. duration: 3000
  371. })
  372. that.setData({
  373. selfCount: that.data.orderInfo.valid_count
  374. })
  375. }
  376. },
  377. onReachBottom: function () {
  378. if (this.data.selfMore && this.data.curTab === 'mine') {
  379. var page = this.data.selfPage + 1
  380. this.setData({
  381. page: page
  382. })
  383. this.getSelfUseOrders()
  384. }
  385. },
  386. onShareAppMessage: function (val) {
  387. return _request.share({
  388. title: this.data.orderInfo.product.share_content || this.data.orderInfo.product.name,
  389. path: '/pages/start/start?url=pages/projects/project-detail/project-detail&id=' + this.data.orderInfo.product.id,
  390. imageUrl: this.data.orderInfo.product.cover,
  391. sc: 'xcx_product',
  392. ri: this.data.orderInfo.product.id,
  393. rp: this.data.orderInfo.product.id
  394. })
  395. },
  396. saleCountMinus () {
  397. var that = this
  398. if (that.data.saleCount > 1) {
  399. that.data.saleCount = that.data.saleCount - 1
  400. that.setData({
  401. saleCount: that.data.saleCount
  402. })
  403. } else {
  404. wx.showToast({
  405. title: '输入数量必须大于等于1',
  406. icon: 'none',
  407. duration: 2000
  408. })
  409. }
  410. },
  411. selfCountMinus () {
  412. var that = this
  413. if (that.data.selfCount > 1) {
  414. that.data.selfCount = that.data.selfCount - 1
  415. that.setData({
  416. selfCount: that.data.selfCount
  417. })
  418. } else {
  419. wx.showToast({
  420. title: '输入数量必须大于等于1',
  421. icon: 'none',
  422. duration: 2000
  423. })
  424. }
  425. },
  426. toOrderList () {
  427. wx.navigateTo({
  428. url: '/packageUser/pages/user/orders/orders'
  429. })
  430. },
  431. showRuleClick () {
  432. var that = this
  433. that.data.showRule = !that.data.showRule
  434. that.setData({
  435. showRule: that.data.showRule
  436. })
  437. },
  438. postback () {
  439. if (Number(this.data.backcount) < 0) {
  440. wx.showToast({
  441. title: '输入数量必须大于等于0',
  442. icon: 'none',
  443. duration: 2000
  444. })
  445. } else {
  446. var that = this
  447. var url = "v1/user/granary/" + that.data.order_id + "/buyback/no"
  448. var params = {
  449. count: that.data.backcount
  450. }
  451. var success = function (val) {
  452. that.setData({
  453. showModal: true
  454. })
  455. // that.getOrderInfo()
  456. console.log(that.data.backcount)
  457. }
  458. _request.$post(url, params, success)
  459. }
  460. },
  461. minusback () {
  462. var that = this
  463. if (that.data.backcount > 0) {
  464. that.data.backcount = that.data.backcount - 1
  465. that.setData({
  466. backcount: that.data.backcount
  467. })
  468. } else {
  469. wx.showToast({
  470. title: '输入数量必须大于等于0',
  471. icon: 'none',
  472. duration: 2000
  473. })
  474. }
  475. },
  476. plusback () {
  477. var that = this
  478. that.data.backcount = Number(that.data.backcount) + 1
  479. if (that.data.backcount <= that.data.orderInfo.buyback_max) {
  480. that.setData({
  481. backcount: that.data.backcount
  482. })
  483. } else {
  484. wx.showToast({
  485. title: '回购数量不能大于回购上限哦~',
  486. icon: 'none',
  487. duration: 3000
  488. })
  489. that.setData({
  490. backcount: that.data.orderInfo.buyback_max
  491. })
  492. }
  493. },
  494. changeback: function (e) {
  495. // console.log(e)
  496. var changecount = e.detail.value
  497. if (changecount < 0) {
  498. this.setData({
  499. changecount: 0,
  500. // backcount: 0
  501. })
  502. } else if (changecount > this.data.orderInfo.buyback_max) {
  503. this.setData({
  504. changecount: this.data.orderInfo.buyback_max,
  505. backcount: this.data.orderInfo.buyback_max
  506. })
  507. } else {
  508. this.setData({
  509. changecount: changecount,
  510. backcount: changecount
  511. })
  512. }
  513. }
  514. })