cm-freight-popup.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. console.log('2222222222', this.handleSupplier.totalPrice)
  227. this.$emit('changePostage', this.handleSupplier, this.index)
  228. }
  229. },
  230. repiceNumSub(arg1, arg2) {
  231. //减法精确,arg2:被减数,arg1:减数
  232. var r1, r2, m, n
  233. try {
  234. r1 = arg1.toString().split('.')[1].length
  235. } catch (e) {
  236. r1 = 0
  237. }
  238. try {
  239. r2 = arg2.toString().split('.')[1].length
  240. } catch (e) {
  241. r2 = 0
  242. }
  243. m = Math.pow(10, Math.max(r1, r2))
  244. // last modify by deeka
  245. // 动态控制精度长度
  246. n = r1 >= r2 ? r1 : r2
  247. return ((arg1 * m - arg2 * m) / m).toFixed(n)
  248. },
  249. handlePupShow() {
  250. this.popupShow = true
  251. },
  252. hidePopup() {
  253. this.popupShow = false
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="scss">
  259. .goods-pros-m {
  260. width: 100%;
  261. box-sizing: border-box;
  262. padding: 10rpx 0;
  263. .freight-main {
  264. width: 100%;
  265. height: 78rpx;
  266. line-height: 78rpx;
  267. font-size: $font-size-28;
  268. color: $text-color;
  269. background: #ffffff;
  270. float: left;
  271. .freight-left {
  272. float: left;
  273. font-weight: bold;
  274. }
  275. .freight-right {
  276. float: right;
  277. color: #333333;
  278. position: relative;
  279. .freight-text {
  280. float: left;
  281. }
  282. .select {
  283. float: right;
  284. height: 78rpx;
  285. padding: 0 20rpx;
  286. line-height: 78rpx;
  287. color: #333333;
  288. font-weight: normal;
  289. position: relative;
  290. .select-text {
  291. display: inline-block;
  292. float: left;
  293. margin-right: 30rpx;
  294. }
  295. .iconfont {
  296. width: 60rpx;
  297. height: 78rpx;
  298. line-height: 78rpx;
  299. text-align: right;
  300. position: absolute;
  301. right: 0;
  302. top: 0;
  303. font-size: $font-size-30;
  304. color: #b2b2b2;
  305. }
  306. }
  307. }
  308. }
  309. .freight-bean {
  310. width: 100%;
  311. height: 58rpx;
  312. line-height: 58rpx;
  313. float: left;
  314. .bean-le {
  315. float: left;
  316. color: #666666;
  317. font-size: $font-size-26;
  318. font-weight: normal;
  319. }
  320. .bean-ri {
  321. float: right;
  322. display: flex;
  323. align-items: center;
  324. .checkbox-box {
  325. display: flex;
  326. width: 60rpx;
  327. float: left;
  328. height: 100%;
  329. font-size: $font-size-26;
  330. margin-top: 8rpx;
  331. .checkbox {
  332. width: 40rpx;
  333. text-align: right;
  334. box-sizing: border-box;
  335. text-align: center;
  336. text-decoration: none;
  337. border-radius: 0;
  338. -webkit-tap-highlight-color: transparent;
  339. overflow: hidden;
  340. color: $color-system;
  341. }
  342. }
  343. }
  344. }
  345. }
  346. .freight-title {
  347. color: #333333;
  348. font-size: 32rpx;
  349. text-align: center;
  350. margin: 40rpx 0;
  351. }
  352. .freight-content {
  353. box-sizing: border-box;
  354. padding: 0 24rpx;
  355. font-weight: normal;
  356. radio {
  357. margin-right: 8rpx;
  358. }
  359. .label {
  360. color: #666666;
  361. font-size: 28rpx;
  362. margin-right: 102rpx;
  363. }
  364. .freight-btn {
  365. height: 90rpx;
  366. background: $btn-confirm;
  367. border-radius: 45rpx;
  368. display: flex;
  369. justify-content: center;
  370. align-items: center;
  371. color: #ffffff;
  372. width: 100%;
  373. margin: 100rpx 0 0 0;
  374. }
  375. }
  376. .freight-form {
  377. margin-top: 50rpx;
  378. width: 100%;
  379. .freight-form-item {
  380. width: 100%;
  381. height: 48rpx;
  382. line-height: 48rpx;
  383. margin-bottom: 24rpx;
  384. color: #666666;
  385. font-size: 28rpx;
  386. .label {
  387. width: 50%;
  388. float: left;
  389. margin-right: 0;
  390. }
  391. .texts {
  392. width: 50%;
  393. float: right;
  394. text-align: right;
  395. &.red {
  396. color: #f94b4b;
  397. }
  398. .iconfont {
  399. margin-left: 20rpx;
  400. color: $color-system;
  401. }
  402. }
  403. }
  404. }
  405. .freight-pay {
  406. position: absolute;
  407. right: -60%;
  408. transform: scale(0.7);
  409. }
  410. </style>