Commit c2274d93f05da0e838cd4e91943983eb7bfb7cd2

Authored by 严涛
1 parent f04a0f09

锁规可填

@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <view class="page"> 2 <view class="page">
3 <scroll-view class="scroll" scroll-y> 3 <scroll-view class="scroll" scroll-y>
4 <view class="lock-page"> 4 <view class="lock-page">
5 - <view class="block" v-for="(item, idx) in items" :key="idx"> 5 + <view class="block" v-for="(item, idx) in items" :key="item.raw && (item.raw.id || item.raw.lineId || item.raw.productId) || ('row-' + idx)">
6 <view class="block-header"> 6 <view class="block-header">
7 <uni-data-checkbox multiple mode="default" :localdata="[{ text: '锁规', value: 'LOCKED' }]" 7 <uni-data-checkbox multiple mode="default" :localdata="[{ text: '锁规', value: 'LOCKED' }]"
8 :modelValue="item.locked ? ['LOCKED'] : []" @change="onLockChange(idx, $event)" /> 8 :modelValue="item.locked ? ['LOCKED'] : []" @change="onLockChange(idx, $event)" />
@@ -14,73 +14,79 @@ @@ -14,73 +14,79 @@
14 </view> 14 </view>
15 15
16 <uni-list v-show="item.collapsed"> 16 <uni-list v-show="item.collapsed">
17 - <uni-list-item title="产品名称">  
18 - <template v-slot:footer>  
19 - <uni-easyinput v-model="item.productName" placeholder="请输入产品名称" :clearable="false"  
20 - disabled /> 17 + <uni-list-item class="select-item" :class="item.productName ? 'is-filled' : 'is-empty'" clickable @click="openProductSheet(idx, 'product')" :rightText="item.productName || '请选择产品名称'" showArrow>
  18 + <template v-slot:body>
  19 + <view class="item-title"><text>产品名称</text></view>
21 </template> 20 </template>
22 </uni-list-item> 21 </uni-list-item>
23 <uni-list-item title="行业"> 22 <uni-list-item title="行业">
24 <template v-slot:footer> 23 <template v-slot:footer>
25 - <uni-easyinput v-model="item.industry" placeholder="请输入行业" :clearable="false"  
26 - disabled /> 24 + <uni-easyinput v-model="item.industry" placeholder="请输入行业" />
27 </template> 25 </template>
28 </uni-list-item> 26 </uni-list-item>
29 <uni-list-item title="牌号"> 27 <uni-list-item title="牌号">
30 <template v-slot:footer> 28 <template v-slot:footer>
31 - <uni-easyinput v-model="item.brand" placeholder="请输入牌号" :clearable="false" disabled /> 29 + <uni-easyinput v-model="item.brand" placeholder="请输入牌号" />
32 </template> 30 </template>
33 </uni-list-item> 31 </uni-list-item>
34 <uni-list-item title="品质"> 32 <uni-list-item title="品质">
35 <template v-slot:footer> 33 <template v-slot:footer>
36 - <uni-easyinput v-model="item.quality" placeholder="请输入品质" :clearable="false" disabled /> 34 + <uni-easyinput v-model="item.quality" placeholder="请输入品质" />
  35 + </template>
  36 + </uni-list-item>
  37 + <uni-list-item title="厚度(mm)">
  38 + <template v-slot:footer>
  39 + <uni-easyinput type="digit" v-model="item.thickness" :inputBorder="false" placeholder="请输入厚度" @input="onNonNegativeInput(idx, 'thickness')" @blur="onNonNegativeBlur(idx, 'thickness', 9)" />
  40 + </template>
  41 + </uni-list-item>
  42 + <uni-list-item title="厚度公差上限(mm)">
  43 + <template v-slot:footer>
  44 + <uni-easyinput type="digit" v-model="item.thicknessTolPos" :inputBorder="false" placeholder="请输入厚度公差上限" @input="onNumberInput(idx, 'thicknessTolPos')" @blur="onNumberBlur(idx, 'thicknessTolPos', 9)" />
  45 + </template>
  46 + </uni-list-item>
  47 + <uni-list-item title="厚度公差下限(mm)">
  48 + <template v-slot:footer>
  49 + <uni-easyinput type="digit" v-model="item.thicknessTolNeg" :inputBorder="false" placeholder="请输入厚度公差下限" @input="onNumberInput(idx, 'thicknessTolNeg')" @blur="onNumberBlur(idx, 'thicknessTolNeg', 9)" />
  50 + </template>
  51 + </uni-list-item>
  52 + <uni-list-item title="宽度(mm)">
  53 + <template v-slot:footer>
  54 + <uni-easyinput type="digit" v-model="item.width" :inputBorder="false" placeholder="请输入宽度" @input="onNonNegativeInput(idx, 'width')" @blur="onNonNegativeBlur(idx, 'width', 9)" />
  55 + </template>
  56 + </uni-list-item>
  57 + <uni-list-item title="宽度公差上限(mm)">
  58 + <template v-slot:footer>
  59 + <uni-easyinput type="digit" v-model="item.widthTolPos" :inputBorder="false" placeholder="请输入宽度公差上限" @input="onNumberInput(idx, 'widthTolPos')" @blur="onNumberBlur(idx, 'widthTolPos', 9)" />
  60 + </template>
  61 + </uni-list-item>
  62 + <uni-list-item title="宽度公差下限(mm)">
  63 + <template v-slot:footer>
  64 + <uni-easyinput type="digit" v-model="item.widthTolNeg" :inputBorder="false" placeholder="请输入宽度公差下限" @input="onNumberInput(idx, 'widthTolNeg')" @blur="onNumberBlur(idx, 'widthTolNeg', 9)" />
  65 + </template>
  66 + </uni-list-item>
  67 + <uni-list-item title="长度(mm)">
  68 + <template v-slot:footer>
  69 + <uni-easyinput type="digit" v-model="item.length" :inputBorder="false" placeholder="请输入长度" @input="onNonNegativeInput(idx, 'length')" @blur="onNonNegativeBlur(idx, 'length', 9)" />
  70 + </template>
  71 + </uni-list-item>
  72 + <uni-list-item title="长度公差上限(mm)">
  73 + <template v-slot:footer>
  74 + <uni-easyinput type="digit" v-model="item.lengthTolPos" :inputBorder="false" placeholder="请输入长度公差上限" @input="onNumberInput(idx, 'lengthTolPos')" @blur="onNumberBlur(idx, 'lengthTolPos', 9)" />
37 </template> 75 </template>
38 </uni-list-item> 76 </uni-list-item>
39 - <uni-list-item title="规格(mm)"> 77 + <uni-list-item title="长度公差下限(mm)">
40 <template v-slot:footer> 78 <template v-slot:footer>
41 - <view class="value value-spec">  
42 - <view v-if="item.thickness" class="value-spec_val">{{ item.thickness }}</view>  
43 - <view v-if="item.thickness" class="value-spec_box">  
44 - <view v-if="item.thicknessTolPos" class="value-spec_box_1">{{  
45 - item.thicknessTolPos > 0 ? '+' + item.thicknessTolPos : item.thicknessTolPos  
46 - }}  
47 - </view>  
48 - <view v-if="item.thicknessTolNeg" class="value-spec_box_2">{{  
49 - item.thicknessTolNeg > 0 ? '+' + item.thicknessTolNeg : item.thicknessTolNeg  
50 - }}  
51 - </view>  
52 - </view>  
53 - <view v-if="item.width" class="value-spec_val p12">*</view>  
54 - <view v-if="item.width" class="value-spec_val">{{ item.width }}</view>  
55 - <view v-if="item.width" class="value-spec_box">  
56 - <view v-if="item.widthTolPos" class="value-spec_box_1">{{ item.widthTolPos > 0 ?  
57 - '+' + item.widthTolPos : item.widthTolPos }}  
58 - </view>  
59 - <view v-if="item.widthTolNeg" class="value-spec_box_2">{{ item.widthTolNeg > 0 ?  
60 - '+' + item.widthTolNeg : item.widthTolNeg }}  
61 - </view>  
62 - </view>  
63 - <view v-if="item.length" class="value-spec_val p12">*</view>  
64 - <view v-if="item.length" class="value-spec_val">{{ item.length }}</view>  
65 - <view v-if="item.length" class="value-spec_box">  
66 - <view v-if="item.lengthTolPos" class="value-spec_box_1">{{ item.lengthTolPos > 0  
67 - ? '+' + item.lengthTolPos : item.lengthTolPos }}  
68 - </view>  
69 - <view v-if="item.lengthTolNeg" class="value-spec_box_2">{{ item.lengthTolNeg > 0  
70 - ? '+' + item.lengthTolNeg : item.lengthTolNeg }}  
71 - </view>  
72 - </view>  
73 - </view> 79 + <uni-easyinput type="digit" v-model="item.lengthTolNeg" :inputBorder="false" placeholder="请输入长度公差下限" @input="onNumberInput(idx, 'lengthTolNeg')" @blur="onNumberBlur(idx, 'lengthTolNeg', 9)" />
74 </template> 80 </template>
75 </uni-list-item> 81 </uni-list-item>
76 <uni-list-item title="物料编码"> 82 <uni-list-item title="物料编码">
77 <template v-slot:footer> 83 <template v-slot:footer>
78 - <uni-easyinput v-model="item.materialCode" placeholder="请输入物料编码" :clearable="false" disabled /> 84 + <uni-easyinput v-model="item.materialCode" placeholder="请输入物料编码" />
79 </template> 85 </template>
80 </uni-list-item> 86 </uni-list-item>
81 <uni-list-item title="状态"> 87 <uni-list-item title="状态">
82 <template v-slot:footer> 88 <template v-slot:footer>
83 - <uni-easyinput v-model="item.status" placeholder="请输入状态" :clearable="false" disabled /> 89 + <uni-easyinput v-model="item.status" placeholder="请输入状态" />
84 </template> 90 </template>
85 </uni-list-item> 91 </uni-list-item>
86 <uni-list-item title="数量"> 92 <uni-list-item title="数量">
@@ -104,33 +110,30 @@ @@ -104,33 +110,30 @@
104 </uni-list-item> --> 110 </uni-list-item> -->
105 <uni-list-item title="总金额"> 111 <uni-list-item title="总金额">
106 <template v-slot:footer> 112 <template v-slot:footer>
107 - <uni-easyinput v-model="item.totalAmount" type="number" :inputBorder="false" disabled  
108 - placeholder="" /> 113 + <uni-easyinput v-model="item.totalAmount" type="number" :inputBorder="false" disabled placeholder="" />
109 </template> 114 </template>
110 </uni-list-item> 115 </uni-list-item>
111 <uni-list-item title="发货日期"> 116 <uni-list-item title="发货日期">
112 <template v-slot:footer> 117 <template v-slot:footer>
113 - <uni-easyinput v-model="item.deliveryDate" :inputBorder="false" disabled /> 118 + <uni-easyinput v-model="item.deliveryDate" :inputBorder="false" />
114 </template> 119 </template>
115 </uni-list-item> 120 </uni-list-item>
116 </uni-list> 121 </uni-list>
117 122
118 <uni-list v-show="!item.collapsed"> 123 <uni-list v-show="!item.collapsed">
119 - <uni-list-item title="产品名称">  
120 - <template v-slot:footer>  
121 - <uni-easyinput v-model="item.productName" placeholder="请输入产品名称" :clearable="false"  
122 - disabled /> 124 + <uni-list-item class="select-item" :class="item.productName ? 'is-filled' : 'is-empty'" clickable @click="openProductSheet(idx, 'product')" :rightText="item.productName || '请选择产品名称'" showArrow>
  125 + <template v-slot:body>
  126 + <view class="item-title"><text>产品名称</text></view>
123 </template> 127 </template>
124 </uni-list-item> 128 </uni-list-item>
125 <uni-list-item title="行业"> 129 <uni-list-item title="行业">
126 <template v-slot:footer> 130 <template v-slot:footer>
127 - <uni-easyinput v-model="item.industry" placeholder="请输入行业" :clearable="false"  
128 - disabled /> 131 + <uni-easyinput v-model="item.industry" placeholder="请输入行业" />
129 </template> 132 </template>
130 </uni-list-item> 133 </uni-list-item>
131 <uni-list-item title="牌号"> 134 <uni-list-item title="牌号">
132 <template v-slot:footer> 135 <template v-slot:footer>
133 - <uni-easyinput v-model="item.brand" placeholder="请输入牌号" :clearable="false" disabled /> 136 + <uni-easyinput v-model="item.brand" placeholder="请输入牌号" />
134 </template> 137 </template>
135 </uni-list-item> 138 </uni-list-item>
136 139
@@ -170,24 +173,36 @@ @@ -170,24 +173,36 @@
170 </view> 173 </view>
171 </view> 174 </view>
172 </scroll-view> 175 </scroll-view>
173 - 176 + <SingleSelectSheet :visible.sync="sheet.visible" :title="sheet.title" :options="sheet.options" v-model="sheet.value" @confirm="onProductConfirm" />
174 </view> 177 </view>
175 </template> 178 </template>
176 179
177 <script> 180 <script>
178 import { getContractApi, specificationLock } from '@/api/contract' 181 import { getContractApi, specificationLock } from '@/api/contract'
  182 +import SingleSelectSheet from '@/components/single-select/index.vue'
  183 +import { getDicByCodes } from '@/utils/dic'
179 import { formatCurrencyToChinese } from '@/utils/common' 184 import { formatCurrencyToChinese } from '@/utils/common'
180 185
181 export default { 186 export default {
182 name: 'ContractUnplanLock', 187 name: 'ContractUnplanLock',
  188 + components: { SingleSelectSheet },
183 data() { 189 data() {
184 return { 190 return {
185 id: '', 191 id: '',
186 items: [], 192 items: [],
187 planQty: 30, 193 planQty: 30,
  194 + sheet: { visible: false, title: '请选择', options: [], idx: -1, value: '', mode: '' },
  195 + options: [],
188 } 196 }
189 }, 197 },
190 computed: { 198 computed: {
  199 + selectOptions() {
  200 + const list = Array.isArray(this.options) ? this.options : []
  201 + return list.map(o => ({
  202 + label: o.label != null ? o.label : (o.text != null ? o.text : (o.name != null ? o.name : '')),
  203 + value: o.value != null ? o.value : (o.id != null ? o.id : o.productId)
  204 + }))
  205 + },
191 totalQuantity() { 206 totalQuantity() {
192 const qty = this.items.filter(it => it.locked).reduce((p, c) => p + this.toNumber(c.quantity), 0) 207 const qty = this.items.filter(it => it.locked).reduce((p, c) => p + this.toNumber(c.quantity), 0)
193 return this.round(qty, 2) 208 return this.round(qty, 2)
@@ -219,8 +234,40 @@ export default { @@ -219,8 +234,40 @@ export default {
219 const id = options && options.id ? options.id : '' 234 const id = options && options.id ? options.id : ''
220 this.id = id 235 this.id = id
221 this.loadDetail() 236 this.loadDetail()
  237 + this.loadProductOptions()
222 }, 238 },
223 methods: { 239 methods: {
  240 + onNonNegativeInput(idx, field) {
  241 + const it = this.items[idx]
  242 + if (!it) return
  243 + const raw = it[field]
  244 + it[field] = String(raw || '').replace(/[^0-9.]/g, '')
  245 + this.$set(this.items, idx, it)
  246 + },
  247 + onNumberInput(idx, field) {
  248 + const it = this.items[idx]
  249 + if (!it) return
  250 + const raw = it[field]
  251 + it[field] = String(raw || '').replace(/[^0-9.\-]/g, '')
  252 + this.$set(this.items, idx, it)
  253 + },
  254 + onNonNegativeBlur(idx, field, digits) {
  255 + const it = this.items[idx]
  256 + if (!it) return
  257 + const num = Math.max(0, this.toNumber(it[field]))
  258 + const rounded = this.round(num, digits)
  259 + it[field] = rounded
  260 + this.$set(this.items, idx, it)
  261 + },
  262 + async loadProductOptions() {
  263 + try {
  264 + const results = await getDicByCodes(['CONTRACT_PRODUCT'])
  265 + const c3 = results && results.CONTRACT_PRODUCT && results.CONTRACT_PRODUCT.data ? results.CONTRACT_PRODUCT.data : []
  266 + this.options = c3.map(it => ({ label: it.name, value: it.code }))
  267 + } catch (e) {
  268 + this.options = []
  269 + }
  270 + },
224 onLockChange(idx, e) { 271 onLockChange(idx, e) {
225 const it = this.items[idx] 272 const it = this.items[idx]
226 if (!it) return 273 if (!it) return
@@ -238,6 +285,7 @@ export default { @@ -238,6 +285,7 @@ export default {
238 locked: false, 285 locked: false,
239 collapsed: true, 286 collapsed: true,
240 raw: v, 287 raw: v,
  288 + productId: v.productId || v.rawProductId || '',
241 productName: v.rawProductName || v.productName || '', 289 productName: v.rawProductName || v.productName || '',
242 industry: v.industry || '', 290 industry: v.industry || '',
243 brand: v.rawProductGrade || v.brand || '', 291 brand: v.rawProductGrade || v.brand || '',
@@ -272,6 +320,31 @@ export default { @@ -272,6 +320,31 @@ export default {
272 it.collapsed = !it.collapsed 320 it.collapsed = !it.collapsed
273 this.$set(this.items, idx, it) 321 this.$set(this.items, idx, it)
274 }, 322 },
  323 + openProductSheet(idx, mode = 'product') {
  324 + let opts = []
  325 + let title = ''
  326 + let value = ''
  327 + const item = this.items[idx]
  328 + if (mode === 'product') {
  329 + opts = this.selectOptions
  330 + const current = item && item.productId
  331 + const match = opts.find(o => o.value === current)
  332 + value = match ? match.value : ''
  333 + title = '请选择产品'
  334 + }
  335 + this.sheet = { ...this.sheet, visible: true, title, options: opts, idx, value, mode }
  336 + },
  337 + onProductConfirm({ value, label }) {
  338 + const { idx, mode } = this.sheet
  339 + const it = this.items[idx]
  340 + if (!it) { this.sheet.visible = false; return }
  341 + if (mode === 'product') {
  342 + it.productId = value
  343 + it.productName = label || ''
  344 + }
  345 + this.$set(this.items, idx, it)
  346 + this.sheet.visible = false
  347 + },
275 onImmediateChange(idx) { 348 onImmediateChange(idx) {
276 this.$nextTick(() => this.recalculate(idx)) 349 this.$nextTick(() => this.recalculate(idx))
277 }, 350 },
@@ -349,6 +422,26 @@ export default { @@ -349,6 +422,26 @@ export default {
349 raw.unitPrice = price 422 raw.unitPrice = price
350 raw.totalAmount = total 423 raw.totalAmount = total
351 // raw.amountExcludingTax = excl 424 // raw.amountExcludingTax = excl
  425 + raw.productId = it.productId || raw.productId
  426 + raw.productName = it.productName
  427 + if (Object.prototype.hasOwnProperty.call(raw, 'rawProductId')) raw.rawProductId = it.productId || raw.rawProductId
  428 + if (Object.prototype.hasOwnProperty.call(raw, 'rawProductName')) raw.rawProductName = it.productName
  429 + raw.industry = it.industry
  430 + raw.quality = it.quality
  431 + raw.brand = it.brand
  432 + if (Object.prototype.hasOwnProperty.call(raw, 'rawProductGrade')) raw.rawProductGrade = it.brand
  433 + raw.thickness = it.thickness
  434 + raw.thicknessTolPos = it.thicknessTolPos
  435 + raw.thicknessTolNeg = it.thicknessTolNeg
  436 + raw.width = it.width
  437 + raw.widthTolPos = it.widthTolPos
  438 + raw.widthTolNeg = it.widthTolNeg
  439 + raw.length = it.length
  440 + raw.lengthTolPos = it.lengthTolPos
  441 + raw.lengthTolNeg = it.lengthTolNeg
  442 + raw.materialCode = it.materialCode
  443 + raw.status = it.status
  444 + raw.deliveryDate = it.deliveryDate
352 return raw 445 return raw
353 }) 446 })
354 if (!selected.length) { 447 if (!selected.length) {
@@ -785,4 +878,4 @@ export default { @@ -785,4 +878,4 @@ export default {
785 height: 60rpx; 878 height: 60rpx;
786 align-items: center; 879 align-items: center;
787 } 880 }
788 -</style>  
  881 +</style>
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 <view class="page"> 2 <view class="page">
3 <scroll-view class="scroll" scroll-y> 3 <scroll-view class="scroll" scroll-y>
4 <view class="lock-page"> 4 <view class="lock-page">
5 - <view class="block" v-for="(item, idx) in items" :key="idx"> 5 + <view class="block" v-for="(item, idx) in items" :key="item.raw && (item.raw.id || item.raw.lineId || item.raw.productId) || ('row-' + idx)">
6 <view class="block-header"> 6 <view class="block-header">
7 <uni-data-checkbox 7 <uni-data-checkbox
8 multiple 8 multiple
@@ -19,63 +19,79 @@ @@ -19,63 +19,79 @@
19 </view> 19 </view>
20 20
21 <uni-list v-show="item.collapsed"> 21 <uni-list v-show="item.collapsed">
22 - <uni-list-item title="产品名称">  
23 - <template v-slot:footer>  
24 - <uni-easyinput v-model="item.productName" placeholder="请输入产品名称" :clearable="false" disabled /> 22 + <uni-list-item class="select-item" :class="item.productName ? 'is-filled' : 'is-empty'" clickable @click="openProductSheet(idx, 'product')" :rightText="item.productName || '请选择产品名称'" showArrow>
  23 + <template v-slot:body>
  24 + <view class="item-title"><text>产品名称</text></view>
25 </template> 25 </template>
26 </uni-list-item> 26 </uni-list-item>
27 <uni-list-item title="行业"> 27 <uni-list-item title="行业">
28 <template v-slot:footer> 28 <template v-slot:footer>
29 - <uni-easyinput v-model="item.industry" placeholder="请输入行业" :clearable="false" disabled /> 29 + <uni-easyinput v-model="item.industry" placeholder="请输入行业" />
30 </template> 30 </template>
31 </uni-list-item> 31 </uni-list-item>
32 <uni-list-item title="牌号"> 32 <uni-list-item title="牌号">
33 <template v-slot:footer> 33 <template v-slot:footer>
34 - <uni-easyinput v-model="item.brand" placeholder="请输入牌号" :clearable="false" disabled /> 34 + <uni-easyinput v-model="item.brand" placeholder="请输入牌号" />
35 </template> 35 </template>
36 </uni-list-item> 36 </uni-list-item>
37 <uni-list-item title="品质"> 37 <uni-list-item title="品质">
38 <template v-slot:footer> 38 <template v-slot:footer>
39 - <uni-easyinput v-model="item.quality" placeholder="请输入品质" :clearable="false" disabled /> 39 + <uni-easyinput v-model="item.quality" placeholder="请输入品质" />
40 </template> 40 </template>
41 </uni-list-item> 41 </uni-list-item>
42 - <uni-list-item title="规格(mm)"> 42 + <uni-list-item title="厚度(mm)">
43 <template v-slot:footer> 43 <template v-slot:footer>
44 - <view class="value value-spec">  
45 - <view v-if="item.thickness" class="value-spec_val">{{ item.thickness }}</view>  
46 - <view v-if="item.thickness" class="value-spec_box">  
47 - <view v-if="item.thicknessTolPos" class="value-spec_box_1">{{ item.thicknessTolPos > 0 ? '+' + item.thicknessTolPos : item.thicknessTolPos }}  
48 - </view>  
49 - <view v-if="item.thicknessTolNeg" class="value-spec_box_2">{{ item.thicknessTolNeg > 0 ? '+' + item.thicknessTolNeg : item.thicknessTolNeg }}  
50 - </view>  
51 - </view>  
52 - <view v-if="item.width" class="value-spec_val p12">*</view>  
53 - <view v-if="item.width" class="value-spec_val">{{ item.width }}</view>  
54 - <view v-if="item.width" class="value-spec_box">  
55 - <view v-if="item.widthTolPos" class="value-spec_box_1">{{ item.widthTolPos > 0 ? '+' + item.widthTolPos : item.widthTolPos }}  
56 - </view>  
57 - <view v-if="item.widthTolNeg" class="value-spec_box_2">{{ item.widthTolNeg > 0 ? '+' + item.widthTolNeg : item.widthTolNeg }}  
58 - </view>  
59 - </view>  
60 - <view v-if="item.length" class="value-spec_val p12">*</view>  
61 - <view v-if="item.length" class="value-spec_val">{{ item.length }}</view>  
62 - <view v-if="item.length" class="value-spec_box">  
63 - <view v-if="item.lengthTolPos" class="value-spec_box_1">{{ item.lengthTolPos > 0 ? '+' + item.lengthTolPos : item.lengthTolPos }}  
64 - </view>  
65 - <view v-if="item.lengthTolNeg" class="value-spec_box_2">{{ item.lengthTolNeg > 0 ? '+' + item.lengthTolNeg : item.lengthTolNeg }}  
66 - </view>  
67 - </view>  
68 - </view> 44 + <uni-easyinput type="digit" v-model="item.thickness" :inputBorder="false" placeholder="请输入厚度" @input="onNonNegativeInput(idx, 'thickness')" @blur="onNonNegativeBlur(idx, 'thickness', 9)" />
  45 + </template>
  46 + </uni-list-item>
  47 + <uni-list-item title="厚度公差上限(mm)">
  48 + <template v-slot:footer>
  49 + <uni-easyinput type="digit" v-model="item.thicknessTolPos" :inputBorder="false" placeholder="请输入厚度公差上限" @input="onNumberInput(idx, 'thicknessTolPos')" @blur="onNumberBlur(idx, 'thicknessTolPos', 9)" />
  50 + </template>
  51 + </uni-list-item>
  52 + <uni-list-item title="厚度公差下限(mm)">
  53 + <template v-slot:footer>
  54 + <uni-easyinput type="digit" v-model="item.thicknessTolNeg" :inputBorder="false" placeholder="请输入厚度公差下限" @input="onNumberInput(idx, 'thicknessTolNeg')" @blur="onNumberBlur(idx, 'thicknessTolNeg', 9)" />
  55 + </template>
  56 + </uni-list-item>
  57 + <uni-list-item title="宽度(mm)">
  58 + <template v-slot:footer>
  59 + <uni-easyinput type="digit" v-model="item.width" :inputBorder="false" placeholder="请输入宽度" @input="onNonNegativeInput(idx, 'width')" @blur="onNonNegativeBlur(idx, 'width', 9)" />
  60 + </template>
  61 + </uni-list-item>
  62 + <uni-list-item title="宽度公差上限(mm)">
  63 + <template v-slot:footer>
  64 + <uni-easyinput type="digit" v-model="item.widthTolPos" :inputBorder="false" placeholder="请输入宽度公差上限" @input="onNumberInput(idx, 'widthTolPos')" @blur="onNumberBlur(idx, 'widthTolPos', 9)" />
  65 + </template>
  66 + </uni-list-item>
  67 + <uni-list-item title="宽度公差下限(mm)">
  68 + <template v-slot:footer>
  69 + <uni-easyinput type="digit" v-model="item.widthTolNeg" :inputBorder="false" placeholder="请输入宽度公差下限" @input="onNumberInput(idx, 'widthTolNeg')" @blur="onNumberBlur(idx, 'widthTolNeg', 9)" />
  70 + </template>
  71 + </uni-list-item>
  72 + <uni-list-item title="长度(mm)">
  73 + <template v-slot:footer>
  74 + <uni-easyinput type="digit" v-model="item.length" :inputBorder="false" placeholder="请输入长度" @input="onNonNegativeInput(idx, 'length')" @blur="onNonNegativeBlur(idx, 'length', 9)" />
  75 + </template>
  76 + </uni-list-item>
  77 + <uni-list-item title="长度公差上限(mm)">
  78 + <template v-slot:footer>
  79 + <uni-easyinput type="digit" v-model="item.lengthTolPos" :inputBorder="false" placeholder="请输入长度公差上限" @input="onNumberInput(idx, 'lengthTolPos')" @blur="onNumberBlur(idx, 'lengthTolPos', 9)" />
  80 + </template>
  81 + </uni-list-item>
  82 + <uni-list-item title="长度公差下限(mm)">
  83 + <template v-slot:footer>
  84 + <uni-easyinput type="digit" v-model="item.lengthTolNeg" :inputBorder="false" placeholder="请输入长度公差下限" @input="onNumberInput(idx, 'lengthTolNeg')" @blur="onNumberBlur(idx, 'lengthTolNeg', 9)" />
69 </template> 85 </template>
70 </uni-list-item> 86 </uni-list-item>
71 <uni-list-item title="物料编码"> 87 <uni-list-item title="物料编码">
72 <template v-slot:footer> 88 <template v-slot:footer>
73 - <uni-easyinput v-model="item.materialCode" placeholder="请输入物料编码" :clearable="false" disabled /> 89 + <uni-easyinput v-model="item.materialCode" placeholder="请输入物料编码" />
74 </template> 90 </template>
75 </uni-list-item> 91 </uni-list-item>
76 <uni-list-item title="状态"> 92 <uni-list-item title="状态">
77 <template v-slot:footer> 93 <template v-slot:footer>
78 - <uni-easyinput v-model="item.status" placeholder="请输入状态" :clearable="false" disabled /> 94 + <uni-easyinput v-model="item.status" placeholder="请输入状态" />
79 </template> 95 </template>
80 </uni-list-item> 96 </uni-list-item>
81 <uni-list-item title="数量"> 97 <uni-list-item title="数量">
@@ -100,25 +116,25 @@ @@ -100,25 +116,25 @@
100 </uni-list-item> 116 </uni-list-item>
101 <uni-list-item title="发货日期"> 117 <uni-list-item title="发货日期">
102 <template v-slot:footer> 118 <template v-slot:footer>
103 - <uni-easyinput v-model="item.deliveryDate" :inputBorder="false" disabled /> 119 + <uni-easyinput v-model="item.deliveryDate" :inputBorder="false" />
104 </template> 120 </template>
105 </uni-list-item> 121 </uni-list-item>
106 </uni-list> 122 </uni-list>
107 123
108 <uni-list v-show="!item.collapsed"> 124 <uni-list v-show="!item.collapsed">
109 - <uni-list-item title="产品名称">  
110 - <template v-slot:footer>  
111 - <uni-easyinput v-model="item.productName" placeholder="请输入产品名称" :clearable="false" disabled /> 125 + <uni-list-item class="select-item" :class="item.productName ? 'is-filled' : 'is-empty'" clickable @click="openProductSheet(idx, 'product')" :rightText="item.productName || '请选择产品名称'" showArrow>
  126 + <template v-slot:body>
  127 + <view class="item-title"><text>产品名称</text></view>
112 </template> 128 </template>
113 </uni-list-item> 129 </uni-list-item>
114 <uni-list-item title="行业"> 130 <uni-list-item title="行业">
115 <template v-slot:footer> 131 <template v-slot:footer>
116 - <uni-easyinput v-model="item.industry" placeholder="请输入行业" :clearable="false" disabled /> 132 + <uni-easyinput v-model="item.industry" placeholder="请输入行业" />
117 </template> 133 </template>
118 </uni-list-item> 134 </uni-list-item>
119 <uni-list-item title="牌号"> 135 <uni-list-item title="牌号">
120 <template v-slot:footer> 136 <template v-slot:footer>
121 - <uni-easyinput v-model="item.brand" placeholder="请输入牌号" :clearable="false" disabled /> 137 + <uni-easyinput v-model="item.brand" placeholder="请输入牌号" />
122 </template> 138 </template>
123 </uni-list-item> 139 </uni-list-item>
124 </uni-list> 140 </uni-list>
@@ -157,24 +173,52 @@ @@ -157,24 +173,52 @@
157 </view> 173 </view>
158 </view> 174 </view>
159 </scroll-view> 175 </scroll-view>
160 - 176 + <SingleSelectSheet :visible.sync="sheet.visible" :title="sheet.title" :options="sheet.options" v-model="sheet.value" @confirm="onProductConfirm" />
161 </view> 177 </view>
162 </template> 178 </template>
163 179
164 <script> 180 <script>
165 import { getContractApi, specificationLock } from '@/api/contract' 181 import { getContractApi, specificationLock } from '@/api/contract'
  182 +import SingleSelectSheet from '@/components/single-select/index.vue'
166 import { formatCurrencyToChinese } from '@/utils/common' 183 import { formatCurrencyToChinese } from '@/utils/common'
  184 +import { getDicByCodes } from '@/utils/dic'
167 185
168 export default { 186 export default {
169 name: 'ContractUnplanLock', 187 name: 'ContractUnplanLock',
  188 + components: { SingleSelectSheet },
170 data() { 189 data() {
171 return { 190 return {
172 id: '', 191 id: '',
173 items: [], 192 items: [],
174 planQty: 30, 193 planQty: 30,
  194 + sheet: { visible: false, title: '请选择', options: [], idx: -1, value: '', mode: '' },
  195 + options: [],
175 } 196 }
176 }, 197 },
177 computed: { 198 computed: {
  199 + selectOptions() {
  200 + const list = Array.isArray(this.options) ? this.options : []
  201 + if (list.length > 0) {
  202 + return list.map(o => ({
  203 + label: o.label != null ? o.label : (o.text != null ? o.text : (o.name != null ? o.name : '')),
  204 + value: o.value != null ? o.value : (o.id != null ? o.id : o.productId)
  205 + }))
  206 + }
  207 + const uniq = {}
  208 + const opts = []
  209 + for (let i = 0; i < this.items.length; i++) {
  210 + const it = this.items[i]
  211 + const id = it.productId || (it.raw && it.raw.productId)
  212 + const name = it.productName || (it.raw && (it.raw.productName || it.raw.rawProductName))
  213 + if (!name) continue
  214 + const key = String(id || name)
  215 + if (uniq[key]) continue
  216 + uniq[key] = true
  217 + opts.push({ label: name, value: id || name })
  218 + }
  219 + return opts
  220 + },
  221 +
178 totalQuantity() { 222 totalQuantity() {
179 const qty = this.items.filter(it => it.locked).reduce((p, c) => p + this.toNumber(c.quantity), 0) 223 const qty = this.items.filter(it => it.locked).reduce((p, c) => p + this.toNumber(c.quantity), 0)
180 return this.round(qty, 2) 224 return this.round(qty, 2)
@@ -206,8 +250,40 @@ export default { @@ -206,8 +250,40 @@ export default {
206 const id = options && options.id ? options.id : '' 250 const id = options && options.id ? options.id : ''
207 this.id = id 251 this.id = id
208 this.loadDetail() 252 this.loadDetail()
  253 + this.loadProductOptions()
209 }, 254 },
210 methods: { 255 methods: {
  256 + async loadProductOptions() {
  257 + try {
  258 + const results = await getDicByCodes(['CONTRACT_PRODUCT'])
  259 + const c3 = results && results.CONTRACT_PRODUCT && results.CONTRACT_PRODUCT.data ? results.CONTRACT_PRODUCT.data : []
  260 + this.options = c3.map(it => ({ label: it.name, value: it.code }))
  261 + } catch (e) {
  262 + this.options = []
  263 + }
  264 + },
  265 + onNonNegativeInput(idx, field) {
  266 + const it = this.items[idx]
  267 + if (!it) return
  268 + const raw = it[field]
  269 + it[field] = String(raw || '').replace(/[^0-9.]/g, '')
  270 + this.$set(this.items, idx, it)
  271 + },
  272 + onNumberInput(idx, field) {
  273 + const it = this.items[idx]
  274 + if (!it) return
  275 + const raw = it[field]
  276 + it[field] = String(raw || '').replace(/[^0-9.\-]/g, '')
  277 + this.$set(this.items, idx, it)
  278 + },
  279 + onNonNegativeBlur(idx, field, digits) {
  280 + const it = this.items[idx]
  281 + if (!it) return
  282 + const num = Math.max(0, this.toNumber(it[field]))
  283 + const rounded = this.round(num, digits)
  284 + it[field] = rounded
  285 + this.$set(this.items, idx, it)
  286 + },
211 onLockChange(idx, e) { 287 onLockChange(idx, e) {
212 const it = this.items[idx] 288 const it = this.items[idx]
213 if (!it) return 289 if (!it) return
@@ -225,6 +301,7 @@ export default { @@ -225,6 +301,7 @@ export default {
225 locked: false, 301 locked: false,
226 collapsed: true, 302 collapsed: true,
227 raw: v, 303 raw: v,
  304 + productId: v.productId || v.rawProductId || '',
228 productName: v.rawProductName || v.productName || '', 305 productName: v.rawProductName || v.productName || '',
229 industry: v.industry || '', 306 industry: v.industry || '',
230 brand: v.rawProductGrade || v.brand || '', 307 brand: v.rawProductGrade || v.brand || '',
@@ -262,6 +339,31 @@ export default { @@ -262,6 +339,31 @@ export default {
262 onImmediateChange(idx) { 339 onImmediateChange(idx) {
263 this.$nextTick(() => this.recalculate(idx)) 340 this.$nextTick(() => this.recalculate(idx))
264 }, 341 },
  342 + openProductSheet(idx, mode = 'product') {
  343 + let opts = []
  344 + let title = ''
  345 + let value = ''
  346 + const item = this.items[idx]
  347 + if (mode === 'product') {
  348 + opts = this.selectOptions
  349 + const current = item && item.productId
  350 + const match = opts.find(o => o.value === current)
  351 + value = match ? match.value : ''
  352 + title = '请选择产品'
  353 + }
  354 + this.sheet = { ...this.sheet, visible: true, title, options: opts, idx, value, mode }
  355 + },
  356 + onProductConfirm({ value, label }) {
  357 + const { idx, mode } = this.sheet
  358 + const it = this.items[idx]
  359 + if (!it) { this.sheet.visible = false; return }
  360 + if (mode === 'product') {
  361 + it.productId = value
  362 + it.productName = label || ''
  363 + }
  364 + this.$set(this.items, idx, it)
  365 + this.sheet.visible = false
  366 + },
265 onNumberBlur(idx, field, digits) { 367 onNumberBlur(idx, field, digits) {
266 const it = this.items[idx] 368 const it = this.items[idx]
267 if (!it) return 369 if (!it) return
@@ -336,6 +438,26 @@ export default { @@ -336,6 +438,26 @@ export default {
336 raw.unitPrice = price 438 raw.unitPrice = price
337 raw.totalAmount = total 439 raw.totalAmount = total
338 raw.amountExcludingTax = excl 440 raw.amountExcludingTax = excl
  441 + raw.productId = it.productId || raw.productId
  442 + raw.productName = it.productName
  443 + if (Object.prototype.hasOwnProperty.call(raw, 'rawProductId')) raw.rawProductId = it.productId || raw.rawProductId
  444 + if (Object.prototype.hasOwnProperty.call(raw, 'rawProductName')) raw.rawProductName = it.productName
  445 + raw.industry = it.industry
  446 + raw.quality = it.quality
  447 + raw.brand = it.brand
  448 + if (Object.prototype.hasOwnProperty.call(raw, 'rawProductGrade')) raw.rawProductGrade = it.brand
  449 + raw.thickness = it.thickness
  450 + raw.thicknessTolPos = it.thicknessTolPos
  451 + raw.thicknessTolNeg = it.thicknessTolNeg
  452 + raw.width = it.width
  453 + raw.widthTolPos = it.widthTolPos
  454 + raw.widthTolNeg = it.widthTolNeg
  455 + raw.length = it.length
  456 + raw.lengthTolPos = it.lengthTolPos
  457 + raw.lengthTolNeg = it.lengthTolNeg
  458 + raw.materialCode = it.materialCode
  459 + raw.status = it.status
  460 + raw.deliveryDate = it.deliveryDate
339 return raw 461 return raw
340 }) 462 })
341 if (!selected.length) { 463 if (!selected.length) {
@@ -767,4 +889,4 @@ export default { @@ -767,4 +889,4 @@ export default {
767 height: 60rpx; 889 height: 60rpx;
768 align-items: center; 890 align-items: center;
769 } 891 }
770 -</style>  
  892 +</style>