product.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <div>
  3. <transition appear enter-active-class="animated fadeIn">
  4. <q-table class="my-sticky-header-column-table shadow-24" :data="table_list" row-key="id" :separator="separator"
  5. :loading="loading" :filter="filter" :columns="columns" hide-bottom :pagination.sync="pagination"
  6. no-data-label="No data" no-results-label="No data you want" :table-style="{ height: height }" flat bordered>
  7. <template v-slot:top>
  8. <q-btn-group push>
  9. <q-btn :label="$t('new')" icon="add" @click="newFormCheck()">
  10. <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"
  11. content-style="font-size: 12px">
  12. {{ $t('newtip') }}
  13. </q-tooltip>
  14. </q-btn>
  15. <q-btn :label="$t('refresh')" icon="refresh" @click="reFresh()">
  16. <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"
  17. content-style="font-size: 12px">
  18. {{ $t('refreshtip') }}
  19. </q-tooltip>
  20. </q-btn>
  21. </q-btn-group>
  22. <q-space />
  23. </template>
  24. <template v-slot:body="props">
  25. <q-tr :props="props">
  26. <template v-if="props.row.id === editid">
  27. <q-td key="product_std" :props="props">
  28. <q-input dense outlined square v-model="editFormData.product_std"
  29. :label="'产品标准'" autofocus
  30. :rules="[val => val && val.length > 0 || error1]" />
  31. </q-td>
  32. </template>
  33. <template v-else-if="props.row.id !== editid">
  34. <q-td key="product_std" :props="props">
  35. {{ props.row.product_std }}
  36. </q-td>
  37. </template>
  38. <template v-if="props.row.id === editid">
  39. <q-td key="product_code" :props="props">
  40. <q-input dense outlined square v-model="editFormData.product_code"
  41. :label="'产品代码'" autofocus
  42. :rules="[val => val && val.length > 0 || error0]" />
  43. </q-td>
  44. </template>
  45. <template v-else-if="props.row.id !== editid">
  46. <q-td key="product_code" :props="props">
  47. {{ props.row.product_code }}
  48. </q-td>
  49. </template>
  50. <template v-if="props.row.id === editid">
  51. <q-td key="product_name" :props="props">
  52. <q-input dense outlined square v-model="editFormData.product_name"
  53. :label="'产品名称'" autofocus
  54. :rules="[val => val && val.length > 0 || error1]" />
  55. </q-td>
  56. </template>
  57. <template v-else-if="props.row.id !== editid">
  58. <q-td key="product_name" :props="props">
  59. {{ props.row.product_name }}
  60. </q-td>
  61. </template>
  62. <q-td key="creater" :props="props">
  63. {{ props.row.creater }}
  64. </q-td>
  65. <q-td key="create_time" :props="props">
  66. {{ props.row.create_time }}
  67. </q-td>
  68. <q-td key="update_time" :props="props">
  69. {{ props.row.update_time }}
  70. </q-td>
  71. <template v-if="!editMode">
  72. <q-td key="action" :props="props" style="width: 100px">
  73. <q-btn round flat push color="purple" icon="edit" @click="editData(props.row)">
  74. <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"
  75. content-style="font-size: 12px">
  76. {{ $t('edit') }}
  77. </q-tooltip>
  78. </q-btn>
  79. <q-btn round flat push color="dark" icon="delete" @click="deleteData(props.row.id)">
  80. <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"
  81. content-style="font-size: 12px">
  82. {{ $t('delete') }}
  83. </q-tooltip>
  84. </q-btn>
  85. </q-td>
  86. </template>
  87. <template v-else-if="editMode">
  88. <template v-if="props.row.id === editid">
  89. <q-td key="action" :props="props" style="width: 100px">
  90. <q-btn round flat push color="secondary" icon="check" @click="editDataSubmit()">
  91. <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"
  92. content-style="font-size: 12px">
  93. {{ $t('confirmedit') }}
  94. </q-tooltip>
  95. </q-btn>
  96. <q-btn round flat push color="red" icon="close" @click="editDataCancel()">
  97. <q-tooltip content-class="bg-amber text-black shadow-4" :offset="[10, 10]"
  98. content-style="font-size: 12px">
  99. {{ $t('canceledit') }}
  100. </q-tooltip>
  101. </q-btn>
  102. </q-td>
  103. </template>
  104. <template v-else-if="props.row.id !== editid"></template>
  105. </template>
  106. </q-tr>
  107. </template>
  108. </q-table>
  109. </transition>
  110. <template>
  111. <div v-show="max !== 0" class="q-pa-lg flex flex-center">
  112. <div>{{ total }} </div>
  113. <q-pagination v-model="current" color="black" :max="max" :max-pages="6" boundary-links @click="getList()" />
  114. <div>
  115. <input v-model="paginationIpt" @blur="changePageEnter" @keyup.enter="changePageEnter"
  116. style="width: 60px; text-align: center" />
  117. </div>
  118. </div>
  119. <div v-show="max === 0" class="q-pa-lg flex flex-center">
  120. <q-btn flat push color="dark" :label="$t('no_data')"></q-btn>
  121. </div>
  122. </template>
  123. <q-dialog v-model="newForm">
  124. <q-card class="shadow-24">
  125. <q-bar class="bg-light-blue-10 text-white rounded-borders" style="height: 50px">
  126. <div>{{ $t('newtip') }}</div>
  127. <q-space />
  128. <q-btn dense flat icon="close" v-close-popup>
  129. <q-tooltip content-class="bg-amber text-black shadow-4">{{ $t('index.close') }}</q-tooltip>
  130. </q-btn>
  131. </q-bar>
  132. <q-card-section style="max-height: 325px; width: 400px" class="scroll">
  133. <q-input dense outlined square v-model="newFormData.product_std"
  134. :label="'产品标准'" autofocus
  135. :rules="[val => val && val.length > 0 || error1]" />
  136. <q-input dense outlined square v-model="newFormData.product_code"
  137. :label="'产品代码'" autofocus
  138. :rules="[val => val && val.length > 0 || error0]" />
  139. <q-input dense outlined square v-model="newFormData.product_name"
  140. :label="'产品名称'" :rules="[val => val && val.length > 0 || error1]"
  141. @keyup.enter="newDataSubmit()" />
  142. </q-card-section>
  143. <div style="float: right; padding: 15px 15px 15px 0">
  144. <q-btn color="white" text-color="black" style="margin-right: 25px" @click="newDataCancel()">{{ $t('cancel')
  145. }}</q-btn>
  146. <q-btn color="primary" @click="newDataSubmit()">{{ $t('submit') }}</q-btn>
  147. </div>
  148. </q-card>
  149. </q-dialog>
  150. <q-dialog v-model="deleteForm">
  151. <q-card class="shadow-24">
  152. <q-bar class="bg-light-blue-10 text-white rounded-borders" style="height: 50px">
  153. <div>{{ $t('delete') }}</div>
  154. <q-space />
  155. <q-btn dense flat icon="close" v-close-popup>
  156. <q-tooltip content-class="bg-amber text-black shadow-4">{{ $t('index.close') }}</q-tooltip>
  157. </q-btn>
  158. </q-bar>
  159. <q-card-section style="max-height: 325px; width: 400px" class="scroll">
  160. {{ $t('deletetip') }}
  161. </q-card-section>
  162. <div style="float: right; padding: 15px 15px 15px 0">
  163. <q-btn color="white" text-color="black" style="margin-right: 25px" @click="deleteDataCancel()">{{ $t('cancel')
  164. }}</q-btn>
  165. <q-btn color="primary" @click="deleteDataSubmit()">{{ $t('submit') }}</q-btn>
  166. </div>
  167. </q-card>
  168. </q-dialog>
  169. </div>
  170. </template>
  171. <router-view />
  172. <script>
  173. import { getauth, postauth, putauth, deleteauth } from 'boot/axios_request'
  174. import { LocalStorage } from 'quasar'
  175. import axios from 'axios'
  176. export default {
  177. name: 'Pageproduct',
  178. data() {
  179. return {
  180. openid: '',
  181. login_name: '',
  182. authin: '0',
  183. pathname: 'warehouse/product/',
  184. pathname_previous: '',
  185. pathname_next: '',
  186. separator: 'cell',
  187. loading: false,
  188. height: '',
  189. table_list: [],
  190. columns: [
  191. { name: 'product_std', required: true, label: '产品标准', align: 'left', field: 'product_std' ,sortable: true},
  192. { name: 'product_code', required: true, label: '产品代码', align: 'left', field: 'product_code' ,sortable: true},
  193. { name: 'product_name', required: true, label: '产品名称', align: 'left', field: 'product_name' ,sortable: true},
  194. { name: 'creater', label: this.$t('creater'), field: 'creater', align: 'center' },
  195. { name: 'action', label: this.$t('action'), align: 'center' }
  196. ],
  197. filter: '',
  198. pagination: {
  199. page: 1,
  200. rowsPerPage: 11
  201. },
  202. newForm: false,
  203. newFormData: {
  204. product_std: '',
  205. product_code: '',
  206. product_name: '',
  207. creater: ''
  208. },
  209. editid: 0,
  210. editFormData: {},
  211. editMode: false,
  212. deleteForm: false,
  213. deleteid: 0,
  214. square_measure: '',
  215. error0: this.$t('warehouse.view_warehouseset.error0'),
  216. error1: this.$t('warehouse.view_warehouseset.error1'),
  217. error2: this.$t('warehouse.view_warehouseset.error2'),
  218. error3: this.$t('warehouse.view_warehouseset.error3'),
  219. error4: this.$t('warehouse.view_warehouseset.error4'),
  220. error5: this.$t('warehouse.view_warehouseset.error5'),
  221. current: 1,
  222. max: 0,
  223. total: 0,
  224. paginationIpt: 1
  225. }
  226. },
  227. methods: {
  228. getList() {
  229. var _this = this
  230. if (LocalStorage.has('auth')) {
  231. getauth(_this.pathname + '?page=' + '' + _this.current, {
  232. }).then(res => {
  233. _this.table_list = res.results
  234. _this.total = res.count
  235. if (res.count === 0) {
  236. _this.max = 0
  237. } else {
  238. if (Math.ceil(res.count / _this.pagination.rowsPerPage) === 1) {
  239. _this.max = 0
  240. } else {
  241. _this.max = Math.ceil(res.count / _this.pagination.rowsPerPage)
  242. }
  243. }
  244. _this.pathname_previous = res.previous
  245. _this.pathname_next = res.next
  246. }).catch(err => {
  247. _this.$q.notify({
  248. message: err.detail,
  249. icon: 'close',
  250. color: 'negative'
  251. })
  252. })
  253. }
  254. },
  255. changePageEnter(e) {
  256. if (Number(this.paginationIpt) < 1) {
  257. this.current = 1
  258. this.paginationIpt = 1
  259. } else if (Number(this.paginationIpt) > this.max) {
  260. this.current = this.max
  261. this.paginationIpt = this.max
  262. } else {
  263. this.current = Number(this.paginationIpt)
  264. }
  265. this.getList()
  266. },
  267. getListPrevious() {
  268. var _this = this
  269. if (LocalStorage.has('auth')) {
  270. getauth(_this.pathname_previous, {
  271. }).then(res => {
  272. _this.table_list = res.results
  273. _this.pathname_previous = res.previous
  274. _this.pathname_next = res.next
  275. }).catch(err => {
  276. _this.$q.notify({
  277. message: err.detail,
  278. icon: 'close',
  279. color: 'negative'
  280. })
  281. })
  282. }
  283. },
  284. getListNext() {
  285. var _this = this
  286. if (LocalStorage.has('auth')) {
  287. getauth(_this.pathname_next, {
  288. }).then(res => {
  289. _this.table_list = res.results
  290. _this.pathname_previous = res.previous
  291. _this.pathname_next = res.next
  292. }).catch(err => {
  293. _this.$q.notify({
  294. message: err.detail,
  295. icon: 'close',
  296. color: 'negative'
  297. })
  298. })
  299. } else {
  300. }
  301. },
  302. reFresh() {
  303. var _this = this
  304. _this.getList()
  305. },
  306. newFormCheck() {
  307. var _this = this
  308. _this.newForm = true
  309. },
  310. newDataSubmit() {
  311. var _this = this
  312. var productsets = []
  313. _this.table_list.forEach(i => {
  314. productsets.push(i.product_name)
  315. })
  316. if (productsets.indexOf(_this.newFormData.product_name) === -1 && _this.newFormData.product_name.length !== 0) {
  317. _this.newFormData.creater = _this.login_name
  318. postauth(_this.pathname, _this.newFormData).then(res => {
  319. _this.getList()
  320. _this.newDataCancel()
  321. _this.$q.notify({
  322. message: 'Success Create',
  323. icon: 'check',
  324. color: 'green'
  325. })
  326. }).catch(err => {
  327. _this.$q.notify({
  328. message: err.detail,
  329. icon: 'close',
  330. color: 'negative'
  331. })
  332. })
  333. } else {
  334. _this.newFormData.creater = _this.login_name
  335. postauth(_this.pathname, _this.newFormData).then(res => {
  336. _this.getList()
  337. _this.newDataCancel()
  338. _this.$q.notify({
  339. message: '',
  340. icon: 'close',
  341. color: 'negative'
  342. })
  343. }).catch(err => {
  344. _this.$q.notify({
  345. message: err.detail,
  346. icon: 'close',
  347. color: 'negative'
  348. })
  349. })
  350. }
  351. productsets = []
  352. },
  353. newDataCancel() {
  354. var _this = this
  355. _this.newForm = false
  356. _this.newFormData = {
  357. product_std: '',
  358. product_code: '',
  359. product_name: '',
  360. creater: ''
  361. }
  362. },
  363. editData(e) {
  364. var _this = this
  365. _this.editMode = true
  366. _this.editid = e.id
  367. _this.editFormData = {
  368. product_std: e.product_std,
  369. product_code: e.product_code,
  370. product_name: e.product_name,
  371. creater: _this.login_name
  372. }
  373. },
  374. editDataSubmit() {
  375. var _this = this
  376. putauth(_this.pathname + _this.editid + '/', _this.editFormData).then(res => {
  377. _this.editDataCancel()
  378. _this.getList()
  379. _this.$q.notify({
  380. message: 'Success Edit Data',
  381. icon: 'check',
  382. color: 'green'
  383. })
  384. }).catch(err => {
  385. _this.$q.notify({
  386. message: err.detail,
  387. icon: 'close',
  388. color: 'negative'
  389. })
  390. })
  391. },
  392. editDataCancel() {
  393. var _this = this
  394. _this.editMode = false
  395. _this.editid = 0
  396. _this.editFormData = {
  397. product_std: '',
  398. product_code: '',
  399. product_name: '',
  400. creater: ''
  401. }
  402. },
  403. deleteData(e) {
  404. var _this = this
  405. _this.deleteForm = true
  406. _this.deleteid = e
  407. },
  408. deleteDataSubmit() {
  409. var _this = this
  410. deleteauth(_this.pathname + _this.deleteid + '/').then(res => {
  411. _this.deleteDataCancel()
  412. _this.getList()
  413. _this.$q.notify({
  414. message: 'Success Edit Data',
  415. icon: 'check',
  416. color: 'green'
  417. })
  418. }).catch(err => {
  419. _this.$q.notify({
  420. message: err.detail,
  421. icon: 'close',
  422. color: 'negative'
  423. })
  424. })
  425. },
  426. deleteDataCancel() {
  427. var _this = this
  428. _this.deleteForm = false
  429. _this.deleteid = 0
  430. }
  431. },
  432. created() {
  433. var _this = this
  434. if (LocalStorage.has('openid')) {
  435. _this.openid = LocalStorage.getItem('openid')
  436. } else {
  437. _this.openid = ''
  438. LocalStorage.set('openid', '')
  439. }
  440. if (LocalStorage.has('login_name')) {
  441. _this.login_name = LocalStorage.getItem('login_name')
  442. } else {
  443. _this.login_name = ''
  444. LocalStorage.set('login_name', '')
  445. }
  446. if (LocalStorage.has('auth')) {
  447. _this.authin = '1'
  448. _this.getList()
  449. } else {
  450. _this.authin = '0'
  451. }
  452. },
  453. mounted() {
  454. var _this = this
  455. if (_this.$q.platform.is.electron) {
  456. _this.height = String(_this.$q.screen.height - 290) + 'px'
  457. } else {
  458. _this.height = _this.$q.screen.height - 290 + '' + 'px'
  459. }
  460. },
  461. updated() {
  462. },
  463. destroyed() {
  464. }
  465. }
  466. </script>