123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- // pages/goodsCate/goodsCate.js
- const utils = require('../../utils/util.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- showTopList: '', // 一级分类列表
- showTop: [], // 一级分类展示
- showTopIndex: '', // 一级分类下标
- showTwoList: [], // 二级分类列表
- showTwo: [], // 二级分类展示
- showTwoIndex: '', // 二级分类下标
- list: [], // 商品列表
- fadeIn: false, // 弹框是否显示
- item: '', // 选中的商品数据
- keywords: '' // 关键词
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (options.productName) {
- this.setData({
- keywords: options.productName
- })
- }
- this.getCategoryTop()
- },
- //一级类目
- getCategoryTop() {
- wx.showLoading({
- title: '加载中...',
- mask: true
- })
- wx.cloud.callFunction({
- name: 'getNxyData',
- data: {
- start: 0,
- count: 50,
- $url: 'getCategoryTop'
- }
- }).then(res => {
- wx.hideLoading()
- let list = res.result.data
- let showTop = []
- let showTopList = []
- this.setData({
- topList: list
- })
- for (let i = 0; i < list.length; i++) {
- if (list[i].parent_code === '') {
- showTopList.push(list[i])
- showTop.push(list[i].name)
- }
- }
- this.setData({
- showTop,
- showTopList
- })
- })
- },
- //二级类目
- getTwo() {
- let parent_code = this.data.showTopList[this.data.showTopIndex].code
- let showTwo = []
- let showTwoList = []
- for (let i = 0; i < this.data.topList.length; i++) {
- let item = this.data.topList[i]
- if (item.parent_code === parent_code) {
- showTwoList.push(item)
- showTwo.push(item.name)
- }
- }
- this.setData({
- showTwoList,
- showTwo
- })
- },
- //设置完一级类目之后才可以设置二级类目
- setTop(e) {
- let showTopIndex = e.detail.value
- this.setData({
- showTopIndex,
- showTwoIndex: '',
- showTwo: []
- })
- this.getTwo()
- this.toFresh()
- },
- //设置二级类目
- setTwo(e) {
- if (this.data.showTopIndex === '') {
- utils.toast('请先选择一级类目')
- return
- }
- this.setData({
- showTwoIndex: e.detail.value
- })
- this.toFresh()
- },
- //获取关键字
- getKeywords(e) {
- let keywords = e.detail.value
- this.setData({
- keywords
- })
- },
- //根据条件查询商品
- getCategoryAll() {
- const params = {
- entTaxId: wx.getStorageSync('entTaxId')
- }
- if (utils.trimAll(this.data.keywords)) {
- params.productName = utils.trimAll(this.data.keywords)
- }
- if (this.data.showTwoList && this.data.showTwoIndex && this.data.showTwoList[this.data.showTwoIndex].code) {
- params.searchCode = this.data.showTwoList[this.data.showTwoIndex].code
- }
- utils.axios({
- method: 'get',
- url: '/sys/product/commoditySearch',
- data: params,
- sendBefore() {
- wx.showLoading({
- title: '加载中...',
- mask: true
- })
- },
- success: res => {
- let list = this.data.list
- for (let i = 0; i < res.data.length; i++) {
- // 税率转化成%
- if (res.data[i].sortedRateSet && res.data[i].sortedRateSet.length > 0) {
- let rateList = []
- for (let j = 0; j < res.data[i].sortedRateSet.length; j++) {
- rateList.push(Number(res.data[i].sortedRateSet[j]) * 100 + '%')
- }
- res.data[i].rate = rateList.join(',')
- }
- }
- list = list.concat(res.data)
- this.setData({
- list
- })
- },
- complete() {
- wx.hideLoading()
- }
- })
- /* let params = {
- start: this.data.list.length,
- count: this.data.count,
- search_code: this.data.showTwoList[this.data.showTwoIndex].code,
- $url: 'getCategoryAll'
- }
- if (utils.trimAll(this.data.keywords) !== '') {
- params.keyword = utils.trimAll(this.data.keywords)
- }
- wx.showLoading({
- title: '加载中...',
- mask: true
- })
- wx.cloud.callFunction({
- name: 'getNxyData',
- data: params
- }).then(res => {
- wx.hideLoading()
- let list = this.data.list
- list = list.concat(res.result.data)
- this.setData({
- list
- })
- }) */
- },
- toFresh() {
- this.setData({
- list: []
- })
- },
- //搜索
- search() {
- this.toFresh()
- this.getCategoryAll()
- },
- //选择展示详情
- chooseItem(e) {
- this.setData({
- fadeIn: true,
- item: this.data.list[e.currentTarget.dataset.index]
- })
- },
- hideMoadal() {
- this.setData({
- fadeIn: false,
- item: ''
- })
- },
- selected() {
- //根据当前默认企业税号和选择的税收分类编码确定可用税率
- let params = {
- entTaxId: wx.getStorageSync('entTaxId'),
- taxCateCode: this.data.item.code
- }
- utils.axios({
- method: 'get',
- url: '/sys/entInfo/rates',
- data: params,
- sendBefore() {
- wx.showLoading({
- title: '加载中...',
- mask: true
- })
- },
- success: res => {
- let rateArray = [0]
- for (let i = 0; i < res.data.length; i++) {
- rateArray.push(res.data[i] * 100)
- }
- utils.funPrev(prev => {
- prev.setData({
- ['taxRate']: rateArray,
- ['params.taxationCateCode']: this.data.item.code,
- ['params.taxationCateName']: this.data.item.name
- })
- wx.navigateBack()
- })
- },
- complete() {
- wx.hideLoading()
- }
- })
- },
- noScroll() {},
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|