123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- // pages/myModule/components/myRelease/myRelease.js
- const $request = require('../../../../utils/request.js');
- const $util = require('../../../../utils/util.js');
- const app = getApp()
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- tabs: [
- {
- tab: "发布中",
- code: 'release'
- },
- {
- tab: "已下架",
- code: 'remove'
- }
- ],
- currentTab: 'release',
- listLoading: false,
- customerId: null,
- // 我发布的需求----
- // item行加载
- itemLoading: false,
- listData: [],
- page: 1,
- size: 10,
- total: 0,
- // 是否加载数据,true加载,false不加载
- onRefresh: true,
- // 搜索值
- keyword: "",
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- const eventChannel = this.getOpenerEventChannel()
- // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据
- eventChannel.on('customerid', data => {
- this.setData({
- customerId: data.customerid,
- listLoading: true,
- })
- this.getListData();
- })
- },
- // tab切换
- tabChange(e) {
- let code = e.currentTarget.dataset.code;
- this.setData({
- currentTab: code
- })
- this.toSearch();
- },
- // 搜索框输入同步值
- bindKeyInput: function (e) {
- this.setData({
- keyword: e.detail.value
- })
- },
- toSearch() {
- this.setData({
- listData: [],
- onRefresh: true,
- listLoading: true,
- page: 1,
- })
- this.getListData();
- },
- // 置顶/取消置顶需求
- productIsOnTop(e) {
- let item = e.currentTarget.dataset.item;
- let that = this;
- if (item.isOnTop) {
- wx.showModal({
- title: '提示',
- content: "是否确认取消置顶?",
- confirmText: "确认",
- cancelText: "取消",
- success(res) {
- if (res.confirm) {
- that.productIsOnTopPost(item);
- }
- }
- })
- } else {
- that.productIsOnTopPost(item);
- }
- },
- // 置顶/取消置顶需求Fn
- productIsOnTopPost(item) {
- let { businessCommunicationDemandId, isOnTop } = item;
- this.showLoading();
- $request.post(`/businessCommunicationDemand/setOnTopOrDown.action`,
- { businessCommunicationDemandId, isOnTop: isOnTop ? 0 : 1, customerId: this.data.customerId }
- ).then(res => {
- wx.hideLoading()
- if (res.status == 0) {
- wx.showToast({
- title: isOnTop ? '取消置顶成功' : '置顶成功',
- icon: 'success',
- duration: 2000
- })
- let listData = this.data.listData;
- listData.forEach(el => {
- if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
- el.isOnTop = isOnTop ? false : true
- }
- })
- this.setData({
- listData
- })
- }else if(res.status == 106){
- wx.showToast({
- title: res.msg,
- icon: 'error',
- duration: 2000
- })
- }
- }).catch(error => {
- console.log(error, 'error appletLogin')
- wx.hideLoading()
- })
- },
- // 上架/下架需求
- productRelease(e) {
- let item = e.currentTarget.dataset.item;
- let that = this;
- if (item.state == 0) {
- wx.showModal({
- title: '提示',
- content: "是否确认下架?",
- confirmText: "确认",
- cancelText: "取消",
- success(res) {
- if (res.confirm) {
- that.productReleasePost(item);
- }
- }
- })
- } else {
- that.productReleasePost(item);
- }
- },
- // 上架/下架需求 Fn
- productReleasePost(item) {
- this.showLoading();
- let { businessCommunicationDemandId, state } = item;
- // 上架传0 下架传-1
- $request.post(`/businessCommunicationDemand/outDemand.action`,
- { businessCommunicationDemandId, state: state != 0 ? 0 : -1 }
- ).then(res => {
- wx.hideLoading()
- if (res.status == 0) {
- wx.showToast({
- title: state == 0 ? '下架成功' : '上架成功',
- icon: 'success',
- duration: 2000
- })
- let listData = this.data.listData;
- listData.forEach((el, inx) => {
- if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
- listData.splice(inx, 1);
- }
- })
- this.setData({
- listData
- })
- }
- }).catch(error => {
- console.log(error, 'error appletLogin')
- wx.hideLoading()
- })
- },
- // 删除需求
- productDel(e) {
- let item = e.currentTarget.dataset.item;
- let that = this;
- wx.showModal({
- title: '提示',
- content: "是否确认删除?",
- confirmText: "确认",
- cancelText: "取消",
- success(res) {
- if (res.confirm) {
- that.productDelPost(item);
- }
- }
- })
- },
- // 删除需求 Fn
- productDelPost(item) {
- let { businessCommunicationDemandId } = item;
- this.showLoading();
- $request.post(`/businessCommunicationDemand/deleteDemand.action`,
- { businessCommunicationDemandId }
- ).then(res => {
- wx.hideLoading()
- if (res.status == 0) {
- wx.showToast({
- title: '删除成功',
- icon: 'success',
- duration: 2000
- })
- let listData = this.data.listData;
- listData.forEach((el, inx) => {
- if (el.businessCommunicationDemandId == businessCommunicationDemandId) {
- listData.splice(inx, 1);
- }
- })
- this.setData({
- listData
- })
- }
- }).catch(error => {
- console.log(error, 'error appletLogin')
- wx.hideLoading()
- })
- },
- // 修改需求
- productEdit(e) {
- let item = e.currentTarget.dataset.item;
- let that = this;
- wx.navigateTo({
- url: '/pages/releaseModule/index',
- success: function (res) {
- // 通过eventChannel向被打开页面传送数据
- res.eventChannel.emit('acceptDataFromOpenerPage', { listDetail: item })
- }
- })
- },
- // 数据加载提示
- showLoading(title) {
- wx.showLoading({
- title: title ? title : '加载中',
- mask: true
- })
- },
- // 显示下架原因
- showOutReason(e){
- let outReason = e.currentTarget.dataset.outreason;
- wx.showModal({
- title: '下架原因',
- content: outReason,
- showCancel: false,
- })
- },
-
- getListData() {
- let { page, size, customerId, keyword, currentTab } = this.data;
- $request.get('/businessCommunicationDemand/getDemandByStateAndCustomerId.action',
- { page, size, customerId, keyword, state: currentTab }
- ).then(res => {
- let tempListData = this.data.listData;
- if (res.status == 0) {
- let datas = res.data;
- // 先push数据
- tempListData.push(...datas.demandList);
- tempListData.forEach(el => {
- el.createdOn = $util.formatTime(new Date(el.createdOn), true);
- el.createdOn = el.createdOn.replaceAll('/', '-');
- if (typeof el.type == 'string') {
- el.type = el.type.split(',');
- }
- })
- // 设置总数
- this.setData({
- listData: tempListData,
- total: datas.total,
- })
- // 如果数据大于了返回的总数
- if (tempListData.length >= this.data.total) {
- // 停止累加数据
- this.setData({
- onRefresh: false,
- itemLoading: false,
- })
- } else {
- this.setData({
- onRefresh: true,
- itemLoading: false,
- page: page + 1
- })
- }
- }
- this.setData({
- listLoading: false,
- })
- }).catch(error => {
- console.log(error, 'error appletLogin')
- })
- },
- //
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- if (this.data.onRefresh) {
- this.setData({
- itemLoading: true
- })
- this.getListData();
- }
- },
-
- })
|