123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <template>
- <div class="subPage" :style="{ padding: '20px' }">
- <div>
- <el-form inline>
- <el-form-item label="案场">
- <el-select v-model="caseId" size="medium" placeholder="请选择案场">
- <el-option
- v-for="item in cases"
- :key="item.CaseId"
- :label="item.CaseName"
- :value="item.CaseId"
- ></el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="条码">
- <el-input v-model="formData.bookBarcode"></el-input>
- </el-form-item>
- <el-form-item label="书名">
- <el-input v-model="formData.bookName"></el-input>
- </el-form-item>
- <el-form-item :style="{ float: 'right' }">
- <el-button type="primary" size="medium" @click="filterList">搜索</el-button>
- </el-form-item>
- </el-form>
- </div>
- <div>
- <el-button plain @click="editBook()" size="medium">图书录入</el-button>
- <el-button plain @click="showBatchInput()" size="medium">批量导入</el-button>
- <div :style="{ margin: '10px 0' }">
- <el-table :data="list" border style="width: 100%">
- <el-table-column label="图片" width="128">
- <template slot-scope="scope">
- <img width="64" :src="scope.row.BookImg + '?x-oss-process=style/compress-rotate'" alt>
- </template>
- </el-table-column>
- <el-table-column prop="BookBarcode" label="条码"></el-table-column>
- <el-table-column prop="BookName" label="书名"></el-table-column>
- <el-table-column label="案场">
- <template slot-scope="scope">
- <span>{{ getCaseName(scope.row.CaseId) }}</span>
- </template>
- </el-table-column>
- <el-table-column label="分类">
- <template slot-scope="scope">
- <span>{{ getTypeName(scope.row.BookTypeId) }}</span>
- </template>
- </el-table-column>
- <el-table-column label="价格">
- <template slot-scope="scope">
- <span>{{ formatPrice(scope.row.Price) }}</span>
- </template>
- </el-table-column>
- <el-table-column prop="BorrowDays" label="借阅(天)"></el-table-column>
- <el-table-column prop="InStock" label="总数量"></el-table-column>
- <el-table-column prop="BorrowNum" label="借出"></el-table-column>
- <el-table-column label="预约">
- <template slot-scope="scope">
- <span>{{ getReserveNum(scope.row) }}</span>
- </template>
- </el-table-column>
- <el-table-column label="录入时间">
- <template slot-scope="scope">
- <span>{{ toolClass.dateFormat(scope.row.CreateDate) }}</span>
- </template>
- </el-table-column>
- <el-table-column fixed="right" label="操作" width="150">
- <template slot-scope="scope">
- <div>
- <el-button type="text" @click="changeStock(scope.row)" size="small">盘点</el-button>
- <el-button @click="setRecommend(scope.row)" type="text" size="small">{{ scope.row.IsRecommend === 1 ? '取消推荐' : '设为推荐' }}</el-button>
- </div>
- <div>
- <el-button @click="editBook(scope.row)" type="text" size="small">编辑</el-button>
- <el-button @click="removeBook(scope.row)" type="text" size="small">删除</el-button>
- </div>
- </template>
- </el-table-column>
- </el-table>
- <el-pagination
- layout="prev, pager, next"
- :current-page="page"
- :total="pagenum"
- @current-change="pageChange"
- ></el-pagination>
- </div>
- </div>
- <el-dialog
- title="批量导入"
- :visible.sync="showDialog"
- width="50%">
- <div :style="{ margin: 'auto', width: '80%' }">
- <div><el-button @click="inputRef.click()" :style="{ width: '100%' }">上传文件</el-button></div>
- <div :style="{ textAlign: 'right', paddingTop: '20px' }"><a href="https://jinchengjiaye.oss-cn-beijing.aliyuncs.com/excel/books-batch-import.xlsx" download="书籍导入模板" :style="{ color: '#409EFF' }">下载导入模板</a></div>
- </div>
- <span slot="footer" class="dialog-footer">
- <el-button type="primary" @click="showDialog = false">确 定</el-button>
- <el-button @click="showDialog = false">取 消</el-button>
- </span>
- </el-dialog>
- </div>
- </template>
-
- <script>
- import { createNamespacedHelpers, mapState } from 'vuex'
- import { Loading } from 'element-ui'
-
- const { mapState: mapLibSate, mapActions, mapMutations } = createNamespacedHelpers('library')
-
- export default {
- name: 'bookList',
- data() {
- return {
- formData: {
- caseId: '',
- bookBarcode: '',
- bookName: '',
- },
- inputRef: undefined,
- showDialog: false,
- }
- },
- computed: {
- ...mapState({
- cases: x => x.app.cases.list,
- defaultCase: x => x.app.cases.default,
- orgid: x => x.app.user.OrgId
- }),
- ...mapLibSate({
- list: s => s.list,
- page: s => s.page,
- pagenum: s => s.pagenum,
- types: s => s.type.list
- }),
- caseId: {
- get() {
- return this.formData.caseId || this.defaultCase
- },
- set(nv) {
- this.formData.caseId = nv
- }
- },
- },
- created() {
- this.resetInputRef()
- },
- beforeRouteLeave (to, from, next) {
- this.resetStore('list')
- next()
- },
- methods: {
- ...mapMutations({
- resetStore: 'clearData',
- }),
- ...mapActions({
- getList: 'getBookList',
- getTypeList: 'getTypeList',
- deleteBook: 'deleteBook',
- setBookRecommend: 'updateBookDetail',
- batchImport: 'batchImport',
- }),
-
- resetInputRef() {
- const ipt = window.document.createElement('input')
-
- ipt.type = 'file'
-
- ipt.accept = 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
- ipt.addEventListener('change', this.importBatch.bind(this))
-
- this.inputRef = ipt
- },
-
-
- filterList({ page = 0 } = {}) {
- const caseId = this.caseId || this.defaultCase
- if (!caseId) {
- this.$message({
- showClose: true,
- message: '请选择案场',
- type: 'error'
- })
- return
- }
-
- this.getTypeList({ page: 0, pagesize: 1000, caseid: caseId })
-
- this.getList({
- page,
- caseid: caseId,
- barcode: this.formData.bookBarcode,
- name: this.formData.bookName
- }).then(({ list }) => {
- if (!list) {
- this.$message({
- showClose: true,
- message: '未查询到数据',
- type: 'error'
- })
- }
- }).catch(err => {
- this.$message({
- showClose: true,
- message: err,
- type: 'error'
- })
- })
- },
-
-
- pageChange(page) {
- this.filterList({ page })
- },
-
-
- removeBook({ BookId: id }) {
- this.$confirm('确认删除此数据?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(() => {
- this.deleteBook({
- BookId: id
- })
- .then(() => {
- this.$message({
- showClose: true,
- message: '删除成功',
- type: 'success'
- })
- })
- .catch(err => {
- this.$message({
- showClose: true,
- message: err,
- type: 'error'
- })
- })
- })
- .catch(x => x)
- },
-
-
- editBook({ BookId: id } = {}) {
- this.$router.push({ name: 'libraryEdit', params: { id } })
- },
-
-
- setRecommend(book) {
- const tipMsg = book.IsRecommend === 1 ? '确定取消推荐?' : '确认设置为推荐?'
-
- this.$confirm(tipMsg, '提示', {
- confirmButtonText: '是',
- cancelButtonText: '否',
- type: 'warning'
- })
- .then(() => {
- book.IsRecommend = Math.abs(book.IsRecommend - 1)
- this.setBookRecommend(book)
- .then(() => {
- this.$message({
- showClose: true,
- message: '设置成功',
- type: 'success'
- })
- })
- .catch(err => {
- this.$message({
- showClose: true,
- message: err,
- type: 'error'
- })
- })
- })
- .catch(x => x)
- },
-
-
- showBatchInput() {
- if (!this.caseId) {
- this.showDialog = false
-
- this.$message({
- showClose: true,
- message: '请选择案场',
- type: 'error'
- })
- return
- }
-
- this.showDialog = true
- },
- importBatch(e) {
- this.resetInputRef()
- this.showDialog = false
-
-
- const caseName = this.getCaseName(this.caseId)
- const file = e.target.files[0]
- if (!file) {
- this.$message({
- showClose: true,
- message: '请选择导入文件',
- type: 'error'
- })
- }
-
- this.$confirm(`数据将被导入至【${caseName}】案场, 是否继续?`, '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(() => {
- const loadding = Loading.service({
- lock: true,
- text: '数据导入中, 可能耗时较长, 请耐心等候...'
- })
-
- const data = {
- caseId: this.caseId,
- excel: file,
- }
-
- this.batchImport(data).then(() => {
- loadding.close()
- this.filterList()
- this.$message({
- showClose: true,
- message: '数据导入完成',
- type: 'success'
- })
- }).catch((err) => {
- loadding.close()
-
- this.$message({
- showClose: true,
- message: err,
- type: 'error'
- })
- })
- })
- .catch(x => x)
- },
-
- getCaseName(id) {
- return (this.cases.filter(x => x.CaseId === id)[0] || {}).CaseName
- },
-
- getTypeName(id) {
- return (this.types.filter(x => x.BookTypeId === id)[0] || {}).BookTypeName
- },
-
- formatPrice(price) {
- return window.Number(price).toFixed(2)
- },
-
- getReserveNum({ InStock, LeftNum, BorrowNum } = {}) {
- return InStock - LeftNum - BorrowNum
- },
-
- changeStock({ BookId: id }) {
- this.$router.push({ name: 'stockChange', params: { id } })
- },
- }
- }
- </script>
|