list.vue 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. }).then(({ list }) => {
  184. if (!list) {
  185. this.$message({
  186. showClose: true,
  187. message: '未查询到数据',
  188. type: 'error'
  189. })
  190. }
  191. }).catch(err => {
  192. this.$message({
  193. showClose: true,
  194. message: err,
  195. type: 'error'
  196. })
  197. })
  198. },
  199. // 分页过滤
  200. pageChange(page) {
  201. this.filterList({ page })
  202. },
  203. // 删除图书
  204. removeBook({ BookId: id }) {
  205. this.$confirm('确认删除此数据?', '提示', {
  206. confirmButtonText: '确定',
  207. cancelButtonText: '取消',
  208. type: 'warning'
  209. })
  210. .then(() => {
  211. this.deleteBook({
  212. BookId: id
  213. })
  214. .then(() => {
  215. this.$message({
  216. showClose: true,
  217. message: '删除成功',
  218. type: 'success'
  219. })
  220. })
  221. .catch(err => {
  222. this.$message({
  223. showClose: true,
  224. message: err,
  225. type: 'error'
  226. })
  227. })
  228. })
  229. .catch(x => x)
  230. },
  231. // 跳转到编辑
  232. editBook({ BookId: id } = {}) {
  233. this.$router.push({ name: 'libraryEdit', params: { id } })
  234. },
  235. // 设为/取消推荐
  236. setRecommend(book) {
  237. const tipMsg = book.IsRecommend === 1 ? '确定取消推荐?' : '确认设置为推荐?'
  238. this.$confirm(tipMsg, '提示', {
  239. confirmButtonText: '是',
  240. cancelButtonText: '否',
  241. type: 'warning'
  242. })
  243. .then(() => {
  244. book.IsRecommend = Math.abs(book.IsRecommend - 1)
  245. this.setBookRecommend(book)
  246. .then(() => {
  247. this.$message({
  248. showClose: true,
  249. message: '设置成功',
  250. type: 'success'
  251. })
  252. })
  253. .catch(err => {
  254. this.$message({
  255. showClose: true,
  256. message: err,
  257. type: 'error'
  258. })
  259. })
  260. })
  261. .catch(x => x)
  262. },
  263. // 批量导入
  264. showBatchInput() {
  265. if (!this.caseId) {
  266. this.showDialog = false
  267. this.$message({
  268. showClose: true,
  269. message: '请选择案场',
  270. type: 'error'
  271. })
  272. return
  273. }
  274. this.showDialog = true
  275. },
  276. importBatch(e) {
  277. this.resetInputRef()
  278. this.showDialog = false
  279. // 需要指定案场
  280. const caseName = this.getCaseName(this.caseId)
  281. const file = e.target.files[0]
  282. if (!file) {
  283. this.$message({
  284. showClose: true,
  285. message: '请选择导入文件',
  286. type: 'error'
  287. })
  288. }
  289. this.$confirm(`数据将被导入至【${caseName}】案场, 是否继续?`, '提示', {
  290. confirmButtonText: '确定',
  291. cancelButtonText: '取消',
  292. type: 'warning'
  293. })
  294. .then(() => {
  295. const loadding = Loading.service({
  296. lock: true,
  297. text: '数据导入中, 可能耗时较长, 请耐心等候...'
  298. })
  299. const data = {
  300. caseId: this.caseId,
  301. excel: file,
  302. }
  303. this.batchImport(data).then(() => {
  304. loadding.close()
  305. this.filterList()
  306. this.$message({
  307. showClose: true,
  308. message: '数据导入完成',
  309. type: 'success'
  310. })
  311. }).catch((err) => {
  312. loadding.close()
  313. this.$message({
  314. showClose: true,
  315. message: err,
  316. type: 'error'
  317. })
  318. })
  319. })
  320. .catch(x => x)
  321. },
  322. getCaseName(id) {
  323. return (this.cases.filter(x => x.CaseId === id)[0] || {}).CaseName
  324. },
  325. getTypeName(id) {
  326. return (this.types.filter(x => x.BookTypeId === id)[0] || {}).BookTypeName
  327. },
  328. formatPrice(price) {
  329. return window.Number(price).toFixed(2)
  330. },
  331. getReserveNum({ InStock, LeftNum, BorrowNum } = {}) {
  332. return InStock - LeftNum - BorrowNum
  333. },
  334. changeStock({ BookId: id }) {
  335. this.$router.push({ name: 'stockChange', params: { id } })
  336. },
  337. }
  338. }
  339. </script>