Pārlūkot izejas kodu

项目关联产品

zhaoxiaohai 3 gadi atpakaļ
vecāks
revīzija
bda178ae55

+ 161 - 0
packageA/project/modules/product/index.js

@@ -0,0 +1,161 @@
+const _Http = getApp().globalData.http,
+    file = require("../../../../utils/matchingFeilType");
+let queue = [],
+    downCounter = null;
+Component({
+    data: {
+        sa_projectid: 0,
+        "content": {
+            nocache: true,
+            "pageNumber": 1,
+            pageTotal: 1,
+            total: null
+        }
+    },
+    lifetimes: {
+        detached: function () {
+            if (downCounter) {
+                clearTimeout(downCounter);
+                this.changeItem(queue)
+            }
+        },
+    },
+    methods: {
+        /* 获取产品列表 */
+        getList(id, init) {
+            let content = this.data.content;
+            content.sa_projectid = id;
+            if (init) content.pageNumber = 1
+            _Http.basic({
+                "id": "20221021145702",
+                content
+            }).then(res => {
+                console.log("项目清单列表", res)
+                if (res.msg != '成功') return wx.showToast({
+                    title: res.data,
+                    icon: "none"
+                })
+                res.data = res.data.map(value => {
+                    if (value.attinfos.length == 0) return value;
+                    value.attinfos = file.fileList(value.attinfos)
+                    let image = value.attinfos.find(v => v.fileType == "image");
+                    value.cover = image ? image.cover : "";
+                    value.className = value.itemclass.length == 0 ? "暂无类目" : value.itemclass.map(v => v.itemclassname);
+                    value.brandName = value.brand.length == 0 ? "暂无品牌" : value.brand.map(v => v.brandname);
+                    value.discountrate = value.discountrate * 100;
+                    return value;
+                })
+                this.setData({
+                    list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
+                    "content.pageNumber": res.pageNumber + 1,
+                    "content.pageSize": res.pageSize,
+                    "content.pageTotal": res.pageTotal,
+                    "content.total": res.total,
+                    sa_projectid: id
+                })
+            })
+        },
+        /* 去选择产品 */
+        addProduct() {
+            console.log("添加产品")
+            let page = getCurrentPages().find(v => v.__route__ == 'packageA/project/detail'),
+                {
+                    sa_projectid
+                } = page.data.detail;
+            if (page) wx.navigateTo({
+                url: '/packageA/select/product/select?params=' + JSON.stringify({
+                    "id": 20221021171802,
+                    "version": 1,
+                    "content": {
+                        nocache: true,
+                        pageNumber: 1,
+                        pageTotal: 1,
+                        total: null,
+                        sa_projectid,
+                        where: {
+                            condition: ""
+                        }
+                    }
+                })
+            })
+        },
+        /* 处理选择产品 */
+        handleSelectProduct(items) {
+            let that = this;
+            wx.showModal({
+                title: '提示',
+                content: '是否确认添加产品?',
+                complete: ({
+                    confirm
+                }) => {
+                    if (confirm) _Http.basic({
+                        "id": 20221021145502,
+                        "version": 1,
+                        "content": {
+                            "sa_projectid": that.data.sa_projectid,
+                            items
+                        }
+                    }).then(res => {
+                        console.log("报价单添加产品", res);
+                        wx.showToast({
+                            title: res.msg != '成功' ? res.msg : '添加成功!',
+                            icon: "none"
+                        });
+                        if (res.msg == '成功') setTimeout(() => {
+                            that.getList(that.data.sa_projectid, true)
+                            wx.navigateBack()
+                        }, 300)
+                    })
+                }
+            })
+
+        },
+        /* 删除产品 */
+        deleteItems({
+            detail
+        }) {
+            _Http.basic({
+                "id": 20221021145602,
+                "content": {
+                    "deletereason": "",
+                    "sa_project_itemsids": detail
+                }
+            }).then(res => {
+                console.log("批量删除产品", res);
+                wx.showToast({
+                    title: res.msg == '成功' ? '删除成功!' : res.msg,
+                    icon: "none"
+                })
+                if (res.msg == '成功') this.setData({
+                    list: this.data.list.filter(v => detail.indexOf(v.sa_project_itemsid) == -1)
+                })
+            })
+        },
+        /* 生成修改队列 */
+        changeQueue({
+            detail
+        }) {
+            let i = queue.findIndex(v => v.sa_project_itemsid == detail.sa_project_itemsid);
+            if (i == -1) {
+                queue.push(detail)
+            } else {
+                queue[i] = detail;
+            };
+            clearTimeout(downCounter)
+            downCounter = setTimeout(() => {
+                this.changeItem(queue)
+            }, 2000);
+        },
+        changeItem(items) {
+            _Http.basic({
+                "id": 20221021145502,
+                "content": {
+                    "sa_projectid": this.data.sa_projectid,
+                    items
+                }
+            }, false).then(res => {
+                console.log("批量修改产品清单", res)
+            })
+        }
+    }
+})

+ 6 - 0
packageA/project/modules/product/index.json

@@ -0,0 +1,6 @@
+{
+    "component": true,
+    "usingComponents": {
+        "List": "./list/index"
+    }
+}

+ 2 - 0
packageA/project/modules/product/index.scss

@@ -0,0 +1,2 @@
+@import "../../../setclient/modules/address/head.scss";
+

+ 12 - 0
packageA/project/modules/product/index.wxml

@@ -0,0 +1,12 @@
+<view class="head">
+    <view class="count">产品清单</view>
+    <view class="expand">
+      <!--   <navigator url="#" class="but">
+            <van-icon name="search" />
+        </navigator> -->
+        <navigator url="#" class="but" bindtap="addProduct">
+            <van-icon name="plus" />
+        </navigator>
+    </view>
+</view>
+<List list='{{list}}' bind:deleteItem='deleteItems' bindchangeQueue='changeQueue' />

+ 51 - 0
packageA/project/modules/product/list/index.js

@@ -0,0 +1,51 @@
+Component({
+    properties: {
+        list: Array,
+        deleteItem: Function,
+        changeQueue: Function, //修改队列
+    },
+    options: {
+        addGlobalClass: true
+    },
+    methods: {
+        /* 步进器回调 */
+        onStepper(e) {
+            let {
+                item,
+                index
+            } = e.currentTarget.dataset;
+            item.qty = e.detail;
+            this.setData({
+                [`list[${index}]`]: item
+            })
+            let obj = {};
+            ["sa_project_itemsid", "itemid", "qty", "remarks"].forEach(v => obj[v] = item[v]);
+            this.triggerEvent("changeQueue", obj)
+        },
+        /* 计算百分比 */
+        getPercent(num, total) {
+            num = parseFloat(num);
+            total = parseFloat(total);
+            if (isNaN(num) || isNaN(total)) {
+                return "-";
+            }
+            return total <= 0 ? "0%" : Math.round((num / total) * 10000) / 100;
+        },
+        deleteProduct(e) {
+            const {
+                sa_project_itemsid,
+                itemname
+            } = e.currentTarget.dataset.item,
+                that = this;
+            wx.showModal({
+                title: '提示',
+                content: `是否确认删除“${itemname}”?`,
+                complete: ({
+                    confirm
+                }) => {
+                    if (confirm) that.triggerEvent("deleteItem", [sa_project_itemsid]);
+                }
+            })
+        },
+    }
+})

+ 6 - 0
packageA/project/modules/product/list/index.json

@@ -0,0 +1,6 @@
+{
+    "component": true,
+    "usingComponents": {
+        "van-stepper": "@vant/weapp/stepper/index"
+    }
+}

+ 71 - 0
packageA/project/modules/product/list/index.scss

@@ -0,0 +1,71 @@
+.product-item {
+    background-color: #fff;
+    box-sizing: border-box;
+    border-bottom: 1rpx solid #DDDDDD;
+    margin-bottom: 20rpx;
+
+    .product {
+        padding: 20rpx 30rpx;
+        box-sizing: border-box;
+
+        .mian {
+            position: relative;
+            display: flex;
+            width: 100%;
+            box-sizing: border-box;
+
+            .img {
+                flex-shrink: 0;
+                width: 112rpx;
+                height: 112rpx;
+                border-radius: 16rpx;
+                margin-right: 20rpx;
+                overflow: hidden;
+            }
+
+            .dec {
+                flex: 1;
+                width: 0;
+                min-height: 128rpx;
+                height: 100%;
+                font-size: 24rpx;
+                font-family: PingFang SC-Regular, PingFang SC;
+                color: #999999;
+
+                .title {
+                    width: 90%;
+                    height: 40rpx;
+                    font-size: 28rpx;
+                    font-weight: 600;
+                    color: #333333;
+                }
+
+                .subfield {
+                    display: flex;
+                    margin-top: 8rpx;
+                    height: 34rpx;
+                    line-height: 34rpx;
+
+                    text {
+                        display: inline-block;
+                        width: 48%;
+                    }
+                }
+
+            }
+
+            .delete {
+                position: absolute;
+                width: 68rpx;
+                height: 68rpx;
+                line-height: 68rpx;
+                right: -30rpx;
+                top: -20rpx;
+                text-align: center;
+                font-size: 32rpx;
+                color: #999;
+            }
+        }
+    }
+
+}

+ 39 - 0
packageA/project/modules/product/list/index.wxml

@@ -0,0 +1,39 @@
+<view class="product-item" wx:for="{{list}}" wx:key="item.sa_project_itemsid">
+    <navigator class="product" url="#">
+        <view class="mian">
+            <view class="img" data-file="{{item.attinfos}}" catchtap="viewImage">
+                <van-image width="100%" height="100%" src="{{item.cover}}" use-loading-slot use-error-slot lazy-load>
+                    <van-loading slot="loading" type="spinner" size="20" vertical />
+                    <text slot="error" style="font-size: 24rpx;">暂无图片</text>
+                </van-image>
+            </view>
+            <view class="dec">
+                <view class="title line-1">
+                    {{item.itemname}}
+                </view>
+                <view class="subfield">
+                    编号:{{item.itemno}}
+                </view>
+                <view class="subfield">
+                    <text class="line-1" style="margin-right: 6rpx;">品牌:{{item.brandName}}</text>
+                    <text class="line-1">产品类别:{{item.className}}</text>
+                </view>
+                <view class="subfield">
+                    <text class="line-1" style="margin-right: 6rpx;">规格:{{item.spec||' --'}}</text>
+                    <text class="line-1">型号:{{item.model||' --'}}</text>
+                </view>
+                <view class="subfield">
+                    <text class="line-1" style="margin-right: 6rpx;">牌价:{{item.marketprice||' --'}}</text>
+                    <view style="display: flex;">
+                        数量({{item.unitname}}):
+                        <van-stepper value="{{ item.qty }}" integer min='1' input-width="80rpx" button-size="40rpx" data-item="{{item}}" data-index='{{index}}' catch:change="onStepper" />
+                    </view>
+                </view>
+            </view>
+            <view class="delete" data-item="{{item}}" catchtap="deleteProduct">
+                <text class="iconfont icon-guanlian-shanchu" />
+            </view>
+        </view>
+    </navigator>
+</view>
+<My_empty wx:if="{{list.length==0}}" />