Newer
Older
smartKitchenFront / src / views / business / report.vue
liyaguang on 28 Nov 2022 24 KB fix: 修改商机管理订单管理
<!--商机报备表单-->
<template>
  <div class="report-container">
    <div class="report-title">基础报备</div>
    <div class="report-from">
      <div class="from-title">基础信息</div>
      <div class="from-inputBox">
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.itemName"
            title="项目名称"
            placeholder="请输入项目名称"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.itemBudget"
            title="项目预算"
            placeholder="请输入项目预算"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue title="预计工期" class="inputWidth">
            <el-date-picker
              v-model="addInfo.itemDuration"
              value-format="yyyy-MM-dd"
              type="date"
              placeholder="选择日期"
              style="width: 380px"
            />
          </inputVue>
        </div>
      </div>
      <div class="from-inputBox">
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.itemManager"
            title="商机负责人"
            placeholder="请输入商机负责人姓名"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.phone"
            title="联系方式"
            placeholder="请输入联系方式"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.organization"
            title="单位组织"
            placeholder="请输入单位组织"
            class="inputWidth"
            width="380px"
          />
        </div>
      </div>
      <div class="from-inputBox">
        <div class="input-item">
          <RedStar />
          <inputVue title="商机状态" class="inputWidth">
            <el-select
              v-model="addInfo.status"
              clearable
              placeholder="请选择"
              style="width: 380px"
            >
              <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </inputVue>
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue title="项目地址" class="inputWidth">
            <el-select
              v-model="addInfo.itemProvince"
              clearable
              placeholder="省/市"
              style="width: 150px; margin-left: 55px"
              @change="provinceChange"
            >
              <el-option
                v-for="item in form.provinceList"
                :key="item.id"
                :label="item.areaName"
                :value="item.areaName"
              />
            </el-select>
          </inputVue>
          <inputVue title="" class="inputWidth">
            <el-select
              v-model="addInfo.itemCity"
              clearable
              placeholder="市/区"
              style="width: 150px"
              @change="cityChange($event)"
            >
              <el-option
                v-for="item in form.cityList"
                :key="item.id"
                :label="item.areaName"
                :value="item.areaName"
              />
            </el-select>
          </inputVue>
          <inputVue title="" class="inputWidth">
            <el-select
              v-model="addInfo.itemArea"
              clearable
              placeholder="县/街道"
              style="width: 150px"
            >
              <el-option
                v-for="item in form.countyList"
                :key="item.id"
                :label="item.areaName"
                :value="item.areaName"
              />
            </el-select>
          </inputVue>
          <inputVue
            v-model="addInfo.itemAddress"
            placeholder="请输入详细地址"
            class="inputWidth"
            width="440px"
          />
        </div>
      </div>
    </div>
    <div class="report-from">
      <div class="from-title">关联方信息</div>
      <div class="from-inputBox">
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.ownerName"
            title="业主方名称"
            placeholder="请输入名称"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.ownerContacts"
            title="业主方联系人"
            placeholder="请输入联系人"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.ownerPhone"
            title="业主方联系方式"
            placeholder="请输入联系方式"
            class="inputWidth"
            width="380px"
          />
        </div>
      </div>
      <div class="from-inputBox">
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.contractName"
            title="总包方名称"
            placeholder="请输入名称"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.contractContacts"
            title="总包方联系人"
            placeholder="请输入联系人"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.contractPhone"
            title="总包方联系方式"
            placeholder="请输入联系方式"
            class="inputWidth"
            width="380px"
          />
        </div>
      </div>
      <div class="from-inputBox">
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.constructName"
            title="施工方名称"
            placeholder="请输入名称"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.constructContacts"
            title="施工方联系人"
            placeholder="请输入联系人"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.constructPhone"
            title="施工方联系方式"
            placeholder="请输入联系方式"
            class="inputWidth"
            width="380px"
          />
        </div>
      </div>
      <div class="from-inputBox">
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.agentName"
            title="代理商名称"
            placeholder="请输入名称"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.agentContacts"
            title="代理商联系人"
            placeholder="请输入联系人"
            class="inputWidth"
            width="380px"
          />
        </div>
        <div class="input-item">
          <RedStar />
          <inputVue
            v-model="addInfo.agentPhone"
            title="代理商联系方式"
            placeholder="请输入联系方式"
            class="inputWidth"
            width="380px"
          />
        </div>
      </div>
    </div>
    <div class="report-from">
      <div class="from-title">产品信息</div>
      <div class="from-table">
        <div style="margin-left: 2px">
          <el-table
            ref="tb"
            :data="addInfo.productList"
            border
            class="el-tab"
            style="width: 100%"
          >
            <el-table-column type="index" label="序号" width="50px" />
            
            <el-table-column prop="brandName" label="产品品牌" width="240px">
              <template slot-scope="{ row, $index }">
                <span v-if="!showEdit[$index]">{{ row.brandName }}</span>
                <!-- <el-input v-if="showEdit[$index]" v-model="addInfo.productList.brandName" placeholder="请输入产品品牌">
                </el-input> -->
                <el-select
                  v-if="showEdit[$index]"
                  v-model="brandName"
                  clearable
                  placeholder="请输入产品品牌"
                >
                  <el-option
                    v-for="item in brandList"
                    :key="item.brandCode"
                    :label="item.brandName"
                    :value="item.brandName"
                  />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="categoryIds" label="产品品类" width="240px">
              <template slot-scope="{ row, $index }">
                <span v-if="!showEdit[$index]">{{ row.categoryIds }}</span>
                <!-- <el-input v-if="showEdit[$index]" v-model="addInfo.productList.categoryIds" placeholder="请输入产品品类">
                </el-input> -->
                <el-select
                  v-if="showEdit[$index]"
                  v-model="categoryIds"
                  clearable
                  placeholder="请输入产品品类"
                  @change="categoryIdChange"
                >
                  <el-option
                    v-for="item in categoryList"
                    :key="item.id"
                    :label="item.categoryName"
                    :value="item.categoryName"
                  />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="productName" label="产品名称" width="200px">
              <template slot-scope="{ row, $index }">
                <span v-if="!showEdit[$index]">{{ row.productName }}</span>
                <el-select
                  v-if="showEdit[$index]"
                  v-model="addInfo.productList.productName"
                  clearable
                  placeholder="请输入产品型号"
                >
                  <el-option
                    v-for="item in CodeList"
                    :key="item.id + 1"
                    :label="item.productName"
                    :value="item.productName"
                  />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column prop="productCode" label="产品型号" width="240px">
              <template slot-scope="{ row, $index }">
                <span v-if="!showEdit[$index]">{{ row.productCode }}</span>
                <!-- <el-input v-if="showEdit[$index]" v-model="addInfo.productList.productCode" placeholder="请输入产品型号">
                </el-input> -->
                <el-select
                  v-if="showEdit[$index]"
                  v-model="addInfo.productList.productCode"
                  clearable
                  placeholder="请输入产品型号"
                >
                  <el-option
                    v-for="item in CodeList"
                    :key="item.id"
                    :label="item.productCode"
                    :value="item.productCode"
                  />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              prop="productQuantity"
              label="产品数量"
              width="200px"
            >
              <template slot-scope="{ row, $index }">
                <span v-if="!showEdit[$index]">{{ row.productQuantity }}</span>
                <el-input
                  v-if="showEdit[$index]"
                  v-model="addInfo.productList.productQuantity"
                  placeholder="请输入产品数量"
                />
              </template>
            </el-table-column>
            <el-table-column prop="productPrice" label="产品单价" width="200px">
              <template slot-scope="{ row, $index }">
                <span v-if="!showEdit[$index]">{{ row.productPrice }}</span>
                <el-input
                  v-if="showEdit[$index]"
                  v-model="addInfo.productList.productPrice"
                  placeholder="请输入产品单价"
                />
              </template>
            </el-table-column>
            <el-table-column
              header-align="center"
              align="center"
              width="200"
              label="操作"
            >
              <template slot-scope="{ row, $index }">
                <el-button
                  v-if="!showEdit[$index]"
                  size="small"
                  @click="showUpdate($index, row)"
                >
                  编辑
                </el-button>
                <el-button
                  v-if="!showEdit[$index]"
                  size="small"
                  @click="showDelete($index, row)"
                >
                  删除
                </el-button>
                <el-button
                  v-if="showEdit[$index]"
                  size="small"
                  style="color: #85ce61"
                  @click="submit($index, row)"
                >
                  确定
                </el-button>
                <el-button
                  v-if="showEdit[$index] && isFirst[$index] > 1"
                  size="small"
                  style="color: red"
                  @click="cancelUpdate($index)"
                >
                  取消
                </el-button>
                <el-button
                  v-if="showEdit[$index] && isFirst[$index] === 1"
                  size="small"
                  style="color: red"
                  @click="showDelete($index)"
                >
                  删除
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div>
        <el-button class="table-btn" @click="handleAddBtn">
          添加项目需求
        </el-button>
      </div>
    </div>
    <div class="btnBox">
      <el-button type="primary" class="save" @click="save"> 保存 </el-button>
      <el-button type="info" class="close" @click="close"> 取消 </el-button>
    </div>
  </div>
</template>

<script>
import RedStar from "../../components/mycomponent/redStar.vue";
import inputVue from "../../components/mycomponent/input/inputVue.vue";

import { list } from "../../api/product/product";
import { C_list } from "../../api/product/category";
import { SelectList } from "../../api/product/brand";
import { add } from "../../api/business/business";
import { order_area } from "../../api/order/order";
import { Message } from "element-ui";
export default {
  components: {
    RedStar,
    inputVue,
  },
  data() {
    return {
      brandName: "",
      categoryIds: "",
      CodeList: [],
      brandList: [],
      categoryList: [],
      checkedDetail: [],
      showEdit: [], // 用来判断是否处于编辑状态
      isFirst: [], // 用来判断是否初次添加
      options: [
        { value: "0", label: "推进" },
        { value: "1", label: "成交" },
        { value: "2", label: "丢失" },
      ],
      addInfo: {
        itemName: "",
        itemBudget: "",
        itemDuration: "",
        itemManager: "",
        phone: "",
        organization: "",
        status: "",
        itemProvince: "",
        itemCity: "",
        itemArea: "",
        itemAddress: "",
        ownerName: "", // 业主方
        ownerContacts: "",
        ownerPhone: "",
        contractName: "", // 总包方
        contractContacts: "",
        contractPhone: "",
        constructName: "", // 施工方
        constructContacts: "",
        constructPhone: "",
        agentName: "", // 代理商
        agentContacts: "",
        agentPhone: "",
        productList: [],
      },
      form: {
        provinceList: [],
        cityList: [],
        countyList: [],
      },
    };
  },
  watch: {
    addInfo: {
      handler(newval, oldval) {
        console.log(newval, oldval);
        if (!this.addInfo.itemProvince) {
          this.addInfo.itemCity = "";
          this.addInfo.itemArea = "";
        } else if (!this.addInfo.itemCity) {
          this.addInfo.itemArea = "";
        }
      },
      deep: true,
      immediate: true,
    },
  },
  created() {
    order_area("pid=0", {}).then((res) => {
      console.log(res, "Sheng");
      this.form.provinceList = res;
    });
  },
  mounted() {},
  methods: {
    save() {
      if (this.valiateForm()) {
        //   this.addInfo.productList = {
        //   productCode: this.addInfo.productList.productCode,
        //   productQuantity: this.addInfo.productList.productQuantity,
        //   productPrice: this.addInfo.productList.productPrice,
        //   productName: ''
        // }
        if(this.addInfo.productList.length && this.showEdit.every(item => item=== false)){
          add(this.addInfo).then((res) => {
          this.setData();
          this.$message({
            message: "保存成功",
            type: "success",
          });
        });
        }else{
          this.$message.error('请先添加或保存产品信息')
        }
      } else {
        this.$message({
          message: "请先完整填写报备信息",
          type: "error",
        });
      }
    },
    close() {
      this.setData();
    },
    provinceChange(e) {
      console.log(e);
      const index = this.form.provinceList.findIndex((item) => {
        return item.areaName == e;
      });
      const code = this.form.provinceList[index].id;
      order_area(`pid=${code}`, {}).then((res) => {
        console.log(res, "Shi");
        this.form.cityList = res;
      });
    },
    cityChange(e) {
      const index = this.form.cityList.findIndex((item) => {
        return item.areaName == e;
      });
      const code = this.form.cityList[index].id;
      order_area(`pid=${code}`, {}).then((res) => {
        console.log(res, "Xian");
        this.form.countyList = res;
      });
    },
    handleAddBtn() {
      if (
        this.showEdit[this.addInfo.productList.length - 1] === false ||
        this.addInfo.productList.length === 0
      ) {
        const obj = {};
        obj.brandName = "";
        obj.categoryIds = "";
        obj.productCode = "";
        obj.productQuantity = "";
        obj.productPrice = "";
        obj.productName = "";
        this.addInfo.productList.push(obj);
        this.showEdit[this.addInfo.productList.length - 1] = true;
        this.isFirst[this.addInfo.productList.length - 1] = 1;
        C_list().then((res) => {
          this.categoryList = res.data;
        });
        SelectList().then((res) => {
          this.brandList = res;
        });
      } else {
        this.$message.warning("请先保存上一次");
      }
    },
    showUpdate(index, row) {
      this.showEdit[index] = true;
      this.$set(this.showEdit, index, true); // 这里要用$set方法,否则页面状态不更新
      this.brandName = row.brandName;
      this.categoryIds = row.categoryIds;
      this.addInfo.productList.productCode = row.productCode;
      this.addInfo.productList.productQuantity = row.productQuantity;
      this.addInfo.productList.productPrice = row.productPrice;
      this.addInfo.productList.productName = row.productName;
    },
    showDelete(index, row) {
      this.$confirm("确认删除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.addInfo.productList = this.addInfo.productList.filter(
            (item, Index) => index !== Index
          );
          this.showEdit = this.showEdit.filter(
            (item, Index) => index !== Index
          );
          this.isFirst = this.isFirst.filter((item, Index) => index !== Index);
          this.$message({
            message: "已删除",
            type: "success",
          });
        })
        .catch(() => {});
    },
    categoryIdChange(e) {
      const index = this.categoryList.findIndex((item) => {
        return item.categoryName == e;
      });
      const code = this.categoryList[index].id;
      console.log(code);
      list({ categoryId: code }).then((res) => {
        console.log(res);
        this.CodeList = res;
        // this.addInfo.productList.productName =''
        // this.addInfo.productList.productCode =''
      });
    },
    cancelUpdate(index) {
      this.$confirm("取消修改?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$set(this.showEdit, index, false);
        })
        .catch(() => {});
    },
    submit(index, row) {
      // 发送请求,隐藏输入框
      const {
        brandName,
        categoryIds,
        addInfo: {
          productList: { productQuantity, productPrice },
        },
      } = this;
      if (categoryIds && brandName) {
        if (productQuantity > 0 && productPrice > 0) {
          row.productCode = this.addInfo.productList.productCode;
          row.brandName = this.brandName;
          row.categoryIds = this.categoryIds;
          row.productQuantity = this.addInfo.productList.productQuantity;
          row.productPrice = this.addInfo.productList.productPrice;
          row.productName = this.addInfo.productList.productName;
          this.$message({
            type: "success",
            message: "已缓存,记得点击保存提交修改喔!",
            duration: 888,
            onClose: () => {
              this.$set(this.showEdit, index, false); // vue添加属性的方法
            },
          });
          row.productCode = this.addInfo.productList.productCode;
          row.brandName = this.brandName;
          row.categoryIds = this.categoryIds;
          row.productQuantity = this.addInfo.productList.productQuantity;
          row.productPrice = this.addInfo.productList.productPrice;
          row.productName = this.addInfo.productList.productName;
          this.$set(this.isFirst, index, 2);
          this.brandName = "";
          this.categoryIds = "";
          this.addInfo.productList.productCode = "";
          this.addInfo.productList.productQuantity = "";
          this.addInfo.productList.productPrice = "";
          this.addInfo.productList.productName = "";
        } else {
          this.$message.error("单价或数量需大于等于1");
        }
      } else {
        this.$message({
          message: "请先完整选择或填写信息",
          type: "error",
        });
      }
    },
    setData() {
      this.addInfo = {
        itemName: "",
        itemBudget: "",
        itemDuration: "",
        itemManager: "",
        phone: "",
        organization: "",
        status: "",
        itemProvince: "",
        itemCity: "",
        itemArea: "",
        itemAddress: "",
        ownerName: "", // 业主方
        ownerContacts: "",
        ownerPhone: "",
        contractName: "", // 总包方
        contractContacts: "",
        contractPhone: "",
        constructName: "", // 施工方
        constructContacts: "",
        constructPhone: "",
        agentName: "", // 代理商
        agentContacts: "",
        agentPhone: "",
        productList: [],
      };
    },
    valiateForm() {
      let arr = [];
      for (var item in this.addInfo) {
        if (this.addInfo[item]) {
          arr.push(1);
        } else {
          arr.push(0);
        }
      }
      return arr.every((item) => item === 1);
    },
  },
};
</script>

<style lang='scss' scoped>
.report-container {
  .report-title {
    font-size: 22px;
    font-weight: bold;
    margin: 10px 0 10px 20px;
  }

  .report-from {
    .from-title {
      font-size: 16px;
      font-weight: bold;
      background-color: #28739e;
      color: white;
      padding: 10px 0 10px 20px;
    }

    .from-inputBox {
      display: flex;
      margin-left: 20px;

      .input-item {
        width: 540px;
        display: flex;
        justify-content: space-between;
        align-items: center;
      }
    }

    .from-table {
      display: flex;
      margin: 10px 20px;

      .table-btn {
        margin-left: 40px;
      }
    }
  }

  .btnBox {
    padding: 30px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-evenly;

    .save,
    .close {
      width: 100px;
    }
  }
}
</style>