| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514 |
- var _request = require('../../../../../utils/request.js')
- Page({
- data: {
- address: null,
- order_id: 0,
- tabLeft: '0',
- tabLeft1: '0',
- tabwidth: '0',
- show: false,
- showModal: false,
- angle: 0,
- curTab: 'sell',
- orderInfo: {},
- saleCount: 1,
- selfCount: 1,
- confirmCount: 0,
- selfPage: 1,
- selfMore: true,
- selfList: [],
- updateSelfList: [],
- saleOrderInfo: {},
- saleOrders: [],
- opt: '',
- per_page: 10,
- confirmLock: false,
- showRule: false,
- backcount:'',
- nowtime: Date.parse(new Date()) / 1000
- },
- onLoad: function (options) {
- this.data.order_id = options.order_id
- if (options.tab === 'sell') {
- this.sellClick()
- } else if (options.tab === 'return') {
- this.returnClick()
- } else if (options.tab === 'mine') {
- this.mineClick()
- } else if (options.tab === 'mine1') {
- this.mineClick1()
- } else {
- this.sellClick()
- }
- this.getOrderInfo()
- this.getSaleInfo()
- this.getSelfUseOrders()
- this.getDefaultAddress()
- },
- onShow: function () {
- this.getDefaultAddress()
- },
- sellClick () {
- var that = this
- that.setData({
- tabLeft: '0',
- tabLeft1: '0',
- curTab: 'sell'
- })
- },
- returnClick () {
- var that = this
- that.setData({
- tabLeft: '33.3%',
- curTab: 'return'
- })
- },
- mineClick () {
- var that = this
- that.setData({
- tabLeft: '66.6%',
- curTab: 'mine'
- })
- },
- mineClick1 () {
- var that = this
- that.setData({
- tabLeft1: '50%',
- curTab: 'mine'
- })
- },
- review () {
- var that = this
- that.data.show = !that.data.show
- if (that.data.show) {
- that.data.angle = 180
- } else {
- that.data.angle = 0
- }
- that.setData({
- show: that.data.show,
- angle: that.data.angle
- })
- },
- setDefaultAddress () {
- // wx.redirectTo({
- // url: '/packageUser/pages/user/address/address'
- // })
- wx.navigateTo({
- url: '/packageUser/pages/user/address/address'
- })
- },
- addDefalutAddress () {
- wx.navigateTo({
- url: '/packageUser/pages/user/newAddress/newAddress'
- })
- },
- toTuiGuang () {
- wx.navigateTo({
- url: '/packageUser/pages/user/invite/invite'
- })
- },
- getSaleInfo () {
- var that = this
- var url = "v1/user/granary/" + that.data.order_id + "/sale/order/info"
- var params = {}
- var success = function (val) {
- if (val.data) {
- that.setData({
- saleOrderInfo: val.data.sale_order,
- saleOrders: val.data.orders
- })
- }
- }
- _request.$get(url, params, success)
- },
- saleCreate () {
- var that = this
- var url = "v1/user/granary/" + that.data.order_id + "/sale/order/operate"
- var params = {
- opt: that.data.opt,
- count: that.data.saleCount
- }
- var success = function (val) {
- if (val.data !== null) {
- // wx.navigateTo({
- // url: '/packageUser/pages/user/granary/granary'
- // })
- wx.showToast({
- title: '已提交',
- icon: 'none',
- duration: 3000
- })
- that.cancelModal()
- that.getOrderInfo()
- that.getSaleInfo()
- }
- }
- _request.$post(url, params, success)
- },
- getDefaultAddress: function () {
- var that = this
- var url = "v1/user/address/default";
- var params = {}
- var success = function (val) {
- if (val.data !== null) {
- that.setData({
- address: val.data
- })
- }
- }
- _request.$get(url, params, success)
- },
- changeSaleCount: function (val) {
- var count = val.detail.value
- var leftcount
- if (!this.data.orderInfo.self_use_count) {
- leftcount = this.data.orderInfo.left_count - this.data.orderInfo.self_use_min
- } else {
- leftcount = this.data.orderInfo.left_count - (this.data.orderInfo.self_use_min - this.data.orderInfo.self_use_count)
- }
- if (count <= 0) {
- this.setData({
- count: 1
- })
- } else if (count > leftcount) {
- this.setData({
- count: leftcount,
- saleCount: leftcount
- })
- } else {
- this.setData({
- count: count,
- saleCount: count
- })
- }
- },
- changeSelfCount: function (val) {
- var count = val.detail.value
- if (count <= 0) {
- this.setData({
- count: 1
- })
- } else if (count > this.data.orderInfo.valid_count) {
- this.setData({
- count: this.data.orderInfo.valid_count,
- selfCount: this.data.orderInfo.valid_count
- })
- } else {
- this.setData({
- count: count,
- selfCount: count
- })
- }
- },
- getOrderInfo () {
- var that = this
- var url = "v1/user/granary/" + that.data.order_id
- var params = {
- cache: false
- }
- var success = function (val) {
- // if (val.data.buyback_min === 0) {
- // that.setData({
- // backcount: 1,
- // orderInfo: val.data
- // })
- // } else {
- that.setData({
- orderInfo: val.data,
- backcount: val.data.buyback_min
- })
- // }
- if (val.data.buyback_max) {
- that.setData({
- tabwidth: "33.3%"
- })
- } else {
- that.setData({
- tabwidth: "50%"
- })
- }
- }
- _request.$get(url, params, success)
- },
- getSelfUseOrders () {
- var that = this
- var url = "v1/user/granary/" + that.data.order_id + "/selfuse/orders";
- var params = {
- page: this.data.selfPage,
- per_page: this.data.per_page
- }
- var success = function (res) {
- var result = that.data.selfList.concat(res.data.list || [])
- that.setData({
- selfList: result
- })
- var listMore = res.data.list_count > that.data.selfList.length
- that.setData({
- selfMore: listMore
- })
- }
- _request.$get(url, params, success)
- },
- secondConfirm (e) {
- var that = this
- that.data.opt = e.currentTarget.dataset.opt
- if (that.data.curTab === 'sell') {
- that.setData({
- confirmCount: that.data.selfCount
- })
- } else if (that.data.curTab === 'mine') {
- that.setData({
- confirmCount: that.data.selfCount
- })
- }
- if (that.data.curTab === 'mine') {
- if (that.data.address && that.data.address.id) {
- that.setData({
- showModal: true
- })
- } else {
- wx.showToast({
- title: '请先填写地址~',
- icon: 'none',
- duration: 3000
- })
- }
- } else {
- that.setData({
- showModal: true
- })
- }
- },
- cancelModal () {
- var that = this
- that.data.showModal = !that.data.showModal
- that.setData({
- showModal: that.data.showModal
- })
- },
- cancelModal1 () {
- var that = this
- that.data.showModal = !that.data.showModal
- that.setData({
- showModal: that.data.showModal
- })
- that.getOrderInfo()
- },
- selfConfirm: function () {
- var that = this
- var url = "v1/user/granary/" + that.data.order_id + "/selfuse/order/create";
- var params = {
- count: that.data.selfCount,
- address_id: that.data.address.id
- }
- var success = function (val) {
- if (val.data) {
- that.cancelModal()
- wx.showToast({
- title: '已自用',
- icon: 'none',
- duration: 3000
- })
- that.data.confirmLock = false
- // that.data.page = 1
- // that.getSelfUseOrders()
- var obj = {
- count: val.data.count,
- paied_at: val.data.paied_at,
- contact: val.data.contact,
- tel: val.data.tel,
- address: val.data.address
- }
- that.data.selfList.unshift(obj)
- that.setData({
- selfList: that.data.selfList
- })
- that.getOrderInfo()
- }
- }
- if (!that.data.confirmLock) {
- _request.$post(url, params, success)
- that.data.confirmLock = true
- }
- },
- saleCountPlus () {
- var that = this
- that.data.saleCount = Number(that.data.saleCount) + 1
- var leftcount
- if (!that.data.orderInfo.self_use_count) {
- leftcount = that.data.orderInfo.left_count - that.data.orderInfo.self_use_min
- } else {
- leftcount = that.data.orderInfo.left_count - (that.data.orderInfo.self_use_min - that.data.orderInfo.self_use_count)
- }
- if (that.data.saleCount <= leftcount) {
- that.setData({
- saleCount: that.data.saleCount
- })
- } else {
- wx.showToast({
- title: '代销数量不能大于剩余数量哦~',
- icon: 'none',
- duration: 3000
- })
- that.setData({
- saleCount: leftcount
- })
- }
- },
- selfCountPlus () {
- var that = this
- that.data.selfCount = Number(that.data.selfCount) + 1
- if (that.data.selfCount <= that.data.orderInfo.valid_count) {
- that.setData({
- selfCount: that.data.selfCount
- })
- } else {
- wx.showToast({
- title: '自用数量不能大于剩余数量哦~',
- icon: 'none',
- duration: 3000
- })
- that.setData({
- selfCount: that.data.orderInfo.valid_count
- })
- }
- },
- onReachBottom: function () {
- if (this.data.selfMore && this.data.curTab === 'mine') {
- var page = this.data.selfPage + 1
- this.setData({
- page: page
- })
- this.getSelfUseOrders()
- }
- },
- onShareAppMessage: function (val) {
- return _request.share({
- title: this.data.orderInfo.product.share_content || this.data.orderInfo.product.name,
- path: '/pages/start/start?url=pages/projects/project-detail/project-detail&id=' + this.data.orderInfo.product.id,
- imageUrl: this.data.orderInfo.product.cover,
- sc: 'xcx_product',
- ri: this.data.orderInfo.product.id,
- rp: this.data.orderInfo.product.id
- })
- },
- saleCountMinus () {
- var that = this
- if (that.data.saleCount > 1) {
- that.data.saleCount = that.data.saleCount - 1
- that.setData({
- saleCount: that.data.saleCount
- })
- } else {
- wx.showToast({
- title: '输入数量必须大于等于1',
- icon: 'none',
- duration: 2000
- })
- }
- },
- selfCountMinus () {
- var that = this
- if (that.data.selfCount > 1) {
- that.data.selfCount = that.data.selfCount - 1
- that.setData({
- selfCount: that.data.selfCount
- })
- } else {
- wx.showToast({
- title: '输入数量必须大于等于1',
- icon: 'none',
- duration: 2000
- })
- }
- },
- toOrderList () {
- wx.navigateTo({
- url: '/packageUser/pages/user/orders/orders'
- })
- },
- showRuleClick () {
- var that = this
- that.data.showRule = !that.data.showRule
- that.setData({
- showRule: that.data.showRule
- })
- },
- postback () {
- if (Number(this.data.backcount) < 0) {
- wx.showToast({
- title: '输入数量必须大于等于0',
- icon: 'none',
- duration: 2000
- })
- } else {
- var that = this
- var url = "v1/user/granary/" + that.data.order_id + "/buyback/no"
- var params = {
- count: that.data.backcount
- }
- var success = function (val) {
- that.setData({
- showModal: true
- })
- // that.getOrderInfo()
- console.log(that.data.backcount)
- }
- _request.$post(url, params, success)
- }
- },
- minusback () {
- var that = this
- if (that.data.backcount > 0) {
- that.data.backcount = that.data.backcount - 1
- that.setData({
- backcount: that.data.backcount
- })
- } else {
- wx.showToast({
- title: '输入数量必须大于等于0',
- icon: 'none',
- duration: 2000
- })
- }
- },
- plusback () {
- var that = this
- that.data.backcount = Number(that.data.backcount) + 1
- if (that.data.backcount <= that.data.orderInfo.buyback_max) {
- that.setData({
- backcount: that.data.backcount
- })
- } else {
- wx.showToast({
- title: '回购数量不能大于回购上限哦~',
- icon: 'none',
- duration: 3000
- })
- that.setData({
- backcount: that.data.orderInfo.buyback_max
- })
- }
- },
- changeback: function (e) {
- // console.log(e)
- var changecount = e.detail.value
- if (changecount < 0) {
- this.setData({
- changecount: 0,
- // backcount: 0
- })
- } else if (changecount > this.data.orderInfo.buyback_max) {
- this.setData({
- changecount: this.data.orderInfo.buyback_max,
- backcount: this.data.orderInfo.buyback_max
- })
- } else {
- this.setData({
- changecount: changecount,
- backcount: changecount
- })
- }
- }
- })
|