borrow.vue 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <div class="subPage edit-book" :style="{ padding: '20px' }">
  3. <div v-if="!active">
  4. <el-form style="text-align: center;">
  5. <el-form-item>
  6. <el-input v-model="customerInfo" placeholder="会员手机号或条形码" :style="{ width: '400px' }"></el-input>
  7. </el-form-item>
  8. <el-form-item :style="{ paddingTop: '20px' }">
  9. <el-button type="primary" @click="nextStep()">下一步</el-button>
  10. </el-form-item>
  11. </el-form>
  12. </div>
  13. <div v-else>
  14. <!-- 用户信息区 -->
  15. <div :style="{ marginBottom: '20px', paddingBottom: '20px', borderBottom: '1px solid #eee' }">
  16. <el-row :gutter="20">
  17. <el-col :span="4">
  18. <span>姓名: </span><span>{{ borrowHistory.Name }}</span>
  19. </el-col>
  20. <el-col :span="4">
  21. <span>手机号: </span><span>{{ borrowHistory.Phone }}</span>
  22. </el-col>
  23. <el-col :span="4">
  24. <span>在借图书数量: </span><span>{{ borrowHistory.BorrowNum }}</span>
  25. </el-col>
  26. <el-col :span="4">
  27. <span>逾期图书数量: </span><span>{{ borrowHistory.LateNum }}</span>
  28. </el-col>
  29. <el-col :span="4">
  30. <span>历史是否有逾期: </span><span>{{ borrowHistory.IsLate === 'yes' ? '是' : '否' }}</span>
  31. </el-col>
  32. </el-row>
  33. </div>
  34. <!-- 过滤条件 -->
  35. <el-form inline>
  36. <el-form-item label="案场">
  37. <el-select v-model="caseId" size="medium" placeholder="请选择案场">
  38. <el-option
  39. v-for="item in cases"
  40. :key="item.CaseId"
  41. :label="item.CaseName"
  42. :value="item.CaseId"
  43. ></el-option>
  44. </el-select>
  45. </el-form-item>
  46. <el-form-item label="条形码">
  47. <el-input ref="barcode" v-model="formData.barcode" :style="{ width: '200px' }"></el-input>
  48. </el-form-item>
  49. <el-form-item label="图书名">
  50. <el-input v-model="formData.name" :style="{ width: '200px' }"></el-input>
  51. </el-form-item>
  52. <el-form-item :style="{ float: 'right' }">
  53. <el-button type="primary" @click="search()">搜索</el-button>
  54. </el-form-item>
  55. </el-form>
  56. <!-- 可借阅列表 -->
  57. <el-table :data="list" border style="width: 100%" @selection-change="x => selectList = x">
  58. <el-table-column
  59. type="selection"
  60. width="55">
  61. </el-table-column>
  62. <el-table-column prop="BookBarcode" label="条形码"></el-table-column>
  63. <el-table-column prop="BookName" label="图书名"></el-table-column>
  64. <el-table-column label="分类">
  65. <template slot-scope="scope">
  66. <span>{{ getTypeName(scope.row.BookTypeId) }}</span>
  67. </template>
  68. </el-table-column>
  69. <el-table-column prop="LeftNum" label="可借数量"></el-table-column>
  70. <el-table-column prop="BorrowDays" label="规定借阅天数"></el-table-column>
  71. </el-table>
  72. <div :style="{ marginTop: '40px', marginBottom: '40px' }">
  73. <el-button type="primary" @click="submit()">立即借阅</el-button>
  74. <el-button @click="cancel()">返回</el-button>
  75. </div>
  76. </div>
  77. </div>
  78. </template>
  79. <script>
  80. import { createNamespacedHelpers, mapState } from 'vuex'
  81. const {
  82. mapState: mapLibSate,
  83. mapActions,
  84. mapMutations,
  85. } = createNamespacedHelpers('library')
  86. export default {
  87. name: 'bookBorrow',
  88. data() {
  89. return {
  90. active: 0,
  91. customerInfo: '',
  92. formData: { caseid: '', barcode: '', name: '' },
  93. selectList: [],
  94. }
  95. },
  96. computed: {
  97. ...mapState({
  98. cases: x => x.app.cases.list,
  99. defaultCase: x => x.app.cases.default,
  100. orgid: x => x.app.user.OrgId
  101. }),
  102. ...mapLibSate({
  103. list: s => s.list,
  104. types: s => s.type.list,
  105. borrowHistory: s => s.borrow.history,
  106. }),
  107. caseId: {
  108. get() {
  109. return this.formData.caseid || this.defaultCase
  110. },
  111. set(val) {
  112. this.formData.caseid = val
  113. },
  114. },
  115. },
  116. beforeRouteLeave (to, from, next) {
  117. this.resetStore('list')
  118. next()
  119. },
  120. methods: {
  121. ...mapMutations({
  122. resetStore: 'clearData',
  123. }),
  124. ...mapActions({
  125. getBorrowHistory: 'getBorrowHistory',
  126. getList: 'getBookList',
  127. getTypeList: 'getTypeList',
  128. borrowBooks: 'borrowBooks',
  129. setListNil: 'setListNil',
  130. }),
  131. nextStep() {
  132. if (!this.customerInfo) {
  133. this.$message({
  134. showClose: true,
  135. message: '请录入会员手机号或条形码',
  136. type: 'error'
  137. })
  138. return
  139. }
  140. this.getBorrowHistory({ customerInfo: this.customerInfo }).then(() => {
  141. this.active = 1
  142. }).catch(err => {
  143. this.$message({
  144. showClose: true,
  145. message: err,
  146. type: 'error'
  147. })
  148. })
  149. },
  150. search() {
  151. // 必须选案场
  152. if (!this.formData.caseid && !this.defaultCase) {
  153. this.$message({
  154. showClose: true,
  155. message: '请选择案场',
  156. type: 'error'
  157. })
  158. return
  159. }
  160. if (!this.formData.caseid) {
  161. this.formData.caseid = this.defaultCase
  162. }
  163. // 先扫码或者输入图书名称
  164. if (!this.formData.barcode && !this.formData.name) {
  165. this.$message({
  166. showClose: true,
  167. message: '请先扫码或者输入图书名称',
  168. type: 'error'
  169. })
  170. return
  171. }
  172. this.getTypeList({ page: 0, pagesize: 1000, caseid: this.formData.caseid })
  173. this.getList({
  174. ...this.formData,
  175. // customerphone: this.borrowHistory.Phone,
  176. }).then(res => {
  177. if (!res.list || res.list.length === 0) {
  178. this.$message({
  179. showClose: true,
  180. message: '没有查询到数据',
  181. type: 'error'
  182. })
  183. }
  184. }).catch(err => {
  185. this.$message({
  186. showClose: true,
  187. message: err,
  188. type: 'error'
  189. })
  190. })
  191. },
  192. submit() {
  193. if (!this.selectList || this.selectList.length === 0) {
  194. this.$message({
  195. showClose: true,
  196. message: '请选择借阅图书',
  197. type: 'error'
  198. })
  199. return
  200. }
  201. this.$confirm('确定借阅此书?', '提示', {
  202. confirmButtonText: '确定',
  203. cancelButtonText: '取消',
  204. type: 'warning'
  205. })
  206. .then(() => {
  207. const bookIds = this.selectList.map(({BookId}) => BookId).join(',')
  208. this.borrowBooks({
  209. bookIds,
  210. customerId: this.borrowHistory.CustomerId,
  211. }).then(() => {
  212. this.$message({
  213. showClose: true,
  214. message: '借阅成功',
  215. type: 'success'
  216. })
  217. this.formData.barcode = ''
  218. this.formData.name = ''
  219. this.getBorrowHistory({ customerInfo: this.customerInfo })
  220. this.setListNil()
  221. }).catch(err => {
  222. this.$message({
  223. showClose: true,
  224. message: err,
  225. type: 'error'
  226. })
  227. })
  228. })
  229. .catch(x => x)
  230. },
  231. getTypeName(id) {
  232. return (this.types.filter(x => x.BookTypeId === id)[0] || {}).BookTypeName
  233. },
  234. cancel() {
  235. this.customerInfo = ''
  236. this.active = 0
  237. }
  238. }
  239. }
  240. </script>
  241. <style lang="scss">
  242. </style>