Просмотр исходного кода

1、修改dk-popup组件和选单共通组件

zhoux 2 лет назад
Родитель
Сommit
cc9dbd17c0

+ 2 - 2
api/pages/mst/goodsBrand.js

@@ -15,8 +15,8 @@ module.exports = {
   },
   routeUrl: {
     goodsBrand: {
-      selectProductAttributeSuppliers:{ //选择供应商
-        key:'selectProductAttributeSuppliers',url:'/package-base-select/pages/select-product-attribute-suppliers/select-product-attribute-suppliers'
+      selectProductAttributeSuppliers: { //选择供应商
+        key: 'selectProductAttributeSuppliers', url: '/package-base-select/pages/select-data/select-data', type: 'supplier', chooseFlag: true
       },
     }
   }

+ 13 - 6
components/dkbase/dk-popup/dk-popup.js

@@ -92,7 +92,6 @@ Component({
     value: {
       type: String,
       observer: function (newVal) {
-        console.log('ff',newVal);
         if (newVal) {
           this.setData({
             form: JSON.parse(newVal) || {}
@@ -210,16 +209,15 @@ Component({
                 bindData: function (data) {  
                   let key = e.currentTarget.dataset.item.code
                   let name = e.currentTarget.dataset.item.name 
-                  console.log('key',key)
+                  console.log('key',key,data)
                   console.log('name',name)
                   let form = that.data.form
                   form[key] = data.data.id
                   form[name] = data.data.name 
+                  form[key+'_data'] = data.data.list
                   that.setData({
                     form: form,
-                    
                   })
-                 
                 }
               },
               success: function (res) {
@@ -235,7 +233,16 @@ Component({
                   data['formType'] = item.button.formType
                 }
                 if(that.data.form){
-                  data['item'] = that.data.form
+                  let form = that.data.form;
+                  data['item'] = form
+                  let key = e.currentTarget.dataset.item.code
+                  if(form[key+ '_data']){
+                    data['item'].data = that.data.form[key+ '_data']
+                    delete form[key+ '_data']
+                    that.setData({
+                      form:form
+                    })
+                  }
                 }
                 data['route'] = route
                 console.log('打开下拉',)
@@ -384,7 +391,7 @@ Component({
    */
   lifetimes: {
     attached: function () {
-      console.log('fffd',this.data.form,this.data.value);
+      console.log('fffd',this.data.form,this.data.contentObj);
     },
     detached: function () {
       // 在组件实例被从页面节点树移除时执行

+ 0 - 1
components/dkbase/dk-popup/dk-popup.wxml

@@ -41,7 +41,6 @@
         <view style="width: 50%;text-align: right;">{{item.rightTitle}}:{{form[item.rightCode]}}</view>
       </view>
     </view>
-
     <!--内容-->
     <view wx:for="{{contentObj}}" wx:for-item="item" data-item="{{item}}" wx:key="index">
       <!--文本框-->

+ 119 - 80
package-base-select/pages/select-data/select-data.js

@@ -34,6 +34,11 @@ Page({
         placeholder: [],
         // tab页签
         tagList: [],
+        // 用于多选
+        valueKey: null,
+        labelKey: null,
+        // 多选时是否允许重复
+        repeatFlag: false,
         // 确定按钮
         buttonList: [{
             name: 'confirm',
@@ -72,9 +77,32 @@ Page({
      */
     chooseData(e) {
         let list = e.detail.list;
-        this.setData({
-            choosedData: list
-        })
+        let valueKey = this.data.valueKey;
+        if (!valueKey) {
+            this.setData({
+                choosedData: list
+            })
+        } else {
+            let choosedData = this.data.choosedData
+            let filters = []
+            if (list && list.length > 0) {
+                list.forEach(it => {
+                    // 不允许重复
+                    if (!this.data.repeatFlag) {
+                        filters = choosedData.filter(t => t[valueKey] == it[valueKey])
+                        if (!filters || filters.length == 0) {
+                            choosedData.push(it);
+                        }
+                    } else {
+                        // 可以重复
+                        choosedData.push(it);
+                    }
+                })
+                this.setData({
+                    choosedData: choosedData
+                })
+            }
+        }
     },
     /**
      * @desc : 确定事件-返回数据
@@ -82,15 +110,12 @@ Page({
      * @date : 2024/3/25 15:16
      */
     confirm() {
-        let listComp = this.selectComponent('#list');
-        let list = []
-        if (listComp) {
-            list = listComp.data.list;
-            list = list.filter(it => it.checked);
-        }
+        let list = [...this.data.choosedData]
+        let id = list.map(it => it[this.data.valueKey])
+        let name = list.map(it => it[this.data.labelKey])
         const eventChannel = this.getOpenerEventChannel();
         eventChannel.emit('bindData', {
-            data: list
+            data: { list, id, name }
         })
         wx.navigateBack({
             delta: 1
@@ -102,7 +127,6 @@ Page({
      * @date : 2022/5/23 15:16
      */
     toDetail(e) {
-        console.log('rrr', e);
         // 如果选择框开启就走确定模式
         if (this.data.chooseFlag) {
             return;
@@ -119,14 +143,14 @@ Page({
                     name: item.orgName
                 }
                 break;
-                // 员工
+            // 员工
             case Constants.chooseType.staff:
                 data = {
                     id: item.staffId,
                     name: item.staffName
                 }
                 break;
-                // 供应商
+            // 供应商
             case Constants.chooseType.supplier:
                 data = {
                     id: item.supId,
@@ -134,7 +158,7 @@ Page({
                     item: item
                 }
                 break;
-                // 对象类型
+            // 对象类型
             case Constants.chooseType.objectType:
                 data = {
                     id: item.objId,
@@ -143,14 +167,14 @@ Page({
                 }
                 break;
 
-                // 仓库
+            // 仓库
             case Constants.chooseType.warehouse:
                 data = {
                     id: item.whId,
                     name: item.whName
                 }
                 break;
-                // 数据字典
+            // 数据字典
             case Constants.chooseType.dictionary:
                 data = {
                     id: item.dataId,
@@ -233,6 +257,7 @@ Page({
      * @author : 周兴
      */
     loadInit(e) {
+        console.log('item', this.data.item);
         let route = this.data.chooseRoute;
         if (!route || !route.type) {
             return;
@@ -254,11 +279,11 @@ Page({
                     contentList: [{
                         name: 'orgCode',
                         title: '部门编码'
-                    }, ],
+                    },],
                     placeholder: ['orgName']
                 })
                 break;
-                // 员工
+            // 员工
             case Constants.chooseType.staff:
                 title = "员工"
                 this.setData({
@@ -267,18 +292,18 @@ Page({
                     method: 'getStaff',
                     title: 'staffName',
                     contentList: [{
-                            name: 'staffCode',
-                            title: '员工编码'
-                        },
-                        {
-                            name: 'orgName',
-                            title: '部门'
-                        },
+                        name: 'staffCode',
+                        title: '员工编码'
+                    },
+                    {
+                        name: 'orgName',
+                        title: '部门'
+                    },
                     ],
                     placeholder: ['staffName']
                 })
                 break;
-                // 供应商
+            // 供应商
             case Constants.chooseType.supplier:
                 title = "供应商"
                 this.setData({
@@ -286,26 +311,34 @@ Page({
                     routeObjName: 'supplier',
                     method: 'selectByCond',
                     title: 'supName',
-                    tagList: [{
-                        title: mixins.$t("all") //全部
-                    }, {
-                        title: mixins.$t("procurementSupplier") //采购供应商
-                    }, {
-                        title: mixins.$t("serviceProvider") // 服务供应商
-                    }],
+                    valueKey: 'supId',
+                    labelKey: 'supName',
+                    chooseFlag: route.chooseFlag,
                     contentList: [{
-                            name: 'supTypeName',
-                            title: '供应商类别'
-                        },
-                        {
-                            name: 'returnAddress',
-                            title: '供应商地址'
-                        },
+                        name: 'supTypeName',
+                        title: '供应商类别'
+                    },
+                    {
+                        name: 'returnAddress',
+                        title: '供应商地址'
+                    },
                     ],
                     placeholder: ['supplier']
                 })
+                // 多选时就不要有其他的tag标签
+                if (!route.chooseFlag) {
+                    this.setData({
+                        tagList: [{
+                            title: mixins.$t("all") //全部
+                        }, {
+                            title: mixins.$t("procurementSupplier") //采购供应商
+                        }, {
+                            title: mixins.$t("serviceProvider") // 服务供应商
+                        }],
+                    })
+                }
                 break;
-                // 仓库
+            // 仓库
             case Constants.chooseType.warehouse:
                 title = "仓库"
                 this.setData({
@@ -314,18 +347,18 @@ Page({
                     method: 'warehouseListBy',
                     title: 'whName',
                     contentList: [{
-                            name: 'supervisor',
-                            title: '仓库主管'
-                        },
-                        {
-                            name: 'contactPhone',
-                            title: '联系电话'
-                        },
+                        name: 'supervisor',
+                        title: '仓库主管'
+                    },
+                    {
+                        name: 'contactPhone',
+                        title: '联系电话'
+                    },
                     ],
                     placeholder: ['whName']
                 })
                 break;
-                // 数据字典
+            // 数据字典
             case Constants.chooseType.dictionary:
                 title = "数据字典"
                 this.setData({
@@ -336,18 +369,18 @@ Page({
                     chooseFlag: route.chooseFlag,
                     title: 'dataValue',
                     contentList: [{
-                            name: 'dataCode',
-                            title: '数据编码'
-                        },
-                        {
-                            name: 'dictCode',
-                            title: '字典项目'
-                        },
+                        name: 'dataCode',
+                        title: '数据编码'
+                    },
+                    {
+                        name: 'dictCode',
+                        title: '字典项目'
+                    },
                     ],
                     placeholder: ['orgName']
                 })
                 break;
-                // 对象类型
+            // 对象类型
             case Constants.chooseType.objectType:
                 title = "对象类型"
                 this.setData({
@@ -355,32 +388,32 @@ Page({
                     method: 'getSupplierAndCustomerData',
                     title: 'objName',
                     contentList: [{
-                            name: 'objCode',
-                            title: '对象编码'
-                        },
-                        {
-                            name: 'objTypeName',
-                            title: '对象'
-                        },
-                        {
-                            name: 'addressFull',
-                            title: '地址'
-                        },
+                        name: 'objCode',
+                        title: '对象编码'
+                    },
+                    {
+                        name: 'objTypeName',
+                        title: '对象'
+                    },
+                    {
+                        name: 'addressFull',
+                        title: '地址'
+                    },
                     ],
                     searchContent: [{
-                            code: 'supplier-customer',
-                            title: '选择对象',
-                            searchType: Constants.searchType.switch,
-                            list: [{
-                                    code: 'supplier',
-                                    title: '供应商'
-                                },
-                                {
-                                    code: 'customer',
-                                    title: '客户'
-                                }
-                            ]
+                        code: 'supplier-customer',
+                        title: '选择对象',
+                        searchType: Constants.searchType.switch,
+                        list: [{
+                            code: 'supplier',
+                            title: '供应商'
                         },
+                        {
+                            code: 'customer',
+                            title: '客户'
+                        }
+                        ]
+                    },
 
                     ],
                     placeholder: ['customerName', 'supplierName', 'address', 'telephone']
@@ -391,6 +424,12 @@ Page({
             default:
                 break;
         }
+        // 多选,数据回显到已选列表
+        if (this.data.chooseFlag && this.data.item && this.data.item.data) {
+            this.setData({
+                choosedData: this.data.item.data
+            })
+        }
         wx.setNavigationBarTitle({
             title: '选择' + title,
         })

+ 1 - 1
package-base-select/pages/select-data/select-data.wxml

@@ -21,7 +21,7 @@
 <dk-list wx:if="{{active == 0}}" id="list" list="{{tableData}}" title="{{title}}" flgPoint="{{false}}" titleImageFlag="{{false}}" content="{{contentList}}" footerInfo="{{footerInfo}}" chooseFlag="{{chooseFlag}}" bind:toDetail="toDetail" bind:choose="chooseData"></dk-list>
 
 <!-- 已选列表区 -->
-<dk-list wx:if="{{chooseFlag && active == 1}}" id="list" list="{{choosedData}}" title="{{title}}" flgPoint="{{false}}" titleImageFlag="{{false}}" content="{{contentList}}" footerInfo="{{footerInfo}}"></dk-list>
+<dk-list wx:if="{{chooseFlag && active == 1}}" id="choosed" list="{{choosedData}}" title="{{title}}" flgPoint="{{false}}" titleImageFlag="{{false}}" content="{{contentList}}" footerInfo="{{footerInfo}}"></dk-list>
 
 <van-divider wx:if="{{noMore}}" contentPosition="center" borderColor="#DCDCDC">{{$t['noMore']}}~</van-divider>
 

+ 4 - 3
package-basic-data/pages/product-attribute/product-attribute.js

@@ -45,7 +45,8 @@ Page({
       [
         { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
         { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
-        { code: 'supplierIds',formMode: 'index', idKey: 'roleId', chooseType:true, name: 'supplierNames', title: 'supplier', type: 'choose', required: true, dropType: 'supplier', required: true, },
+        { code: 'supplierIds',formMode: 'index', idKey: 'roleId', chooseType:true, name: 'supplierNames',
+         title: mixins.$t('supplier'), type: 'choose', required: true, dropType: 'supplier', required: true, },
         { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
       ],
     sideKey: 0,
@@ -315,7 +316,7 @@ Page({
         [
           { code: 'brandCode', type: 'str', title: mixins.$t('brandCode'), required: false, readonly: true, },
           { code: 'brandName', type: 'str', title: mixins.$t('brandName'), required: true },
-          { code: 'supplierIds', name: 'supplierNames', title: 'supplier', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductAttributeSuppliers', code: 'supplierIds',formMode: 'index', idKey: 'roleId', },
+          { code: 'supplierIds', name: 'supplierNames', title: 'supplier', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductAttributeSuppliers', code: 'supplierIds',formMode: 'index', idKey: 'roleId',  title:mixins.$t('supplier')},
       
           { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
         ]
@@ -325,7 +326,7 @@ Page({
       popContent =
         [
           { code: 'catCode', type: 'str', title: mixins.$t('catCode'), required: false, readonly: true, },
-          { code: 'parentId', name: 'parentName', title: 'parent', type: 'choose', required: true, dropType: 'supplier', required: true, urlKey: 'selectProductTypes', },
+          { code: 'parentId', name: 'parentName', title: 'parent', type: 'choose', required: true,  required: true, urlKey: 'selectProductTypes', },
           { code: 'catName', type: 'str', title: mixins.$t('catName'), required: true },
           { code: 'remarks', type: 'str', title: mixins.$t('remarks'), required: false }
         ]