AdminStoreBasketShow.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <div class="AdminDiscountShow"
  3. :style="localOptions.style">
  4. <div class="flex justify-end">
  5. <q-btn flat
  6. color="grey"
  7. @click="$router.go(-1)">
  8. بازگشت
  9. >
  10. </q-btn>
  11. </div>
  12. <entity-show v-if="mounted"
  13. ref="entityShow"
  14. v-model:value="inputs"
  15. title="جزییات صورتحساب"
  16. :api="api"
  17. :entity-id-key="entityIdKey"
  18. :entity-param-key="entityParamKey"
  19. :show-close-button="false"
  20. :show-edit-button="false"
  21. :show-expand-button="false"
  22. :show-reload-button="false"
  23. :show-index-button="false"
  24. :after-load-input-data="afterLoadInputData">
  25. <template #before-form-builder>
  26. <div class="basket-form-header row">
  27. <div class="col-md-4 col-12 flex justify-start items-center">
  28. <q-icon name="shopping_cart" />
  29. شناسه:
  30. {{ basket.id }}
  31. </div>
  32. <div class="col-md-8 col-12">
  33. <span class="text-info">
  34. {{ basket.status_info.label }}
  35. </span>
  36. <q-linear-progress :value="basketStatusProgress"
  37. color="info"
  38. size="16px"
  39. rounded
  40. class="q-mt-سپ" />
  41. </div>
  42. </div>
  43. </template>
  44. </entity-show>
  45. <div class="q-mt-md">
  46. <entity-index v-if="basket.id"
  47. v-model:value="tableInputs"
  48. title="لیست محصولات سفارش"
  49. :table="table"
  50. :loaded-data="basket"
  51. :table-keys="tableKeys"
  52. :show-search-button="false"
  53. :show-expand-button="false"
  54. :show-reload-button="false">
  55. <template #entity-index-table-cell="{inputData}">
  56. <template v-if="inputData.col.name === 'number'">
  57. {{ inputData.rowNumber }}
  58. </template>
  59. <template v-else-if="inputData.col.name === 'thumbnail'">
  60. <q-img :src="inputData.col.value"
  61. width="100px" />
  62. </template>
  63. <template v-else-if="inputData.col.name === 'action'">
  64. <q-btn color="primary"
  65. outline
  66. :to="{name: inputData.props.row.product ? 'Admin.Store.Product.Show' : 'Admin.Store.Package.Show', params: {id: inputData.props.row.product || inputData.props.row.package}}">
  67. <q-icon name="visibility"
  68. class="q-mr-sm" />
  69. مشاهده
  70. </q-btn>
  71. </template>
  72. <template v-else>
  73. {{ inputData.col.value }}
  74. </template>
  75. </template>
  76. </entity-index>
  77. </div>
  78. </div>
  79. </template>
  80. <script>
  81. import { shallowRef } from 'vue'
  82. import { Basket } from 'src/models/Basket.js'
  83. import { Product } from 'src/models/Product.js'
  84. import { mixinWidget } from 'src/mixin/Mixins.js'
  85. import { APIGateway } from 'src/api/APIGateway.js'
  86. import BtnControl from 'components/Control/btn.vue'
  87. import { EntityShow, EntityIndex } from 'quasar-crud'
  88. import { FormBuilderAssist } from 'quasar-form-builder'
  89. import { Package } from 'src/models/Package'
  90. const BtnControlComp = shallowRef(BtnControl)
  91. export default {
  92. name: 'AdminStoreBasketShow',
  93. components: {
  94. EntityShow,
  95. EntityIndex
  96. },
  97. mixins: [mixinWidget],
  98. data () {
  99. return {
  100. mounted: false,
  101. entityLoading: false,
  102. api: APIGateway.basket.APIAdresses.byId(this.$route.params.id),
  103. entityIdKey: 'id',
  104. entityParamKey: 'id',
  105. indexRouteName: 'Admin.Store.Basket.List',
  106. inputs: [],
  107. tableKeys: {
  108. data: 'items_info.list',
  109. total: 'count',
  110. currentPage: 'current',
  111. perPage: 'per_page',
  112. pageKey: 'page'
  113. },
  114. tableInputs: [],
  115. table: {
  116. columns: [
  117. {
  118. name: 'number',
  119. required: true,
  120. label: 'شماره',
  121. align: 'left',
  122. field: () => ''
  123. },
  124. {
  125. name: 'id',
  126. required: true,
  127. label: 'شناسه',
  128. align: 'left',
  129. field: row => row.id
  130. },
  131. {
  132. name: 'title',
  133. required: true,
  134. label: 'نام محصول',
  135. align: 'left',
  136. field: row => (row.product_info || row.package_info).title
  137. },
  138. {
  139. name: 'is_package_or_product',
  140. required: true,
  141. label: 'نوع محصول',
  142. align: 'left',
  143. field: row => row.package ? 'بسته' : 'تکی'
  144. },
  145. {
  146. name: 'content_category',
  147. required: true,
  148. label: 'دسته بندی اصلی',
  149. align: 'left',
  150. field: row => row.content_category
  151. },
  152. {
  153. name: 'count',
  154. required: true,
  155. label: 'تعداد',
  156. align: 'left',
  157. field: row => row.count
  158. },
  159. {
  160. name: 'is_physical_info',
  161. required: true,
  162. label: 'نوع جنس',
  163. align: 'left',
  164. field: row => row.product_info ? (new Product(row.product_info)).is_physical_info.label : (new Package(row.product_info)).is_physical_info.label
  165. },
  166. {
  167. name: 'physical_type_info',
  168. required: true,
  169. label: 'نوع محصول',
  170. align: 'left',
  171. field: row => row.product_info ? (new Product(row.product_info)).physical_type_info.label : '-'
  172. },
  173. {
  174. name: 'unit_price',
  175. required: true,
  176. label: 'قیمت',
  177. align: 'left',
  178. field: row => parseInt((row.product_info || row.package_info).unit_price.toString()).toLocaleString('fa')
  179. },
  180. {
  181. name: 'action',
  182. required: true,
  183. label: 'عملیات',
  184. align: 'left',
  185. field: row => ''
  186. }
  187. ]
  188. },
  189. basket: new Basket()
  190. }
  191. },
  192. computed: {
  193. basketStatusProgress () {
  194. if (this.basket.status === 'OPEN') {
  195. return 0.1
  196. }
  197. if (this.basket.status === 'CANCELED') {
  198. return 0
  199. }
  200. if (this.basket.status === 'PAID') {
  201. return 0.5
  202. }
  203. if (this.basket.status === 'CLOSED') {
  204. return 1
  205. }
  206. if (this.basket.status === 'SENT') {
  207. return 1
  208. }
  209. return 0.5
  210. }
  211. },
  212. created() {
  213. this.inputs = [
  214. { type: 'separator', name: 'space1', label: 'مشخصات خریدار', className: 'custom-separator', col: 'col-12' },
  215. { type: 'input', name: 'owner_info.firstname', responseKey: 'owner_info.firstname', label: 'نام', placeholder: ' ', col: 'col-md-2 col-12' },
  216. { type: 'input', name: 'owner_info.lastname', responseKey: 'owner_info.lastname', label: 'نام خانوادگی', placeholder: ' ', col: 'col-md-2 col-12' },
  217. { type: 'input', name: 'owner_info.national_code', responseKey: 'owner_info.national_code', label: 'کد ملی', placeholder: ' ', col: 'col-md-2 col-12' },
  218. { type: 'input', name: 'owner_info.phone_number', responseKey: 'owner_info.phone_number', label: 'تلفن همراه', placeholder: ' ', col: 'col-md-3 col-12' },
  219. { type: 'input', name: 'owner_info.email', responseKey: 'owner_info.email', label: 'ایمیل', placeholder: ' ', col: 'col-md-3 col-12' },
  220. { type: 'input', name: 'owner_info.living_city', responseKey: 'owner_info.living_city', label: 'شهر', placeholder: ' ', col: 'col-md-2 col-12' },
  221. { type: 'input', name: 'postal_code', responseKey: 'postal_code', label: 'کد پستی', placeholder: ' ', col: 'col-md-2 col-12' },
  222. { type: 'input', name: 'owner_info.living_address', responseKey: 'owner_info.living_address', label: 'آدرس', placeholder: ' ', col: 'col-md-5 col-12' },
  223. { type: BtnControlComp, name: 'btn', responseKey: 'btn', label: 'مشخصات کاربر', placeholder: ' ', outline: true, ignoreValue: true, atClick: this.showUserPage, loading: this.entityLoading, col: 'col-md-2 col-12' },
  224. { type: 'separator', name: 'space1', label: 'مشخصات سفارش', className: 'custom-separator', col: 'col-12' },
  225. { type: 'input', name: 'id', responseKey: 'id', label: 'شناسه', placeholder: ' ', col: 'col-md-2 col-12' },
  226. { type: 'input', name: 'items_info.length', responseKey: 'items_info.length', label: 'تعداد اقلام', placeholder: ' ', col: 'col-md-2 col-12' },
  227. { type: 'dateTime', name: 'creation_time', responseKey: 'creation_time', outsideLabel: 'تاریخ ثبت', placeholder: ' ', disable: true, col: 'col-md-3 col-12' },
  228. { type: 'input', name: 'overall_order_price', responseKey: 'overall_order_price', label: 'قیمت کل(تومان)', placeholder: ' ', col: 'col-md-3 col-12' },
  229. { type: BtnControlComp, name: 'btnSent', responseKey: 'btnSent', label: 'ارسال', placeholder: ' ', outline: true, ignoreValue: true, atClick: this.sendBasket, loading: this.entityLoading, col: 'col-md-2 col-12' }
  230. ]
  231. },
  232. mounted() {
  233. this.mounted = true
  234. },
  235. methods: {
  236. showUserPage () {
  237. const routeData = this.$router.resolve({ name: 'Admin.User.Show', params: { id: this.basket.owner } })
  238. window.open(routeData.href, '_blank')
  239. },
  240. sendBasket () {
  241. this.entityLoading = true
  242. APIGateway.basket.send(this.basket.id)
  243. .finally(() => {
  244. this.entityLoading = false
  245. this.reloadData()
  246. })
  247. },
  248. afterLoadInputData (data) {
  249. this.entityLoading = false
  250. this.basket = new Basket(data)
  251. if (this.basket.status === 'SENT' || this.basket.status === 'CANCELED' || this.basket.status === 'CLOSED') {
  252. FormBuilderAssist.setAttributeByName(this.inputs, 'btnSent', 'type', 'hidden')
  253. }
  254. FormBuilderAssist.setAttributeByName(this.inputs, 'overall_order_price', 'value', parseInt(data.overall_order_price).toLocaleString('fa'))
  255. },
  256. reloadData (data) {
  257. if (!this.$refs.entityShow) {
  258. return
  259. }
  260. this.$refs.entityShow.getData()
  261. }
  262. }
  263. }
  264. </script>
  265. <style scoped lang="scss">
  266. .AdminDiscountShow {
  267. .title {
  268. font-style: normal;
  269. font-weight: 700;
  270. font-size: 24px;
  271. line-height: 140%;
  272. color: #424242;
  273. margin-bottom: 27px;
  274. display: flex;
  275. flex-flow: row;
  276. position: relative;
  277. .static-title {
  278. }
  279. .dynamic-title {
  280. }
  281. .back-action {
  282. position: absolute;
  283. right: 0;
  284. top: 0;
  285. }
  286. }
  287. .basket-form-header {
  288. background: #FCF9F4;
  289. border: 1px solid #DFE1EC;
  290. margin: -16px -16px 0 -16px;
  291. padding: 16px 40px;
  292. .q-icon {
  293. color: #AAA095;
  294. }
  295. }
  296. :deep(.form) {
  297. padding: 24px;
  298. }
  299. }
  300. </style>