123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- // pages/index/components/listDetails/Details.js
- const app = getApp()
- const $request = require('../../utils/request.js');
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- currentIndex: 1,
- pageLoading: false,
- tags: [],
- min: 0,
- max: 300,
- // 用户有无点击过tag
- isClickTag: false,
- // 选中tag
- selectedTag: [],
- detailValue: "",
- saveLoading:false,
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad() {
- this.getTags();
- },
- // 输入框输入
- textareaInput(e) {
- let value = e.detail.value;
- let len = e.detail.cursor;;
- this.setData({
- min: len
- });
- this.setData({
- detailValue: value
- })
- },
- // tag选择切换
- tagSelectedChange(e) {
- let typename = e.currentTarget.dataset.typename;
- let selectedTag = this.data.selectedTag;
- let tempArr = [];
- // 1 如果选中的数组里没有当前type
- if (selectedTag.indexOf(typename) == -1) {
- // 2 如果选中的数组的长度小于3 直接push
- if (selectedTag.length < 3) {
- selectedTag.push(typename)
- }
- }
- // 3 如果选中的数组里有它,直接删除
- else {
- selectedTag.forEach((el, inx) => {
- if (el == typename) {
- selectedTag.splice(inx, 1);
- }
- })
- }
- let tags = this.data.tags;
- tags.forEach(el => {
- el.isActive = false
- if (selectedTag.indexOf(el.typeName) != -1) {
- el.isActive = true;
- }
- })
- this.setData({
- selectedTag,
- tags
- })
- // console.log(this.data.selectedTag,'selectedTag');
- // console.log(this.data.tags,'tags');
- },
- // 发布需求
- releaseDemands() {
- this.setData({
- saveLoading:true
- })
- let { selectedTag, detailValue } = this.data;
- let param = {
- customerId: 666967,
- info: this.trimRight(detailValue),
- type: selectedTag.join(','),
- businessCommunicationDemandId: null,
- };
- $request.post('/businessCommunicationDemand/saveDemand.action', param).then(res => {
- this.setData({
- saveLoading:false
- })
- let that = this;
- if (res.status == 0) {
- wx.showModal({
- title: '发布成功',
- content: "请关注平台公众号,如有咨询,可及时接收消息通知!",
- confirmText: "去关注",
- cancelText:"关闭",
- success (res1) {
- if (res1.confirm) {
- that.clearData();
- console.log('用户点击确定')
- } else if (res1.cancel) {
- let listDetail = res.data;
- if (typeof listDetail.type == 'string') {
- listDetail.type = listDetail.type.split(',');
- }
- that.clearData();
- wx.navigateTo({
- url: '/pages/index/components/listDetails/Details',
- success: function (res2) {
- // 通过eventChannel向被打开页面传送数据
- res2.eventChannel.emit('acceptDataFromOpenerPage', { listDetail })
- }
- })
- }
- }
- })
- } else if (res.status == 501) {
- wx.showModal({
- title: '发布失败',
- content: res.msg,
- showCancel: false,
- })
- }
- }).catch(err => {
- console.log(err);
- this.setData({
- saveLoading:false
- })
- })
- },
- clearData(){
- this.setData({
- selectedTag:[],
- detailValue:"",
- })
- },
- trimRight(s) {
- if (s == null) return "";
- var whitespace = new String(" \t\n\r");
- var str = new String(s);
- if (whitespace.indexOf(str.charAt(str.length - 1)) != -1) {
- var i = str.length - 1;
- while (i >= 0 && whitespace.indexOf(str.charAt(i)) != -1) {
- i--;
- }
- str = str.substring(0, i + 1);
- }
- return str;
- },
- // 获取tag
- getTags() {
- this.setData({
- pageLoading: true,
- })
- $request.get('/businessCommunicationType/getAllType.action').then(res => {
- this.setData({
- pageLoading: false,
- })
- if (res.status == 0) {
- let datas = res.data;
- datas.forEach(el => {
- el.isActive = false;
- })
- this.setData({
- tags: datas,
- })
- }
- console.log(this.data.tags, 'tags')
- }).catch(error => {
- console.log(error, 'error appletLogin')
- })
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
-
- }
- })
|