Browse Source

发布供需

zhaoxiaohai 3 years ago
parent
commit
1ecbb3b94a

+ 2 - 0
README.md

@@ -38,6 +38,8 @@
 
 ​	My_Checkbox -- 多选框 经营类目
 
+​	My_MultipleChoice -- 单选框 供需类型
+
 ​	My_SupplyAndDemandItemBox -- 供需子项盒子
 
 ​	My_adsorbRight -- 右边吸附按钮 -- 发布需求

+ 3 - 1
app.json

@@ -21,7 +21,9 @@
         "van-grid": "@vant/weapp/grid/index",
         "van-grid-item": "@vant/weapp/grid-item/index",
         "van-tab": "@vant/weapp/tab/index",
-        "van-tabs": "@vant/weapp/tabs/index"
+        "van-tabs": "@vant/weapp/tabs/index",
+        "van-action-sheet": "@vant/weapp/action-sheet/index",
+        "My_Checkbox": "/components/My_Checkbox/index"
     },
     "window": {
         "backgroundTextStyle": "light",

+ 86 - 0
components/My_MultipleChoice/index.js

@@ -0,0 +1,86 @@
+import {
+    ApiModel
+} from "../../utils/api"
+const _Http = new ApiModel();
+Component({
+    /**
+     * 组件的属性列表
+     */
+    properties: {
+        /* 标题 */
+        title: {
+            type: String,
+        },
+        /* 选中项 */
+        pitchOnItem: {
+            type: String,
+            value: ""
+        },
+        /* 回调 */
+        optionChange: {
+            type: Function
+        }
+    },
+    lifetimes: {
+        attached: function () {
+            // 在组件实例进入页面节点树时执行
+            _Http.basic({
+                "accesstoken": wx.getStorageSync('userData').token,
+                "classname": "enterprise.system.supplyanddemand",
+                "method": "query_typeselectList",
+                "content": {}
+            }).then(res => {
+                console.log(res)
+                if (res.msg != "成功") return;
+                let dataList = []
+                for (let i = 0; i < res.data.length; i++) {
+                    let checked = false;
+                    if (res.data[i] == this.data.pitchOnItem) checked = true;
+                    dataList.push({
+                        value: res.data[i],
+                        index: i,
+                        checked: checked
+                    })
+                }
+                this.setData({
+                    dataList
+                })
+            })
+        },
+    },
+
+    /**
+     * 组件的初始数据
+     */
+    data: {
+        dataList: [], //类目列表
+        pitchOn: '', //选中
+    },
+
+    /**
+     * 组件的方法列表
+     */
+    methods: {
+        /* 确定 */
+        confirm() {
+            this.triggerEvent("optionChange", this.data.pitchOn)
+        },
+        /* 多选框返回数值 */
+        radioChange(e) {
+            this.setData({
+                pitchOn: e.detail.value
+            })
+        },
+        /* 添加背景色 */
+        pitchOn(e) {
+            let dataList = this.data.dataList;
+            for (let i = 0; i < dataList.length; i++) {
+                dataList[i].checked = false
+            }
+            dataList[e.currentTarget.dataset.index].checked = !dataList[e.currentTarget.dataset.index].checked
+            this.setData({
+                dataList
+            })
+        }
+    }
+})

+ 6 - 0
components/My_MultipleChoice/index.json

@@ -0,0 +1,6 @@
+{
+    "component": true,
+    "usingComponents": {
+
+    }
+}

+ 12 - 0
components/My_MultipleChoice/index.wxml

@@ -0,0 +1,12 @@
+<view class="checkbox_title">{{title}}</view>
+<radio-group class="checkbox_list" bindchange="radioChange">
+    <view wx:for="{{dataList}}" data-index="{{index}}" wx:key="{{item.index}}" bindtap="pitchOn">
+        <label class="checkbox_item {{item.checked?'choice':''}}" for="{{item.index}}">{{item.value}}</label>
+        <radio hidden="{{true}}" id="{{item.index}}" checked="{{item.checked}}" value="{{item.value}}"></radio>
+    </view>
+</radio-group>
+<view class="checkbox_but">
+    <view>
+        <van-button type="info" size="large" color="#4EBFCF" custom-class="customClass" bindtap="confirm">确定</van-button>
+    </view>
+</view>

+ 62 - 0
components/My_MultipleChoice/index.wxss

@@ -0,0 +1,62 @@
+/* 标题 */
+.checkbox_title {
+    font-size: 32rpx;
+    font-weight: 600;
+    color: #000000;
+    margin: 40rpx 0 30rpx 54rpx;
+}
+
+/* 列表 */
+.checkbox_list {
+    display: flex;
+    flex-wrap: wrap;
+    justify-content: space-between;
+    width: 100vw;
+    min-height: 200rpx;
+    padding: 0 60rpx;
+    box-sizing: border-box;
+}
+
+/* 子项 */
+.checkbox_item {
+    display: block;
+    min-width: 180rpx;
+    height: 64rpx;
+    line-height: 64rpx;
+    text-align: center;
+    background: #F6F7F8;
+    border-radius: 40rpx;
+    font-size: 28rpx;
+    color: rgba(0, 0, 0, .5);
+    padding: 0 8rpx;
+    margin-bottom: 30rpx;
+}
+
+/* 选中后背景颜色 */
+.choice {
+    background-color: #4EBFCF;
+    color: #ffffff;
+}
+
+/* 按钮 */
+.checkbox_but {
+    position: relative;
+    width: 100vw;
+    margin: 30rpx 0 80rpx 0;
+    box-sizing: border-box;
+}
+
+.checkbox_but>view {
+    position: absolute;
+    width: 188rpx;
+    height: 64rpx;
+    background: #4EBFCF;
+    border-radius: 14rpx;
+    right: 60rpx;
+    overflow: hidden;
+}
+
+.customClass{
+    width: 100% !important;
+    height: 100% !important;
+}

+ 10 - 0
components/My_adsorbRight/index.js

@@ -18,10 +18,20 @@ Component({
      * 组件的方法列表
      */
     methods: {
+        /* 显示隐藏 */
         isButtonShow() {
             this.setData({
                 show: !this.data.show
             })
         },
+        /* 跳转到发布需求 */
+        jumpToRelease() {
+            this.setData({
+                show: false
+            })
+            wx.navigateTo({
+                url: '/pages/announceDemand/index',
+            })
+        }
     }
 })

+ 1 - 1
components/My_adsorbRight/index.wxml

@@ -3,7 +3,7 @@
         <image src="../../static/icon-01.png" mode="aspectFill"></image>
     </view>
     <van-transition show="{{ show }}" name="slide-right">
-        <view class="but-right">
+        <view class="but-right" bindtap="jumpToRelease">
             发布
         </view>
     </van-transition>

+ 152 - 6
pages/announceDemand/index.js

@@ -1,20 +1,154 @@
-// pages/announceDemand/index.js
+import {
+    ApiModel
+} from "../../utils/api";
+const _Http = new ApiModel;
+import {
+    TestVerify
+} from "../../utils/verify";
+const _Verify = new TestVerify();
 Page({
-
     /**
      * 页面的初始数据
      */
     data: {
-
+        tsupplyanddemandid: 0, //ID 0为新增
+        newAdd: false, //是否新增 新增未保存直接退出页面会删除该供需
+        popups: false, //弹出层控制
+        ftype: "", //供需类型
+        ftitle: "", //供需标题
+        fcontent: "", //需求内容	
+        fenddate: "", //截止日期
+        fissupply: "", //1供/0需,
+        /* 必填 */
+        errTips: {
+            ftype: false,
+            ftitle: false,
+            fcontent: false
+        }
     },
 
     /**
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
-
+        if (options.data == undefined) {
+            console.log('新增')
+            //新增
+            this.addOrModify()
+            this.setData({
+                newAdd: true
+            })
+        } else {
+            //修改
+
+        }
+    },
+    /* 表单验证 */
+    formVerify() {
+        let errTips = this.data.errTips,
+            verify = true;
+        /* 验证分类 */
+        if (!_Verify.required(this.data.ftype)) {
+            errTips.ftype = true;
+            verify = false;
+        }
+        /* 验证标题  */
+        if (!_Verify.required(this.data.ftitle)) {
+            errTips.ftitle = true;
+            verify = false;
+        }
+        /* 验证内容  */
+        if (!_Verify.required(this.data.fcontent)) {
+            errTips.fcontent = true;
+            verify = false;
+        }
+        this.setData({
+            errTips
+        })
+        return verify;
+    },
+    /* 提交 */
+    submit() {
+        if (!this.formVerify()) return wx.showToast({
+            title: '请检查表单内容',
+            icon: "error"
+        });
+    },
+    /* 新增或修改 */
+    addOrModify() {
+        let content = {};
+        if (this.data.tsupplyanddemandid == 0) {
+            //新增产品
+            content = {
+                "tsupplyanddemandid": 0,
+                "fissupply": 0
+            }
+        } else {
+            //修改需求
+            content = {
+                "tsupplyanddemandid": this.data.tsupplyanddemandid,
+                "ftype": this.data.ftype,
+                "ftitle": this.data.ftitle,
+                "fcontent": this.data.fcontent,
+                "fenddate": this.data.fenddate,
+                "fissupply": this.data.fissupply
+            }
+        }
+        console.log(content)
+        /* 发送请求 */
+        _Http.basic({
+            "accesstoken": wx.getStorageSync('userData').token,
+            "classname": "customer.supplyanddemand.supplyanddemand",
+            "method": "insertormodify",
+            "content": content
+        }).then(res => {
+            console.log(res)
+            this.setData({
+                tsupplyanddemandid: res.data[0].tsupplyanddemandid
+            })
+        })
+    },
+    /* 弹出层 */
+    showPop() {
+        this.setData({
+            popups: !this.data.popups
+        })
+    },
+    /* 单选改变 */
+    radioChange(value) {
+        this.setData({
+            ftype: value.detail,
+            popups: false,
+            "errTips.ftype": false
+        })
+    },
+    /* 获取焦点 */
+    inputFocus(e) {
+        const {
+            name
+        } = e.currentTarget.dataset;
+        let errTips = this.data.errTips;
+        errTips[name] = false;
+        this.setData({
+            errTips
+        })
+    },
+    /* 失去焦点 */
+    inputBlur(e) {
+        const {
+            name
+        } = e.currentTarget.dataset;
+        const {
+            value
+        } = e.detail;
+        if (value.trim() == "") {
+            let errTips = this.data.errTips;
+            errTips[name] = true;
+            this.setData({
+                errTips
+            })
+        }
     },
-
     /**
      * 生命周期函数--监听页面初次渲染完成
      */
@@ -40,7 +174,19 @@ Page({
      * 生命周期函数--监听页面卸载
      */
     onUnload: function () {
-
+        //新增未保存,退出页面删除新增
+        if (this.data.newAdd) {
+            _Http.basic({
+                "accesstoken": wx.getStorageSync('userData').token,
+                "classname": "customer.supplyanddemand.supplyanddemand",
+                "method": "deletesupplyanddemand",
+                "content": {
+                    "tsupplyanddemandid": this.data.tsupplyanddemandid
+                }
+            }).then(res => {
+                console.log(res)
+            })
+        }
     },
 
     /**

+ 3 - 1
pages/announceDemand/index.json

@@ -1,3 +1,5 @@
 {
-  "usingComponents": {}
+  "usingComponents": {
+    "My_MultipleChoice":"/components/My_MultipleChoice/index"
+  }
 }

+ 9 - 3
pages/announceDemand/index.wxml

@@ -1,18 +1,20 @@
 <My_GeneralTemplate padBot="20rpx">
     <view class="store_message">
         <My_GreyRectangleForm title="需求分类" required>
-            <van-field autosize model:value="{{ fname }}" data-name="fname" bind:focus='inputFocus' bindblur='inputBlur' error="{{errTips.fname}}" input-class="input-class" placeholder="点击填写" border="{{ false }}" />
+            <view style="width: 100%; height: 100%; z-index: 999; position: absolute;" bindtap="showPop"></view>
+            <van-field autosize model:value="{{ ftype }}" data-name="ftype" bind:focus='inputFocus' bindblur='inputBlur' error="{{errTips.ftype}}" input-class="input-class" placeholder="点击设置" border="{{ false }}" />
         </My_GreyRectangleForm>
 
         <My_GreyRectangleForm title="需求标题" required>
-            <van-field autosize model:value="{{ fname }}" data-name="fname" bind:focus='inputFocus' bindblur='inputBlur' error="{{errTips.fname}}" input-class="input-class" placeholder="点击填写" border="{{ false }}" />
+            <van-field autosize model:value="{{ ftitle }}" data-name="ftitle" bind:focus='inputFocus' bindblur='inputBlur' error="{{errTips.ftitle}}" input-class="input-class" placeholder="点击填写" border="{{ false }}" />
         </My_GreyRectangleForm>
 
         <My_GreyRectangleForm title="需求内容" required>
-            <van-field autosize model:value="{{ fname }}" data-name="fname" bind:focus='inputFocus' bindblur='inputBlur' error="{{errTips.fname}}" input-class="input-class" placeholder="点击填写" border="{{ false }}" />
+            <van-field autosize model:value="{{ fcontent }}" data-name="fcontent" bind:focus='inputFocus' bindblur='inputBlur' error="{{errTips.fcontent}}" input-class="input-class" placeholder="点击填写" border="{{ false }}" />
         </My_GreyRectangleForm>
 
         <My_GreyRectangleForm title="产品图">
+            <My_UploadFiles fileList="{{attinfos}}" upType="productImage" UploadShow="{{true}}" maxCount="3" tagents_productid="{{tagents_productid}}" previewSize="65px"></My_UploadFiles>
         </My_GreyRectangleForm>
 
 
@@ -21,6 +23,10 @@
 
     </view>
 </My_GeneralTemplate>
+<!-- 弹出层 -->
+<van-action-sheet show="{{ popups }}" bind:close="showPop">
+    <My_MultipleChoice title="需求分类" dataList="{{ftypeList}}" pitchOnItem="{{ftype}}" bind:optionChange="radioChange"></My_MultipleChoice>
+</van-action-sheet>
 <!-- 提交按钮 -->
 <view class="submit_but">
     <van-button bindtap="submit" custom-class="custom-class" round color="linear-gradient(180deg, #82E0E9 0%, #4BBECF 100%);">发 布</van-button>

+ 1 - 3
pages/login/index.json

@@ -3,8 +3,6 @@
     "My_Background": "../../components/My_Background/index",
     "My_RectangularFrame": "../../components/My_RectangularFrame/index",
     "My_ChangeUser": "../../components/My_ChangeUser/index",
-    "My_UploadFiles": "../../components/My_UploadFiles/index",
-    "van-action-sheet": "@vant/weapp/action-sheet/index",
-    "My_Checkbox":"/components/My_Checkbox/index"
+    "My_UploadFiles": "../../components/My_UploadFiles/index"
   }
 }

+ 1 - 2
pages/storeMessage/index.json

@@ -1,6 +1,5 @@
 {
   "usingComponents": {
-    "van-action-sheet": "@vant/weapp/action-sheet/index",
-    "My_Checkbox":"/components/My_Checkbox/index"
+
   }
 }

+ 6 - 0
project.private.config.json

@@ -71,6 +71,12 @@
                     "pathName": "pages/tabbar-pages/supplyAndDemand/index",
                     "query": "",
                     "scene": null
+                },
+                {
+                    "name": "发布需求",
+                    "pathName": "pages/announceDemand/index",
+                    "query": "",
+                    "scene": null
                 }
             ]
         }