purchaseOrder.vue 14.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
<!-- 采购订单 -->
<template>
  <d2-container class="container">
    <div class="header"
         slot="header">
      <d2-search ref="showSearch"
                 class="show-search"
                 :search-form="searchForm"
                 :form-data="showFormData">
      </d2-search>
      <div class="up-btns">
        <el-button :id="tableParams.btnId"
                   size="small"
                   type="primary"
                   handle>
          查询
        </el-button>
        <el-button size="small"
                   @click="handleReset">
          重置
        </el-button>
      </div>
    </div>
    <div class="d2-container-content">
      <d2-table-header>
        <span slot="left"
              v-if="!userInfo.beSuper && userInfo.beYQMerchant">
          <!-- <auth-button category="Button" /> -->
          <auth-button category="Button" />
        </span>
        <span>
          <!-- <el-button type="primary"
                     size="mini"
                     @click="handleExport">
            导出
          </el-button> -->
          <auth-button category="Button" :show-btn-ids="['9090106']" />
        </span>
      </d2-table-header>
      <d2-table ref="purchaseOrderTable"
                :search-form="tableSearchForm"
                :table-params="tableParams"
                :table-data="tableData"
                :get-list-api="getListApi"
                :before-search-fn="beforeSearchFn">
        <div slot="auth-button"
             slot-scope="scope">
          <!-- 查看 -->
          <span style="margin-right: 10px;">
            <auth-button :data="scope.scope"
                         :show-btn-ids="['9090102']" />
          </span>
          <!-- 取消 -->
          <span style="margin-right: 10px;"
                v-show="scope.scope.status == 1 && !userInfo.beSuper && userInfo.beYQMerchant">
            <auth-button :data="scope.scope"
                         :show-btn-ids="['9090103']" />
          </span>
          <!-- 入库 -->
          <span style="margin-right: 10px;"
                v-show="scope.scope.putStatus == 1 && !userInfo.beSuper && userInfo.beYQMerchant">
            <auth-button :data="scope.scope"
                         :show-btn-ids="['9090104']" />
          </span>
          <span style="margin-right: 10px;"
                v-show="(scope.scope.purchaseType == 1 && scope.scope.deliveryStatus == 2) || (scope.scope.purchaseType == 1 && scope.scope.deliveryStatus == 3)||(scope.scope.purchaseType == 1 && scope.scope.deliveryStatus == 4)">
            <auth-button :data="scope.scope"
                         :show-btn-ids="['9090105']" />
          </span>
        </div>
      </d2-table>
    </div>
    <orderDeatilDialog :visible.sync="detailVisible"
                       v-if="detailVisible"
                       :params-obj="paramsObj"
                       :show-film-roll-no="paramsObj.purchaseType != 1"></orderDeatilDialog>
  </d2-container>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import { defaultStatusOptions, defaultStatusOptionsForTable, defaultDeliveryStatusOptions, defaultPutStatusOptions, purchaseTypeList } from './constant'
import { mapActions, mapState } from 'vuex'
import { getPurchaseOrderList, getMerchantList, purchaseOrderCancelOrCheck, purchaseOrderPutIn } from '@/api/purchaseShopping.js'
import orderDeatilDialog from './components/orderDetailDialog'
export default {
  name: 'PurchaseOrder',
  components: {
    orderDeatilDialog
  },
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      searchForm: {
        status: '',
        deliveryStatus: '',
        putStatus: '',
        // merchantId: '',
        // putMerchantId: '',
        merchantName: '',
        putMerchantName: '',
        sortType: 1,
        orderTimeStr: [],
        // putTimeStr: [],
        purchaseType: ''
      },
      tableSearchForm: {},
      tableData: [],
      showFormData: [
        {
          label: '订单编号',
          name: 'orderCode',
          type: 'input',
          isClear: true
        },
        {
          label: '下单时间',
          name: 'placeOrderTimeStr',
          type: 'datePicker',
          isClear: true,
          pickerOptions: 'rangePickerOptions'
        },
        {
          label: '下单商户',
          name: 'merchantName',
          type: 'input',
          isClear: true
        },
        {
          label: '订单状态',
          name: 'statuses',
          type: 'select',
          optionList: [],
          optionId: 'id',
          optionLabel: 'label',
          optionsName: 'defaultStatusOptions'
        },
        {
          label: '发货状态',
          name: 'deliveryStatus',
          type: 'select',
          optionList: [],
          optionId: 'id',
          optionLabel: 'label',
          optionsName: 'defaultDeliveryStatusOptions'
        },
        {
          label: '入库状态',
          name: 'putStatus',
          type: 'select',
          optionList: [],
          optionId: 'id',
          optionLabel: 'label',
          optionsName: 'defaultPutStatusOptions'
        },
        {
          label: '采购类型',
          name: 'purchaseType',
          type: 'select',
          optionList: [],
          optionId: 'id',
          optionLabel: 'label',
          optionsName: 'purchaseTypeList'
        }
        // {
        //   label: '入库时间',
        //   name: 'warehousingTimeStr',
        //   type: 'datePicker',
        //   isClear: true,
        //   pickerOptions: 'rangePickerOptions'
        // },
        // {
        //   label: '下单门店',
        //   name: 'merchantId',
        //   type: 'select',
        //   optionList: [],
        //   optionId: 'merchantNo',
        //   optionLabel: 'merchantName',
        //   optionsName: 'merchantName'
        // },
        // {
        //   label: '入库门店',
        //   name: 'putMerchantId',
        //   type: 'select',
        //   optionList: [],
        //   optionId: 'merchantNo',
        //   optionLabel: 'merchantName',
        //   optionsName: 'merchantName'
        // }
        // {
        //   label: '入库门店',
        //   name: 'putMerchantName',
        //   type: 'input',
        //   isClear: true
        // },
      ],
      getListApi: getPurchaseOrderList,
      // 表格参数
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '订单编号',
            prop: 'orderCode'
          },
          {
            label: '订单总价',
            prop: 'totalPrice',
            formatter: (cellValue) => {
              return "¥" + cellValue.totalPrice
            }
          },
          {
            label: '下单时间',
            prop: 'orderTime',
            formatter: (cellValue) => {
              return Util.dateFormate(cellValue.orderTime, 'YYYY-MM-DD HH:mm:ss')
            },
            width: 150
          },
          {
            label: '下单商户',
            prop: 'merchantName'
          },
          {
            label: '采购类型',
            prop: 'purchaseType',
            formatter: (cellValue) => {
              return purchaseTypeList.find(item => item.id == cellValue.purchaseType)?.label || '-'
            }
          },
          {
            label: '发货状态',
            prop: 'deliveryStatus',
            formatter: (cellValue) => {
              return defaultDeliveryStatusOptions.find(item => item.id == cellValue.deliveryStatus)?.label || '-'
            },
            className: (cellValue) => {
              return {
                1: 'ashSpot',
                2: 'greenSpot',
                3: 'yellowSpot',
                4: 'redSpot'
              }[cellValue.deliveryStatus]
            }
          },
          // {
          //   label: '承运公司',
          //   prop: 'deliveryCompany',
          //   formatter: (cellValue) => {
          //     return cellValue.deliveryCompany || '--'
          //   }
          // },
          // {
          //   label: '承运单号',
          //   prop: 'deliveryNumber',
          //   formatter: (cellValue) => {
          //     return cellValue.deliveryNumber || '--'
          //   }
          // },
          {
            label: '入库状态',
            prop: 'putStatus',
            formatter: (cellValue) => {
              return defaultPutStatusOptions.find(item => item.id == cellValue.putStatus)?.label || '-'
            },
            className: (cellValue) => {
              return {
                1: 'ashSpot',
                2: 'greenSpot',
                3: 'yellowSpot'
              }[cellValue.putStatus]
            }
          },
          // {
          //   label: '入库时间',
          //   prop: 'putTime',
          //   formatter: (cellValue) => {
          //     return cellValue.putTime ? Util.dateFormate(cellValue.putTime, 'YYYY-MM-DD HH:mm:ss') : '--'
          //   },
          //   width: 150
          // },
          // {
          //   label: '入库门店',
          //   prop: 'putMerchantName',
          //   formatter: (cellValue) => {
          //     return cellValue.putMerchantName || '--'
          //   }
          // },
          {
            label: '订单状态',
            prop: 'status',
            formatter: (cellValue) => {
              return defaultStatusOptionsForTable.find(item => item.id == cellValue.status)?.label || '-'
            },
            className: (cellValue) => {
              return {
                1: 'yellowSpot',
                2: 'yellowSpot',
                3: 'ashSpot',
                4: 'redSpot',
                5: 'greenSpot',
                6: 'redSpot',
                7: 'redSpot'
              }[cellValue.status]
            }
          }
        ]
      },
      // 查看门店
      detailVisible: false,
      // 基本数据
      baseData: {
        defaultStatusOptions: [],
        defaultDeliveryStatusOptions: [],
        defaultPutStatusOptions: [],
        purchaseTypeList: [],
        defaultStatusOptionsForTable: []
      },
      paramsObj: {}
    }
  },
  computed: {
    ...mapState({
      dowloadList: (state) => state.d2admin.user.dowloadList
    })
  },

  mounted() {
    getMerchantList({}).then(res => {
      const opt = {
        merchantNo: '',
        merchantName: '全部'
      }
      res.unshift(opt)
      this.getBaseData(res)
    })
  },

  methods: {
    ...mapActions('d2admin/user', ['actionSetDownloadList']),
    getBaseData(res) {
      const allOpt = {
        id: '',
        label: '全部'
      }
      this.baseData = {
        defaultStatusOptions: deepClone(defaultStatusOptions),
        defaultDeliveryStatusOptions: deepClone(defaultDeliveryStatusOptions),
        defaultPutStatusOptions: deepClone(defaultPutStatusOptions),
        purchaseTypeList: deepClone(purchaseTypeList),
        defaultStatusOptionsForTable: deepClone(defaultStatusOptionsForTable)
      }
      this.showFormData.forEach((item, index) => {
        if (item.type === 'select' && this.baseData[item.optionsName]) {
          this.baseData[item.optionsName].unshift(allOpt)
          this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
        }
        if (item.type === 'select' && (item.name === 'merchantId' || item.name == 'putMerchantId')) {
          this.$set(this.showFormData[index], 'optionList', res)
        }
      })
    },

    beforeSearchFn() {
      return new Promise(resolve => {
        this.filterSearchTime()
        resolve()
      })
    },
    filterSearchTime() {
      this.tableSearchForm = deepClone(this.searchForm)
      if (this.tableSearchForm.placeOrderTimeStr) {
        this.tableSearchForm.orderTimeStr[0] = new Date(this.tableSearchForm.placeOrderTimeStr[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        this.tableSearchForm.orderTimeStr[1] = new Date(this.tableSearchForm.placeOrderTimeStr[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
        delete this.tableSearchForm.placeOrderTimeStr
      }
      if (this.tableSearchForm.statuses) {
        if (this.tableSearchForm.statuses == 4) {
          this.tableSearchForm.statuses = [4, 6, 7]
        } else {
          this.tableSearchForm.statuses = [this.tableSearchForm.statuses]
        }
      }
    },
    handleReset() {
      for (const key in this.searchForm) {
        this.searchForm[key] = ''
      }
      this.searchForm.sortType = 1
      this.searchForm.orderTimeStr = []
      // this.searchForm.putTimeStr = []
      this.$refs.purchaseOrderTable.refreshTable()
    },
    // 创建采购
    handleCreatePurchase() {
      this.$router.push({
        name: 'purchasingMall'
      })
    },
    // 导出
    handleExport() {
      this.filterSearchTime()
      var params = this.tableSearchForm
      // 处理查询条件时间
      for (const key in params) {
        if (key == 'orderTimeStr' || key == 'putTimeStr' || key == 'statuses') {
          params[key].forEach((v, index) => {
            params[`${key}[${index}]`] = v
          })
          delete params[key]
        }
      }
      params.method = 'dj.api.smarcarlife.purchaseOrder.export.async'
      const list = [
        ...this.dowloadList,
        {
          name: '采购订单',
          exportParam: JSON.stringify(params),
          status: 'waiting',
          timeid: new Date().getTime()
        }
      ]
      this.actionSetDownloadList({ list, type: 'dowloadList' })
    },
    // 取消
    handleCancel(row) {
      this.$confirm(`订单取消后即自动作废该订单,且无法撤回。是否确定取消?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        purchaseOrderCancelOrCheck({
          orderCode: row.orderCode,
          operateType: 2
        }).then(() => {
          this.notice.okTips()
          this.$refs.purchaseOrderTable.refreshTable()
        }).catch(() => { })
      })
    },
    // 入库
    handleWarehousing(row) {
      this.$confirm('订单入库后自动更新对应的库存,可在入库管理中查看记录。是否确定入库?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        purchaseOrderPutIn({
          orderCode: row.orderCode
        }).then(() => {
          this.notice.okTips()
          this.$refs.purchaseOrderTable.refreshTable()
        }).catch(() => { })
      })
    },
    // 查看详情
    handleDetail(row) {
      this.paramsObj = {
        orderCode: row.orderCode,
        merchantName: row.merchantName,
        purchaseType: row.purchaseType
      }
      this.detailVisible = true
    },
    // 发货单
    handleSendgoods(row) {
      this.$router.push({
        name: 'invoiceRecord',
        params: {
          orderCode: row.orderCode
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped></style>