| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 |
- <template>
- <view class="mainBox">
- <view v-for="(item, index) in tableList" :key="index" style="position: relative;">
- <myCard :item="item" :btnList="btnList" :index="index+1" :columns="columns" @del="del(index)">
- <u--input slot="totalCount" @input="changeCount(item,index)" type="number" placeholder="请输入"
- border="surround" :disabled="!!contractId" v-model="item.totalCount">
- </u--input>
- <u--input :disabled="!!contractId" slot="singleWeight" @input="singleWeightChange(item,index)"
- type="number" placeholder="请输入" border="surround" v-model="item.singleWeight"></u--input>
- <u--input :disabled="!!contractId" slot="singlePrice" style="flex:none;width: 50%;"
- @input="getTotalPrice()" type="number" placeholder="请输入" border="surround"
- v-model="item.singlePrice">
- <template slot="suffix">元</template>
- </u--input>
- <uni-datetime-picker :disabled="!!contractId" type="date" slot="customerExpectDeliveryDeadline"
- v-model="item.customerExpectDeliveryDeadline">
- </uni-datetime-picker>
- <u--input :disabled="!!contractId" slot="guaranteePeriod" placeholder="请输入" border="surround"
- v-model="item.guaranteePeriod"></u--input>
- <uni-data-picker :readonly="!!contractId" slot="guaranteePeriodUnitCode"
- v-model="item.guaranteePeriodUnitCode" placeholder="请选择" :localdata="date_unit">
- </uni-data-picker>
- <u--input slot="customerMark" placeholder="请输入" border="surround" v-model="item.customerMark">
- </u--input>
- <u--input slot="productBrand" placeholder="请输入" border="surround" :disabled="item.productCode"
- v-model="item.productBrand">
- </u--input>
- <u--input slot="specification" placeholder="请输入" border="surround" :disabled="item.productCode"
- v-model="item.specification">
- </u--input>
- <u--input slot="measuringUnit" placeholder="请输入" border="surround" :disabled="item.productCode"
- v-model="item.measuringUnit">
- </u--input>
- <u--input slot="modelType" placeholder="请输入" border="surround" :disabled="item.productCode"
- v-model="item.modelType">
- </u--input>
- <u--input slot="productName" placeholder="请输入" border="surround" :disabled="item.productCode"
- v-model="item.productName">
- </u--input>
- </myCard>
- </view>
- <view style="height: 84rpx;" v-if="isDrawer"></view>
- <view class="footerButton" v-if="isDrawer">
- <u-button type="primary" @click="save" text="保存"></u-button>
- </view>
- <view class="add" @click="add" v-if="!contractId">
- <u-icon name="plus" color="#fff"></u-icon>
- </view>
- <u-action-sheet :actions="addList" :show="show" :closeOnClickOverlay="true" :closeOnClickAction="true"
- @close="show=false" @select='select'> </u-action-sheet>
- </view>
- </template>
- <script>
- import {
- getByCode
- } from '@/api/pda/common.js'
- import myCard from './myCard.vue'
- export default {
- data() {
- return {
- tableList: [],
- addList: [{
- name: '选择物品清单',
- },
- {
- name: '新增临时产品',
- }
- ],
- show: false,
- current: {},
- date_unit: [],
- allPrice: '',
- btnList: [{
- name: '删除',
- apiName: 'del',
- btnType: 'error ',
- type: '2',
- pageUrl: '',
- }],
- defaultForm: {
- key: null,
- endTime: '',
- isFirst: 0,
- name: '',
- startTime: '',
- workHour: '',
- guaranteePeriodUnitCode: '',
- technicalDrawings: [],
- arrivalWay: 1
- }
- }
- },
- props: {
- isDrawer: {
- default: false
- },
- pricingWay: {
- default: 1
- },
- isTemporary: {
- //临时
- type: Boolean,
- default: false
- },
- contractId: '',
- columns: {
- type: Array,
- default: () => [
- [{
- label: '产品名称:',
- prop: 'productName',
- slot: 'productName',
- type: 'title',
- className: 'perce100',
- }],
- [{
- label: '编码:',
- prop: 'productCode'
- }, {
- label: '牌号:',
- prop: 'productBrand',
- slot: 'productBrand',
- }],
- [{
- label: '规格:',
- prop: 'specification',
- slot: 'specification',
- }, {
- label: '型号:',
- prop: 'modelType',
- slot: 'modelType',
- }],
- [{
- label: '数量:',
- prop: 'totalCount',
- slot: 'totalCount',
- }, {
- label: '计量单位:',
- prop: 'measuringUnit',
- slot: 'measuringUnit',
- }],
- [{
- label: '单重:',
- prop: 'singleWeight',
- slot: 'singleWeight',
- }, {
- label: '总重:',
- prop: 'totalWeight',
- }],
- [{
- label: '单价:',
- prop: 'singlePrice',
- slot: 'singlePrice',
- }, {
- label: '合计:',
- prop: 'totalPrice',
- formatter: (item) => {
- return (item.totalPrice || '') + '元'
- }
- }],
- [{
- label: '客户期望交期:',
- prop: 'customerExpectDeliveryDeadline',
- slot: 'customerExpectDeliveryDeadline',
- className: 'perce100',
- }],
- [{
- label: '质保期:',
- prop: 'guaranteePeriod',
- slot: 'guaranteePeriod',
- }, {
- label: '单位:',
- prop: 'guaranteePeriodUnitCode',
- slot: 'guaranteePeriodUnitCode',
- }],
- [{
- label: '操作:',
- prop: 'action',
- type: 'action',
- className: 'perce100',
- }],
- ]
- }
- },
- components: {
- myCard
- },
- created() {
- uni.$off('setProduceList')
- uni.$on('setProduceList', (data) => {
- data.forEach(item => {
- item['productId'] = item.id
- item['categoryName'] = item.name
- item['productCategoryId'] = item.categoryLevelId
- item['productBrand'] = item.brandNum
- item['productCategoryName'] = item.categoryLevelPath
- item['productCode'] = item.code
- item['productName'] = item.name
- item['approvalNumber'] = item.extField.approvalNumber
- item['packingSpecification'] = item.extField.packingSpecification
- item['packageDispositionList'] = item.packageDispositionList
- if (item.packageDispositionList?.length) {
- item['saleUnitId'] = item.packageDispositionList[0].id
- item['saleUnit'] = item.packageDispositionList[0].conversionUnit
- }
- })
- this.tableList.push(...data)
- })
- this.getByCode()
- },
- watch: {
- contractId(val) {
- if (val) {
- this.btnList = []
- }
- }
- },
- methods: {
- add() {
- if (this.isTemporary) {
- this.show = true
- } else {
- uni.navigateTo({
- url: '/pages/saleManage/components/selectProduce?isAll=' + 1
- })
- }
- },
- select({
- name
- }) {
- if (name == '选择物品清单') {
- uni.navigateTo({
- url: '/pages/saleManage/components/selectProduce?isAll=' + 1
- })
- } else {
- this.handlAdd()
- }
- },
- // 添加
- handlAdd() {
- let item = JSON.parse(JSON.stringify(this.defaultForm));
- item.key = this.tableList.length + 1;
- this.tableList.push(item);
- },
- init(list) {
- if (list) {
- this.tableList = JSON.parse(JSON.stringify(list))
- this.getTotalPrice(list)
- }
- },
- getValue() {
- return this.tableList
- },
- del(index) {
- this.tableList.splice(index, 1);
- },
- getByCode() {
- const codeS = ['date_unit']
- codeS.forEach(async (code) => {
- const codeValue = await getByCode(code);
- this[code] = codeValue.map(item => {
- const key = Object.keys(item)[0]
- return {
- value: key,
- text: item[key]
- }
- })
- })
- },
- save() {
- uni.$emit('setBusinessOpportunity')
- },
- //改变数量
- changeCount(row, index) {
- this.singleWeightChange(row, index);
- this.getTotalPrice();
- },
- //计算总金额
- getTotalPrice(row) {
- if (this.tableList.length) {
- let sum = 0;
- sum = this.getNumTotalPrice();
- let allsum = sum.toFixed(2);
- this.allPrice = allsum;
- if (!row) {
- uni.$emit('allsum', allsum)
- }
- return allsum;
- } else {
- this.allPrice = 0.0;
- if (!row) {
- uni.$emit('allsum', allsum)
- }
- return 0.0;
- }
- //回显总金额
- },
- //计算总金额
- getNumTotalPrice(sum = 0) {
- this.tableList.forEach((r, index) => {
- this.$set(
- r,
- 'discountSinglePrice',
- r.singlePrice ? Number(r.singlePrice) : ''
- );
- if (r.singlePrice && r.totalCount) {
- r.totalPrice = this.getAllPrice(r);
- r.discountTotalPrice = this.getDiscountTotalPrice(r);
- this.$set(this.tableList[index], 'totalPrice', Number(r.totalPrice));
- this.$set(
- this.tableList[index],
- 'discountTotalPrice',
- Number(r.discountTotalPrice)
- );
- sum += Number(r.totalPrice);
- } else {
- this.$set(r, 'totalPrice', '');
- this.$set(r, 'discountTotalPrice', '');
- }
- });
- return isNaN(sum) ? 0 : sum;
- },
- //计算单重
- singleWeightChange(row, index) {
- if (row.weightUnit == row.measuringUnit) {
- this.$set(this.tableList[index], 'totalWeight', row.totalCount);
- } else if (row.totalCount && row.singleWeight) {
- this.$set(this.tableList[index], 'totalWeight', (row.singleWeight * row.totalCount).toFixed(2) || 0);
- } else {
- this.$set(this.tableList[index], 'totalWeight', 0);
- }
- },
- //获取合计
- getAllPrice(row) {
- let num = Number(row.singlePrice) * Number(row.totalCount);
- return isNaN(num) ? '' : num.toFixed(2);
- },
- //设置优惠后总金额修改产品单价
- discountInputByOrder(val) {
- //获取优惠金额和总计的差价
- this.tableList.forEach((item) => {
- if (val === 0) {
- item.discountTotalPrice = 0;
- item.discountSinglePrice = 0;
- return;
- }
- if (!val) {
- item.discountTotalPrice = item.totalPrice;
- item.discountSinglePrice = item.singlePrice;
- return;
- }
- //获取折让单价
- item.discountSinglePrice = this.getDiscountSinglePrice(item, val);
- item.discountTotalPrice = this.getDiscountTotalPrice(item, val);
- });
- this.$forceUpdate()
- },
- //获取折让单价
- getDiscountSinglePrice(row, val) {
- let num =
- (Number(val) / Number(this.allPrice)) *
- Number(row.singlePrice);
- return isNaN(num) ? '' : num;
- },
- //获取折让合计
- getDiscountTotalPrice(row, val) {
- let num = Number(row.discountSinglePrice) * Number(row.totalCount);
- return isNaN(num) ? '' : num.toFixed(2);
- },
- //设置客户代号
- setCustomerMark(val) {
- this.tableList.forEach((item, index) => {
- this.$set(this.tableList[index], 'customerMark', val)
- })
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .add {
- width: 96rpx;
- height: 96rpx;
- border-radius: 48rpx;
- background: #3c9cff;
- position: fixed;
- bottom: 100rpx;
- right: 24rpx;
- display: flex;
- align-items: center;
- justify-content: center;
- z-index: 99;
- }
- .footerButton {
- width: 100%;
- height: 84rpx;
- display: flex;
- position: fixed;
- bottom: 0;
- z-index: 10;
- /deep/.u-button {
- height: 100%;
- }
- >view {
- flex: 1;
- }
- }
- /deep/.u-swipe-action-item__right__button__wrapper {
- background-color: #f56c6c !important;
- }
- </style>
|