inquiryTable.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <view>
  3. <view class="mainBox" v-for="(supplier, sIndex) in supplierList" :key="supplier.supplierId || sIndex">
  4. <!-- 供应商头部 -->
  5. <view class="supplier-header">
  6. <view class="supplier-name">
  7. <text class="label">供应商:</text>
  8. <text class="value">{{ supplier.supplierName || '-' }}</text>
  9. </view>
  10. <view class="supplier-summary">
  11. <view class="summary-item">
  12. <text class="label">总价:</text>
  13. <text class="value price">{{ supplier.totalPrice || '-' }}</text>
  14. </view>
  15. <view class="summary-item">
  16. <text class="label">优惠后:</text>
  17. <text v-if="isView" class="value price">{{ supplier.preferentialPrice || '-' }}</text>
  18. <u--input v-else type="number" border="surround" v-model="supplier.preferentialPrice"
  19. placeholder="请输入优惠金额" style="width: 200rpx; display: inline-block;"></u--input>
  20. </view>
  21. <view class="summary-item">
  22. <text class="label">结算方式:</text>
  23. <text v-if="isView" class="value">{{ supplier.settlementModeName || '-' }}</text>
  24. <uni-data-picker v-else v-model="supplier.settlementMode" placeholder="请选择"
  25. :localdata="settlementModeList" @change="onSettlementChange(supplier)"></uni-data-picker>
  26. </view>
  27. <view class="summary-item">
  28. <text class="label">交货日期:</text>
  29. <text v-if="isView" class="value">{{ supplier.deliveryDate || '-' }}</text>
  30. <uni-datetime-picker v-else type="date" v-model="supplier.deliveryDate"
  31. @change="onDeliveryDateChange(supplier)"></uni-datetime-picker>
  32. </view>
  33. </view>
  34. <view class="supplier-summary">
  35. <view class="summary-item">
  36. <text class="label">附件:</text>
  37. </view>
  38. <fileMain :type="isView ? 'view' : ''" :value="supplier.files"
  39. @input="val => onSupplierFilesChange(sIndex, val)"></fileMain>
  40. </view>
  41. </view>
  42. <!-- 报价明细 -->
  43. <view v-for="(item, index) in (supplier.resultList || [])" :key="index">
  44. <myCard :item="item" :btnList="btnList" :index="index + 1" :columns="columns"
  45. @del="delProduct(sIndex, index)">
  46. <!-- 名称 -->
  47. <view slot="productName">
  48. <text style="font-weight: 600;">{{ item.productName || '-' }}</text>
  49. </view>
  50. <!-- 是否中标 -->
  51. <view slot="isWinner">
  52. <u-tag v-if="isView && item.isWinner == 1" text="中标" size="mini" type="success"></u-tag>
  53. <u-tag v-else-if="isView" text="未中标" size="mini" type="warning"></u-tag>
  54. <uni-data-picker v-else v-model="item.isWinner" placeholder="请选择"
  55. :localdata="isWinnerList"></uni-data-picker>
  56. </view>
  57. <!-- 数量 -->
  58. <view slot="purchaseCount">
  59. <view v-if="isView">{{ (item.purchaseCount || item.totalCount || '-') + ' ' + (item.purchaseUnit || item.measuringUnit || '') }}</view>
  60. <view v-else>
  61. <u-row>
  62. <u-col span="6">
  63. <u--input type="number" placeholder="数量" border="surround" v-model="item.purchaseCount"
  64. @input="changeCount(supplier, sIndex, index)"></u--input>
  65. </u-col>
  66. <u-col span="6">
  67. <uni-data-picker v-model="item.purchaseUnitId" placeholder="单位"
  68. :localdata="item.packageDispositionList || []"
  69. :map="{
  70. text: 'conversionUnit',
  71. value: 'id'
  72. }"
  73. @change="changeCount(supplier, sIndex, index)"></uni-data-picker>
  74. </u-col>
  75. </u-row>
  76. </view>
  77. </view>
  78. <!-- 单价 -->
  79. <view slot="singlePrice">
  80. <text v-if="isView">{{ item.singlePrice ? item.singlePrice + ' 元' : '-' }}</text>
  81. <u--input v-else type="number" placeholder="请输入单价" border="surround" v-model="item.singlePrice"
  82. @input="changeCount(supplier, sIndex, index)"></u--input>
  83. </view>
  84. <!-- 金额 -->
  85. <view slot="totalPrice">
  86. <text v-if="item.totalPrice">{{ item.totalPrice }} 元</text>
  87. <text v-else>-</text>
  88. </view>
  89. <!-- 税率(必填) -->
  90. <view slot="taxRate">
  91. <text v-if="isView">{{ item.taxRate || item.taxRate === 0 ? item.taxRate + '%' : '-' }}</text>
  92. <u--input v-else type="number" placeholder="请输入税率" border="surround" v-model="item.taxRate"
  93. @input="calcItemTotal(supplier, index)"></u--input>
  94. </view>
  95. <!-- 供应商产品名称 -->
  96. <view slot="supplierProductName">
  97. <text v-if="isView">{{ item.supplierProductName || item.supplierProductCode || '-' }}</text>
  98. <u--input v-else placeholder="请输入供应商产品名称" border="surround" v-model="item.supplierProductName"></u--input>
  99. </view>
  100. <!-- 供应商产品编码 -->
  101. <view slot="supplierProductCode">
  102. <text v-if="isView">{{ item.supplierProductCode || '-' }}</text>
  103. <u--input v-else placeholder="供应商产品编码" border="surround" v-model="item.supplierProductCode"></u--input>
  104. </view>
  105. <!-- 不含税单价 -->
  106. <view slot="notaxSinglePrice">
  107. <text>{{ item.notaxSinglePrice ? item.notaxSinglePrice + ' 元' : '-' }}</text>
  108. </view>
  109. <!-- 型号 -->
  110. <view slot="modelType">
  111. <text v-if="isView">{{ item.modelType || '-' }}</text>
  112. <u--input v-else placeholder="型号" border="surround" v-model="item.modelType"></u--input>
  113. </view>
  114. <!-- 规格 -->
  115. <view slot="specification">
  116. <text v-if="isView">{{ item.specification || '-' }}</text>
  117. <u--input v-else placeholder="规格" border="surround" v-model="item.specification"></u--input>
  118. </view>
  119. <!-- 产地(多选) -->
  120. <view slot="provenance">
  121. <text v-if="isView">{{ getProvenanceLabel(item.provenance) || '-' }}</text>
  122. <u--input v-else placeholder="点击选择产地" border="surround"
  123. :value="getProvenanceLabel(item.provenance)" @click.native="openProvenancePicker(sIndex, index)"></u--input>
  124. </view>
  125. <!-- 交期 -->
  126. <view slot="deliveryDays">
  127. <text v-if="isView">{{ item.deliveryDays || '-' }}</text>
  128. <u--input v-else type="number" placeholder="交期(天)" border="surround" v-model="item.deliveryDays"></u--input>
  129. </view>
  130. <!-- 有效期 -->
  131. <view slot="guaranteePeriod">
  132. <text v-if="isView">{{ item.guaranteePeriod || '-' }}</text>
  133. <u--input v-else type="number" placeholder="有效期" border="surround" v-model="item.guaranteePeriod"></u--input>
  134. </view>
  135. <!-- 有效期单位 -->
  136. <view slot="guaranteePeriodUnitCode">
  137. <text v-if="isView">{{ getGuaranteeUnitLabel(item.guaranteePeriodUnitCode) || '-' }}</text>
  138. <uni-data-picker v-else v-model="item.guaranteePeriodUnitCode" placeholder="请选择" :localdata="guaranteeUnitList" @change="onGuaranteeUnitChange(item)"></uni-data-picker>
  139. </view>
  140. <!-- 备注 -->
  141. <view slot="remark">
  142. <text v-if="isView">{{ item.remark || '-' }}</text>
  143. <u--input v-else placeholder="备注" border="surround" v-model="item.remark"></u--input>
  144. </view>
  145. <!-- 附件 -->
  146. <view slot="files">
  147. <fileMain :value="item.files || []" :type="isView ? 'view' : ''" v-if="item.files && item.files.length"></fileMain>
  148. <text v-else>-</text>
  149. </view>
  150. </myCard>
  151. </view>
  152. <u-gap height="20" bgColor="#f0f0f0"></u-gap>
  153. </view>
  154. <ba-tree-picker ref="provenancePicker" :multiple="true" @select-change="provenanceConfirm"
  155. title="选择产地" :localdata="provenanceList" valueKey="value" textKey="text" childrenKey="children" />
  156. </view>
  157. </template>
  158. <script>
  159. import myCard from '@/pages/purchasingManage/components/myCard.vue'
  160. import fileMain from "@/pages/doc/index.vue"
  161. import { changeCountNew as productChangeCount } from '@/utils/setProduct.js'
  162. import dictMixns from "@/mixins/dictMixins";
  163. import { mapGetters, mapActions } from 'vuex'
  164. import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
  165. export default {
  166. mixins: [dictMixns],
  167. components: {
  168. myCard,
  169. fileMain,
  170. baTreePicker
  171. },
  172. props: {
  173. supplierList: {
  174. type: Array,
  175. default: () => []
  176. },
  177. status: {
  178. type: String,
  179. default: 'edit'
  180. }
  181. },
  182. data() {
  183. return {
  184. isWinnerList: [
  185. { text: '是', value: 1 },
  186. { text: '否', value: 0 }
  187. ],
  188. settlementModeList: [],
  189. provenanceList: [],
  190. guaranteeUnitList: [],
  191. curProvenanceSIndex: -1,
  192. curProvenancePIndex: -1
  193. }
  194. },
  195. computed: {
  196. ...mapGetters(['dict', 'getDict', 'getDictValue']),
  197. isView() {
  198. return this.status === 'Detail'
  199. },
  200. btnList() {
  201. return this.isView ? [] : [{
  202. name: '删除',
  203. apiName: 'del',
  204. btnType: 'error',
  205. type: '2'
  206. }]
  207. },
  208. columns() {
  209. return [
  210. [{
  211. label: '产品名称:', prop: 'productName', slot: 'productName',
  212. type: 'title', className: 'perce100'
  213. }],
  214. [{ label: '编码:', prop: 'productCode' }, {
  215. label: '是否中标:', prop: 'isWinner', slot: 'isWinner',
  216. isRequired: !this.isView
  217. }],
  218. [{
  219. label: '数量:', prop: 'purchaseCount', slot: 'purchaseCount',
  220. isRequired: !this.isView
  221. }, {
  222. label: '采购单价:', prop: 'singlePrice', slot: 'singlePrice',
  223. isRequired: !this.isView
  224. }],
  225. [{ label: '采购金额:', prop: 'totalPrice', slot: 'totalPrice' }, {
  226. label: '税率:', prop: 'taxRate', slot: 'taxRate',
  227. isRequired: !this.isView
  228. }],
  229. [{ label: '不含税单价:', prop: 'notaxSinglePrice', slot: 'notaxSinglePrice', className: 'perce100' }],
  230. [{
  231. label: '供应商产品:', prop: 'supplierProductName', slot: 'supplierProductName',
  232. className: 'perce100', isRequired: !this.isView
  233. }],
  234. [{
  235. label: '供应商产品编码:', prop: 'supplierProductCode', slot: 'supplierProductCode',
  236. className: 'perce100'
  237. }],
  238. [{ label: '型号:', prop: 'modelType', slot: 'modelType' }, { label: '规格:', prop: 'specification', slot: 'specification' }],
  239. [{ label: '产地:', prop: 'provenance', slot: 'provenance', className: 'perce100' }],
  240. [{ label: '需求数量:', prop: 'reqTotalCount' }, { label: '库存:', prop: 'availableCountBase' }],
  241. [{ label: '最低订购量:', prop: 'minimumOrderQuantity' }, { label: '包装规格:', prop: 'packingSpecification' }],
  242. [{ label: '交期(天):', prop: 'deliveryDays', slot: 'deliveryDays' }, {
  243. label: '有效期:', prop: 'guaranteePeriod', slot: 'guaranteePeriod'
  244. }],
  245. [{
  246. label: '有效期单位:', prop: 'guaranteePeriodUnitCode', slot: 'guaranteePeriodUnitCode',
  247. className: 'perce100'
  248. }],
  249. [{ label: '工序:', prop: 'taskName' }, { label: '批次号:', prop: 'batchNo' }],
  250. [{ label: '备注:', prop: 'remark', slot: 'remark', className: 'perce100' }],
  251. // [{ label: '附件:', prop: 'files', slot: 'files', className: 'perce100' }]
  252. ]
  253. }
  254. },
  255. async created() {
  256. if (!this.isView) {
  257. await this.requestDict('结算方式')
  258. await this.requestDict('产地')
  259. await this.requestDict('质保期单位')
  260. this.settlementModeList = this.dict?.['settlement_mode']?.map(item => ({
  261. text: item.dictValue,
  262. value: item.dictCode
  263. })) || []
  264. this.provenanceList = this.dict?.['purchase_origin']?.map(item => ({
  265. text: item.dictValue,
  266. value: item.dictCode
  267. })) || []
  268. this.guaranteeUnitList = this.dict?.['date_unit']?.map(item => ({
  269. text: item.dictValue,
  270. value: item.dictCode
  271. })) || []
  272. this.setDeliveryDays()
  273. }
  274. },
  275. methods: {
  276. // 改变数量/单价 → 重算金额
  277. changeCount(supplier, sIndex, pIndex) {
  278. console.log(supplier, sIndex, pIndex)
  279. const item = supplier.resultList[pIndex]
  280. if (!item) return
  281. // 包装单位换算
  282. const changed = productChangeCount(item, {
  283. countKey: 'purchaseCount',
  284. unitKey: 'purchaseUnit',
  285. unitIdKey: 'purchaseUnitId'
  286. })
  287. this.$set(supplier.resultList, pIndex, changed)
  288. // 计算金额
  289. this.calcItemTotal(supplier, pIndex)
  290. // 更新总价
  291. this.calcSupplierTotal(supplier)
  292. },
  293. // 单项金额 = 数量 * 单价
  294. calcItemTotal(supplier, pIndex) {
  295. console.log('calcItemTotal', supplier, pIndex)
  296. const item = supplier.resultList[pIndex]
  297. if (item.singlePrice && item.purchaseCount) {
  298. item.totalPrice = +(item.singlePrice * item.purchaseCount).toFixed(2)
  299. }
  300. // 不含税单价(税率在报价明细中,每个产品独立)
  301. if (item.singlePrice && item.taxRate) {
  302. item.notaxSinglePrice = +(item.singlePrice / (1 + item.taxRate / 100)).toFixed(2)
  303. }
  304. },
  305. // 供应商总价 = 所有报价项金额之和
  306. calcSupplierTotal(supplier) {
  307. let total = 0
  308. supplier.resultList.forEach(item => {
  309. total += item.totalPrice || 0
  310. })
  311. supplier.totalPrice = +total.toFixed(2)
  312. supplier.preferentialPrice = supplier.totalPrice
  313. },
  314. onSettlementChange(supplier) {
  315. const found = this.settlementModeList.find(i => i.value === supplier.settlementMode)
  316. if (found) supplier.settlementModeName = found.text
  317. },
  318. onDeliveryDateChange(supplier) {
  319. supplier.resultList.forEach((item, index) => {
  320. if (supplier.deliveryDate && item.expectReceiveDate) {
  321. const deliver = new Date(supplier.deliveryDate).getTime()
  322. const expect = new Date(item.expectReceiveDate).getTime()
  323. if (deliver > expect) {
  324. uni.showToast({ title: '交货日期大于到货日期', icon: 'none' })
  325. }
  326. }
  327. })
  328. },
  329. onSupplierFilesChange(sIndex, val) {
  330. const supplier = this.supplierList[sIndex]
  331. if (supplier) this.$set(supplier, 'files', val)
  332. },
  333. getProvenanceLabel(val) {
  334. if (!val || !val.length) return ''
  335. return val.map(v => {
  336. const found = this.provenanceList.find(p => p.value == v)
  337. return found ? found.text : v
  338. }).join(', ')
  339. },
  340. getGuaranteeUnitLabel(val) {
  341. const found = this.guaranteeUnitList.find(g => g.value == val)
  342. return found ? found.text : val || ''
  343. },
  344. onGuaranteeUnitChange(item) {
  345. const found = this.guaranteeUnitList.find(g => g.value == item.guaranteePeriodUnitCode)
  346. if (found) item.guaranteePeriodUnitName = found.text
  347. },
  348. openProvenancePicker(sIndex, pIndex) {
  349. this.curProvenanceSIndex = sIndex
  350. this.curProvenancePIndex = pIndex
  351. this.$refs.provenancePicker._show()
  352. },
  353. provenanceConfirm(data, name, allList) {
  354. if (this.curProvenanceSIndex === -1 || this.curProvenancePIndex === -1) return
  355. const supplier = this.supplierList[this.curProvenanceSIndex]
  356. const item = supplier?.resultList[this.curProvenancePIndex]
  357. if (!item) return
  358. const selectedValues = (allList || []).map(s => s.id)
  359. console.log(selectedValues, allList)
  360. this.$set(item, 'provenance', selectedValues)
  361. this.curProvenanceSIndex = -1
  362. this.curProvenancePIndex = -1
  363. },
  364. delProduct(sIndex, pIndex) {
  365. const supplier = this.supplierList[sIndex]
  366. if (!supplier) return
  367. supplier.resultList.splice(pIndex, 1)
  368. },
  369. // 获取表格数据(供父组件保存时调用)
  370. getTableValue() {
  371. return this.supplierList
  372. },
  373. setDeliveryDays() {
  374. this.supplierList.forEach(supplier => {
  375. supplier.resultList.forEach((item, index) => {
  376. let day =
  377. supplier.deliveryDate &&
  378. (new Date(supplier.deliveryDate).getTime() -
  379. new Date().getTime()) /
  380. 1000 /
  381. 60 /
  382. 60 /
  383. 24;
  384. this.$set(
  385. supplier.resultList[index],
  386. 'deliveryDays',
  387. Math.ceil(day) || 1
  388. );
  389. });
  390. })
  391. this.$forceUpdate();
  392. },
  393. }
  394. }
  395. </script>
  396. <style lang="scss" scoped>
  397. .mainBox {
  398. background: #fff;
  399. margin-bottom: 10rpx;
  400. }
  401. .supplier-header {
  402. padding: 20rpx 30rpx;
  403. background: #f8fdf8;
  404. border-bottom: 2rpx solid #e5e5e5;
  405. .supplier-name {
  406. font-size: 30rpx;
  407. font-weight: 600;
  408. color: #333;
  409. margin-bottom: 12rpx;
  410. .label {
  411. color: #999;
  412. font-weight: 400;
  413. }
  414. .value {
  415. color: #157A2C;
  416. font-weight: 600;
  417. }
  418. }
  419. .supplier-summary {
  420. display: flex;
  421. flex-wrap: wrap;
  422. align-items: center;
  423. .summary-item {
  424. margin-right: 30rpx;
  425. margin-bottom: 6rpx;
  426. display: flex;
  427. align-items: center;
  428. .label {
  429. font-size: 24rpx;
  430. color: #999;
  431. }
  432. .value {
  433. font-size: 24rpx;
  434. color: #333;
  435. &.price {
  436. color: #E6A23C;
  437. font-weight: 600;
  438. }
  439. }
  440. }
  441. }
  442. }
  443. .price-tag {
  444. color: #E6A23C;
  445. font-weight: 600;
  446. }
  447. /deep/.u-input {
  448. padding: 0 !important;
  449. height: 44rpx !important;
  450. font-size: 26rpx !important;
  451. }
  452. /deep/.uni-date-editor--x .uni-date__icon-clear {
  453. border: none !important;
  454. }
  455. /deep/.uni-date__x-input,
  456. /deep/.uni-date-x {
  457. padding: 0 !important;
  458. height: 44rpx !important;
  459. font-size: 26rpx !important;
  460. }
  461. </style>