Commit f879cf5f by zhangxw

施工单技师选择组件修改

1 parent c2b24063
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<view class="box-title"> <view class="box-title">
<view>技师</view> <view>技师</view>
<!-- <view class="tips">使用<text bind:tap="goMiniprogram">生意助手小程序</text>登录创建技师</view> --> <!-- <view class="tips">使用<text bind:tap="goMiniprogram">生意助手小程序</text>登录创建技师</view> -->
<view class="tips" wx:if="{{ multiple }}">产生副手技师,请主技师为副手技师分配整单提成比例</view> <view class="tips" wx:if="{{ multiple && deputyFlag }}">产生副手技师,请主技师为副手技师分配整单提成比例</view>
</view> </view>
<block wx:if="{{ artificerList.length }}"> <block wx:if="{{ artificerList.length }}">
<scroll-view <scroll-view
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<view class="text_box"> <view class="text_box">
<view class="text-hide {{ item.disabled ? 'disabled' : '' }}">{{item.staffName}}</view> <view class="text-hide {{ item.disabled ? 'disabled' : '' }}">{{item.staffName}}</view>
</view> </view>
<view class="shareRatioBox" wx:if="{{ multiple && item.active }}"> <view class="shareRatioBox" wx:if="{{ multiple && item.active && deputyFlag }}">
整单分成比例 整单分成比例
<input <input
placeholder="整数" placeholder="整数"
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
<block wx:else> <block wx:else>
<empty-data style="width: 100%;" /> <empty-data style="width: 100%;" />
</block> </block>
<view class="tips bottomTips" wx:if="{{ multiple }}"> <view class="tips bottomTips" wx:if="{{ multiple && deputyFlag }}">
主技师整单分成比例 主技师整单分成比例
<text class="text">{{ showMainShareRatio }}%</text> <text class="text">{{ showMainShareRatio }}%</text>
</view> </view>
......
const IMG_URL =
'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
// components/subShopMerchant/subShopMerchant.js
Component({
/**
* 组件的属性列表
*/
properties: {
show: {
type: Boolean,
observer: function (n) {
if (n) {
let {
copyArtificerList,
artificerSelectObj,
disabledSelectObj,
deputyFlag
} = this.data
const selectArr = Array.isArray(artificerSelectObj)
? artificerSelectObj?.map(val => {
return val.uuid
})
: [artificerSelectObj?.uuid]
const selectedList = Array.isArray(artificerSelectObj)
? artificerSelectObj
: artificerSelectObj
? [artificerSelectObj]
: []
const ratioMap = selectedList.reduce((m, v) => {
const k = v.uuid
m[k] = v.shareRatio
return m
}, {})
copyArtificerList = copyArtificerList.map(i => {
const id = artificerSelectObj.find(v => v.uuid == i.uuid)?.id || undefined // 技师列表id没实际用途,将id替换成已选技师的主键id
const active = selectArr?.includes(i.uuid)
const disabled =
disabledSelectObj?.findIndex(val => val.uuid == i.uuid) > -1
const shareRatio = active ? ratioMap[i.uuid] ?? '' : ''
return { ...i, id, active, disabled, shareRatio }
})
// 是副手技师选中两个后其余置灰
if (selectArr.length == 2 && deputyFlag) {
copyArtificerList.forEach(i => {
if (!selectArr.includes(i.uuid)) i.disabled = true
})
}
const sum = (copyArtificerList || [])
.filter(i => i.active)
.map(i => parseInt(i.shareRatio || 0))
.reduce((a, b) => a + (isNaN(b) ? 0 : b), 0)
let showMainShareRatio = 100 - sum
if (showMainShareRatio < 0) showMainShareRatio = 0
if (showMainShareRatio > 100) showMainShareRatio = 100
console.log(copyArtificerList, 'copyArtificerList')
this.setData({
artificerList: wx.$util.deepClone(copyArtificerList),
copyArtificerList,
selectedTechnicianId: selectArr,
searchValue: '',
showMainShareRatio
})
}
}
},
title: String,
orderInfo: Object,
artificerSelectObj: Object,
copyArtificerList: Array,
multiple: Boolean,
disabledSelectObj: {
type: Array
},
deputyFlag: Boolean // 是否选择副手技师
},
/**
* 组件的初始数据
*/
data: {
orderObj: {},
IMG_URL,
artificerList: [],
searchValue: '',
showMainShareRatio: 100
},
/**
* 组件的方法列表
*/
methods: {
noop() {},
changeShareRatio(e) {
let { value } = e.detail
let { index } = e.currentTarget.dataset
let { artificerList, copyArtificerList } = this.data
let v = parseInt(value, 10)
if (isNaN(v)) v = 0
if (v > 100) v = 100
const sumOthers = (artificerList || [])
.filter((i, idx) => i.active && idx !== index)
.map(i => parseInt(i.shareRatio || 0))
.reduce((a, b) => a + (isNaN(b) ? 0 : b), 0)
const allowed = Math.max(0, 100 - sumOthers)
v = Math.min(v, allowed)
artificerList[index].shareRatio = v
const targetId = artificerList[index]?.uuid
if (Array.isArray(copyArtificerList)) {
const ci = copyArtificerList.findIndex(i => i.uuid === targetId)
if (ci >= 0) copyArtificerList[ci].shareRatio = v
}
const sum = sumOthers + v
let showMainShareRatio = 100 - sum
if (showMainShareRatio < 0) showMainShareRatio = 0
if (showMainShareRatio > 100) showMainShareRatio = 100
this.setData({
artificerList,
copyArtificerList,
showMainShareRatio
})
},
search(e) {
let { copyArtificerList } = wx.$util.deepClone(this.data)
let { selectedTechnicianId } = this.data
console.log(selectedTechnicianId)
let { value } = e.detail
if (!value) {
copyArtificerList.map(i => {
i.active = false
if (selectedTechnicianId.includes(i.uuid)) i.active = true
return i
})
this.setData({
artificerList: copyArtificerList
})
} else {
let arr = []
copyArtificerList.map(i => {
i.active = false
if (selectedTechnicianId.includes(i.uuid)) i.active = true
if (i.staffName.indexOf(value) != -1) {
arr.push(i)
}
})
this.setData({
artificerList: arr
})
}
},
changeItem(e) {
let { target } = e.currentTarget.dataset
let { artificerList, multiple, deputyFlag, disabledSelectObj } = this.data
let { copyArtificerList } = wx.$util.deepClone(this.data)
// 禁用项不允许点击切换
if (target.disabled) return
const targetId = target?.uuid
// 同步切换 active 状态;在单选模式下,其他项自动取消激活
// 对未激活项清空 shareRatio,保持分成比例与选中状态一致
const updateList = list =>
list.map(i => {
const active =
i.uuid === targetId ? !i.active : multiple ? i.active : false
return { ...i, active, shareRatio: active ? i.shareRatio : '' }
})
artificerList = updateList(artificerList)
copyArtificerList = updateList(copyArtificerList)
// 当前选中的技师 uuid 集合
const arr = copyArtificerList.filter(v => v.active).map(v => v.uuid)
// 副手模式:选满两个后将其他置灰;未满两个时根据预设禁用恢复
if (deputyFlag) {
if (arr.length === 2) {
const disableIfNotSelected = i => ({
...i,
disabled: !arr.includes(i.uuid)
})
artificerList = artificerList.map(disableIfNotSelected)
copyArtificerList = copyArtificerList.map(disableIfNotSelected)
} else {
const isPresetDisabled = i =>
disabledSelectObj?.findIndex(val => val.uuid == i.uuid) > -1
const enableWithPreset = i => ({
...i,
disabled: isPresetDisabled(i)
})
artificerList = artificerList.map(enableWithPreset)
copyArtificerList = copyArtificerList.map(enableWithPreset)
}
}
// 更新视图与选中集合(单选返回当前 uuid,多选返回所有选中)
const sum = (artificerList || [])
.filter(i => i.active)
.map(i => parseInt(i.shareRatio || 0))
.reduce((a, b) => a + (isNaN(b) ? 0 : b), 0)
let showMainShareRatio = 100 - sum
if (showMainShareRatio < 0) showMainShareRatio = 0
if (showMainShareRatio > 100) showMainShareRatio = 100
this.setData({
artificerList,
copyArtificerList,
selectedTechnicianId: multiple ? arr : [targetId],
showMainShareRatio
})
},
cancel() {
let thisPage = wx.$router.getPageInstance()
thisPage.setData({
artificerSelectPopup: false
})
this.triggerEvent('cancel')
},
// 打开生意助手小程序
goMiniprogram() {
wx.navigateToMiniProgram({
appId: 'wx2c28337db96364d2'
})
},
async confirm() {
let {
copyArtificerList,
orderInfo,
artificerSelectObj,
selectedTechnicianId,
deputyFlag
} = this.data
let arr = copyArtificerList?.filter(v => v.active) || []
console.log(arr, 'arr')
if (!arr.length) {
// 未选技师 将selectedTechnicianId清除
this.setData({
selectedTechnicianId: []
})
return wx.$util.showToast('请选择技师')
}
if (deputyFlag) {
const invalid = arr.some(
v =>
v.shareRatio === '' ||
v.shareRatio === undefined ||
v.shareRatio === null
)
if (invalid) {
return wx.$util.showToast('请填写副手技师分成比例')
}
}
let obj = {
...artificerSelectObj,
technicianUuid: arr[0]?.uuid || '',
technicianName: arr[0]?.staffName || '',
selectedTechnicians: arr
}
// orderInfo.technicianUuid = arr[0]?.uuid || ''
// orderInfo.technicianId = arr[0]?.id || ''
// orderInfo.technicianName = arr[0]?.staffName || ''
this.triggerEvent('confirm', obj)
}
}
})
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file \ No newline at end of file
/* components/subShopMerchant/subShopMerchant.wxss */
.artificer-select-popup-box {
height: 100%;
width: calc(100% + var(--fontSize64));
transform: translateX(calc(-1 * var(--fontSize32)));
}
.sub-title {
height: var(--fontSize100);
font-size: var(--fontSize32);
color: #333333;
background-color: #fff;
z-index: 2;
border-bottom: var(--fontSize2) solid #F9F9F9;
}
.text-hide {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.text-center {
display: flex;
align-items: center;
justify-content: center;
}
.box {
height: 100%;
padding: 0 var(--fontSize32);
}
.artificer-box {
height: calc(100% - var(--fontSize102));
overflow: hidden;
transition: all .25s;
}
.box-title {
color: #333333;
font-size: var(--fontSize32);
height: var(--fontSize88);
line-height: var(--fontSize88);
display: flex;
align-items: center;
/* justify-content: space-between; */
}
.box-title .tips {
font-size: 24rpx;
margin-left: 8rpx;
color: #888888;
}
.box-title .tips text {
color: #347BFF;
}
.artificerList {
width: calc(100% - var(--fontSize50));
height: var(--fontSize98);
display: flex;
align-items: center;
font-size: var(--fontSize28);
font-size: 28rpx;
color: #292D33;
padding: 0 var(--fontSize25);
transition: all .5s;
.shareRatioBox {
display: flex;
font-size: 24rpx;
color: #5A5E66;
align-items: center;
font-weight: 400;
.shareRatioInput {
box-sizing: border-box;
width: 88rpx;
height: 68rpx;
margin: 0 8rpx;
background: #FFFFFF;
padding: 0 16rpx;
border: 2rpx solid #EFF0F2;
border-radius: 12rpx;
}
}
}
.checked_img {
width: var(--fontSize32);
height: var(--fontSize32);
flex-shrink: 0;
margin-right: var(--fontSize20);
}
.artificerList .text_box {
flex: 1;
border-bottom: var(--fontSize2) solid #F9F9F9;
height: 100%;
line-height: var(--fontSize98);
}
.artificerList .text_box .disabled {
opacity: .5;
}
.artificerList.active {
color: #347BFF;
font-weight: 700;
position: relative;
}
.bottomTips {
text-align: center;
color: #5a5e66;
font-size: 24rpx;
margin-top: 10rpx;
.text {
color: #347bff;
}
}
\ No newline at end of file \ No newline at end of file
<popup
show="{{ show }}"
bindconfirm="confirm"
bindcancel="cancel"
height="85%"
slotStyle="height: calc(100% - var(--fontSize150));"
>
<view class="artificer-select-popup-box">
<view class="box">
<view class="sub-title text-center">{{title}}</view>
<view class="artificer-box">
<search-input bindsearch="search" value="{{ searchValue }}" />
<view class="box-title">
<view>技师</view>
<!-- <view class="tips">使用<text bind:tap="goMiniprogram">生意助手小程序</text>登录创建技师</view> -->
<view class="tips" wx:if="{{ multiple }}">产生副手技师,请主技师为副手技师分配整单提成比例</view>
</view>
<block wx:if="{{ artificerList.length }}">
<scroll-view
scroll-y
style="{{ multiple? 'height: calc(100% - var(--fontSize236))':'height: calc(100% - var(--fontSize194))' }}"
enhanced="{{ true }}"
show-scrollbar="{{ false }}"
>
<block wx:for="{{ artificerList }}" wx:key="index">
<view
class="artificerList {{ item.active?'active':'' }}"
bindtap="changeItem"
data-target="{{ item }}"
data-index="{{ index }}"
>
<view class="checked_img">
<block wx:if="{{ multiple }}">
<image src="{{ item.active ? '../images/radio.png' : '../images/radio_icon.png' }}" />
</block>
<block wx:else>
<image wx:if="{{ item.active }}" src="{{ IMG_URL }}checked.png"></image>
</block>
</view>
<view class="text_box">
<view class="text-hide {{ item.disabled ? 'disabled' : '' }}">{{item.staffName}}</view>
</view>
<view class="shareRatioBox" wx:if="{{ multiple && item.active }}">
整单分成比例
<input
placeholder="整数"
class="shareRatioInput"
type="number"
maxlength="3"
value="{{ item.shareRatio }}"
placeholder-style="color:#BEC1C7"
catchinput="changeShareRatio"
catchtap="noop"
data-index="{{ index }}"
/>
%
</view>
</view>
</block>
</scroll-view>
</block>
<block wx:else>
<empty-data style="width: 100%;" />
</block>
<view class="tips bottomTips" wx:if="{{ multiple }}">
主技师整单分成比例
<text class="text">{{ showMainShareRatio }}%</text>
</view>
</view>
</view>
</view>
</popup>
\ No newline at end of file \ No newline at end of file
...@@ -104,7 +104,6 @@ Page({ ...@@ -104,7 +104,6 @@ Page({
?.filter(val => val.technicianType == 0) ?.filter(val => val.technicianType == 0)
?.map(it => { ?.map(it => {
return { return {
technicianId: it.technicianId,
staffName: it.technicianName, staffName: it.technicianName,
id: it.id, id: it.id,
uuid: it.technicianUuid, uuid: it.technicianUuid,
...@@ -116,7 +115,6 @@ Page({ ...@@ -116,7 +115,6 @@ Page({
?.filter(val => val.technicianType == 1) ?.filter(val => val.technicianType == 1)
?.map(it => { ?.map(it => {
return { return {
technicianId: it.technicianId,
staffName: it.technicianName, staffName: it.technicianName,
id: it.id, id: it.id,
uuid: it.technicianUuid, uuid: it.technicianUuid,
...@@ -435,7 +433,6 @@ Page({ ...@@ -435,7 +433,6 @@ Page({
const mainTechnicianList = [ const mainTechnicianList = [
...(mainSelected?.map(val => ({ ...(mainSelected?.map(val => ({
id: val.id, id: val.id,
technicianId: val.technicianId || val.id,
technicianName: val.staffName, technicianName: val.staffName,
technicianUuid: val.uuid, technicianUuid: val.uuid,
technicianType: 0, technicianType: 0,
...@@ -444,7 +441,6 @@ Page({ ...@@ -444,7 +441,6 @@ Page({
})) || []), })) || []),
...(deputySelected?.map(val => ({ ...(deputySelected?.map(val => ({
id: val.id, id: val.id,
technicianId: val.technicianId || val.id,
technicianName: val.staffName, technicianName: val.staffName,
technicianUuid: val.uuid, technicianUuid: val.uuid,
technicianType: 1, technicianType: 1,
...@@ -483,7 +479,6 @@ Page({ ...@@ -483,7 +479,6 @@ Page({
requesting: true requesting: true
}) })
console.log(params) console.log(params)
return
api.confirmConstruction(params).then(res => { api.confirmConstruction(params).then(res => {
let { code, message } = res let { code, message } = res
if (code == 0) { if (code == 0) {
......
{ {
"usingComponents": { "usingComponents": {
"relate-goods-popup": "../../components/relateGoodsPop/index", "relate-goods-popup": "../../components/relateGoodsPop/index",
"artificer-select-popup" : "/components/ArtificerSelectPopup/artificerSelectPopup", "technician-select-popup" : "/components/TechnicianSelectPopup/TechnicianSelectPopup",
"select-service-popup": "../../components/servicePopup/index" "select-service-popup": "../../components/servicePopup/index"
}, },
"navigationBarTitleText": "施工单确认" "navigationBarTitleText": "施工单确认"
......
...@@ -187,7 +187,7 @@ ...@@ -187,7 +187,7 @@
bindcancel="handelRelateGoodsCancel" bindcancel="handelRelateGoodsCancel"
baseConfigData="{{ baseConfigData }}" baseConfigData="{{ baseConfigData }}"
></relate-goods-popup> ></relate-goods-popup>
<artificer-select-popup <technician-select-popup
show="{{ artificerSelectPopup }}" show="{{ artificerSelectPopup }}"
title="选择技师" title="选择技师"
copyArtificerList="{{ artificerList }}" copyArtificerList="{{ artificerList }}"
......
...@@ -300,7 +300,6 @@ Page({ ...@@ -300,7 +300,6 @@ Page({
?.filter(val => val.technicianType == 0) ?.filter(val => val.technicianType == 0)
?.map(it => { ?.map(it => {
return { return {
technicianId: it.technicianId,
staffName: it.technicianName, staffName: it.technicianName,
id: it.id, id: it.id,
uuid: it.technicianUuid, uuid: it.technicianUuid,
...@@ -312,7 +311,6 @@ Page({ ...@@ -312,7 +311,6 @@ Page({
?.filter(val => val.technicianType == 1) ?.filter(val => val.technicianType == 1)
?.map(it => { ?.map(it => {
return { return {
technicianId: it.technicianId,
staffName: it.technicianName, staffName: it.technicianName,
id: it.id, id: it.id,
uuid: it.technicianUuid, uuid: it.technicianUuid,
...@@ -845,20 +843,20 @@ Page({ ...@@ -845,20 +843,20 @@ Page({
const mainTechnicianList = [ const mainTechnicianList = [
...(Array.isArray(mainSelected) ...(Array.isArray(mainSelected)
? mainSelected.map(it => ({ ? mainSelected.map(it => ({
id: it.id,
technicianName: it.staffName, technicianName: it.staffName,
technicianType: 0, technicianType: 0,
technicianUuid: it.uuid, technicianUuid: it.uuid,
technicianId: it.id,
staffPhone: it.staffPhone, staffPhone: it.staffPhone,
shareRatio: ((it.shareRatio ?? 0) * 1) / 100 shareRatio: ((it.shareRatio ?? 0) * 1) / 100
})) }))
: []), : []),
...(Array.isArray(deputySelected) ...(Array.isArray(deputySelected)
? deputySelected.map(it => ({ ? deputySelected.map(it => ({
id: it.id,
technicianName: it.staffName, technicianName: it.staffName,
technicianType: 1, technicianType: 1,
technicianUuid: it.uuid, technicianUuid: it.uuid,
technicianId: it.id,
staffPhone: it.staffPhone, staffPhone: it.staffPhone,
shareRatio: ((it.shareRatio ?? 0) * 1) / 100 shareRatio: ((it.shareRatio ?? 0) * 1) / 100
})) }))
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"outbound-popup": "../../components/outboundPopup/index", "outbound-popup": "../../components/outboundPopup/index",
"rework-popup": "../../components/reworkPopup/index", "rework-popup": "../../components/reworkPopup/index",
"review-popup": "../../components/reviewPopup/index", "review-popup": "../../components/reviewPopup/index",
"artificer-select-popup": "/components/ArtificerSelectPopup/artificerSelectPopup" "technician-select-popup" : "/components/TechnicianSelectPopup/TechnicianSelectPopup"
}, },
"navigationBarTitleText": "施工单详情" "navigationBarTitleText": "施工单详情"
} }
...@@ -311,7 +311,7 @@ ...@@ -311,7 +311,7 @@
bindconfirm="handleReworkConfirm" bindconfirm="handleReworkConfirm"
></rework-popup> ></rework-popup>
<review-popup show="{{ reviewVisible }}" bindcancel="reviewCancel" bindconfirm="reviewConfirm" bindclose="reviewClose"></review-popup> <review-popup show="{{ reviewVisible }}" bindcancel="reviewCancel" bindconfirm="reviewConfirm" bindclose="reviewClose"></review-popup>
<artificer-select-popup <technician-select-popup
show="{{ artificerSelectPopup }}" show="{{ artificerSelectPopup }}"
title="选择技师" title="选择技师"
copyArtificerList="{{ artificerList }}" copyArtificerList="{{ artificerList }}"
......
...@@ -63,7 +63,6 @@ Page({ ...@@ -63,7 +63,6 @@ Page({
technicianName: it.staffName, technicianName: it.staffName,
technicianType: 0, technicianType: 0,
technicianUuid: it.uuid, technicianUuid: it.uuid,
technicianId: it.id,
staffPhone: it.staffPhone, staffPhone: it.staffPhone,
shareRatio: ((it.shareRatio ?? 0) * 1) / 100 shareRatio: ((it.shareRatio ?? 0) * 1) / 100
}) })
...@@ -73,7 +72,6 @@ Page({ ...@@ -73,7 +72,6 @@ Page({
technicianName: it.staffName, technicianName: it.staffName,
technicianType: 1, technicianType: 1,
technicianUuid: it.uuid, technicianUuid: it.uuid,
technicianId: it.id,
staffPhone: it.staffPhone, staffPhone: it.staffPhone,
shareRatio: ((it.shareRatio ?? 0) * 1) / 100 shareRatio: ((it.shareRatio ?? 0) * 1) / 100
}) })
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
"enablePullDownRefresh": true, "enablePullDownRefresh": true,
"usingComponents": { "usingComponents": {
"relate-goods-popup": "../../components/relateGoodsPop/index", "relate-goods-popup": "../../components/relateGoodsPop/index",
"artificer-select-popup": "/components/ArtificerSelectPopup/artificerSelectPopup" "technician-select-popup": "/components/TechnicianSelectPopup/TechnicianSelectPopup"
} }
} }
...@@ -166,7 +166,7 @@ ...@@ -166,7 +166,7 @@
bindcancel="handelRelateGoodsCancel" bindcancel="handelRelateGoodsCancel"
baseConfigData="{{ baseConfigData }}" baseConfigData="{{ baseConfigData }}"
></relate-goods-popup> ></relate-goods-popup>
<artificer-select-popup <technician-select-popup
show="{{ artificerSelectPopup }}" show="{{ artificerSelectPopup }}"
title="选择技师" title="选择技师"
copyArtificerList="{{ artificerList }}" copyArtificerList="{{ artificerList }}"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!