produceList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <template>
  2. <view class="mainBox">
  3. <view v-for="(item, index) in tableList" :key="index" style="position: relative;">
  4. <myCard :item="item" :btnList="btnList" :index="index+1" :columns="columns" @del="del(index)">
  5. <u--input slot="totalCount" @input="changeCount(item,index)" type="number" placeholder="请输入"
  6. border="surround" :disabled="!!contractId" v-model="item.totalCount">
  7. </u--input>
  8. <u--input :disabled="!!contractId" slot="singleWeight" @input="singleWeightChange(item,index)"
  9. type="number" placeholder="请输入" border="surround" v-model="item.singleWeight"></u--input>
  10. <u--input :disabled="!!contractId" slot="singlePrice" style="flex:none;width: 50%;"
  11. @input="getTotalPrice()" type="number" placeholder="请输入" border="surround"
  12. v-model="item.singlePrice">
  13. <template slot="suffix">元</template>
  14. </u--input>
  15. <uni-datetime-picker :disabled="!!contractId" type="date" slot="customerExpectDeliveryDeadline"
  16. v-model="item.customerExpectDeliveryDeadline">
  17. </uni-datetime-picker>
  18. <u--input :disabled="!!contractId" slot="guaranteePeriod" placeholder="请输入" border="surround"
  19. v-model="item.guaranteePeriod"></u--input>
  20. <uni-data-picker :readonly="!!contractId" slot="guaranteePeriodUnitCode"
  21. v-model="item.guaranteePeriodUnitCode" placeholder="请选择" :localdata="date_unit">
  22. </uni-data-picker>
  23. <u--input slot="customerMark" placeholder="请输入" border="surround" v-model="item.customerMark">
  24. </u--input>
  25. <u--input slot="productBrand" placeholder="请输入" border="surround" :disabled="item.productCode"
  26. v-model="item.productBrand">
  27. </u--input>
  28. <u--input slot="specification" placeholder="请输入" border="surround" :disabled="item.productCode"
  29. v-model="item.specification">
  30. </u--input>
  31. <u--input slot="measuringUnit" placeholder="请输入" border="surround" :disabled="item.productCode"
  32. v-model="item.measuringUnit">
  33. </u--input>
  34. <u--input slot="modelType" placeholder="请输入" border="surround" :disabled="item.productCode"
  35. v-model="item.modelType">
  36. </u--input>
  37. <u--input slot="productName" placeholder="请输入" border="surround" :disabled="item.productCode"
  38. v-model="item.productName">
  39. </u--input>
  40. </myCard>
  41. </view>
  42. <view style="height: 84rpx;" v-if="isDrawer"></view>
  43. <view class="footerButton" v-if="isDrawer">
  44. <u-button type="primary" @click="save" text="保存"></u-button>
  45. </view>
  46. <view class="add" @click="add" v-if="!contractId">
  47. <u-icon name="plus" color="#fff"></u-icon>
  48. </view>
  49. <u-action-sheet :actions="addList" :show="show" :closeOnClickOverlay="true" :closeOnClickAction="true"
  50. @close="show=false" @select='select'> </u-action-sheet>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. getByCode
  56. } from '@/api/pda/common.js'
  57. import myCard from './myCard.vue'
  58. export default {
  59. data() {
  60. return {
  61. tableList: [],
  62. addList: [{
  63. name: '选择物品清单',
  64. },
  65. {
  66. name: '新增临时产品',
  67. }
  68. ],
  69. show: false,
  70. current: {},
  71. date_unit: [],
  72. allPrice: '',
  73. btnList: [{
  74. name: '删除',
  75. apiName: 'del',
  76. btnType: 'error ',
  77. type: '2',
  78. pageUrl: '',
  79. }],
  80. defaultForm: {
  81. key: null,
  82. endTime: '',
  83. isFirst: 0,
  84. name: '',
  85. startTime: '',
  86. workHour: '',
  87. guaranteePeriodUnitCode: '',
  88. technicalDrawings: [],
  89. arrivalWay: 1
  90. }
  91. }
  92. },
  93. props: {
  94. isDrawer: {
  95. default: false
  96. },
  97. pricingWay: {
  98. default: 1
  99. },
  100. isTemporary: {
  101. //临时
  102. type: Boolean,
  103. default: false
  104. },
  105. contractId: '',
  106. columns: {
  107. type: Array,
  108. default: () => [
  109. [{
  110. label: '产品名称:',
  111. prop: 'productName',
  112. slot: 'productName',
  113. type: 'title',
  114. className: 'perce100',
  115. }],
  116. [{
  117. label: '编码:',
  118. prop: 'productCode'
  119. }, {
  120. label: '牌号:',
  121. prop: 'productBrand',
  122. slot: 'productBrand',
  123. }],
  124. [{
  125. label: '规格:',
  126. prop: 'specification',
  127. slot: 'specification',
  128. }, {
  129. label: '型号:',
  130. prop: 'modelType',
  131. slot: 'modelType',
  132. }],
  133. [{
  134. label: '数量:',
  135. prop: 'totalCount',
  136. slot: 'totalCount',
  137. }, {
  138. label: '计量单位:',
  139. prop: 'measuringUnit',
  140. slot: 'measuringUnit',
  141. }],
  142. [{
  143. label: '单重:',
  144. prop: 'singleWeight',
  145. slot: 'singleWeight',
  146. }, {
  147. label: '总重:',
  148. prop: 'totalWeight',
  149. }],
  150. [{
  151. label: '单价:',
  152. prop: 'singlePrice',
  153. slot: 'singlePrice',
  154. }, {
  155. label: '合计:',
  156. prop: 'totalPrice',
  157. formatter: (item) => {
  158. return (item.totalPrice || '') + '元'
  159. }
  160. }],
  161. [{
  162. label: '客户期望交期:',
  163. prop: 'customerExpectDeliveryDeadline',
  164. slot: 'customerExpectDeliveryDeadline',
  165. className: 'perce100',
  166. }],
  167. [{
  168. label: '质保期:',
  169. prop: 'guaranteePeriod',
  170. slot: 'guaranteePeriod',
  171. }, {
  172. label: '单位:',
  173. prop: 'guaranteePeriodUnitCode',
  174. slot: 'guaranteePeriodUnitCode',
  175. }],
  176. [{
  177. label: '操作:',
  178. prop: 'action',
  179. type: 'action',
  180. className: 'perce100',
  181. }],
  182. ]
  183. }
  184. },
  185. components: {
  186. myCard
  187. },
  188. created() {
  189. uni.$off('setProduceList')
  190. uni.$on('setProduceList', (data) => {
  191. data.forEach(item => {
  192. item['productId'] = item.id
  193. item['categoryName'] = item.name
  194. item['productCategoryId'] = item.categoryLevelId
  195. item['productBrand'] = item.brandNum
  196. item['productCategoryName'] = item.categoryLevelPath
  197. item['productCode'] = item.code
  198. item['productName'] = item.name
  199. item['approvalNumber'] = item.extField.approvalNumber
  200. item['packingSpecification'] = item.extField.packingSpecification
  201. item['packageDispositionList'] = item.packageDispositionList
  202. if (item.packageDispositionList?.length) {
  203. item['saleUnitId'] = item.packageDispositionList[0].id
  204. item['saleUnit'] = item.packageDispositionList[0].conversionUnit
  205. }
  206. })
  207. this.tableList.push(...data)
  208. })
  209. this.getByCode()
  210. },
  211. watch: {
  212. contractId(val) {
  213. if (val) {
  214. this.btnList = []
  215. }
  216. }
  217. },
  218. methods: {
  219. add() {
  220. if (this.isTemporary) {
  221. this.show = true
  222. } else {
  223. uni.navigateTo({
  224. url: '/pages/saleManage/components/selectProduce?isAll=' + 1
  225. })
  226. }
  227. },
  228. select({
  229. name
  230. }) {
  231. if (name == '选择物品清单') {
  232. uni.navigateTo({
  233. url: '/pages/saleManage/components/selectProduce?isAll=' + 1
  234. })
  235. } else {
  236. this.handlAdd()
  237. }
  238. },
  239. // 添加
  240. handlAdd() {
  241. let item = JSON.parse(JSON.stringify(this.defaultForm));
  242. item.key = this.tableList.length + 1;
  243. this.tableList.push(item);
  244. },
  245. init(list) {
  246. if (list) {
  247. this.tableList = JSON.parse(JSON.stringify(list))
  248. this.getTotalPrice(list)
  249. }
  250. },
  251. getValue() {
  252. return this.tableList
  253. },
  254. del(index) {
  255. this.tableList.splice(index, 1);
  256. },
  257. getByCode() {
  258. const codeS = ['date_unit']
  259. codeS.forEach(async (code) => {
  260. const codeValue = await getByCode(code);
  261. this[code] = codeValue.map(item => {
  262. const key = Object.keys(item)[0]
  263. return {
  264. value: key,
  265. text: item[key]
  266. }
  267. })
  268. })
  269. },
  270. save() {
  271. uni.$emit('setBusinessOpportunity')
  272. },
  273. //改变数量
  274. changeCount(row, index) {
  275. this.singleWeightChange(row, index);
  276. this.getTotalPrice();
  277. },
  278. //计算总金额
  279. getTotalPrice(row) {
  280. if (this.tableList.length) {
  281. let sum = 0;
  282. sum = this.getNumTotalPrice();
  283. let allsum = sum.toFixed(2);
  284. this.allPrice = allsum;
  285. if (!row) {
  286. uni.$emit('allsum', allsum)
  287. }
  288. return allsum;
  289. } else {
  290. this.allPrice = 0.0;
  291. if (!row) {
  292. uni.$emit('allsum', allsum)
  293. }
  294. return 0.0;
  295. }
  296. //回显总金额
  297. },
  298. //计算总金额
  299. getNumTotalPrice(sum = 0) {
  300. this.tableList.forEach((r, index) => {
  301. this.$set(
  302. r,
  303. 'discountSinglePrice',
  304. r.singlePrice ? Number(r.singlePrice) : ''
  305. );
  306. if (r.singlePrice && r.totalCount) {
  307. r.totalPrice = this.getAllPrice(r);
  308. r.discountTotalPrice = this.getDiscountTotalPrice(r);
  309. this.$set(this.tableList[index], 'totalPrice', Number(r.totalPrice));
  310. this.$set(
  311. this.tableList[index],
  312. 'discountTotalPrice',
  313. Number(r.discountTotalPrice)
  314. );
  315. sum += Number(r.totalPrice);
  316. } else {
  317. this.$set(r, 'totalPrice', '');
  318. this.$set(r, 'discountTotalPrice', '');
  319. }
  320. });
  321. return isNaN(sum) ? 0 : sum;
  322. },
  323. //计算单重
  324. singleWeightChange(row, index) {
  325. if (row.weightUnit == row.measuringUnit) {
  326. this.$set(this.tableList[index], 'totalWeight', row.totalCount);
  327. } else if (row.totalCount && row.singleWeight) {
  328. this.$set(this.tableList[index], 'totalWeight', (row.singleWeight * row.totalCount).toFixed(2) || 0);
  329. } else {
  330. this.$set(this.tableList[index], 'totalWeight', 0);
  331. }
  332. },
  333. //获取合计
  334. getAllPrice(row) {
  335. let num = Number(row.singlePrice) * Number(row.totalCount);
  336. return isNaN(num) ? '' : num.toFixed(2);
  337. },
  338. //设置优惠后总金额修改产品单价
  339. discountInputByOrder(val) {
  340. //获取优惠金额和总计的差价
  341. this.tableList.forEach((item) => {
  342. if (val === 0) {
  343. item.discountTotalPrice = 0;
  344. item.discountSinglePrice = 0;
  345. return;
  346. }
  347. if (!val) {
  348. item.discountTotalPrice = item.totalPrice;
  349. item.discountSinglePrice = item.singlePrice;
  350. return;
  351. }
  352. //获取折让单价
  353. item.discountSinglePrice = this.getDiscountSinglePrice(item, val);
  354. item.discountTotalPrice = this.getDiscountTotalPrice(item, val);
  355. });
  356. this.$forceUpdate()
  357. },
  358. //获取折让单价
  359. getDiscountSinglePrice(row, val) {
  360. let num =
  361. (Number(val) / Number(this.allPrice)) *
  362. Number(row.singlePrice);
  363. return isNaN(num) ? '' : num;
  364. },
  365. //获取折让合计
  366. getDiscountTotalPrice(row, val) {
  367. let num = Number(row.discountSinglePrice) * Number(row.totalCount);
  368. return isNaN(num) ? '' : num.toFixed(2);
  369. },
  370. //设置客户代号
  371. setCustomerMark(val) {
  372. this.tableList.forEach((item, index) => {
  373. this.$set(this.tableList[index], 'customerMark', val)
  374. })
  375. },
  376. }
  377. }
  378. </script>
  379. <style lang="scss" scoped>
  380. .add {
  381. width: 96rpx;
  382. height: 96rpx;
  383. border-radius: 48rpx;
  384. background: #3c9cff;
  385. position: fixed;
  386. bottom: 100rpx;
  387. right: 24rpx;
  388. display: flex;
  389. align-items: center;
  390. justify-content: center;
  391. z-index: 99;
  392. }
  393. .footerButton {
  394. width: 100%;
  395. height: 84rpx;
  396. display: flex;
  397. position: fixed;
  398. bottom: 0;
  399. z-index: 10;
  400. /deep/.u-button {
  401. height: 100%;
  402. }
  403. >view {
  404. flex: 1;
  405. }
  406. }
  407. /deep/.u-swipe-action-item__right__button__wrapper {
  408. background-color: #f56c6c !important;
  409. }
  410. </style>