cm-freight-popup.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. <template name="freight">
  2. <!-- 运费信息 -->
  3. <view>
  4. <view class="goods-pros-m">
  5. <template v-if="supplier.postageFlag === 0">
  6. <view class="freight-main">
  7. <view class="freight-left">运费:</view>
  8. <view class="freight-right"><view class="freight-text">包邮</view></view>
  9. </view>
  10. </template>
  11. <template v-if="supplier.postageFlag === 1 && supplier.designatedFlag === 1">
  12. <view class="freight-main">
  13. <view class="freight-left">运费:</view>
  14. <view class="freight-right">
  15. <view class="freight-text">¥{{ handleTotalPostage | NumFormat }}</view>
  16. <view class="select" v-if="supplier.coldChain > 0" @click="handlePupShow">
  17. <text class="iconfont icon-xiayibu"></text>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <template
  23. v-if="
  24. (supplier.postageFlag === 1 && supplier.designatedFlag === 2) ||
  25. (supplier.postageFlag === 1 && supplier.designatedFlag === 3)
  26. "
  27. >
  28. <view class="freight-main">
  29. <view class="freight-left">运费:</view>
  30. <view class="freight-right">
  31. <template v-if="handlePostageFlag === 1">
  32. <view class="freight-text">¥{{ handleTotalPostage | NumFormat }}</view>
  33. </template>
  34. <template v-if="handlePostageFlag === 2">
  35. <view v-if="handleSupplier.isColdChina" class="freight-text"
  36. >¥{{ handleTotalPostage | NumFormat }}</view
  37. >
  38. <view v-else class="freight-text">到付</view>
  39. </template>
  40. <view class="select" v-if="supplier.coldChain > 0" @click="handlePupShow">
  41. <text class="iconfont icon-xiayibu"></text>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <template v-if="supplier.postageFlag === 2">
  47. <view class="freight-main">
  48. <view class="freight-left">运费:</view>
  49. <view class="freight-right"> <view class="freight-text">到付</view></view>
  50. </view>
  51. </template>
  52. <tui-bottom-popup :radius="true" :show="popupShow" @close="hidePopup">
  53. <view class="freight-title">运费设置</view>
  54. <view class="freight-content">
  55. <!-- <radio-group @change="radioChange" v-if="handleDesignatedFlag != 1">
  56. <label v-for="(item, index) in radioItems" :key="index">
  57. <radio
  58. style="transform:scale(0.7)"
  59. color="#FF5B00"
  60. :id="item.value"
  61. :value="item.value"
  62. :checked="item.checked"
  63. />
  64. <label :for="item.value" class="label">
  65. <text>{{ item.name }}</text>
  66. </label>
  67. </label>
  68. </radio-group> -->
  69. <template v-if="handlePostageFlag === 1">
  70. <view class="freight-form">
  71. <view class="freight-form-item" v-if="handleSupplier.coldChain > 0">
  72. <view class="label">冷链运输费</view>
  73. <view class="texts">
  74. <text>¥{{ handleSupplier.coldChain | NumFormat }}</text>
  75. <text
  76. class="iconfont"
  77. :class="[isColdChina ? 'icon-yixuanze' : 'icon-weixuanze']"
  78. @click.stop="handleChangeColdChina"
  79. >
  80. </text>
  81. </view>
  82. </view>
  83. <view class="freight-form-item" v-if="handleDesignatedFlag != 1">
  84. <view class="label">其他运费 </view>
  85. <view class="texts red">¥{{ handleSupplier.postage | NumFormat }} </view>
  86. </view>
  87. <view class="freight-form-item">
  88. <view class="label">总运费 </view>
  89. <view class="texts red">¥{{ handleTotalPostage | NumFormat }} </view>
  90. </view>
  91. </view>
  92. </template>
  93. <template v-if="handlePostageFlag === 2">
  94. <view class="freight-form">
  95. <view class="freight-form-item" v-if="handleSupplier.coldChain > 0">
  96. <view class="label">冷链运输费</view>
  97. <view class="texts">
  98. <text>¥{{ handleSupplier.coldChain | NumFormat }}</text>
  99. <text
  100. class="iconfont"
  101. :class="[isColdChina ? 'icon-yixuanze' : 'icon-weixuanze']"
  102. @click.stop="handleChangeColdChina"
  103. >
  104. </text>
  105. </view>
  106. </view>
  107. <view class="freight-form-item">
  108. <view class="label">其他运费 </view><view class="texts red">到付</view>
  109. </view>
  110. <view class="freight-form-item">
  111. <view class="label">总运费</view>
  112. <view class="texts red" v-if="handleSupplier.isColdChina"
  113. >¥{{ handleSupplier.coldChain | NumFormat }}</view
  114. >
  115. <view class="texts red" v-else>到付</view>
  116. </view>
  117. </view>
  118. </template>
  119. <view class="freight-btn" @click="popupShow = false"> 确定 </view>
  120. </view>
  121. </tui-bottom-popup>
  122. </view>
  123. </view>
  124. </template>
  125. <script>
  126. export default {
  127. name: 'freight',
  128. props: {
  129. supplier: {
  130. type: Object
  131. },
  132. index: {
  133. type: Number
  134. }
  135. },
  136. data() {
  137. return {
  138. popupShow: false,
  139. isColdChina: false,
  140. handlePostage: 0,
  141. handlePostageFlag: 1,
  142. handleDesignatedFlag: 0,
  143. radioItems: [
  144. {
  145. name: '不包邮',
  146. value: 1,
  147. checked: true
  148. }
  149. // {
  150. // name: '到付',
  151. // value: 2
  152. // }
  153. ],
  154. handleSupplier: {}
  155. }
  156. },
  157. filters: {
  158. NumFormat(value) {
  159. //处理金额
  160. return Number(value).toFixed(2)
  161. }
  162. },
  163. created() {
  164. this.infoSupplier(this.supplier)
  165. },
  166. computed: {
  167. // 计算总运费
  168. handleTotalPostage() {
  169. if (this.handleSupplier.isColdChina) {
  170. return (this.handleSupplier.postage * 100 + this.handleSupplier.coldChain * 100) / 100
  171. } else {
  172. return this.handleSupplier.postage
  173. }
  174. }
  175. },
  176. watch: {
  177. supplier: {
  178. handler: function(el) {
  179. //监听对象的变换使用 function,箭头函数容易出现this指向不正确
  180. this.supplier = el
  181. },
  182. deep: true
  183. }
  184. },
  185. methods: {
  186. // 初始化
  187. infoSupplier(data) {
  188. this.handleSupplier = data
  189. this.isColdChina = data.isColdChina
  190. this.handlePostage = data.postage
  191. this.handlePostageFlag = data.handlePostageFlag
  192. this.handleDesignatedFlag = data.designatedFlag
  193. },
  194. // 勾选冷链费
  195. handleChangeColdChina() {
  196. this.isColdChina = !this.isColdChina
  197. this.handleSupplier.isColdChina = this.isColdChina
  198. if (this.isColdChina) {
  199. this.handleSupplier.totalPrice = Number(
  200. (this.handleSupplier.totalPrice * 100 + this.handleSupplier.coldChain * 100) / 100
  201. )
  202. this.$emit('changeColdChina', this.handleSupplier, this.index)
  203. } else {
  204. this.handleSupplier.totalPrice = Number(
  205. this.repiceNumSub(this.handleSupplier.totalPrice, this.handleSupplier.coldChain)
  206. )
  207. this.$emit('changeColdChina', this.handleSupplier, this.index)
  208. }
  209. },
  210. // 切换运费类型 1 不包邮 2 到付
  211. radioChange($event) {
  212. // const postage = this.isColdChina ? ( this.handleSupplier.postage + this.handleSupplier.coldChain ) : this.handleSupplier.postage
  213. this.handlePostageFlag = this.handleSupplier.handlePostageFlag = $event.detail.value * 1
  214. console.log('handlePostageFlag', this.handlePostageFlag)
  215. if (this.handlePostageFlag === 1) {
  216. this.handleSupplier.postage = this.handlePostage
  217. this.handleSupplier.totalPrice = Number(
  218. (this.handleSupplier.totalPrice * 100 + this.handleSupplier.postage * 100) / 100
  219. )
  220. this.$emit('changePostage', this.handleSupplier, this.index)
  221. } else {
  222. this.handleSupplier.totalPrice = Number(
  223. this.repiceNumSub(this.handleSupplier.totalPrice, this.handleSupplier.postage)
  224. )
  225. this.handleSupplier.postage = 0
  226. this.$emit('changePostage', this.handleSupplier, this.index)
  227. }
  228. },
  229. repiceNumSub(arg1, arg2) {
  230. //减法精确,arg2:被减数,arg1:减数
  231. var r1, r2, m, n
  232. try {
  233. r1 = arg1.toString().split('.')[1].length
  234. } catch (e) {
  235. r1 = 0
  236. }
  237. try {
  238. r2 = arg2.toString().split('.')[1].length
  239. } catch (e) {
  240. r2 = 0
  241. }
  242. m = Math.pow(10, Math.max(r1, r2))
  243. // last modify by deeka
  244. // 动态控制精度长度
  245. n = r1 >= r2 ? r1 : r2
  246. return ((arg1 * m - arg2 * m) / m).toFixed(n)
  247. },
  248. handlePupShow() {
  249. this.popupShow = true
  250. },
  251. hidePopup() {
  252. this.popupShow = false
  253. }
  254. }
  255. }
  256. </script>
  257. <style lang="scss">
  258. .goods-pros-m {
  259. width: 100%;
  260. box-sizing: border-box;
  261. padding: 10rpx 0;
  262. .freight-main {
  263. width: 100%;
  264. height: 78rpx;
  265. line-height: 78rpx;
  266. font-size: $font-size-28;
  267. color: $text-color;
  268. background: #ffffff;
  269. float: left;
  270. .freight-left {
  271. float: left;
  272. font-weight: bold;
  273. }
  274. .freight-right {
  275. float: right;
  276. color: #333333;
  277. position: relative;
  278. .freight-text {
  279. float: left;
  280. }
  281. .select {
  282. float: right;
  283. height: 78rpx;
  284. padding: 0 20rpx;
  285. line-height: 78rpx;
  286. color: #333333;
  287. font-weight: normal;
  288. position: relative;
  289. .select-text {
  290. display: inline-block;
  291. float: left;
  292. margin-right: 30rpx;
  293. }
  294. .iconfont {
  295. width: 60rpx;
  296. height: 78rpx;
  297. line-height: 78rpx;
  298. text-align: right;
  299. position: absolute;
  300. right: 0;
  301. top: 0;
  302. font-size: $font-size-30;
  303. color: #b2b2b2;
  304. }
  305. }
  306. }
  307. }
  308. .freight-bean {
  309. width: 100%;
  310. height: 58rpx;
  311. line-height: 58rpx;
  312. float: left;
  313. .bean-le {
  314. float: left;
  315. color: #666666;
  316. font-size: $font-size-26;
  317. font-weight: normal;
  318. }
  319. .bean-ri {
  320. float: right;
  321. display: flex;
  322. align-items: center;
  323. .checkbox-box {
  324. display: flex;
  325. width: 60rpx;
  326. float: left;
  327. height: 100%;
  328. font-size: $font-size-26;
  329. margin-top: 8rpx;
  330. .checkbox {
  331. width: 40rpx;
  332. text-align: right;
  333. box-sizing: border-box;
  334. text-align: center;
  335. text-decoration: none;
  336. border-radius: 0;
  337. -webkit-tap-highlight-color: transparent;
  338. overflow: hidden;
  339. color: $color-system;
  340. }
  341. }
  342. }
  343. }
  344. }
  345. .freight-title {
  346. color: #333333;
  347. font-size: 32rpx;
  348. text-align: center;
  349. margin: 40rpx 0;
  350. }
  351. .freight-content {
  352. box-sizing: border-box;
  353. padding: 0 24rpx;
  354. font-weight: normal;
  355. radio {
  356. margin-right: 8rpx;
  357. }
  358. .label {
  359. color: #666666;
  360. font-size: 28rpx;
  361. margin-right: 102rpx;
  362. }
  363. .freight-btn {
  364. height: 90rpx;
  365. background: $btn-confirm;
  366. border-radius: 45rpx;
  367. display: flex;
  368. justify-content: center;
  369. align-items: center;
  370. color: #ffffff;
  371. width: 100%;
  372. margin: 100rpx 0 0 0;
  373. }
  374. }
  375. .freight-form {
  376. margin-top: 50rpx;
  377. width: 100%;
  378. .freight-form-item {
  379. width: 100%;
  380. height: 48rpx;
  381. line-height: 48rpx;
  382. margin-bottom: 24rpx;
  383. color: #666666;
  384. font-size: 28rpx;
  385. .label {
  386. width: 50%;
  387. float: left;
  388. margin-right: 0;
  389. }
  390. .texts {
  391. width: 50%;
  392. float: right;
  393. text-align: right;
  394. &.red {
  395. color: #f94b4b;
  396. }
  397. .iconfont {
  398. margin-left: 20rpx;
  399. color: $color-system;
  400. }
  401. }
  402. }
  403. }
  404. .freight-pay {
  405. position: absolute;
  406. right: -60%;
  407. transform: scale(0.7);
  408. }
  409. </style>