PageFour.vue 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  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. }
  860. const orderToCheck = latestOrder || this.orderDetail
  861. if (orderToCheck.status != '3') {
  862. uni.$u.toast('该订单未收单,不能入库')
  863. return
  864. }
  865. } catch (e) {
  866. console.error('获取订单状态失败', e)
  867. uni.$u.toast('获取订单状态失败')
  868. return
  869. }
  870. // 校验表单
  871. this.$refs.form.validate().then(() => {
  872. uni.showModal({
  873. title: '确认入库',
  874. content: `是否确认入库该订单:${this.orderDetail.item}-${this.currentReceipt.brand}?`,
  875. success: async (res) => {
  876. if (res.confirm) {
  877. //点击了确认入库,执行入库方法
  878. try {
  879. // 获取品牌ID
  880. const brandObj = this.brandList.find(item => item.dictLabel === this.currentReceipt.brand)
  881. const brandId = brandObj ? brandObj.dictValue : ''
  882. //建立入库data
  883. // 获取 PageThree 的高清实物图的 fileUrl 数组,顺序与 PageThree 的 displayImages 一致(按 fileIds 排序)
  884. let goodPicFileUrls = []
  885. if (this.currentReceipt.id && this.orderDetail.itemBrand) {
  886. try {
  887. const list = await imageUpload.getFileList(
  888. '2',
  889. '3',
  890. this.currentReceipt.id,
  891. this.orderDetail.itemBrand,
  892. this.currentReceipt.clueId
  893. )
  894. // 按 currentReceipt.fileIds 排序,与 PageThree 的 loadDetailImages 逻辑一致
  895. let sortedList = list || []
  896. if (this.currentReceipt.fileIds && sortedList.length > 0) {
  897. const sortedIds = this.currentReceipt.fileIds.split(',')
  898. sortedList = [...sortedList].sort((a, b) => {
  899. const indexA = sortedIds.indexOf(a.id)
  900. const indexB = sortedIds.indexOf(b.id)
  901. if (indexA === -1 && indexB === -1) return 0
  902. if (indexA === -1) return 1
  903. if (indexB === -1) return -1
  904. return indexA - indexB
  905. })
  906. }
  907. goodPicFileUrls = sortedList.map(item => item.fileUrl).filter(url => url)
  908. } catch (error) {
  909. console.error('获取高清实物图失败:', error)
  910. }
  911. }
  912. const warehouseData = {
  913. goodPicFileList: goodPicFileUrls,//商品图片 page3的高清实物图的url数组
  914. type: this.warehouseInfo.category || '',//商品分类
  915. dictLabel: this.currentReceipt.brand || '',//品牌名称
  916. dictValue: brandId || '',//品牌id
  917. indentifyCode: this.warehouseInfo.codeStorage || '',//独立编码
  918. costPrice: this.computedTotalCost || '',//总成本价
  919. recycleTime: dayjs().format('YYYY-MM-DD'),//回收时间 必填
  920. stockStatus: 0,//库存状态,0待入库,1已入库,因为是我们是预入库,所以是0
  921. origin: this.orderDetail.website,//来源
  922. actualPrice: this.currentReceipt.sellingPrice || '',//实价,也就是顶部的第三个价格sellingPrice
  923. price: this.currentReceipt.sellingPrice || '',//官方指导价,也就是顶部的第三个价格sellingPrice
  924. model: this.warehouseInfo.model || '',//型号
  925. }
  926. if (!this.currentReceipt.warehouseId) {
  927. //当没有仓库id的时候调用新增仓库接口
  928. await uni.$u.api.wareHouseAdd(warehouseData)
  929. } else {
  930. // //当有仓库id的时候调用编辑仓库接口
  931. // warehouseData.id = this.currentReceipt.warehouseId
  932. // await uni.$u.api.wareHouseUpdate(warehouseData)
  933. }
  934. this.$refs.uToast.show({
  935. type: 'success',
  936. message: '入库成功',
  937. complete: () => {
  938. // uni.navigateBack({
  939. // delta: 1
  940. // })
  941. }
  942. })
  943. } catch (error) {
  944. console.error('入库失败:', error)
  945. uni.$u.toast('入库失败')
  946. }
  947. }
  948. }
  949. })
  950. }).catch(() => {
  951. uni.$u.toast('请输入正确的信息')
  952. })
  953. },
  954. /**
  955. * 上传分成
  956. */
  957. async addShare() {
  958. for (const item of this.profitSharingList) {
  959. const data = {
  960. id: item.id || '',
  961. accountType: item.accountType == '1' ? 1 : 2,
  962. clueId: this.currentReceipt.clueId,
  963. commissionRate: item.commissionRate,
  964. isCompanyPerformance: item.isCompanyPerformance == '1' ? 1 : 2,
  965. sendFormId: this.currentReceipt.sendFormId,
  966. userId: item.userId,
  967. userName: item.userName,
  968. receiptFormId: this.currentReceipt.id
  969. }
  970. if (item.id) {
  971. await uni.$u.api.clueCommissionUpdate(data)
  972. } else {
  973. await uni.$u.api.clueCommissionAdd(data)
  974. }
  975. }
  976. },
  977. selectIsWarehouse() {
  978. this.showIsWarehousePicker = true
  979. },
  980. handleConfirmIsWarehouse({ value }) {
  981. this.isWarehouse = value[0].value
  982. this.isWarehouseLabel = value[0].label
  983. this.showIsWarehousePicker = false
  984. },
  985. }
  986. }
  987. </script>
  988. <style scoped lang="scss">
  989. @import '../styles/common.scss';
  990. .page-four-container {
  991. @extend .page-container;
  992. padding-bottom: 100rpx;
  993. }
  994. .address-section {
  995. padding: 20rpx;
  996. // 防止 label 换行
  997. ::v-deep .u-form-item__body__left__content__label {
  998. white-space: nowrap !important;
  999. overflow: visible;
  1000. }
  1001. }
  1002. .info-row {
  1003. margin-bottom: 20rpx;
  1004. }
  1005. .info-input {
  1006. height: 65rpx;
  1007. border-radius: 8rpx;
  1008. border: 1rpx solid #e5e7eb;
  1009. padding: 20rpx 16rpx;
  1010. width: 100%;
  1011. box-sizing: border-box;
  1012. }
  1013. .info-textarea {
  1014. width: 100%;
  1015. box-sizing: border-box;
  1016. ::v-deep .u-textarea {
  1017. min-height: 200rpx;
  1018. border-radius: 8rpx;
  1019. border: 1rpx solid #e5e7eb;
  1020. padding: 20rpx 16rpx;
  1021. line-height: 1.5;
  1022. }
  1023. ::v-deep textarea {
  1024. min-height: 200rpx;
  1025. border-radius: 8rpx;
  1026. width: 100%;
  1027. box-sizing: border-box;
  1028. line-height: 1.5;
  1029. font-size: 28rpx;
  1030. }
  1031. }
  1032. .click-wrapper {
  1033. width: 100%;
  1034. cursor: pointer;
  1035. display: flex;
  1036. align-items: center;
  1037. }
  1038. .image-uploader {
  1039. width: 100%;
  1040. height: 65rpx;
  1041. border: 2rpx dashed #409eff;
  1042. border-radius: 8rpx;
  1043. display: flex;
  1044. align-items: center;
  1045. justify-content: center;
  1046. cursor: pointer;
  1047. background-color: #ecf5ff;
  1048. }
  1049. .image-preview {
  1050. width: 100%;
  1051. height: 100%;
  1052. object-fit: cover;
  1053. border-radius: 10rpx;
  1054. }
  1055. .split-table {
  1056. width: 100%;
  1057. margin-top: 20rpx;
  1058. }
  1059. .split-table-header {
  1060. background-color: #f5f7fa;
  1061. padding: 15rpx 0;
  1062. border-bottom: 1rpx solid #e4e7ed;
  1063. }
  1064. .split-table-row {
  1065. padding: 15rpx 0;
  1066. border-bottom: 1rpx solid #e4e7ed;
  1067. align-items: center;
  1068. }
  1069. .header-text {
  1070. @include font-styles($size: tiny, $weight: regular, $color: tertiary);
  1071. text-align: center;
  1072. display: block;
  1073. }
  1074. .table-cell {
  1075. display: flex;
  1076. align-items: center;
  1077. justify-content: center;
  1078. padding: 0 10rpx;
  1079. }
  1080. .percentage-input {
  1081. text-align: center;
  1082. background-color: #f9f9f9;
  1083. padding: 0rpx !important;
  1084. }
  1085. .account-type {
  1086. padding: 4rpx 16rpx;
  1087. border-radius: 12rpx;
  1088. font-size: 24rpx;
  1089. font-weight: 500;
  1090. color: #fff;
  1091. text-align: center;
  1092. cursor: pointer;
  1093. &.frontend {
  1094. background-color: #409eff;
  1095. }
  1096. &.backend {
  1097. background-color: #909399;
  1098. }
  1099. }
  1100. .radio-wrapper {
  1101. cursor: pointer;
  1102. display: flex;
  1103. align-items: center;
  1104. justify-content: center;
  1105. }
  1106. .radio-circle {
  1107. width: 32rpx;
  1108. height: 32rpx;
  1109. border-radius: 50%;
  1110. border: 2rpx solid #dcdfe6;
  1111. display: flex;
  1112. align-items: center;
  1113. justify-content: center;
  1114. transition: all 0.3s ease;
  1115. &.active {
  1116. border-color: #67c23a;
  1117. background-color: #67c23a;
  1118. }
  1119. }
  1120. .confirm-button-container {
  1121. padding: 40rpx 0;
  1122. margin-top: 20rpx;
  1123. }
  1124. .confirm-button-container .next-btn {
  1125. width: 100%;
  1126. height: 80rpx;
  1127. line-height: 80rpx;
  1128. text-align: center;
  1129. border-radius: 11px;
  1130. }
  1131. .add-button-container {
  1132. justify-content: space-between;
  1133. }
  1134. </style>