123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- // pages/filter/index.js
- import http from '../../utils/http'
- import util from '../../utils/util'
- import api from '../../utils/api'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- active: 0,
- devices: [],
- device_ids: [''],
- names: [],
- device_name_ids: [''],
- specs: [],
- spec_ids: [''],
- rent_types: [],
- rent_type_ids: ['']
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
-
- },
- onChange: function(e) {
- var name = e.currentTarget.dataset.name
- this.setData({
- [name]: e.detail
- })
- if(['device_id', 'device_name_id'].indexOf(name) != -1) {
- if(name == 'device_id') {
- this.setData({
- device_name_id: '',
- spec_id: ''
- })
- }
- if(name == 'device_name_id') {
- this.setData({
- spec_id: ''
- })
- }
- this.updateNameSpec()
- }
- },
- confirm: function() {
- this.saveFilter()
- wx.navigateBack()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- delete: function(e) {
- var name = e.currentTarget.dataset.name
- var index = e.currentTarget.dataset.index
- var items = this.data[name]
- if(index == 0) return false;
- items.splice(index, 1)
- this.setData({
- [name]: items
- })
- },
- add: function(e) {
- var name = e.currentTarget.dataset.name
- var items = this.data[name]
- if(!items[items.length - 1]) {
- util.error('请先选择');
- return false
- }
- items.push('')
- this.setData({
- [name]: items
- })
- },
- onDropChange: function(e) {
- var index = e.currentTarget.dataset.index
- var name = e.currentTarget.dataset.name
- var val = e.detail
- var items = this.data[name]
- items[index] = val
- this.setData({
- [name]: items
- })
- if(name == 'device_ids') {
- this.updateDeviceNames()
- }
- if(name == 'device_name_ids') {
- this.updateSpecs()
- }
- },
- updateDeviceNames() {
- var that = this;
- that.setData({
- device_name_ids: ['']
- })
- api.getByName(this, 'device-names/get', 'names', {type: 'drop_menu', device_ids: this.data.device_ids}, function() {
- that.updateSpecs();
- });
- },
- updateSpecs() {
- var that = this;
- that.setData({
- spec_ids: ['']
- })
- api.getByName(this, 'specs/get', 'specs', {type: 'drop_menu', device_name_ids: this.data.device_name_ids});
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- var data = wx.getStorageSync('sg-data-filters')
- this.setData(data)
- api.getByName(this, 'devices/get', 'devices', {type: 'drop_menu'});
- api.getByName(this, 'device-names/get', 'names', {type: 'drop_menu', device_ids: this.data.device_ids});
- api.getByName(this, 'specs/get', 'specs', {type: 'drop_menu', device_name_ids: this.data.device_name_ids});
- api.getByName(this, 'rent-types/get', 'rent_types', {type: 'drop_menu'});
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- this.saveFilter()
- },
- saveFilter() {
- var data = {
- devices: this.data.devices,
- device_ids: this.data.device_ids,
- names: this.data.names,
- device_name_ids: this.data.device_name_ids,
- specs: this.data.specs,
- spec_ids: this.data.spec_ids,
- rent_types: this.data.rent_types,
- rent_type_ids: this.data.rent_type_ids
- }
- wx.setStorageSync('sg-data-filters', data)
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|