cm-freight-popup.vue 10 KB

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