cartAddress.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <template>
  2. <div class="cart-address">
  3. <div class="cart-address__title">
  4. <q-icon name="place" />
  5. آدرس:
  6. </div>
  7. <div v-if="mounted"
  8. class="cart-address__info">
  9. <div class="cart-address__selected-address">
  10. <q-radio v-model="addressRadio"
  11. :val="1"
  12. :label="basket.getFullAddressString()" />
  13. </div>
  14. <div class="cart-address__edit-btn">
  15. <q-btn color="primary"
  16. outline
  17. @click="openDialog">
  18. <q-icon name="edit" />
  19. ویرایش
  20. </q-btn>
  21. </div>
  22. </div>
  23. <q-dialog v-if="mounted"
  24. v-model="dialog">
  25. <q-card class="cart-address__dialog-cart">
  26. <q-card-section class="cart-address__dialog-cart-title-section flex justify-between">
  27. <div>
  28. ویرایش آدرس
  29. </div>
  30. <q-btn v-close-popup
  31. icon="close"
  32. flat
  33. round
  34. dense />
  35. </q-card-section>
  36. <q-separator />
  37. <q-card-section class="cart-address__dialog-cart-form-section">
  38. <form-builder v-model:value="addressInputs"
  39. :loading="setAddressLoading" />
  40. <div class="flex justify-end q-mt-lg">
  41. <q-btn :loading="setAddressLoading"
  42. color="primary"
  43. @click="setAddress">
  44. ویرایش و ثبت
  45. </q-btn>
  46. </div>
  47. </q-card-section>
  48. </q-card>
  49. </q-dialog>
  50. </div>
  51. </template>
  52. <script>
  53. import { Basket } from 'src/models/Basket.js'
  54. import { APIGateway } from 'src/api/APIGateway.js'
  55. import { FormBuilder, FormBuilderAssist } from 'quasar-form-builder'
  56. import { Provinces, Cities, getCitiesOfProvince } from 'src/assets/js/IranianCities.js'
  57. export default {
  58. name: 'CartAddress',
  59. components: { FormBuilder },
  60. props: {
  61. basket: {
  62. type: Basket,
  63. default: new Basket()
  64. }
  65. },
  66. emits: ['set-address'],
  67. data () {
  68. return {
  69. addressRadio: 1,
  70. mounted: false,
  71. dialog: false,
  72. setAddressLoading: false,
  73. addressInputs: [
  74. {
  75. type: 'input',
  76. name: 'province',
  77. options: Provinces,
  78. optionLabel: 'name',
  79. optionValue: 'name',
  80. createNewValue: true,
  81. newValueMode: 'add-unique',
  82. responseKey: 'province',
  83. label: 'استان',
  84. placeholder: ' ',
  85. col: 'col-md-4 col-12'
  86. },
  87. {
  88. type: 'input',
  89. name: 'city',
  90. options: Cities,
  91. optionLabel: 'name',
  92. optionValue: 'name',
  93. createNewValue: true,
  94. newValueMode: 'add-unique',
  95. responseKey: 'city',
  96. label: 'شهر',
  97. placeholder: ' ',
  98. col: 'col-md-4 col-12'
  99. },
  100. { type: 'input', name: 'postal_code', responseKey: 'postal_code', label: 'کد پستی', placeholder: ' ', col: 'col-md-4 col-12' },
  101. { type: 'input', name: 'address', responseKey: 'address', label: 'آدرس پستی', placeholder: ' ', col: 'col-12' }
  102. ]
  103. }
  104. },
  105. computed: {
  106. addressString () {
  107. return 'file_download'
  108. },
  109. selectedProvince () {
  110. return FormBuilderAssist.getInputsByName(this.addressInputs, 'province').value
  111. }
  112. },
  113. watch: {
  114. selectedProvince (newValue) {
  115. if (!newValue) {
  116. // FormBuilderAssist.setAttributeByName(this.addressInputs, 'city', 'value', null)
  117. FormBuilderAssist.setAttributeByName(this.addressInputs, 'city', 'disable', true)
  118. return
  119. }
  120. const filteredCities = getCitiesOfProvince(this.selectedBirthProvince)
  121. // FormBuilderAssist.setAttributeByName(this.addressInputs, 'city', 'value', null)
  122. FormBuilderAssist.setAttributeByName(this.addressInputs, 'city', 'options', filteredCities)
  123. FormBuilderAssist.setAttributeByName(this.addressInputs, 'city', 'disable', false)
  124. }
  125. },
  126. mounted() {
  127. this.setFormData()
  128. this.mounted = true
  129. },
  130. methods: {
  131. openDialog () {
  132. this.dialog = true
  133. },
  134. closeDialog () {
  135. this.dialog = false
  136. },
  137. setAddress () {
  138. this.setAddressLoading = true
  139. APIGateway.basket.setAddress(this.basket.id, this.getFormData())
  140. .finally(() => {
  141. this.setAddressLoading = false
  142. this.closeDialog()
  143. this.$emit('set-address')
  144. })
  145. },
  146. getFormData () {
  147. return FormBuilderAssist.getFormData(this.addressInputs)
  148. },
  149. setFormData () {
  150. FormBuilderAssist.setInputValues(this.basket, this.addressInputs)
  151. }
  152. }
  153. }
  154. </script>
  155. <style scoped lang="scss">
  156. .cart-address {
  157. border-radius: 8px;
  158. background: #F9F9FB;
  159. border: 1px solid #DFE1EC;
  160. padding: 20px 30px 46px 38px;
  161. .cart-address__title {
  162. color: #727272;
  163. font-size: 16px;
  164. margin-bottom: 22px;
  165. }
  166. .cart-address__info {
  167. display: flex;
  168. flex-flow: row;
  169. justify-content: space-between;
  170. .cart-address__selected-address {
  171. }
  172. .cart-address__edit-btn {
  173. }
  174. @media screen and (max-width: 800px) {
  175. & {
  176. flex-flow: column;
  177. }
  178. }
  179. }
  180. :global(.cart-address__dialog-cart) {
  181. width: 700px;
  182. max-width: 90vw;
  183. }
  184. }
  185. </style>