app-form-send.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view>
  3. <appFormRadioBtn title="配送方式" :currenSelect.sync="formData.sendType" />
  4. <tui-list-cell
  5. class="line-cell"
  6. :hover="false"
  7. :arrow="true"
  8. v-if="formData.sendType == 3"
  9. >
  10. <view class="tui-title">快递</view>
  11. <picker
  12. mode="selector"
  13. :value="sendSideIndex"
  14. :range="deliveryList"
  15. :range-key="'name'"
  16. @change="selectSideEvent"
  17. class="tui-input"
  18. >
  19. <view v-if="formData.sendSide" class="tui-input">
  20. {{ getCurSideName }}
  21. </view>
  22. <view v-else class="tui-placeholder">请选择快递公司</view>
  23. <input name="sendSide" hidden />
  24. </picker>
  25. <!-- <view v-if="formData.sendSide" class="tui-input">
  26. {{ getCurSideName }}
  27. </view>
  28. <view v-else class="tui-placeholder" @click="">请选择快递公司</view>
  29. <input name="sendSide" hidden /> -->
  30. </tui-list-cell>
  31. <!-- 门店送或快递送需要设置地址 -->
  32. <appAddressGroup
  33. v-if="formData.sendType == 2 || formData.sendType == 3"
  34. cityTitle="配送城市"
  35. @selectAdress="selectAdress"
  36. ></appAddressGroup>
  37. <appSendTime
  38. :sendDate.sync="formData.sendDate"
  39. :sendTime.sync="formData.sendTime"
  40. ></appSendTime>
  41. <tui-list-cell class="line-cell" :hover="false" :arrow="false">
  42. <view class="tui-title">运费</view>
  43. <view v-if="formData.sendCost" class="tui-input">
  44. {{ formData.sendCost }}
  45. </view>
  46. <view v-else class="tui-placeholder">留空表示免运费</view>
  47. <input name="sendCost" hidden />
  48. </tui-list-cell>
  49. </view>
  50. </template>
  51. <script>
  52. import TuiListCell from "@/components/plugin/list-cell";
  53. import { freight } from "@/api/order";
  54. import appFormRadioBtn from "@/components/app-formRadio-btn";
  55. import appAddressGroup from "@/components/app-address-group";
  56. import appSendTime from "@/components/app-send-time";
  57. export default {
  58. components: {
  59. TuiListCell,
  60. appFormRadioBtn,
  61. appAddressGroup,
  62. appSendTime
  63. },
  64. props: {
  65. form: {
  66. type: Object
  67. }
  68. },
  69. data() {
  70. return {
  71. formData: {
  72. sendCost: "",
  73. receiveProvince: "",
  74. receiveCity: "",
  75. receiveFloor: "",
  76. receiveAddress: "",
  77. receiveLong: "",
  78. receiveLat: "",
  79. sendSide: "2",
  80. sendType: "3", //1自取 2本店送 3快递送
  81. sendDate: "",
  82. sendTime: ""
  83. },
  84. deliveryList: [
  85. {
  86. name: "达达配送",
  87. value: "2"
  88. },
  89. {
  90. name: "顺丰同城",
  91. value: "3"
  92. },
  93. {
  94. name: "闪送",
  95. value: "4"
  96. },
  97. {
  98. name: "美团",
  99. value: "5"
  100. }
  101. ]
  102. };
  103. },
  104. created() {
  105. this.initData();
  106. },
  107. computed: {
  108. getCurSideName() {
  109. let name = "";
  110. if (this.formData.sendSide) {
  111. const curItem = this.deliveryList.find(ele => {
  112. return ele.value == this.formData.sendSide;
  113. });
  114. if (curItem) {
  115. name = curItem.name;
  116. }
  117. }
  118. return name;
  119. }
  120. },
  121. methods: {
  122. initData() {
  123. for (const key in this.formData) {
  124. if (Object.hasOwnProperty.call(this.formData, key)) {
  125. const element = this.form[key];
  126. this.formData[key] = element;
  127. }
  128. }
  129. },
  130. selectAdress(info) {
  131. this.formData.receiveProvince = info.province;
  132. this.formData.receiveCity = info.city;
  133. this.formData.receiveFloor = info.floor;
  134. this.formData.receiveAddress = info.address;
  135. this.formData.receiveLong = info.longitude;
  136. this.formData.receiveLat = info.latitude;
  137. this.$nextTick(() => {
  138. let params = {
  139. sendSide: this.formData.sendSide,
  140. receiveLong: info.longitude,
  141. receiveLat: info.latitude
  142. };
  143. this.freightCount(params);
  144. });
  145. },
  146. // 计算运费
  147. freightCount(option) {
  148. freight(option).then(res => {
  149. this.formData.sendCost = res.data.sndCost;
  150. });
  151. },
  152. selectSideEvent(event) {
  153. const {
  154. detail: { value }
  155. } = event;
  156. console.log(2222, value, this.deliveryList[value].value);
  157. this.sendSideIndex = value;
  158. this.formData.sendSide = this.deliveryList[value].value;
  159. }
  160. },
  161. watch: {
  162. formData: {
  163. handler(val) {
  164. if (val) {
  165. let info = { ...this.form, ...val };
  166. if (this.formData.sendTime) {
  167. info.sendTime = `${this.formData.sendDate} ${this.formData.sendTime}`;
  168. }
  169. console.log(2222, info);
  170. this.$emit("update:form", info);
  171. }
  172. },
  173. deep: true
  174. },
  175. ["formData.sendType"](val) {
  176. if (val != "3") {
  177. //不是快递配送不包含运费
  178. this.formData.sendCost = "";
  179. }
  180. }
  181. }
  182. };
  183. </script>
  184. <style></style>