| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- <template>
- <view class="mx3">
- <my-add-button @handleClick="openSpare" />
- <view class="main-color-bg main-bg-future"></view>
- <view class="p3 bg-color-white form-view">
- <u-form :model="form" :error-type="['message']" ref="uForm" >
- <view class="main-color-text f-size-32 f-weight-6">领用信息</view>
- <u-form-item label="仓库名称" prop="storeId" required label-width="150">
- <my-select
- :list="storeList"
- :value-name="'id'"
- :label-name="'name'"
- v-model="form.storeId"
- placeholder="请选择仓库"
- @selected="storeSelect"
- />
- </u-form-item>
- <u-form-item label="备品用途" prop="type" label-width="150">
- <my-select
- :list="reasonList"
- v-model="form.reason"
- @selected="typeSelect"
- placeholder="请选择备品用途" />
- </u-form-item>
- <u-form-item label="领用说明" label-width="150">
- <u-input type="textarea" v-model="form.remark" />
- </u-form-item>
- </u-form>
- </view>
- <view class="shop-car">
- <commonCar :list="goodsProducts" @delect="delect" @accounts="accounts">
- </commonCar>
- <image src="" mode=""></image>
- </view>
- </view>
- </template>
- <script>
- import commonCar from '@/components/shopCar/shopCar.vue'
- export default {
- components: { commonCar },
- data() {
- return {
- goodsProducts: [{
- name: '华为旗舰店',
- checked: 1,
- goods: []
- }],
- form: {
- storeId: '',
- type: '',
- reason: '',
- storeName: null
- },
- receiveDetailFormList: [
- ],
- backSpareId: '',
- backSpareName: '',
- backFormName: '',
- backPrice: 0,
- isRefreshDetail: true,
- sbSpareList: [],
- storeList: [],
- reasonList: [
- {
- label: '施工领用',
- value: '施工领用'
- }, {
- label: '办公领用',
- value: '办公领用'
- }, {
- label: '维修领用',
- value: '维修领用'
- }, {
- label: '其他领用',
- value: '其他领用'
- }
- ],
- rules: {
- reason: [
- {
- required: true,
- message: '请选择备品用途',
- trigger: ['change']
- }
- ],
- storeId: [
- {
- required: true,
- message: '请选择仓库',
- trigger: ['change']
- }
- ]
- },
- detailFormRules: {
- spareId: [
- {
- required: true,
- message: '请选择备品',
- trigger: ['change']
- }
- ],
- num: [
- {
- required: true,
- message: '请填写数量',
- trigger: ['change', 'blur']
- }
- ]
- },
- id: '', // 列表 id
- aId: 0
- };
- },
- created () {
- },
- onShow() {
- // 获取设备与仓库
- this.initData();
- const pages = getCurrentPages();
- const currPage = pages[pages.length - 1];
- if(currPage.goods != null && currPage.goods.length > 0){
- currPage.goods.forEach(item => {
- let find = false
- this.goodsProducts[0].goods.forEach(spare => {
- if (spare.spareId === item.spareId) {
- find = true
- return
- }
- })
- if(!find){
- this.goodsProducts[0].goods.push(item)
- }
- })
- currPage.goods = null
- }
- },
- onLoad(options) {},
- methods: {
- // 刪除
- delect(e){
- this.goodsProducts[0].goods.forEach((item,index) => {
- if (item.checked === 2) {
- this.goodsProducts[0].goods.splice(index, 1)
- return
- }
- })
- },
- // 提交
- accounts(e){
- const params = { ...this.form }
- const detailList = []
- this.goodsProducts[0].goods.forEach(item => {
- const detail = {
- spareId: item.spareId,
- num: item.number,
- price: item.price,
- spareName: item.spareName,
- totalPrice: this.$BaseTool.Number.mul(item.number, item.price)
- }
- detailList.push(detail);
- })
- params.detailList = detailList;
- this.$Http.addSparePickForm(params).then(res => {
- uni.redirectTo({
- url: '/pages/receive/receive-detail?id=' + res.data.id
- });
- })
- },
- del(index) {
- console.log(this.receiveDetailFormList);
- this.receiveDetailFormList.splice(index, 1)
- console.log(this.receiveDetailFormList);
- },
- handleSelect(formName) {
- console.log('formName:' + formName)
- uni.navigateTo({
- url: '/pages/search/spare-search?storeId=' + encodeURIComponent(JSON.stringify(this.form.storeId)) + '&formName=' + encodeURIComponent(JSON.stringify(formName))
- })
- },
- initData() {
- if(this.storeList.length == 0){
- this.$Http.getStorePage({ filter: 2, pageNum: 1, pageSize: 1000 })
- .then(res => {
- this.storeList = res.data.rows
- })
- }
- },
- openSpare() {
- if (this.$BaseTool.String.isBlank(this.form.storeId)) {
- uni.showToast({
- title: '请先选择仓库',
- icon: 'none'
- });
- return
- }
- uni.navigateTo({
- url: '/pages/search/spare-search-goods?storeId=' + encodeURIComponent(JSON.stringify(this.form.storeId))
- })
- },
- storeSelect(value, item) {
- this.form.storeName = item.name;
- this.isRefreshDetail = true;
- this.receiveDetailFormList = []
- },
- typeSelect(value, item) {
- this.isRefreshDetail = true;
- //this.receiveDetailFormList = []
- },
- spareSelect(value, item) {
- this.receiveDetailFormList.forEach(spare => {
- if (spare.spareId === item.spareId) {
- spare.item = item;
- } else {
- console.log(2222, spare.spareId, item.id)
- }
- })
- },
- // 提交
- submit() {
- if (this.receiveDetailFormList == null || this.receiveDetailFormList.length === 0) {
- uni.showToast({
- title: '请添加领用明细',
- icon: 'none'
- });
- return
- }
- const promiseList = []
- promiseList.push(
- new Promise((resolve, reject) => {
- this.$refs.uForm.validate().then(valid => {
- if (valid) {
- resolve(valid);
- } else {
- reject(valid);
- }
- })
- })
- );
- this.receiveDetailFormList.forEach(item => {
- promiseList.push(
- new Promise((resolve, reject) => {
- this.$refs[item.formName][0].validate(valid => {
- if (valid) {
- resolve(valid);
- } else {
- reject(valid);
- }
- })
- })
- );
- })
- Promise.all(promiseList).then(res => {
- // 执行
- const params = { ...this.form }
- const detailList = []
- this.receiveDetailFormList.forEach(item => {
- const space = item.item;
- const detail = {
- spareId: item.spareId,
- num: item.num,
- price: item.price,
- spareName: item.spareName,
- storeNum: item.num,
- totalPrice: this.$BaseTool.Number.mul(item.num, item.price)
- }
- detailList.push(detail);
- })
- params.detailList = detailList;
- console.log(33, params)
- this.$Http.addSparePickForm(params).then(res => {
- uni.redirectTo({
- url: '/pages/receive/receive'
- });
- })
- }, err => {
- console.log(err)
- })
- }
- },
- onReady() {
- console.log(4444, this.$refs.uForm)
- this.$refs.uForm.setRules(this.rules);
- }
- };
- </script>
- <style lang="less">
- page {
- background-color: #f4f4f4;
- }
- .mt-3-imt {
- margin-top: 30rpx;
- }
- .shop-car {
- min-height: 100vh;
- display: flex;
- flex-direction: column;
- align-items: center;
- background: #F5F5F5;
- }
- </style>
|