123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- import { getStorage } from '@/common/utils/storage.js'
- export default {
- data() {
- return {
- // 网点下拉选项
- websitList: [],
- // 网点下拉选项选中的下标
- index: 0,
- // 类型切换选中值
- selected: 1,
- // 是否显示类型切换
- showTypeSwitching: true,
- // 下拉刷新状态
- refresherTriggered: false,
- // 配件类型列表
- accessoriesList: [],
- // 类型选中下标
- accessoriesIndex: -1,
- // 列表数据
- list: [],
- // 名称搜索
- partsName: '',
- option: {},
- apis: {
- default: {
- getGroupUrl: '/app/parts/stock/exist/websit/group/list',
- getStockUrl: '/app/parts/stock/exist/websit/stock/list'
- },
- applicationParts: {
- getGroupUrl: '/app/parts/websit/stock/group/list',
- getStockUrl: '/app/parts/websit/stock/list'
- }
- }
- }
- },
- onLoad(option) {
- this.option = option
- if (!option.partsWebsitNumber && !option.websitId) {
- this.getWebsitInfo()
- }
- },
- computed: {
- accessoriesParams() {
- if (this.option.partsWebsitNumber && this.option.websitId) {
- return {
- identity: this.userInfo.idCard,
- partsWebsitNumber: this.option.partsWebsitNumber,
- websitId: this.option.websitId
- }
- }
- var data = this.websitList[this.index]
- if (data) {
- return {
- identity: this.userInfo.idCard,
- partsAttr: ['OLD', 'NEW'][this.selected],
- partsWebsitNumber: data.partsWebsitNumber,
- websitId: data.websitId
- }
- } else {
- return false
- }
- },
- userInfo() {
- return getStorage('user')
- },
- idcard() {
- return this.userInfo.idCard
- }
- },
- watch: {
- accessoriesParams(newVal) {
- this.getGroup(newVal)
- this.list = []
- },
- accessoriesList(newVal) {
- if (this.accessoriesIndex !== 0) {
- this.accessoriesIndex = 0
- } else {
- this.getStock()
- }
- },
- accessoriesIndex() {
- this.getStock()
- },
- partsName() {
- this.getStock()
- }
- },
- methods: {
- // 获取网点
- getWebsitInfo() {
- this.$api
- .post('/app/parts/stock/exist/websit/list', {
- identity: this.idcard
- })
- .then(res => {
- console.log(res.data)
- this.websitList = res.data
- })
- .catch(() => {
- this.websitList = []
- })
- },
- // 获取分组
- getGroup(params) {
- if (params) {
- this.$api
- .post(this.apis[this.option.apiType || 'default'].getGroupUrl, params)
- .then(res => {
- this.accessoriesList = res.data
- })
- .catch(() => {
- this.accessoriesList = []
- })
- } else {
- this.accessoriesList = []
- }
- },
- // 获取配件
- getStock() {
- if (this.accessoriesList.length && this.accessoriesList[this.accessoriesIndex]) {
- this.$api
- .post(this.apis[this.option.apiType || 'default'].getStockUrl, {
- ...this.accessoriesParams,
- materialGroupId: this.accessoriesList[this.accessoriesIndex].id,
- partsName: this.partsName
- })
- .then(res => {
- this.list = res.data
- })
- .catch(() => {
- this.list = []
- })
- } else {
- this.list = []
- }
- },
- // 搜索按钮
- search(val) {
- this.partsName = val
- },
- // 监听下拉选项
- bindPickerChange(e) {
- this.index = e.detail.value
- },
- // 滚动到底部
- carScrolltolower(e) {},
- // 触发下拉刷新
- carRefresherrefresh(e) {
- this.refresherTriggered = true
- setTimeout(() => {
- this.refresherTriggered = false
- }, 3000)
- },
- // 下拉刷新结束
- carRefresherrestore(e) {},
- // 点击购买配件
- buyAccessories() {}
- }
- }
|