produceList.vue 9.1 KB

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