123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827 |
- <script>
- import orderApi from "@/api/business/purchase/purchase-order";
- import { initColumns, initDicts, initRules, initParams } from "@/utils/init";
- import { async } from "q";
- import { Columns, TabColumns } from "./column";
- const NewColumns = initColumns(Columns);
- const NewTabColumns = TabColumns.map((element) => ({
- ...element,
- tableColumns: initColumns(element.tableColumns),
- }));
- const SelectColumns = NewColumns.filter(
- (column) => column.inputType === "Select"
- );
- NewTabColumns.forEach((column) => {
- SelectColumns.push(
- ...column.tableColumns.filter((cColumn) => cColumn.inputType === "Select")
- );
- });
- export default {
- name: "AddPurchaseOrderDrawer",
- dicts: initDicts(SelectColumns),
- components: {
- FileUploadCenter: () => import("../components/FileUploadCenter/index.vue"),
- popDialog: () => import("@/components/PopDialog/index.vue"),
- },
- data() {
- return {
- visible: false,
- columns: NewColumns,
- rules: initRules(NewColumns),
- params: {
- ...initParams(NewColumns),
- puOrderItemList: [],
- puOrderExecuteList: [],
- },
- tabColumns: NewTabColumns,
- tabName: "puOrderItemList",
- isCopy:false,
- };
- },
- computed: {},
- watch: {
- "params.puOrderItemList": {
- handler(nVal, oVal) {
- this.visible &&
- this.handleSynchronousMaterial(
- "puOrderItemList",
- "puOrderExecuteList"
- );
- },
- deep: true,
- },
- "params.puOrderExecuteList": {
- handler(nVal, oVal) {
- this.visible &&
- this.handleSynchronousMaterial(
- "puOrderExecuteList",
- "puOrderItemList"
- );
- },
- deep: true,
- },
- // "params.puOrg": {
- // handler(nVal, oVal) {
- // console.log('nVal', nVal, 'oVal',oVal);
- // console.log(this.isCopy, 'this.isCopy');
- // // 组织变化
- // // if (this.visible && nVal.puOrg != oVal.puOrg) {
- // if (this.visible && oVal && nVal != oVal) {
- // for (const key in this.params) {
- // if (Array.isArray(this.params[key])) {
- // this.params[key] = [];
- // } else if (
- // key != "puOrg" &&
- // key != "puOrgName" &&
- // key != "buyer" &&
- // key != "buyerName" &&
- // key != "puDept" &&
- // key != "puDeptName" &&
- // key != "status"
- // ) {
- // this.params[key] = "";
- // } else {
- // }
- // }
- // }
- // },
- // deep: true,
- // },
- },
- methods: {
- beforeOpen() {
- if(!this.isCopy){
- const { deptName, deptId, name, nickName, orgName, orgId } = this.$store.state.user;
- this.params.puOrg = orgId;
- this.params.puOrgName = orgName;
- this.params.buyer = name;
- this.params.buyerName = nickName;
- this.params.puDept = deptId;
- this.params.puDeptName = deptName;
- this.params.billDate = new Date().Format('yyyy-MM-dd');
- console.log(this.params,'this.params');
- this.addTableRow();
- }
- },
- setVisible(prop,iscopy) {
- this.visible = prop;
- this.isCopy = iscopy;
- if(!this.visible){
- this.$refs['orderAddForm'].clearValidate();
- }
- },
- // 复制赋值
- async setCopyParams(id) {
- try {
- const { code, msg, data } = await orderApi.details(id);
- if (code === 200) {
- this.params = {
- ...data,
- id: "",
- code: "",
- isEnd:'N',
- status: "0",
- source: "3",
- isClose:'N',
- closeTime:'',
- isInvoice:'N',
- isSendWms:'N',
- rebateMoney:'',
- invoiceMoney:'',
- paymentMoney:'',
- applyPaymentMoney:'',
- };
- for (const key in this.params) {
- // if (Array.isArray(this.params[key])) {
- if (key === 'puOrderItemList' || key === 'puOrderExecuteList') {
- this.params[key].forEach((v) => {
- v.id = "";
- });
- }
- }
- // 清空 累计本币开票金额、
- // 累计付款金额、累计付款申请金额、累计开票主数量、最终关闭时间
- // 、最终关闭、已同步WMS 、订单抵扣余额金额、订单使用返利金额、 发票标识
-
- }
- } catch (err) {
- //
- } finally {
- // this.loading = false;
- }
- },
- // 增行
- addTableRow(prop) {
- for (const key in this.params) {
- // if (Array.isArray(this.params[key])) {
- if (key === 'puOrderItemList' || key === 'puOrderExecuteList') {
- const arr = this.tabColumns.find(
- (element) => element.key === key
- ).tableColumns;
- let rowData = initParams(arr, "key", "value");
-
- "rowno" in rowData &&
- (rowData["rowno"] = this.params[key].length + 1);
- // 物料
- if("rowNo" in rowData){
- rowData["rowNo"] = this.params[key].length + 1;
- // 扣税类别
- rowData["taxDeductClassify"] = '1';
- // 价格类型
- rowData["priceType"] = 'order';
- // 币种
- rowData["currency"] = '1002Z0100000000001K1';
- rowData["currencyName"] = '人民币';
- }
-
- // 是否完成询价,新增明细行需默认明细为false
- rowData["whetherCompleteInquiry"] = false;
- this.params[key].push(rowData);
- }
- }
- // const arr = this.tabColumns.find(
- // (element) => element.key === this.tabName
- // ).tableColumns;
- // prop.push(initParams(arr, "key", "value"));
- },
- // 删行
- async delTableRow(prop, index) {
- for (const key in this.params) {
- // if (Array.isArray(this.params[key])) {
- if (key === 'puOrderItemList' || key === 'puOrderExecuteList') {
- this.params[key].splice(index, 1);
- }
- }
- await this.handleGetPrice();
- // prop.splice(index, 1);
- },
- // 同步子表物料
- handleSynchronousMaterial(tableOne, tableTwo) {
- let _this = this;
- // this.params[tableOne]-- -> this.params[tableTwo]
- this.params[tableOne] &&
- this.params[tableOne].forEach((item, index) => {
- for (const key in item) {
- if(!_this.params[tableTwo][index]){
- const arr = _this.tabColumns.find(
- (element) => element.key === tableTwo
- ).tableColumns;
- _this.params[tableTwo].push(initParams(arr, "key", "value"));
- }
-
- if (key in _this.params[tableTwo][index]) {
- _this.params[tableTwo][index].material = item.material;
- key !== 'id' && ( _this.params[tableTwo][index][key] = item[key]);
- }
- }
- });
- },
- // 取消
- handleCancel() {
- this.params = {
- ...initParams(this.columns),
- puOrderItemList: [],
- puOrderExecuteList: [],
- };
- this.setVisible(false);
- },
- // 判断保存条件
- judgeSaveCondition(cb){
- this.$refs['orderAddForm'].validate(async (valid) => {
- if (valid) {
- if(!this.params['puOrderItemList'].length || !this.params['puOrderExecuteList'].length){
- this.$message.error('请填写订单行!');
- return false;
- }
- // puOrderItemList
- let isPrice = this.params.puOrderItemList.filter(item => !item.whetherCompleteInquiry);
- if(isPrice.length){
- this.$message.error('询价失败!');
- return false
- }
- console.log(isPrice,'isPrice');
- cb();
- } else {
- this.$message.error('存在必填项未填写');
- console.log('error submit!!');
- return false;
- }
- });
- },
- // 保存
- handleSava() {
- console.log(this.params,'this.params---------');
- this.judgeSaveCondition(async()=>{
- try {
- this.loading = true;
- const { code, msg } = await orderApi.create(this.params);
- if (code === 200) {
- this.handleCancel();
- }
- } catch (err) {
- //
- } finally {
- this.loading = false;
- }
- })
- },
- // 保存并新增
- async handleSubmit() {
- this.judgeSaveCondition(async()=>{
- try {
- const createById = this.params.buyer;
- const createByName = this.params.buyerName;
- const updateById = this.$store.state.user.id;
- const updateByName = this.$store.state.user.name;
- const { code, msg } = await orderApi.create({
- createById,
- createByName,
- updateById,
- updateByName,
- ...this.params,
- });
- if (code === 200) {
- this.setVisible(false);
- }
- } catch (err) {
- this.$notify.error({ title: "error", message: err });
- } finally {
- // this.setVisible(false);
- }
- })
- },
- // 主表参照改变之后
- async handleReferChange(val, type, source){
- // 供应商选择
- if( type === 'SUPPLIER_PARAM' ){
- let page = { pageNum: 1 , pageSize: 10 };
- let relevanceRefer = [
- {
- // 供应商联系人
- key:'supplierContacts',
- params:{
- type:'SUPPLIERCONTACTS_PARAM',
- supplierId:val.id,
- }
- },
- {
- // 供应商业务员
- key:'supplierPersonal',
- params:{
- type:'PSNLICENSE_PARAM',
- supplierId:val.id,
- pkOrg: source.puOrg,
- }
- }
- ]
- await relevanceRefer.forEach(async (refer) =>{
- try {
- const { code, rows} = await orderApi.REFER(
- {
- ...refer.params,
- search: "",
- isPage: true,
- }, page );
- if (code === 200) {
- source[refer.key] = rows[0]? rows[0].id :'';
- source[`${refer.key}Name`] = rows[0] ? rows[0].name :'';
- }
-
- } catch (error) {}
-
- })
-
- }
- // 组织
- if(type === 'ORG_PARAM'){
- for (const key in this.params) {
- // if (Array.isArray(this.params[key])) {
- if (key === 'puOrderItemList' || key === 'puOrderExecuteList') {
- this.params[key] = [];
- }
- else if(key === 'sysFileRecordList'){
- this.params[key] = [];
- }
- else if (
- key != "puOrg" &&
- key != "puOrgName" &&
- key != "buyer" &&
- key != "buyerName" &&
- key != "puDept" &&
- key != "puDeptName" &&
- key != "status"
- ) {
- this.params[key] = "";
- } else {
- }
- }
-
- }
- },
- // 下拉框选择改变
- handleSelectChange(val,typeName){
- if(val === 'billType'){
- this.params['billTypeName'] = this.dict.type[typeName].find(item => item.value == this.params[val]).label;
- }
- },
- // 子表参照改变之后
- async handleTabReferChange(val, type, source) {
- // 触发物料参照询价 && source.qty && source.qty != ""
- if (type == "MATERIAL_PARAM" && source.qty && source.qty != "") {
- source['qty'] = 0;
- source['whetherCompleteInquiry'] = false;
- source['taxPrice'] = 0;
- source['money'] = 0;
- source['taxDeductMoneya'] = 0;
- source['price'] = 0;
-
- source['notaxMoney'] = 0;
- source['tax'] = 0;
- this.params['qty'] = 0;
- this.params['originalQty'] = 0;
- this.params['money'] = 0;
- this.params['originalMoney'] = 0;
- this.params['notaxMoney'] = 0;
- source.isDrug = val.materialMedcine.isDrug == '0' ? 'Y' : 'N';
- // await this.handleGetPrice();
- }
- },
- // 子表下拉框改变
- async handleTabSelectChange(type,row){
-
- if(type == 'priceType' && row.material && row.qty && row.qty != ""){
- row['whetherCompleteInquiry'] = false;
- await this.handleGetPrice();
- }
- },
- // 子表inputNumber
- handleInputChange(row, type) {
- // 物料数量变化----询价
- if (type == "qty" && row.material) {
- row['whetherCompleteInquiry'] = false;
- row.qty && this.handleGetPrice();
- }
- },
- // 子表多选框改变
- handleTabCheckbox(type,source){
- // 勾选赠品,价税合计更新为0,含税单价、无税单价更新为0
- if(type === 'isGift' && source.material && source.qty && source.qty != ""){
- source['whetherCompleteInquiry'] = false;
- this.handleGetPrice()
- }
- },
- // 询价 getPrice
- async handleGetPrice() {
- try {
- // let { puOrg, priceType, customer, assignSupplier, material, } = data;
- let { code, data } = await orderApi.getPrice({ ...this.params });
- if (code == 200) {
- this.params = data;
- }
- } catch (error) {
- } finally {
- }
- },
-
- },
- created() {
- console.log("ADD CREATED", this.params);
- },
- mounted() {},
- destroyed() {},
- };
- </script>
- <template>
- <el-drawer
- direction="btt"
- size="100%"
- :with-header="false"
- :visible.sync="visible"
- @open="beforeOpen"
- @close="$emit('close')"
- >
- <el-form
- size="mini"
- label-position="right"
- ref="orderAddForm"
- label-width="140px"
- :model="params"
- :rules="rules"
- >
- <el-card
- :body-style="{
- padding: '20px',
- display: 'flex',
- 'flex-wrap': 'wrap',
- }"
- style="margin: 10px"
- >
- <div
- slot="header"
- style="
- display: flex;
- justify-content: space-between;
- align-items: center;
- "
- >
- <h3>新增</h3>
- <div style="text-align: right">
- <el-button size="mini" @click="handleCancel">取消</el-button>
- <el-button
- size="mini"
- type="danger"
- @click="handleSava"
- >保存</el-button>
- <!-- <el-button size="mini" type="info" @click="handleSubmit">
- 保存并新增
- </el-button> -->
- </div>
- </div>
- <el-row style="display: flex; flex-wrap: wrap">
- <el-col
- v-for="(column, index) in columns"
- :key="index"
- :span="column.span || 6"
- >
- <el-form-item
- :prop="column.key"
- :label="column.title"
- v-if="column.isShow"
- >
- <el-input
- v-if="column.inputType === 'Input'"
- v-model="params[column.key]"
- :placeholder="column.placeholder"
- :clearable="column.clearable"
- :disabled="column.disabled"
- style="width: 100%"
- >
- </el-input>
- <dr-popover-select
- v-if="column.inputType === 'PopoverSelect'"
- v-model="params[column.key]"
- :value-key="column.valueKey"
- :source.sync="params"
- :title="column.title"
- :type="column.referName"
- :disabled="column.disabled"
- :multiple="column.multiple"
- :placeholder="column.placeholder"
- :data-mapping="column.dataMapping"
- :query-params="column.queryParams"
- @change="handleReferChange"
- ></dr-popover-select>
- <el-input
- v-if="column.inputType === 'Textarea'"
- v-model="params[column.key]"
- type="textarea"
- :placeholder="column.placeholder"
- :clearable="column.clearable"
- :disabled="column.disabled"
- style="width: 100%"
- ></el-input>
- <el-input-number
- v-if="column.inputType === 'InputNumber'"
- v-model="params[column.key]"
- :controls-position="column.controlsPosition"
- :placeholder="column.placeholder"
- :clearable="column.clearable"
- :disabled="column.disabled"
- style="width: 100%"
- >
- </el-input-number>
- <el-select
- v-if="column.inputType === 'Select'"
- v-model="params[column.key]"
- :disabled="column.disabled"
- :clearable="column.clearable"
- :placeholder="column.placeholder"
- style="width: 100%"
- @change="handleSelectChange(column.key,column.referName)"
- >
- <el-option
- v-for="item in dict.type[column.referName]"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- ></el-option>
- </el-select>
- <el-select
- v-if="column.inputType === 'TagSelect'"
- v-model="params[column.key]"
- multiple
- clearable
- collapse-tags
- :placeholder="column.placeholder"
- :clearable="column.clearable"
- :disabled="column.disabled"
- style="width: 100%"
- >
- <template #prefix>
- <el-icon
- class="el-icon-view"
- style="cursor: pointer"
- @click.stop="$message.info(234)"
- >
- </el-icon>
- </template>
- <el-option
- v-for="item in options"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- ></el-option>
- </el-select>
- <el-date-picker
- v-if="column.inputType === 'DatePicker'"
- v-model="params[column.key]"
- :type="column.type"
- :placeholder="column.placeholder"
- :clearable="column.clearable"
- :disabled="column.disabled"
- :picker-options="column.pickerOptions"
- style="width: 100%"
- ></el-date-picker>
- <el-checkbox
- v-if="column.inputType === 'Checkbox'"
- v-model="params[column.key]"
- :disabled="column.disabled"
- true-label="Y"
- false-label="N"
- ></el-checkbox>
- <file-upload-center
- v-if="column.inputType === 'Upload'"
- v-model="params[column.key]"
- :file-type="column.fileType"
- ></file-upload-center>
- </el-form-item>
- </el-col>
- </el-row>
- </el-card>
- <el-card
- :body-style="{
- padding: '20px',
- display: 'flex',
- 'flex-wrap': 'wrap',
- position: 'relative',
- }"
- style="margin: 10px"
- >
- <el-tabs v-model="tabName" style="width: 100%">
- <el-tab-pane
- v-for="(column, index) in tabColumns"
- :key="index"
- :label="column.title"
- :name="column.key"
- >
- <el-table
- :data="params[column.key]"
- style="width: 100%"
- :height="params[column.key].length ? 300 : 100"
- >
- <el-table-column
- v-for="(cColumn, cIndex) in column.tableColumns"
- :key="cIndex"
-
- :label="cColumn.title"
- :width="cColumn.width || 80"
- >
- <template slot-scope="scope">
- <el-form-item
- label-width="0"
- :prop="`${column.key}.${scope.$index}.${[cColumn.key]}`"
- :rules="{ required: cColumn.require || false, message: `${cColumn.title}不能为空`, trigger: 'change' }"
- >
- <el-tag v-if="cColumn.key === 'index'" >
- {{ scope.$index + 1 }}
- </el-tag>
- <el-input
- v-if="cColumn.inputType === 'Input'"
- v-model="scope.row[cColumn.key]"
- :placeholder="cColumn.placeholder"
- :clearable="cColumn.clearable"
- :disabled="cColumn.disabled"
- size="mini"
- style="width: 100%"
- ></el-input>
- <!-- -->
- <dr-popover-select
- v-if="cColumn.inputType === 'PopoverSelect'"
- v-model="scope.row[cColumn.key]"
- :source.sync="scope.row"
- :title="cColumn.title"
- :value-key="cColumn.valueKey"
- :type="cColumn.referName"
- :disabled="cColumn.disabled"
- :multiple="cColumn.multiple"
- :placeholder="cColumn.placeholder"
- :data-mapping="cColumn.dataMapping"
- :query-params="cColumn.queryParams"
- @change="handleTabReferChange"
- size="mini"
- >
- </dr-popover-select>
- <el-input-number
- v-if="cColumn.inputType === 'InputNumber'"
- v-model="scope.row[cColumn.key]"
- :controls-position="cColumn.controlsPosition"
- :placeholder="cColumn.placeholder"
- @change="handleInputChange(scope.row, cColumn.key)"
- :clearable="cColumn.clearable"
- :disabled="cColumn.disabled"
- size="mini"
- style="width: 100%"
- ></el-input-number>
- <el-select
- v-if="cColumn.inputType === 'Select'"
- v-model="scope.row[cColumn.key]"
-
- size="mini"
- :disabled="cColumn.disabled"
- :clearable="cColumn.clearable"
- :placeholder="cColumn.placeholder"
- style="width: 100%"
- @change="handleTabSelectChange(cColumn.key,scope.row)"
- >
- <el-option
- v-for="item in dict.type[cColumn.referName]"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- ></el-option>
- </el-select>
- <el-checkbox
- v-if="cColumn.inputType === 'Checkbox'"
- v-model="scope.row[cColumn.key]"
- :disabled="cColumn.disabled"
- true-label="Y"
- false-label="N"
- @change="handleTabCheckbox(cColumn.key,scope.row)"
- ></el-checkbox>
- </el-form-item>
- </template>
- </el-table-column>
- <el-table-column fixed="right" label="操作" width="80">
- <template slot-scope="scope">
- <el-button
- @click.native.prevent="
- delTableRow(params[tabName], scope.$index)
- "
- type="text"
- size="small"
- >
- 删行
- </el-button>
- </template>
- </el-table-column>
- </el-table>
- </el-tab-pane>
- </el-tabs>
- <el-row style="position: absolute; top: 20px; right: 20px">
- <el-button size="mini" @click="addTableRow(params[tabName])"
- >增行</el-button
- >
- </el-row>
- </el-card>
- </el-form>
- </el-drawer>
- </template>
|