123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- // pages/order/deposit/deposit.js
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- orderList: [
- ],
- logisticsStatus: "",
- show: false,
- result: false,
- result2: false,
- countDownNum: 15,
- spot_id: 0,
- device_no: "",
- order_num: "",
- is_deposit: 1,
- netwrok_id: 0,
- order_type: 0,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var order_type = options.order_type ? options.order_type : 2
- var netwrok_id = options.network_id;
- var order_num = options.order_num;
- var is_deposit = options.is_deposit;
- var device_id = options.device_id?options.device_id:0;
- console.log(options);
- this.setData({
- logisticsStatus: app.globalData.logisticsStatus,
- order_num: order_num,
- netwrok_id: netwrok_id,
- is_deposit: is_deposit,
- device_id:device_id,
- order_type: order_type
- })
- this.getorderList(order_type, netwrok_id, device_id);
- if (this.data.is_deposit != 1) {
- wx.setNavigationBarTitle({
- title: '等待取出',
- })
- }
- },
- onClose(e) {
- var no = e.currentTarget.dataset.no
- var type = e.currentTarget.dataset.type
- var device_id = e.currentTarget.dataset.device_id
- var spout_device_id = e.currentTarget.dataset.spout_device_id
- wx.nextTick(() => {
- this.setData({
- show: !this.data.show
- })
- })
- if (this.data.is_deposit != 1) {
- if (this.data.spot_id == 0) {
- this.setData({
- spot_id: spout_device_id,
- device_no: device_id
- });
- }
- this.opentask1(no, type, this.data.device_no, this.data.spot_id)
- } else {
- this.opentask(no, type);
- }
- },
- countDown: function () {
- let that = this;
- let countDownNum = that.data.countDownNum;//获取倒计时初始值
- //如果将定时器设置在外面,那么用户就看不到countDownNum的数值动态变化,所以要把定时器存进data里面
- that.setData({
- timer: setInterval(function () {//这里把setInterval赋值给变量名为timer的变量
- //每隔一秒countDownNum就减一,实现同步
- countDownNum--;
- //然后把countDownNum存进data,好让用户知道时间在倒计着
- that.setData({
- countDownNum: countDownNum
- })
- //在倒计时还未到0时,这中间可以做其他的事情,按项目需求来
- if (countDownNum == 0) {
- //这里特别要注意,计时器是始终一直在走的,如果你的时间为0,那么就要关掉定时器!不然相当耗性能
- //因为timer是存在data里面的,所以在关掉时,也要在data里取出后再关闭
- clearInterval(that.data.timer);
- //关闭定时器之后,可作其他处理codes go here
- }
- }, 1000)
- })
- },
- takeClothes() {
- wx.nextTick(() => {
- this.setData({
- result: !this.data.result
- })
- })
- },
- storeClothes() {
- wx.nextTick(() => {
- this.setData({
- result2: !this.data.result2
- })
- })
- },
- getorderList(order_type, network_id, device_id = "") {
- var that = this;
- var nid = network_id
- var data = {
- network_id: nid,
- order_type: order_type,
- order_num: this.data.order_num,
- logistics_status: that.data.is_deposit == 1 ? 1 : 6,
- is_deposit: that.data.is_deposit
- }
- console.log(data);
- app.api.useApi(app.globalData.baseAppUrl + "api/order/index", data, "get").then(function (res) {
- if (res.code != 200) {
- console.log(res)
- wx.showLoading({
- title: '订单加载失败',
- })
- } else {
- that.setData({
- orderList: res.message.data.data,
- network: res.message.network,
- is_something: res.message.is_something
- })
- }
- wx.hideLoading();
- }).catch(function (err) {
- console.log(err);
- })
- },
- opentask(no = "", type = "") {
- var that = this;
- if (no && type) {
- this.setData({
- order_no: no,
- type: type,
- order_num: that.data.order_num
- })
- } else {
- no = this.data.order_no;
- type = this.data.order_type;
- }
- app.api.useApi(app.globalData.baseAppUrl + "api/save", {
- // status: status,
- order_no: no,
- order_num: that.data.device_id,
- }, "post").then(function (res) {
- if (res.code != 200) {
- that.countDown();
- that.setData({
- device_no: res.message.data.device_no,
- })
- wx.showToast({
- title: res.message.msg,
- })
- console.log(res.message.msg)
- // wx.setTimeout(() => {
- // wx.hideLoading();
- // }, 1000);
- setTimeout(function () {
- // wx.hideLoading();
- that.setData({
- show: !that.data.show
- })
- }, 3000)
- } else {
- console.log(res);
- that.setData({
- show: false,
- spot_id: res.message.data.spot_id,
- device_no: res.message.data.device_id
- })
-
- if (type == 1) {
- that.storeClothes()
- } else {
- that.takeClothes()
- }
- }
- // wx.hideLoading();
- }).catch(function (err) {
- console.log(err.message)
- })
- },
- goto() {
- var order_no = this.data.order_no;
- this.setData({
- result: false,
- result2: false,
- show: false
- })
- if (this.data.is_deposit != 1) {
- app.api.useApi(app.globalData.baseAppUrl + "api/UserConfirm", {
- // status: status,
- device_id: this.data.device_no,
- spout_device_id: this.data.spot_id,
- }, "post").then(function (res) {
- if (res.code != 200) {
- wx.showLoading({
- title: res.message.msg,
- })
- wx.setTimeout(() => {
- wx.hideLoading();
- }, 1000);
- } else {
- let p = getCurrentPages().pop().options
- console.log(p);
- that.getorderList(p.order_type, p.network_id);
- console.log(res);
- if (is_deposit == 1) {
- that.storeClothes()
- } else {
- that.takeClothes()
- }
- that.setData({
- show: !this.data.show
- })
- }
- wx.hideLoading();
- }).catch(function (err) {
- console.log(222);
- })
- } else {
- app.api.useApi(app.globalData.baseAppUrl + "api/saved", {
- // status: status,
- order_no: order_no,
- spot_id: this.data.spot_id,
- }, "post").then(function (res) {
- if (res.code != 200) {
- wx.showLoading({
- title: res.message.msg,
- })
- wx.setTimeout(() => {
- wx.hideLoading();
- }, 1000);
- } else {
- that.getorderList(that.data.order_type, that.data.netwrok_id);
- console.log(res);
- if (type == 1) {
- that.storeClothes()
- } else {
- that.takeClothes()
- }
- that.setData({
- show: !this.data.show
- })
- }
- wx.hideLoading();
- }).catch(function (err) {
- console.log(222);
- })
- }
- },
- /**
- * @name 开柜取出
- * @param {*} no
- * @param {*} type
- */
- opentask1(no = "", type = "", device_id, spout_device_id) {
- var that = this;
- if (no && type) {
- this.setData({
- order_no: no,
- type: type,
- })
- } else {
- no = this.data.order_no;
- type = this.data.order_type;
- }
- app.api.useApi(app.globalData.baseAppUrl + "api/UserOpenDevices", {
- // status: status,
- device_id: device_id,
- spout_device_id: spout_device_id
- }, "post").then(function (res) {
- if (res.code != 200) {
- wx.showLoading({
- title: res.message.msg,
- })
- that.countDown();
- that.setData({
- device_no: res.message.data.device_no,
- })
- // wx.setTimeout(() => {
- // wx.hideLoading();
- // }, 1000);
- setTimeout(function () {
- wx.hideLoading();
- that.setData({
- show: !that.data.show
- })
- }, 3000)
- } else {
- console.log(res);
- if (that.is_deposit == 1) {
- that.storeClothes()
- } else {
- that.takeClothes()
- }
- }
- wx.hideLoading();
- }).catch(function (err) {
- console.log(err.message)
- })
- },
- onPullDownRefresh: function () {
- let p = getCurrentPages().pop().options
- console.log(p);
- this.getorderList(p.order_type, p.network_id);
- }
- })
|