inventoryCost.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <view class="content">
  3. <view class="cost-list" v-for="(item,index) in costList">
  4. <view style="display: flex;justify-content: space-between;">
  5. <view class="title">{{item.warehouseName}}</view>
  6. <view class="button" @click="toDetail(item.warehouseName)">详细记录</view>
  7. </view>
  8. <view class="goods-table">
  9. <view class="goods-table-title">
  10. <view class="font">货名</view>
  11. <view class="font">储量(吨)</view>
  12. <view class="font">价值(元)</view>
  13. </view>
  14. <view class="goods-table-content" v-for="(item1,index1) in item.goodList">
  15. <view class="font" :class="item.goodList.length>1&&index1==item.goodList.length-1?'active':''">{{item1.goodsName}}</view>
  16. <view class="font" :class="item.goodList.length>1&&index1==item.goodList.length-1?'active':''">{{item1.storage}}</view>
  17. <view class="font">{{item1.cost}}</view>
  18. </view>
  19. </view>
  20. </view>
  21. <u-modal class="record" v-model="isShowDetailBtn" :title-style="{fontSize: '18px',fontWeight:'500'}"
  22. :content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='导出记录'
  23. showCancelButton='false' @confirm="alertBtn" @cancel="cancelClick">
  24. <view>
  25. <u-radio-group v-model="value">
  26. <u-radio active-color="#22C572" @change="radioChange" v-for="(item, index) in list" :key="index"
  27. :name="item.name" :disabled="item.disabled">
  28. {{item.name}}
  29. </u-radio>
  30. </u-radio-group>
  31. <view class="modal-row">
  32. <view class="">查询日期</view>
  33. <view class="" @click="selectDate">
  34. {{parameter.endDate?parameter.startDate+'-'+parameter.endDate:'请选择查询日期'}}
  35. </view>
  36. </view>
  37. <view class="modal-row">
  38. <view class="">仓库名称</view>
  39. <view>{{parameter.warehouseName}}</view>
  40. </view>
  41. </view>
  42. </u-modal>
  43. <u-calendar v-model="show" :mode="mode" @change="change" range-color='#22C572' btn-type='success'
  44. range-bg-color='rgba(25, 190, 107, 0.13)' active-bg-color='#22C572'></u-calendar>
  45. </view>
  46. </template>
  47. <script>
  48. export default {
  49. data() {
  50. return {
  51. parameter: {
  52. startDate: "",
  53. endDate: '',
  54. warehouseName: ''
  55. },
  56. show: false,
  57. mode: 'range',
  58. list: [{
  59. name: '入库记录',
  60. disabled: false
  61. },
  62. {
  63. name: '出库记录',
  64. disabled: false
  65. }
  66. ],
  67. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  68. value: '入库记录',
  69. costList: [],
  70. isShowDetailBtn: false
  71. }
  72. },
  73. onLoad: function(option) {
  74. this.init()
  75. },
  76. methods: {
  77. selectDate() {
  78. this.show = true
  79. },
  80. change(e) {
  81. this.parameter.startDate = e.startDate
  82. this.parameter.endDate = e.endDate
  83. },
  84. radioChange(e) {
  85. console.log(e);
  86. },
  87. alertBtn() {
  88. let _url = ''
  89. if (this.value == '入库记录') {
  90. _url = '/warehouseBaseInfo/exportphone'
  91. } else {
  92. _url = "/warehouseBaseInfo/exportPhoneOut"
  93. }
  94. uni.showLoading({
  95. title: '正在加载'
  96. })
  97. this.$api.doRequest('post', _url, {
  98. startDate: this.parameter.startDate,
  99. endDate: this.parameter.endDate,
  100. warehouseName: this.parameter.warehouseName
  101. }).then(res => {
  102. uni.hideLoading()
  103. console.log('-----------')
  104. console.log(res.data.data)
  105. uni.downloadFile({
  106. url: res.data.data,
  107. success: function(res) {
  108. var filePath = res.tempFilePath;
  109. uni.openDocument({
  110. filePath: filePath,
  111. showMenu: true,
  112. success: function(res) {
  113. console.log('打开文档成功');
  114. }
  115. });
  116. }
  117. });
  118. })
  119. },
  120. cancelClick() {
  121. this.isShowDetailBtn = false
  122. },
  123. toDetail(warehouseName) {
  124. this.parameter.warehouseName = warehouseName
  125. this.isShowDetailBtn = true
  126. },
  127. init() {
  128. uni.showLoading({
  129. title: '正在加载'
  130. })
  131. this.$api.doRequest('get', '/costManagementInfo/selectCostManagementInfo', {
  132. compId: uni.getStorageSync('pcUserInfo').compId,
  133. warehouseType: 1
  134. }).then(res => {
  135. uni.hideLoading()
  136. const results = this.makeGroupData(res.data.data, function(item) {
  137. return [item.warehouseName];
  138. });
  139. console.log('this.costList')
  140. console.log(this.costList)
  141. let _data = []
  142. for (let i = 0; i < results.length; i++) {
  143. let _obj = {}
  144. _obj.warehouseName = results[i][0].warehouseName
  145. // 大于两条添加合计行
  146. if (results[i].length > 1) {
  147. let _price = 0
  148. for (let k = 0; k < results[i].length; k++) {
  149. _price += results[i][k].storage
  150. }
  151. _price = _price.toFixed(2)
  152. results[i].push({
  153. 'goodsName': '合计',
  154. 'storage': _price
  155. })
  156. }
  157. _obj.goodList = results[i]
  158. _data.push(_obj)
  159. }
  160. console.log(_data)
  161. this.costList = _data
  162. })
  163. },
  164. makeGroupData(array, fn) {
  165. const groups = {};
  166. array.forEach(function(item) {
  167. const group = JSON.stringify(fn(item));
  168. groups[group] = groups[group] || [];
  169. groups[group].push(item);
  170. });
  171. return Object.keys(groups).map(function(group) {
  172. return groups[group];
  173. })
  174. }
  175. }
  176. }
  177. </script>
  178. <style scoped lang="scss">
  179. .active{
  180. font-size: 32rpx;
  181. font-weight: 700;
  182. }
  183. .modal-row {
  184. display: flex;
  185. justify-content: space-between;
  186. padding: 10rpx 60rpx ;
  187. margin-top: 20rpx;
  188. margin-bottom: 20rpx;
  189. }
  190. .u-radio-group {
  191. width: 100%;
  192. display: flex;
  193. justify-content: space-between;
  194. }
  195. .u-radio {
  196. width: 50% !important;
  197. display: flex;
  198. justify-content: center;
  199. }
  200. .record {
  201. background: red;
  202. display: flex;
  203. justify-content: center;
  204. }
  205. .button {
  206. font-size: 24rpx;
  207. padding: 4rpx 20rpx;
  208. border-radius: 15px;
  209. background: #22C572;
  210. color: white;
  211. // margin: 0 10px;
  212. }
  213. .cost-list {
  214. margin: 20rpx;
  215. background: white;
  216. border-radius: 20rpx;
  217. padding: 20rpx;
  218. .title {
  219. font-size: 32rpx;
  220. font-weight: 500;
  221. color: #333333;
  222. }
  223. .goods-table {
  224. margin-top: 22rpx;
  225. }
  226. .goods-table-title {
  227. display: flex;
  228. border-bottom: 1px solid #EEEEEE;
  229. padding-bottom: 16rpx;
  230. // margin-bottom: ;
  231. .font {
  232. font-size: 27rpx;
  233. font-weight: 400;
  234. color: #B2B3BB;
  235. }
  236. .font:nth-of-type(1) {
  237. width: 40%;
  238. }
  239. .font:nth-of-type(2) {
  240. width: 30%;
  241. }
  242. .font:nth-of-type(3) {
  243. width: 30%;
  244. text-align: right;
  245. }
  246. }
  247. .goods-table-content {
  248. display: flex;
  249. margin: 22rpx;
  250. font-size: 28rpx;
  251. font-weight: 400;
  252. color: #333333;
  253. .font:nth-of-type(1) {
  254. width: 40%;
  255. }
  256. .font:nth-of-type(2) {
  257. width: 30%;
  258. }
  259. .font:nth-of-type(3) {
  260. width: 30%;
  261. text-align: right;
  262. }
  263. }
  264. }
  265. </style>