index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <view>
  3. <u-modal :show="showModal" ref="uModal" :asyncClose="false" showCancelButton @cancel="closeDialog"
  4. cancelColor="#909399" :confirmText="'确定'" confirmColor="#2979ff" @confirm="confirm" @close="closeDialog"
  5. :closeOnClickOverlay="false">
  6. <view class="title_wrap">
  7. <view class="title">
  8. {{ title }}
  9. </view>
  10. <view class="modal_wrap">
  11. <text @click="handleBrandClick" class="item"
  12. :class="info.dictLabel ? 'brand' : 'brand placeholder'">{{ info.dictLabel || '品牌' }}</text>
  13. <text class="divider">|</text>
  14. <u--input placeholder="型号" class="item" border="none" v-model="info.model" clearable></u--input>
  15. <text class="divider">|</text>
  16. <u--input class="code-input item" placeholder="编码" border="none" v-model="info.code"
  17. clearable></u--input>
  18. </view>
  19. </view>
  20. <view class="img_wrap">
  21. <imgs-row-scroll v-if="info.imgsUrl.length > 0" :isShowDeleteIcon="true"
  22. @deleteImgInfo="getDeleteImgInfo" imgMode="aspectFill" :totalWidth="400" :images="info.imgsUrl"
  23. :previewEnabled="true" :imageWidth="150" :imageHeight="150"></imgs-row-scroll>
  24. <u-upload @afterRead="afterRead" name="3" multiple :maxCount="10"></u-upload>
  25. </view>
  26. <view class="price_wrap">
  27. <u--input v-if="editOrAdd === 'edit'" type="number" class="price" placeholder="价格" border="bottom" v-model="info.price"
  28. clearable></u--input>
  29. <u--input v-if="editOrAdd === 'edit'" placeholder="备注" border="bottom" v-model="info.remark"
  30. clearable></u--input>
  31. </view>
  32. <qiun-data-charts v-if="isShowChart" type="column" :chartData="chartData" canvasId="priceChart" :opts="opts" :ontouch="true"
  33. width="700rpx" height="600rpx" backgroundColor="#fff" />
  34. <view v-if="isShowHistory" class="history_wrap">
  35. <view class="title">
  36. {{ type === 1 ? '询价历史' : '核价历史' }}
  37. </view>
  38. <u-cell v-for="(item, index) in historyList" :key="index" :title="(index+1)+'. ¥'+item.price" :value="'备注:'+ (item.remark || '无') "></u-cell>
  39. <u-empty v-if="historyList.length === 0"></u-empty>
  40. </view>
  41. </u-modal>
  42. <brandList ref="brandListRef" @selectedBrand="handleSelectedBrand"></brandList>
  43. </view>
  44. </template>
  45. <script>
  46. import imgsRowScroll from '@/components/imgs-row-scroll/index.vue'
  47. import brandList from '@/components/brand-list/index.vue'
  48. export default {
  49. name: 'AddInquiryDialog',
  50. components: {
  51. imgsRowScroll,
  52. brandList
  53. },
  54. props: {
  55. clueId: {
  56. type: String,
  57. default: ''
  58. },
  59. show: {
  60. type: Boolean,
  61. default: false
  62. },
  63. editOrAdd: {
  64. type: String,
  65. default: ''// edit 编辑(有价格), editForm 编辑询价单(无价格), add 新增询价单, receptFormAdd 新增接收询价单 线索页面:第一次点击是新增(不需要回显),status传1,第二次点击是无价格编辑status传1;接单中心:第一次点击是新增(需要回显)status传1,第二次点击是无价格编辑status传1;只有edit是有价格编辑status传2
  66. },
  67. editInfo: {
  68. type: Object,
  69. default: () => { }
  70. },
  71. type: {
  72. type: Number,
  73. default: 1
  74. },
  75. isClue: {
  76. type: Boolean,
  77. default: false
  78. },
  79. title: {
  80. type: String,
  81. default: ''
  82. },
  83. isShowChart: {
  84. type: Boolean,
  85. default: false
  86. },
  87. isShowHistory: {
  88. type: Boolean,
  89. default: false
  90. }
  91. },
  92. emits: ['submitSuccess'],
  93. inject: {
  94. refreshData: {
  95. default: null
  96. }
  97. },
  98. data() {
  99. return {
  100. showModal: false,
  101. info: {
  102. model: '',
  103. code: '',
  104. id: '',
  105. price: '',
  106. dictLabel: '',
  107. dictValue: '',
  108. imgsUrl: [],
  109. remark: ''
  110. },
  111. historyList: [],
  112. rules: {
  113. brand: [
  114. { required: true, message: '请输入品牌', trigger: 'blur' }
  115. ]
  116. },
  117. opts: {
  118. color: [this.getRandomColor()],
  119. padding: [15, 15, 0, 5],
  120. touchMoveLimit: 24,
  121. enableScroll: true,
  122. legend: {},
  123. xAxis: {
  124. disableGrid: true,
  125. scrollShow: true,
  126. itemCount: 4
  127. },
  128. yAxis: {
  129. data: [
  130. {
  131. min: 0
  132. }
  133. ]
  134. },
  135. extra: {
  136. column: {
  137. type: "group",
  138. width: 30,
  139. activeBgColor: "#000000",
  140. activeBgOpacity: 0.08,
  141. seriesGap: 5,
  142. barBorderRadius: [6,6,6,6]
  143. }
  144. }
  145. },
  146. chartData:{}
  147. }
  148. },
  149. watch: {
  150. show: {
  151. handler(newVal) {
  152. this.showModal = newVal;
  153. },
  154. immediate: true
  155. }
  156. },
  157. methods: {
  158. getRandomColor() {
  159. var letters = '0123456789ABCDEF';
  160. var color = '#';
  161. for (var i = 0; i < 6; i++) {
  162. color += letters[Math.floor(Math.random() * 16)];
  163. }
  164. return color;
  165. },
  166. // 编辑回显
  167. initData() {
  168. this.$nextTick(() => {
  169. this.info = JSON.parse(JSON.stringify(this.editInfo))
  170. if(this.isShowChart){
  171. this.chartData = {
  172. categories: this.info.priceChart.map((item, index) => item.userName),
  173. series: [
  174. {
  175. name: "价格",
  176. data: this.info.priceChart.map(item => item.price)
  177. }
  178. ]
  179. };
  180. }
  181. if(this.isShowHistory){
  182. this.historyList = JSON.parse(this.info.myPriceHistory) || []
  183. }
  184. this.showModal = true;
  185. })
  186. },
  187. // 获取删除图片信息
  188. getDeleteImgInfo(info) {
  189. this.info.imgsUrl = info.newImages
  190. },
  191. handleBrandClick() {
  192. this.$refs.brandListRef.showBrandList();
  193. },
  194. handleSelectedBrand(info) {
  195. this.info.dictLabel = info.dictLabel
  196. this.info.dictValue = info.dictValue
  197. },
  198. // 上传图片
  199. afterRead(info) {
  200. info.file.forEach(item => {
  201. uni.$u.api.uploadFile(item.url).then((res) => {
  202. this.info.imgsUrl.push(res.data.url);
  203. uni.$u.toast("文件上传成功");
  204. }).catch(() => {
  205. uni.$u.toast("上传文件失败");
  206. })
  207. })
  208. },
  209. // 确认添加
  210. confirm() {
  211. if (!this.info.dictLabel || !this.info.dictValue) {
  212. uni.showToast({
  213. title: '请选择品牌',
  214. icon: 'none'
  215. })
  216. return
  217. }
  218. if (!this.info.model) {
  219. uni.showToast({
  220. title: '请输入型号',
  221. icon: 'none'
  222. })
  223. return
  224. }
  225. if (!this.info.code) {
  226. uni.showToast({
  227. title: '请输入编码',
  228. icon: 'none'
  229. })
  230. return
  231. }
  232. if (this.info.imgsUrl.length == 0) {
  233. uni.showToast({
  234. title: '请上传图片',
  235. icon: 'none'
  236. })
  237. return
  238. }
  239. if (this.editOrAdd === 'edit' && !this.info.price) {
  240. uni.showToast({
  241. title: '请输入价格',
  242. icon: 'none'
  243. })
  244. return
  245. }
  246. const data = {
  247. clueId: this.clueId,
  248. dictValue: this.info.dictValue,
  249. dictLabel: this.info.dictLabel,
  250. model: this.info.model,
  251. code: this.info.code,
  252. id: (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm') ? this.info.id : '',
  253. price: this.editOrAdd === 'edit' ? this.info.price : '',
  254. imgsUrl: this.info.imgsUrl,
  255. status: this.editOrAdd === 'edit' ? '2' : '1',
  256. type: this.type,
  257. remark: this.info.remark
  258. }
  259. uni.$u.api.addInquiry(data).then(res => {
  260. uni.$u.toast('保存成功')
  261. this.closeDialog()
  262. this.$emit('submitSuccess')
  263. if (this.isClue && this.refreshData) this.refreshData.resetData(); //线索公海页面需要刷新列表
  264. }).catch((err) => {
  265. uni.$u.toast(err)
  266. })
  267. },
  268. showDialog() {
  269. if (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm' || this.editOrAdd === 'receptFormAdd') {
  270. this.initData();
  271. } else if (this.editOrAdd === 'add') {
  272. this.clearForm()
  273. this.showModal = true;
  274. }
  275. },
  276. clearForm() {
  277. this.info = {
  278. dictLabel: '',
  279. dictValue: '',
  280. model: '',
  281. code: '',
  282. id: '',
  283. price: '',
  284. imgsUrl: []
  285. }
  286. },
  287. closeDialog() {
  288. this.showModal = false;
  289. },
  290. }
  291. };
  292. </script>
  293. <style lang="scss" scoped>
  294. @import './index.scss'
  295. </style>