PageFour.vue 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235
  1. <template>
  2. <view class="page-four-container">
  3. <!-- 入库信息卡片 -->
  4. <view class="card-wrap">
  5. <u--form labelPosition="top" :model="warehouseInfo" ref="form" :rules="rules" class="address-section">
  6. <view class="address-header">
  7. <u-icon name="car-fill" size="36rpx" color="#108cff" class="location-icon" />
  8. <text class="address-title">入库信息</text>
  9. </view>
  10. <!-- 编码、快递单号、物流图片 -->
  11. <!-- 收单物品、收单类型 -->
  12. <u-row class="info-row" justify="space-between">
  13. <u-col span="5.8">
  14. <u-form-item label="收单物品" prop="item">
  15. <u--input v-model="warehouseInfo.item" placeholder="请输入收单物品" class="info-input"
  16. @blur="saveWarehouseInfoOnBlur" />
  17. </u-form-item>
  18. </u-col>
  19. <u-col span="5.8">
  20. <view @tap="selectCustomerServiceName">
  21. <u-form-item label="收单类型" prop="customerServiceNameLabel">
  22. <view class="click-wrapper info-input">
  23. {{ warehouseInfo.customerServiceNameLabel || '点击选择收单类型' }}
  24. </view>
  25. </u-form-item>
  26. <u-picker :show="showCustomerServicePicker" :columns="customerServiceColumns" confirm keyName="label"
  27. @confirm="handleConfirmCustomerService" @cancel="showCustomerServicePicker = false" />
  28. </view>
  29. </u-col>
  30. </u-row>
  31. <!-- 类别、是否需要查码 -->
  32. <u-row class="info-row" justify="space-between">
  33. <u-col span="5.8">
  34. <view @tap="selectCategory">
  35. <u-form-item label="类别" prop="category">
  36. <view class="click-wrapper info-input">
  37. {{ warehouseInfo.categoryLabel || '点击选择类别' }}
  38. </view>
  39. </u-form-item>
  40. <u-picker :show="showCategoryPicker" :columns="categoryColumns" confirm keyName="label"
  41. @confirm="handleConfirmCategory" @cancel="showCategoryPicker = false" />
  42. </view>
  43. </u-col>
  44. <u-col span="5.8">
  45. <view @tap="selectNeedCheckCode">
  46. <u-form-item label="是否需要查码" prop="needCheckCode">
  47. <view class="click-wrapper info-input">
  48. {{ warehouseInfo.needCheckCodeLabel || '点击选择是否需要查码' }}
  49. </view>
  50. </u-form-item>
  51. <u-picker :show="showNeedCheckCodePicker" :columns="needCheckCodeColumns" confirm keyName="label"
  52. @confirm="handleConfirmNeedCheckCode" @cancel="showNeedCheckCodePicker = false" />
  53. </view>
  54. </u-col>
  55. </u-row>
  56. <u-row class="info-row" justify="space-between">
  57. <u-col span="4.5">
  58. <u-form-item label="编码" prop="codeStorage">
  59. <u--input v-model="warehouseInfo.codeStorage" placeholder="请输入编码" class="info-input"
  60. :disabled="warehouseInfo.needCheckCode === '2'" @blur="saveWarehouseInfoOnBlur" />
  61. </u-form-item>
  62. </u-col>
  63. <u-col span="4.5">
  64. <u-form-item label="快递单号" prop="expressOrderNo">
  65. <u--input v-model="warehouseInfo.expressOrderNo" placeholder="请输入快递单号" class="info-input"
  66. @blur="saveWarehouseInfoOnBlur" />
  67. </u-form-item>
  68. </u-col>
  69. <u-col span="2">
  70. <u-form-item label="物流图片" prop="uploadedImage">
  71. <view class="image-uploader" @click="selectImage">
  72. <u-icon v-if="!warehouseInfo.uploadedImage" name="camera-fill" size="48rpx" color="#909399"
  73. class="camera-icon" />
  74. <image v-else :src="warehouseInfo.uploadedImage" mode="aspectFill" class="image-preview" />
  75. </view>
  76. </u-form-item>
  77. </u-col>
  78. </u-row>
  79. <!-- 表款、查码费 -->
  80. <u-row class="info-row" justify="space-between">
  81. <u-col span="5.8">
  82. <u-form-item label="表款">
  83. <u--input v-model="warehouseInfo.watchPrice" placeholder="请输入表款" class="info-input" type="number"
  84. @blur="saveWarehouseInfoOnBlur" />
  85. </u-form-item>
  86. </u-col>
  87. <u-col span="5.8">
  88. <u-form-item label="查码费">
  89. <u--input v-model="warehouseInfo.checkCodeFee" placeholder="请输入查码费" class="info-input" type="number"
  90. :disabled="warehouseInfo.needCheckCode === '2'" @blur="saveWarehouseInfoOnBlur" />
  91. </u-form-item>
  92. </u-col>
  93. </u-row>
  94. <!-- 好处费、运费 -->
  95. <u-row class="info-row" justify="space-between">
  96. <u-col span="5.8">
  97. <u-form-item label="好处费">
  98. <u--input v-model="warehouseInfo.benefitFee" placeholder="请输入好处费" class="info-input" type="number"
  99. @blur="saveWarehouseInfoOnBlur" />
  100. </u-form-item>
  101. </u-col>
  102. <u-col span="5.8">
  103. <u-form-item label="运费">
  104. <u--input v-model="warehouseInfo.freight" placeholder="请输入运费" class="info-input" type="number"
  105. @blur="saveWarehouseInfoOnBlur" />
  106. </u-form-item>
  107. </u-col>
  108. </u-row>
  109. <!-- 维修金额、分单比例 -->
  110. <u-row class="info-row" justify="space-between">
  111. <u-col span="5.8">
  112. <u-form-item label="维修金额">
  113. <u--input v-model="warehouseInfo.repairAmount" placeholder="请输入维修金额" class="info-input" type="number"
  114. @blur="saveWarehouseInfoOnBlur" />
  115. </u-form-item>
  116. </u-col>
  117. <u-col span="5.8">
  118. <u-form-item label="分单比例(0~100)">
  119. <u--input v-model="warehouseInfo.splitRatio" placeholder="请输入分单比例(0~100)" class="info-input"
  120. type="number" @blur="saveWarehouseInfoOnBlur" />
  121. </u-form-item>
  122. </u-col>
  123. </u-row>
  124. <u-row class="info-row" justify="space-between">
  125. <u-col span="5.8">
  126. <u-form-item label="型号" required prop="model">
  127. <u--input v-model="warehouseInfo.model" placeholder="请输入型号" class="info-input"
  128. @blur="saveWarehouseInfoOnBlur" />
  129. </u-form-item>
  130. </u-col>
  131. </u-row>
  132. <!-- 成本合计、业绩、毛业绩 -->
  133. <u-row class="info-row" justify="space-between">
  134. <u-col span="3.8">
  135. <u-form-item label="成本合计">
  136. <u--input :disabled="true" :value="computedTotalCost" placeholder="成本合计自动计算" class="info-input"
  137. type="number" />
  138. </u-form-item>
  139. </u-col>
  140. <u-col span="3.8">
  141. <u-form-item label="业绩">
  142. <u--input :disabled="true" :value="computedPerformance" placeholder="业绩自动计算" class="info-input"
  143. type="number" />
  144. </u-form-item>
  145. </u-col>
  146. <u-col span="3.8">
  147. <u-form-item label="毛业绩">
  148. <u--input :disabled="true" :value="computedGrossPerformance" placeholder="毛业绩自动计算" class="info-input"
  149. type="number" />
  150. </u-form-item>
  151. </u-col>
  152. </u-row>
  153. <!-- 是否入库 -->
  154. <!-- <u-row class="info-row">
  155. <u-col span="12">
  156. <view @tap="selectIsWarehouse">
  157. <u-form-item label="是否入库" prop="isWarehouse">
  158. <view class="click-wrapper info-input">
  159. {{ isWarehouseLabel || '点击选择是否入库' }}
  160. </view>
  161. </u-form-item>
  162. <u-picker :show="showIsWarehousePicker" :columns="isWarehouseColumns" confirm keyName="label"
  163. @confirm="handleConfirmIsWarehouse" @cancel="showIsWarehousePicker = false" />
  164. </view>
  165. </u-col>
  166. </u-row> -->
  167. <!-- 收单备注 -->
  168. <u-row class="info-row">
  169. <u-col span="12">
  170. <u-form-item label="收单备注">
  171. <u--textarea v-model="warehouseInfo.remarks" placeholder="请输入收单备注" class="info-textarea"
  172. confirmType="done" rows="4" @blur="saveWarehouseInfoOnBlur" />
  173. </u-form-item>
  174. </u-col>
  175. </u-row>
  176. </u--form>
  177. </view>
  178. <!-- 分成信息卡片 -->
  179. <view class="card-wrap">
  180. <view class="address-section">
  181. <view class="address-header add-button-container">
  182. <text class="address-title">分成信息</text>
  183. <view class="add-button" @click="addSplit">
  184. <u-icon name="plus" size="24rpx" color="#108cff" />
  185. <text>添加</text>
  186. </view>
  187. </view>
  188. <!-- 分成信息表格 -->
  189. <view class="split-table">
  190. <u-row class="split-table-header">
  191. <u-col span="4"><text class="header-text">关联</text></u-col>
  192. <u-col span="2"><text class="header-text">分成人</text></u-col>
  193. <u-col span="2"><text class="header-text">比例</text></u-col>
  194. <u-col span="1"><text class="header-text">类型</text></u-col>
  195. <u-col span="1"><text class="header-text">公司</text></u-col>
  196. <u-col span="2" class="action-column"><text class="header-text">操作</text></u-col>
  197. </u-row>
  198. <u-row v-for="(item, index) in profitSharingList" :key="item.uuid" class="split-table-row">
  199. <u-col span="4">
  200. <view class="table-cell">
  201. <u-button @click="handleSelectOrg(item)" :text="item.orgName || '选择组织'" plain />
  202. </view>
  203. </u-col>
  204. <u-col span="2">
  205. <view class="table-cell">
  206. <u-button @click="handleSelectPerson(item)" :text="item.userName || '选择人员'" plain />
  207. </view>
  208. </u-col>
  209. <u-col span="2">
  210. <view class="table-cell">
  211. <u--input v-model="item.commissionRate" type="number" class="percentage-input"
  212. @input="handlePercentageInput(item)" min="0" max="100" precision="0" />
  213. </view>
  214. </u-col>
  215. <u-col span="1">
  216. <view class="table-cell">
  217. <view :class="['account-type', item.accountType == '1' ? 'frontend' : 'backend']"
  218. @click="toggleAccountType(item)">
  219. {{ item.accountType == '1' ? '前' : '后' }}
  220. </view>
  221. </view>
  222. </u-col>
  223. <u-col span="1">
  224. <view class="table-cell">
  225. <view class="radio-wrapper" @click="toggleBelongToCompany(item)">
  226. <view :class="['radio-circle', item.isCompanyPerformance == '1' ? 'active' : '']">
  227. <u-icon v-if="item.isCompanyPerformance == '1'" name="checkmark" size="20rpx" color="#fff" />
  228. </view>
  229. </view>
  230. </view>
  231. </u-col>
  232. <u-col span="2" class="action-column">
  233. <view class="table-cell">
  234. <u-button type="error" plain shape="circle" size="mini" @click="deleteRow(item.id, item.uuid)"
  235. class="delete-btn">
  236. <u-icon name="trash" size="20rpx" color="#ff6b6b" />
  237. </u-button>
  238. </view>
  239. </u-col>
  240. </u-row>
  241. </view>
  242. </view>
  243. </view>
  244. <!-- 确认收单、确认入库按钮 -->
  245. <view class="confirm-button-container">
  246. <u-row gutter="24">
  247. <u-col span="6">
  248. <u-button class="next-btn" type="success" @click="confirmReceiveOrder">
  249. <u-icon name="checkmark-circle-fill" size="28rpx" color="#fff" />
  250. <text style="margin-left: 8rpx;">确认收单</text>
  251. </u-button>
  252. </u-col>
  253. <u-col span="6">
  254. <u-button class="next-btn" type="success" @click="confirmWarehouseEntry">
  255. <u-icon name="checkmark-circle-fill" size="28rpx" color="#fff" />
  256. <text style="margin-left: 8rpx;">确认入库</text>
  257. </u-button>
  258. </u-col>
  259. </u-row>
  260. </view>
  261. <!-- 组织选择器 -->
  262. <u-picker :show="showOrgPicker" title="请选择组织" :columns="columnsOrgList" keyName="label" @confirm="handleOrgConfirm"
  263. @cancel="showOrgPicker = false" />
  264. <!-- 人员选择器 -->
  265. <u-picker :show="showPersonPicker" title="请选择分成人" :columns="columnsPersonList" keyName="label"
  266. @confirm="handleConfirmPerson" @cancel="handleCancelPerson" />
  267. <u-toast ref="uToast" />
  268. </view>
  269. </template>
  270. <script>
  271. import imageUpload from '../utils/imageUpload.js'
  272. import dayjs from 'dayjs'
  273. export default {
  274. name: 'PageFour',
  275. props: {
  276. orderDetail: {
  277. type: Object,
  278. default: () => ({})
  279. },
  280. currentReceipt: {
  281. type: Object,
  282. default: () => ({})
  283. }
  284. },
  285. data() {
  286. return {
  287. warehouseInfo: {
  288. codeStorage: '',
  289. expressOrderNo: '',
  290. uploadedImage: '',
  291. item: '',
  292. checkCodeFee: '',
  293. watchPrice: '',
  294. benefitFee: '',
  295. freight: '',
  296. repairAmount: '',
  297. grossPerformance: '',
  298. performance: '',
  299. splitRatio: '',
  300. remarks: '',
  301. customerServiceNameLabel: '',
  302. customerServiceName: '',
  303. categoryLabel: '',
  304. category: '',
  305. needCheckCodeLabel: '',
  306. needCheckCode: ''
  307. },
  308. profitSharingList: [],
  309. showOrgPicker: false,
  310. showPersonPicker: false,
  311. columnsOrgList: [],
  312. columnsPersonList: [],
  313. showCustomerServicePicker: false,
  314. customerServiceColumns: [[
  315. { label: '收单类', value: '1' },
  316. { label: '维修类', value: '2' },
  317. { label: '销售类', value: '3' }
  318. ]],
  319. showCategoryPicker: false,
  320. categoryColumns: [[
  321. { label: '腕表', value: '1' },
  322. { label: '包包', value: '2' },
  323. { label: '首饰', value: '4' },
  324. { label: '其他', value: '3' }
  325. ]],
  326. showNeedCheckCodePicker: false,
  327. needCheckCodeColumns: [[
  328. { label: '是', value: '1' },
  329. { label: '否', value: '2' }
  330. ]],
  331. currentEditItem: '',
  332. isWarehouse: '2',
  333. isWarehouseLabel: '不入库',
  334. showIsWarehousePicker: false,
  335. isWarehouseColumns: [[
  336. { label: '确认入库', value: '1' },
  337. { label: '不入库', value: '2' }
  338. ]],
  339. brandList: [],
  340. rules: {
  341. model: [
  342. { required: true, message: '请输入型号', trigger: 'blur' }
  343. ]
  344. }
  345. }
  346. },
  347. computed: {
  348. computedTotalCost() {
  349. const freight = Number(this.warehouseInfo.freight) || 0
  350. const benefitFee = Number(this.warehouseInfo.benefitFee) || 0
  351. const checkCodeFee = Number(this.warehouseInfo.checkCodeFee) || 0
  352. const watchPrice = Number(this.warehouseInfo.watchPrice) || 0
  353. const repairAmount = Number(this.warehouseInfo.repairAmount) || 0
  354. return freight + benefitFee + checkCodeFee + watchPrice + repairAmount
  355. },
  356. computedPerformance() {
  357. const sellingPrice = Number(this.currentReceipt.sellingPrice) || 0
  358. return sellingPrice - this.computedTotalCost
  359. },
  360. computedGrossPerformance() {
  361. const performance = this.computedPerformance || 0
  362. const splitRatio = Number(this.warehouseInfo.splitRatio) / 100 || 0
  363. return (performance * splitRatio).toFixed(2)
  364. }
  365. },
  366. watch: {
  367. currentReceipt: {
  368. handler(newVal) {
  369. if (newVal) {
  370. this.initWarehouseInfo(newVal)
  371. this.loadShareList()
  372. }
  373. },
  374. immediate: true,
  375. deep: true
  376. }
  377. },
  378. mounted() {
  379. this.loadCommissionUserList()
  380. this.loadBrandList()
  381. },
  382. methods: {
  383. /**
  384. * 加载品牌列表
  385. */
  386. async loadBrandList() {
  387. try {
  388. const res = await this.$getDicts('crm_form_brand')
  389. this.brandList = res
  390. } catch (error) {
  391. console.error('加载品牌列表失败:', error)
  392. }
  393. },
  394. /**
  395. * 初始化入库信息
  396. */
  397. initWarehouseInfo(data) {
  398. const receiptRemark = data.receiptRemark || ''
  399. const remarkParts = receiptRemark.split(';')
  400. // 设置默认值:收单类型默认为"收单类",类别默认为"腕表",是否需要查码默认为"是"
  401. const defaultCustomerServiceName = data.customerServiceName || '1'
  402. const defaultCategory = data.category || '1'
  403. const defaultNeedCheckCode = data.needCheckCode || '1'
  404. this.warehouseInfo = {
  405. codeStorage: data.code || '',
  406. expressOrderNo: data.expressOrderNo || '',
  407. uploadedImage: remarkParts[1] || '',
  408. item: data.item || '',
  409. checkCodeFee: data.checkCodeFee || '',
  410. watchPrice: data.tableFee || '',
  411. benefitFee: data.benefitFee || '',
  412. freight: data.freight || '',
  413. repairAmount: data.repairAmount || '',
  414. grossPerformance: data.grossPerformance || '',
  415. performance: data.performance || '',
  416. splitRatio: data.splitRatio || '',
  417. remarks: remarkParts[0] || '',
  418. model: data.model || '',
  419. customerServiceName: defaultCustomerServiceName,
  420. customerServiceNameLabel: this.getLabelByValue(
  421. this.customerServiceColumns[0],
  422. defaultCustomerServiceName
  423. ),
  424. category: defaultCategory,
  425. categoryLabel: this.getLabelByValue(
  426. this.categoryColumns[0],
  427. defaultCategory
  428. ),
  429. needCheckCode: defaultNeedCheckCode,
  430. needCheckCodeLabel: this.getLabelByValue(
  431. this.needCheckCodeColumns[0],
  432. defaultNeedCheckCode
  433. )
  434. }
  435. },
  436. /**
  437. * 根据值获取标签
  438. */
  439. getLabelByValue(columns, value) {
  440. const item = columns.find(col => col.value == value)
  441. return item ? item.label : ''
  442. },
  443. /**
  444. * 入库信息失焦 / 物流图片变更后保存
  445. */
  446. async saveWarehouseInfoOnBlur() {
  447. if (!this.currentReceipt || !this.currentReceipt.id) return
  448. try {
  449. await uni.$u.api.updateReceiptForm({
  450. id: this.currentReceipt.id,
  451. code: this.warehouseInfo.codeStorage || '',
  452. expressOrderNo: this.warehouseInfo.expressOrderNo || '',
  453. item: this.warehouseInfo.item || '',
  454. checkCodeFee: this.warehouseInfo.checkCodeFee || '',
  455. tableFee: this.warehouseInfo.watchPrice || '',
  456. benefitFee: this.warehouseInfo.benefitFee || '',
  457. freight: this.warehouseInfo.freight || '',
  458. repairAmount: this.warehouseInfo.repairAmount || '',
  459. grossPerformance: this.computedGrossPerformance || '',
  460. performance: this.computedPerformance || '',
  461. splitRatio: this.warehouseInfo.splitRatio || '',
  462. receiptRemark: `${this.warehouseInfo.remarks || ''};${this.warehouseInfo.uploadedImage || ''}`,
  463. customerServiceName: this.warehouseInfo.customerServiceName || '',
  464. category: this.warehouseInfo.category || '',
  465. needCheckCode: this.warehouseInfo.needCheckCode || '',
  466. totalCost: this.computedTotalCost || '',
  467. model: this.warehouseInfo.model || ''
  468. })
  469. } catch (e) {
  470. console.error('保存入库信息失败:', e)
  471. }
  472. },
  473. /**
  474. * 选择物流图片(选完后即保存)
  475. */
  476. async selectImage() {
  477. try {
  478. const tempFilePaths = await imageUpload.chooseImage(1)
  479. if (!tempFilePaths || tempFilePaths.length === 0) {
  480. uni.$u.toast('未获取到图片路径,请重试')
  481. return
  482. }
  483. const tempFilePath = tempFilePaths[0]
  484. const rep = await uni.$u.api.uploadFile(tempFilePath)
  485. if (rep.code == 200) {
  486. this.warehouseInfo.uploadedImage = rep.data.url
  487. await this.saveWarehouseInfoOnBlur()
  488. }
  489. } catch (error) {
  490. console.error('上传图片失败:', error)
  491. }
  492. },
  493. /**
  494. * 加载分成人名单
  495. */
  496. async loadCommissionUserList() {
  497. try {
  498. const res = await uni.$u.api.getCustomerManagerAllList()
  499. this.columnsOrgList = [res.data[0].children]
  500. } catch (error) {
  501. console.error('加载分成人名单失败:', error)
  502. }
  503. },
  504. /**
  505. * 加载分成列表
  506. */
  507. async loadShareList() {
  508. if (!this.currentReceipt.sendFormId) return
  509. try {
  510. const { rows } = await uni.$u.api.selectCommissionList({
  511. pageSize: 9999,
  512. pageNum: 1
  513. }, { sendFormId: this.currentReceipt.sendFormId })
  514. const newRows = rows
  515. .filter(item => item.receiptFormId == this.currentReceipt.id)
  516. .map(item => ({
  517. ...item,
  518. uuid: Math.random()
  519. }))
  520. this.profitSharingList = newRows
  521. } catch (error) {
  522. console.error('加载分成列表失败:', error)
  523. }
  524. },
  525. /**
  526. * 添加分成行
  527. */
  528. addSplit() {
  529. this.profitSharingList.push({
  530. deptId: '',
  531. accountType: '1',
  532. userId: '',
  533. commissionRate: 0,
  534. isCompanyPerformance: '2',
  535. orgName: '',
  536. userName: '',
  537. id: '',
  538. uuid: Math.random()
  539. })
  540. this.calculateTotalPercentage()
  541. },
  542. /**
  543. * 重新计算分成比例
  544. */
  545. calculateTotalPercentage() {
  546. const frontItems = this.profitSharingList.filter(item => item.accountType == '1')
  547. const backItems = this.profitSharingList.filter(item => item.accountType == '2')
  548. const totalFrontItems = frontItems.length || 1
  549. const totalBackItems = backItems.length || 1
  550. this.profitSharingList.forEach(item => {
  551. if (item.accountType == '1') {
  552. item.commissionRate = Math.floor(100 / totalFrontItems)
  553. }
  554. if (item.accountType == '2') {
  555. item.commissionRate = Math.floor(100 / totalBackItems)
  556. }
  557. })
  558. },
  559. /**
  560. * 切换账户类型
  561. */
  562. toggleAccountType(item) {
  563. item.accountType = item.accountType == '1' ? '2' : '1'
  564. this.calculateTotalPercentage()
  565. },
  566. /**
  567. * 处理百分比输入
  568. */
  569. handlePercentageInput(item) {
  570. let value = Number(item.commissionRate)
  571. if (isNaN(value)) value = 0
  572. if (value < 0) value = 0
  573. if (value > 100) value = 100
  574. item.commissionRate = Math.floor(value)
  575. },
  576. /**
  577. * 切换归属公司
  578. */
  579. toggleBelongToCompany(item) {
  580. item.isCompanyPerformance = item.isCompanyPerformance == '1' ? '2' : '1'
  581. },
  582. /**
  583. * 选择组织
  584. */
  585. handleSelectOrg(item) {
  586. this.currentEditItem = item.uuid
  587. this.showPersonPicker = true
  588. this.columnsPersonList = this.columnsOrgList
  589. },
  590. /**
  591. * 选择人员
  592. */
  593. handleSelectPerson(item) {
  594. this.currentEditItem = item.uuid
  595. const deptId = item.deptId
  596. const org = this.findOrg(this.columnsOrgList[0], deptId)
  597. if (org) {
  598. this.columnsPersonList = [org.children]
  599. }
  600. this.showPersonPicker = true
  601. },
  602. /**
  603. * 递归查找组织
  604. */
  605. findOrg(orgList, deptId) {
  606. for (const org of orgList) {
  607. if (org.id == deptId) {
  608. return org
  609. }
  610. if (org.children && org.children.length > 0) {
  611. const found = this.findOrg(org.children, deptId)
  612. if (found) return found
  613. }
  614. }
  615. return null
  616. },
  617. /**
  618. * 确认选择组织
  619. */
  620. handleOrgConfirm({ value }) {
  621. this.profitSharingList.forEach(item => {
  622. if (item.uuid == this.currentEditItem) {
  623. item.orgName = value[0].label
  624. item.deptId = value[0].id
  625. item.userId = ''
  626. item.userName = ''
  627. }
  628. })
  629. this.showOrgPicker = false
  630. },
  631. /**
  632. * 确认选择人员
  633. */
  634. handleConfirmPerson({ value }) {
  635. if (value[0].isUser) {
  636. this.profitSharingList.forEach(item => {
  637. if (item.uuid == this.currentEditItem) {
  638. item.userName = value[0].label
  639. item.userId = value[0].id
  640. }
  641. })
  642. this.columnsPersonList = []
  643. this.showPersonPicker = false
  644. } else {
  645. this.profitSharingList.forEach(item => {
  646. if (item.uuid == this.currentEditItem) {
  647. item.orgName = value[0].label
  648. item.deptId = value[0].id
  649. }
  650. })
  651. this.columnsPersonList = [value[0].children]
  652. }
  653. },
  654. /**
  655. * 取消选择人员
  656. */
  657. handleCancelPerson() {
  658. this.columnsPersonList = []
  659. this.showPersonPicker = false
  660. },
  661. /**
  662. * 删除分成行
  663. */
  664. async deleteRow(id, uuid) {
  665. uni.showModal({
  666. title: '确认删除',
  667. content: '是否确认删除当前行分成比例?',
  668. success: async (res) => {
  669. if (res.confirm) {
  670. if (!id) {
  671. this.profitSharingList = this.profitSharingList.filter(item => item.uuid != uuid)
  672. this.calculateTotalPercentage()
  673. return
  674. }
  675. try {
  676. await uni.$u.api.deleteClueCommissionForm(id)
  677. uni.$u.toast('删除成功')
  678. this.loadShareList()
  679. } catch (error) {
  680. uni.$u.toast('删除失败')
  681. }
  682. }
  683. }
  684. })
  685. },
  686. /**
  687. * 选择收单类型
  688. */
  689. selectCustomerServiceName() {
  690. this.showCustomerServicePicker = true
  691. },
  692. /**
  693. * 确认收单类型
  694. */
  695. handleConfirmCustomerService({ value }) {
  696. this.warehouseInfo.customerServiceNameLabel = value[0].label
  697. this.warehouseInfo.customerServiceName = value[0].value
  698. this.showCustomerServicePicker = false
  699. this.saveWarehouseInfoOnBlur()
  700. },
  701. /**
  702. * 选择类别
  703. */
  704. selectCategory() {
  705. this.showCategoryPicker = true
  706. },
  707. /**
  708. * 确认类别
  709. */
  710. handleConfirmCategory({ value }) {
  711. this.warehouseInfo.categoryLabel = value[0].label
  712. this.warehouseInfo.category = value[0].value
  713. this.showCategoryPicker = false
  714. this.saveWarehouseInfoOnBlur()
  715. },
  716. /**
  717. * 选择是否需要查码
  718. */
  719. selectNeedCheckCode() {
  720. this.showNeedCheckCodePicker = true
  721. },
  722. /**
  723. * 确认是否需要查码
  724. */
  725. handleConfirmNeedCheckCode({ value }) {
  726. this.warehouseInfo.needCheckCodeLabel = value[0].label
  727. this.warehouseInfo.needCheckCode = value[0].value
  728. // 如果选择"否",清空编码和查码费
  729. if (value[0].value === '2') {
  730. this.warehouseInfo.codeStorage = ''
  731. this.warehouseInfo.checkCodeFee = ''
  732. }
  733. this.showNeedCheckCodePicker = false
  734. this.saveWarehouseInfoOnBlur()
  735. },
  736. /**
  737. * 确认收单
  738. */
  739. async confirmReceiveOrder() {
  740. // 校验表单
  741. await this.$refs.form.validate().then(() => {
  742. uni.showModal({
  743. title: '确认收单',
  744. content: `是否确认收单该订单:${this.orderDetail.item}?`,
  745. success: async (res) => {
  746. if (res.confirm) {
  747. try {
  748. // 先判断当前的状态是不是3(收单),如果是3的话就不调这个接口,修改订单状态
  749. if (this.orderDetail.status != '3') {
  750. // 当前的收单状态不是收单状态,则修改订单状态
  751. await uni.$u.api.oderForm({
  752. status: '3',
  753. id: this.orderDetail.id
  754. })
  755. }
  756. // 更新收单表单
  757. await uni.$u.api.updateReceiptForm({
  758. id: this.currentReceipt.id,
  759. code: this.warehouseInfo.codeStorage || '',
  760. expressOrderNo: this.warehouseInfo.expressOrderNo || '',
  761. item: this.warehouseInfo.item || '',
  762. checkCodeFee: this.warehouseInfo.checkCodeFee || '',
  763. tableFee: this.warehouseInfo.watchPrice || '',
  764. benefitFee: this.warehouseInfo.benefitFee || '',
  765. freight: this.warehouseInfo.freight || '',
  766. repairAmount: this.warehouseInfo.repairAmount || '',
  767. grossPerformance: this.computedGrossPerformance || '',
  768. performance: this.computedPerformance || '',
  769. splitRatio: this.warehouseInfo.splitRatio || '',
  770. receiptRemark: `${this.warehouseInfo.remarks || ''};${this.warehouseInfo.uploadedImage || ''}`,
  771. customerServiceName: this.warehouseInfo.customerServiceName || '',
  772. category: this.warehouseInfo.category || '',
  773. needCheckCode: this.warehouseInfo.needCheckCode || '',
  774. totalCost: this.computedTotalCost || '',
  775. model: this.warehouseInfo.model || '',
  776. })
  777. // 上传分成数据
  778. await this.addShare()
  779. // //新增仓库或者编辑仓库
  780. // //等于1的时候放入仓库表
  781. // if (this.isWarehouse == '1') {
  782. // // 获取品牌ID
  783. // const brandObj = this.brandList.find(item => item.dictLabel === this.currentReceipt.brand)
  784. // const brandId = brandObj ? brandObj.dictValue : ''
  785. // //建立入库data
  786. // // 获取 PageThree 的高清实物图的 fileUrl 数组
  787. // // 直接使用 imageUpload 获取图片列表,与 PageThree 保持一致
  788. // let goodPicFileUrls = []
  789. // if (this.currentReceipt.id && this.orderDetail.itemBrand) {
  790. // try {
  791. // const list = await imageUpload.getFileList(
  792. // '2',
  793. // '3',
  794. // this.currentReceipt.id,
  795. // this.orderDetail.itemBrand,
  796. // this.currentReceipt.clueId
  797. // )
  798. // // 获取前6个图片的 fileUrl(与 PageThree 的 displayImages 保持一致)
  799. // // goodPicFileUrls = (list || []).slice(0, 6).map(item => item.fileUrl).filter(url => url)
  800. // goodPicFileUrls = (list || []).map(item => item.fileUrl).filter(url => url)
  801. // } catch (error) {
  802. // console.error('获取高清实物图失败:', error)
  803. // }
  804. // }
  805. // const warehouseData = {
  806. // goodPicFileList: goodPicFileUrls,//商品图片 page3的高清实物图的url数组
  807. // type: this.warehouseInfo.category || '',//商品分类
  808. // dictLabel: this.currentReceipt.brand || '',//品牌名称
  809. // dictValue: brandId || '',//品牌id
  810. // indentifyCode:this.warehouseInfo.codeStorage|| '',//独立编码
  811. // costPrice: this.computedTotalCost || '',//总成本价
  812. // recycleTime: dayjs().format('YYYY-MM-DD'),//回收时间 必填
  813. // stockStatus:0,//库存状态,0待入库,1已入库,因为是我们是预入库,所以是0
  814. // origin:this.orderDetail.website//来源
  815. // }
  816. // if (!this.currentReceipt.warehouseId) {
  817. // //当没有仓库id的时候调用新增仓库接口
  818. // await uni.$u.api.wareHouseAdd(warehouseData)
  819. // } else {
  820. // //当有仓库id的时候调用编辑仓库接口
  821. // warehouseData.id = this.currentReceipt.warehouseId
  822. // await uni.$u.api.wareHouseUpdate(warehouseData)
  823. // }
  824. // } else if (this.isWarehouse == '2') {
  825. // //等于2的时候不放入仓库表
  826. // }
  827. this.$refs.uToast.show({
  828. type: 'success',
  829. message: '收单成功',
  830. complete: () => {
  831. // uni.navigateBack({
  832. // delta: 1
  833. // })
  834. }
  835. })
  836. } catch (error) {
  837. console.error('收单失败:', error)
  838. uni.$u.toast('收单失败')
  839. }
  840. }
  841. }
  842. })
  843. }).catch(() => {
  844. uni.$u.toast('请输入正确的信息')
  845. })
  846. },
  847. //确认入库
  848. async confirmWarehouseEntry() {
  849. if (!this.orderDetail || !this.orderDetail.id) {
  850. uni.$u.toast('订单信息不存在')
  851. return
  852. }
  853. // 先请求最新订单状态,避免刚点完「确认收单」后仍是旧数据
  854. try {
  855. const res = await uni.$u.api.getClueSendFormVoByOrderId({ id: this.orderDetail.id })
  856. const latestOrder = (res.code === 200 && res.data) ? res.data : null
  857. if (latestOrder) {
  858. this.$emit('update-order-detail', latestOrder)
  859. this._latestOrderForWarehouse = latestOrder
  860. } else {
  861. this._latestOrderForWarehouse = null
  862. }
  863. const orderToCheck = latestOrder || this.orderDetail
  864. if (orderToCheck.status != '3') {
  865. uni.$u.toast('该订单未收单,不能入库')
  866. return
  867. }
  868. } catch (e) {
  869. console.error('获取订单状态失败', e)
  870. uni.$u.toast('获取订单状态失败')
  871. return
  872. }
  873. // 校验表单
  874. this.$refs.form.validate().then(() => {
  875. uni.showModal({
  876. title: '确认入库',
  877. content: `是否确认入库该订单:${this.orderDetail.item}-${this.currentReceipt.brand}?`,
  878. success: async (res) => {
  879. if (res.confirm) {
  880. //点击了确认入库,执行入库方法
  881. try {
  882. // 获取品牌ID
  883. const brandObj = this.brandList.find(item => item.dictLabel === this.currentReceipt.brand)
  884. const brandId = brandObj ? brandObj.dictValue : ''
  885. //建立入库data
  886. // 获取 PageThree 的高清实物图的 fileUrl 数组,顺序与 PageThree 的 displayImages 一致(按 fileIds 排序)
  887. let goodPicFileUrls = []
  888. if (this.currentReceipt.id && this.orderDetail.itemBrand) {
  889. try {
  890. const list = await imageUpload.getFileList(
  891. '2',
  892. '3',
  893. this.currentReceipt.id,
  894. this.orderDetail.itemBrand,
  895. this.currentReceipt.clueId
  896. )
  897. // 按 currentReceipt.fileIds 排序,与 PageThree 的 loadDetailImages 逻辑一致
  898. let sortedList = list || []
  899. if (this.currentReceipt.fileIds && sortedList.length > 0) {
  900. const sortedIds = this.currentReceipt.fileIds.split(',')
  901. sortedList = [...sortedList].sort((a, b) => {
  902. const indexA = sortedIds.indexOf(a.id)
  903. const indexB = sortedIds.indexOf(b.id)
  904. if (indexA === -1 && indexB === -1) return 0
  905. if (indexA === -1) return 1
  906. if (indexB === -1) return -1
  907. return indexA - indexB
  908. })
  909. }
  910. goodPicFileUrls = sortedList.map(item => item.fileUrl).filter(url => url)
  911. } catch (error) {
  912. console.error('获取高清实物图失败:', error)
  913. }
  914. }
  915. const warehouseData = {
  916. goodPicFileList: goodPicFileUrls,//商品图片 page3的高清实物图的url数组
  917. type: this.warehouseInfo.category || '',//商品分类
  918. dictLabel: this.currentReceipt.brand || '',//品牌名称
  919. dictValue: brandId || '',//品牌id
  920. indentifyCode: this.warehouseInfo.codeStorage || '',//独立编码
  921. costPrice: this.computedTotalCost || '',//总成本价
  922. recycleTime: dayjs().format('YYYY-MM-DD'),//回收时间 必填
  923. stockStatus: 0,//库存状态,0待入库,1已入库,因为是我们是预入库,所以是0
  924. origin: this.orderDetail.website,//来源
  925. actualPrice: this.currentReceipt.sellingPrice || '',//实价,也就是顶部的第三个价格sellingPrice
  926. price: this.currentReceipt.sellingPrice || '',//官方指导价,也就是顶部的第三个价格sellingPrice
  927. model: this.warehouseInfo.model || '',//型号
  928. recyclePerson: (this._latestOrderForWarehouse && this._latestOrderForWarehouse.receiptNickName != null) ? this._latestOrderForWarehouse.receiptNickName : (this.warehouseInfo.recyclePerson || ''),//回收人员:使用接口返回的收单人员姓名
  929. recyclePersonId: (this._latestOrderForWarehouse && this._latestOrderForWarehouse.receiptUserId != null) ? this._latestOrderForWarehouse.receiptUserId : (this.warehouseInfo.recyclePersonId || ''),//回收人员id:使用接口返回的收单人员id
  930. }
  931. if (!this.currentReceipt.warehouseId) {
  932. //当没有仓库id的时候调用新增仓库接口
  933. await uni.$u.api.wareHouseAdd(warehouseData)
  934. } else {
  935. // //当有仓库id的时候调用编辑仓库接口
  936. // warehouseData.id = this.currentReceipt.warehouseId
  937. // await uni.$u.api.wareHouseUpdate(warehouseData)
  938. }
  939. this.$refs.uToast.show({
  940. type: 'success',
  941. message: '入库成功',
  942. complete: () => {
  943. // uni.navigateBack({
  944. // delta: 1
  945. // })
  946. }
  947. })
  948. } catch (error) {
  949. console.error('入库失败:', error)
  950. uni.$u.toast('入库失败')
  951. }
  952. }
  953. }
  954. })
  955. }).catch(() => {
  956. uni.$u.toast('请输入正确的信息')
  957. })
  958. },
  959. /**
  960. * 上传分成
  961. */
  962. async addShare() {
  963. for (const item of this.profitSharingList) {
  964. const data = {
  965. id: item.id || '',
  966. accountType: item.accountType == '1' ? 1 : 2,
  967. clueId: this.currentReceipt.clueId,
  968. commissionRate: item.commissionRate,
  969. isCompanyPerformance: item.isCompanyPerformance == '1' ? 1 : 2,
  970. sendFormId: this.currentReceipt.sendFormId,
  971. userId: item.userId,
  972. userName: item.userName,
  973. receiptFormId: this.currentReceipt.id
  974. }
  975. if (item.id) {
  976. await uni.$u.api.clueCommissionUpdate(data)
  977. } else {
  978. await uni.$u.api.clueCommissionAdd(data)
  979. }
  980. }
  981. },
  982. selectIsWarehouse() {
  983. this.showIsWarehousePicker = true
  984. },
  985. handleConfirmIsWarehouse({ value }) {
  986. this.isWarehouse = value[0].value
  987. this.isWarehouseLabel = value[0].label
  988. this.showIsWarehousePicker = false
  989. },
  990. }
  991. }
  992. </script>
  993. <style scoped lang="scss">
  994. @import '../styles/common.scss';
  995. .page-four-container {
  996. @extend .page-container;
  997. padding-bottom: 100rpx;
  998. }
  999. .address-section {
  1000. padding: 20rpx;
  1001. // 防止 label 换行
  1002. ::v-deep .u-form-item__body__left__content__label {
  1003. white-space: nowrap !important;
  1004. overflow: visible;
  1005. }
  1006. }
  1007. .info-row {
  1008. margin-bottom: 20rpx;
  1009. }
  1010. .info-input {
  1011. height: 65rpx;
  1012. border-radius: 8rpx;
  1013. border: 1rpx solid #e5e7eb;
  1014. padding: 20rpx 16rpx;
  1015. width: 100%;
  1016. box-sizing: border-box;
  1017. }
  1018. .info-textarea {
  1019. width: 100%;
  1020. box-sizing: border-box;
  1021. ::v-deep .u-textarea {
  1022. min-height: 200rpx;
  1023. border-radius: 8rpx;
  1024. border: 1rpx solid #e5e7eb;
  1025. padding: 20rpx 16rpx;
  1026. line-height: 1.5;
  1027. }
  1028. ::v-deep textarea {
  1029. min-height: 200rpx;
  1030. border-radius: 8rpx;
  1031. width: 100%;
  1032. box-sizing: border-box;
  1033. line-height: 1.5;
  1034. font-size: 28rpx;
  1035. }
  1036. }
  1037. .click-wrapper {
  1038. width: 100%;
  1039. cursor: pointer;
  1040. display: flex;
  1041. align-items: center;
  1042. }
  1043. .image-uploader {
  1044. width: 100%;
  1045. height: 65rpx;
  1046. border: 2rpx dashed #409eff;
  1047. border-radius: 8rpx;
  1048. display: flex;
  1049. align-items: center;
  1050. justify-content: center;
  1051. cursor: pointer;
  1052. background-color: #ecf5ff;
  1053. }
  1054. .image-preview {
  1055. width: 100%;
  1056. height: 100%;
  1057. object-fit: cover;
  1058. border-radius: 10rpx;
  1059. }
  1060. .split-table {
  1061. width: 100%;
  1062. margin-top: 20rpx;
  1063. }
  1064. .split-table-header {
  1065. background-color: #f5f7fa;
  1066. padding: 15rpx 0;
  1067. border-bottom: 1rpx solid #e4e7ed;
  1068. }
  1069. .split-table-row {
  1070. padding: 15rpx 0;
  1071. border-bottom: 1rpx solid #e4e7ed;
  1072. align-items: center;
  1073. }
  1074. .header-text {
  1075. @include font-styles($size: tiny, $weight: regular, $color: tertiary);
  1076. text-align: center;
  1077. display: block;
  1078. }
  1079. .table-cell {
  1080. display: flex;
  1081. align-items: center;
  1082. justify-content: center;
  1083. padding: 0 10rpx;
  1084. }
  1085. .percentage-input {
  1086. text-align: center;
  1087. background-color: #f9f9f9;
  1088. padding: 0rpx !important;
  1089. }
  1090. .account-type {
  1091. padding: 4rpx 16rpx;
  1092. border-radius: 12rpx;
  1093. font-size: 24rpx;
  1094. font-weight: 500;
  1095. color: #fff;
  1096. text-align: center;
  1097. cursor: pointer;
  1098. &.frontend {
  1099. background-color: #409eff;
  1100. }
  1101. &.backend {
  1102. background-color: #909399;
  1103. }
  1104. }
  1105. .radio-wrapper {
  1106. cursor: pointer;
  1107. display: flex;
  1108. align-items: center;
  1109. justify-content: center;
  1110. }
  1111. .radio-circle {
  1112. width: 32rpx;
  1113. height: 32rpx;
  1114. border-radius: 50%;
  1115. border: 2rpx solid #dcdfe6;
  1116. display: flex;
  1117. align-items: center;
  1118. justify-content: center;
  1119. transition: all 0.3s ease;
  1120. &.active {
  1121. border-color: #67c23a;
  1122. background-color: #67c23a;
  1123. }
  1124. }
  1125. .confirm-button-container {
  1126. padding: 40rpx 0;
  1127. margin-top: 20rpx;
  1128. }
  1129. .confirm-button-container .next-btn {
  1130. width: 100%;
  1131. height: 80rpx;
  1132. line-height: 80rpx;
  1133. text-align: center;
  1134. border-radius: 11px;
  1135. }
  1136. .add-button-container {
  1137. justify-content: space-between;
  1138. }
  1139. </style>