cm-freight-popup.vue 12 KB

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