list.vue 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div class="subPage" :style="{ padding: '20px' }">
  3. <div>
  4. <el-form inline>
  5. <el-form-item label="案场">
  6. <el-select v-model="caseId" size="medium" placeholder="请选择案场">
  7. <el-option
  8. v-for="item in cases"
  9. :key="item.CaseId"
  10. :label="item.CaseName"
  11. :value="item.CaseId"
  12. ></el-option>
  13. </el-select>
  14. </el-form-item>
  15. <el-form-item label="条码">
  16. <el-input v-model="formData.bookBarcode"></el-input>
  17. </el-form-item>
  18. <el-form-item label="书名">
  19. <el-input v-model="formData.bookName"></el-input>
  20. </el-form-item>
  21. <el-form-item :style="{ float: 'right' }">
  22. <el-button type="primary" size="medium" @click="filterList">搜索</el-button>
  23. </el-form-item>
  24. </el-form>
  25. </div>
  26. <div>
  27. <el-button plain @click="editBook()" size="medium">图书录入</el-button>
  28. <el-button plain @click="showBatchInput()" size="medium">批量导入</el-button>
  29. <div :style="{ margin: '10px 0' }">
  30. <el-table :data="list" border style="width: 100%">
  31. <el-table-column label="图片" width="128">
  32. <template slot-scope="scope">
  33. <img width="64" :src="scope.row.BookImg + '?x-oss-process=style/compress-rotate'" alt>
  34. </template>
  35. </el-table-column>
  36. <el-table-column prop="BookBarcode" label="条码"></el-table-column>
  37. <el-table-column prop="BookName" label="书名"></el-table-column>
  38. <el-table-column label="案场">
  39. <template slot-scope="scope">
  40. <span>{{ getCaseName(scope.row.CaseId) }}</span>
  41. </template>
  42. </el-table-column>
  43. <el-table-column label="分类">
  44. <template slot-scope="scope">
  45. <span>{{ getTypeName(scope.row.BookTypeId) }}</span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column label="价格">
  49. <template slot-scope="scope">
  50. <span>{{ formatPrice(scope.row.Price) }}</span>
  51. </template>
  52. </el-table-column>
  53. <el-table-column prop="BorrowDays" label="借阅(天)"></el-table-column>
  54. <el-table-column prop="InStock" label="总数量"></el-table-column>
  55. <el-table-column prop="BorrowNum" label="借出"></el-table-column>
  56. <el-table-column label="预约">
  57. <template slot-scope="scope">
  58. <span>{{ getReserveNum(scope.row) }}</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="录入时间">
  62. <template slot-scope="scope">
  63. <span>{{ toolClass.dateFormat(scope.row.CreateDate) }}</span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column fixed="right" label="操作" width="150">
  67. <template slot-scope="scope">
  68. <div>
  69. <el-button type="text" @click="changeStock(scope.row)" size="small">盘点</el-button>
  70. <el-button @click="setRecommend(scope.row)" type="text" size="small">{{ scope.row.IsRecommend === 1 ? '取消推荐' : '设为推荐' }}</el-button>
  71. </div>
  72. <div>
  73. <el-button @click="editBook(scope.row)" type="text" size="small">编辑</el-button>
  74. <el-button @click="removeBook(scope.row)" type="text" size="small">删除</el-button>
  75. </div>
  76. </template>
  77. </el-table-column>
  78. </el-table>
  79. <el-pagination
  80. layout="prev, pager, next"
  81. :current-page="page"
  82. :total="pagenum"
  83. @current-change="pageChange"
  84. ></el-pagination>
  85. </div>
  86. </div>
  87. <el-dialog
  88. title="批量导入"
  89. :visible.sync="showDialog"
  90. width="50%">
  91. <div :style="{ margin: 'auto', width: '80%' }">
  92. <div><el-button @click="inputRef.click()" :style="{ width: '100%' }">上传文件</el-button></div>
  93. <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>
  94. </div>
  95. <span slot="footer" class="dialog-footer">
  96. <el-button type="primary" @click="showDialog = false">确 定</el-button>
  97. <el-button @click="showDialog = false">取 消</el-button>
  98. </span>
  99. </el-dialog>
  100. </div>
  101. </template>
  102. <script>
  103. import { createNamespacedHelpers, mapState } from 'vuex'
  104. import { Loading } from 'element-ui'
  105. const { mapState: mapLibSate, mapActions, mapMutations } = createNamespacedHelpers('library')
  106. export default {
  107. name: 'bookList',
  108. data() {
  109. return {
  110. formData: {
  111. caseId: '',
  112. bookBarcode: '',
  113. bookName: '',
  114. },
  115. inputRef: undefined,
  116. showDialog: false,
  117. }
  118. },
  119. computed: {
  120. ...mapState({
  121. cases: x => x.app.cases.list,
  122. defaultCase: x => x.app.cases.default,
  123. orgid: x => x.app.user.OrgId
  124. }),
  125. ...mapLibSate({
  126. list: s => s.list,
  127. page: s => s.page,
  128. pagenum: s => s.pagenum,
  129. types: s => s.type.list
  130. }),
  131. caseId: {
  132. get() {
  133. return this.formData.caseId || this.defaultCase
  134. },
  135. set(nv) {
  136. this.formData.caseId = nv
  137. }
  138. },
  139. },
  140. created() {
  141. this.resetInputRef()
  142. },
  143. beforeRouteLeave (to, from, next) {
  144. this.resetStore('list')
  145. next()
  146. },
  147. methods: {
  148. ...mapMutations({
  149. resetStore: 'clearData',
  150. }),
  151. ...mapActions({
  152. getList: 'getBookList',
  153. getTypeList: 'getTypeList',
  154. deleteBook: 'deleteBook',
  155. setBookRecommend: 'updateBookDetail',
  156. batchImport: 'batchImport',
  157. }),
  158. resetInputRef() {
  159. const ipt = window.document.createElement('input')
  160. ipt.type = 'file'
  161. // https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types
  162. ipt.accept = 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  163. ipt.addEventListener('change', this.importBatch.bind(this))
  164. this.inputRef = ipt
  165. },
  166. // 查询过滤
  167. filterList({ page = 0 } = {}) {
  168. const caseId = this.caseId || this.defaultCase
  169. if (!caseId) {
  170. this.$message({
  171. showClose: true,
  172. message: '请选择案场',
  173. type: 'error'
  174. })
  175. return
  176. }
  177. this.getTypeList({ page: 0, pagesize: 1000, caseid: caseId })
  178. this.getList({
  179. page,
  180. caseid: caseId,
  181. barcode: this.formData.bookBarcode,
  182. name: this.formData.bookName
  183. }).catch(err => {
  184. this.$message({
  185. showClose: true,
  186. message: err,
  187. type: 'error'
  188. })
  189. })
  190. },
  191. // 分页过滤
  192. pageChange(page) {
  193. this.filterList({ page })
  194. },
  195. // 删除图书
  196. removeBook({ BookId: id }) {
  197. this.$confirm('确认删除此数据?', '提示', {
  198. confirmButtonText: '确定',
  199. cancelButtonText: '取消',
  200. type: 'warning'
  201. })
  202. .then(() => {
  203. this.deleteBook({
  204. BookId: id
  205. })
  206. .then(() => {
  207. this.$message({
  208. showClose: true,
  209. message: '删除成功',
  210. type: 'success'
  211. })
  212. })
  213. .catch(err => {
  214. this.$message({
  215. showClose: true,
  216. message: err,
  217. type: 'error'
  218. })
  219. })
  220. })
  221. .catch(x => x)
  222. },
  223. // 跳转到编辑
  224. editBook({ BookId: id } = {}) {
  225. this.$router.push({ name: 'libraryEdit', params: { id } })
  226. },
  227. // 设为/取消推荐
  228. setRecommend(book) {
  229. const tipMsg = book.IsRecommend === 1 ? '确定取消推荐?' : '确认设置为推荐?'
  230. this.$confirm(tipMsg, '提示', {
  231. confirmButtonText: '是',
  232. cancelButtonText: '否',
  233. type: 'warning'
  234. })
  235. .then(() => {
  236. book.IsRecommend = Math.abs(book.IsRecommend - 1)
  237. this.setBookRecommend(book)
  238. .then(() => {
  239. this.$message({
  240. showClose: true,
  241. message: '设置成功',
  242. type: 'success'
  243. })
  244. })
  245. .catch(err => {
  246. this.$message({
  247. showClose: true,
  248. message: err,
  249. type: 'error'
  250. })
  251. })
  252. })
  253. .catch(x => x)
  254. },
  255. // 批量导入
  256. showBatchInput() {
  257. if (!this.caseId) {
  258. this.showDialog = false
  259. this.$message({
  260. showClose: true,
  261. message: '请选择案场',
  262. type: 'error'
  263. })
  264. return
  265. }
  266. this.showDialog = true
  267. },
  268. importBatch(e) {
  269. this.resetInputRef()
  270. this.showDialog = false
  271. // 需要指定案场
  272. const caseName = this.getCaseName(this.caseId)
  273. const file = e.target.files[0]
  274. if (!file) {
  275. this.$message({
  276. showClose: true,
  277. message: '请选择导入文件',
  278. type: 'error'
  279. })
  280. }
  281. this.$confirm(`数据将被导入至【${caseName}】案场, 是否继续?`, '提示', {
  282. confirmButtonText: '确定',
  283. cancelButtonText: '取消',
  284. type: 'warning'
  285. })
  286. .then(() => {
  287. const loadding = Loading.service({
  288. lock: true,
  289. text: '数据导入中, 可能耗时较长, 请耐心等候...'
  290. })
  291. const data = {
  292. caseId: this.caseId,
  293. excel: file,
  294. }
  295. this.batchImport(data).then(() => {
  296. loadding.close()
  297. this.filterList()
  298. this.$message({
  299. showClose: true,
  300. message: '数据导入完成',
  301. type: 'success'
  302. })
  303. }).catch((err) => {
  304. loadding.close()
  305. this.$message({
  306. showClose: true,
  307. message: err,
  308. type: 'error'
  309. })
  310. })
  311. })
  312. .catch(x => x)
  313. },
  314. getCaseName(id) {
  315. return (this.cases.filter(x => x.CaseId === id)[0] || {}).CaseName
  316. },
  317. getTypeName(id) {
  318. return (this.types.filter(x => x.BookTypeId === id)[0] || {}).BookTypeName
  319. },
  320. formatPrice(price) {
  321. return window.Number(price).toFixed(2)
  322. },
  323. getReserveNum({ InStock, LeftNum, BorrowNum } = {}) {
  324. return InStock - LeftNum - BorrowNum
  325. },
  326. changeStock({ BookId: id }) {
  327. this.$router.push({ name: 'stockChange', params: { id } })
  328. },
  329. }
  330. }
  331. </script>